0

When I generate code from StructureDefinitions, it would be obvious to use the class for the resource referenced in base as superclass.

A resource that is based on another resource can change the the type of a property of the base resource (for example from String to List<String> if max="0" is overridden by max="*").

This would break in strongly typed languages because a subclass has to conform to the interface of the super class (can only specialize but not generalize).

What would be the correct strategy to deal with that?

I can use snapshot instead of differential and not extend the class of the base resource.

Should I still extend one of the more general super classes like Element, BackboneElement, Resource, DomainResource?

Are there any flaws in my reasoning?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

1

Resources can't "extend" other resources. If the base resource has a cardinality for an element of 1..1, the derived model can't change the lower cardinality below 1, nor the upper cardinality above 1.

The primary way of "extending" a resource is to make use of the "extension" element which is defined as being 0..* pretty much everywhere in the base resources. So technically when you're creating a profile, you're always constraining - either tightening down core elements or constraining expectations for at least some of the repetitions of the "extension" element.

You can find more information about allowed cardinality changes here

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
  • Great, thanks for clarification. So this means using `base` as super class and generate the subclass from `differential` (and also applying extensions) should be safe? – Günter Zöchbauer Sep 02 '16 at 13:44
  • Well, the whole notion of sub-class is a bit tricky when you talk about profiling. If I slice a repeating item into 5 different sets of constraints, how do you want to make that visible in a sub-class? Is it 5 elements? Is it still one repeating element? Is it two different views on the same collection? We haven't yet fully wrapped our head around how best to represent profiles as classes. – Lloyd McKenzie Sep 02 '16 at 22:14
  • Thanks, that helps. I have yet to wrap my head around what slices are exactly though. Are there any docs that show more examples? Most stuff I found is quite abstract and doesn't go too much into detail. The docs are great for checking facts but quite hard when you try to wrap your head around concepts one is not yet familiar with. Also are there any places where the FHIR community is discussing online? Not all kind of questions are a good fit for SO. – Günter Zöchbauer Sep 05 '16 at 07:12
  • 1
    http://chat.fhir.org is the best place for discussions. Essentially slicing lets you define different sets of constraints on different repetitions or different data type choices. You can look at http://hl7.org/fhir/profiling.html and can look at some of the examples. Beyond that, you can search the web for FHIR video and there are some that tackle profiling and will touch on slicing and how it works. – Lloyd McKenzie Sep 05 '16 at 19:09