FHIR / sushi

SUSHI (aka "SUSHI Unshortens Short Hand Inputs") is a reference implementation command-line interpreter/compiler for FHIR Shorthand (FSH).
Apache License 2.0
145 stars 44 forks source link

Wish: SUSHI allows to define (custom) complex-types #1145

Open stefan-hubert-bl opened 2 years ago

stefan-hubert-bl commented 2 years ago

(being pretty new to FHIR and SUSHI) I learned that using FHIR Shorthand (and SUSHI) I can generate FHIR artefacts e.g. to define FHIR StructureDefinition of these "kind"s:

Now I want to define a new complex-type that I can reuse in multiple custom Resource definitions. Currently I have not seen a way to achieve this using FHIR Shorthand syntax.

Question/Wish: If there really is no way yet to achieve this in SUSHI (maybe I just didn't try the right thing), would such an enhancement make sense at all?

cmoesel commented 2 years ago

Believe it or not, you're the first to request this. While SUSHI doesn't have official support for creating complex datatypes, they're really not all that different from resources. I think the primary differences are that the StructureDefinition.kind is complex-type and the StructureDefinition.baseDefinition is http://hl7.org/fhir/StructureDefinition/Element. As such, you can kind of hack the FSH to get what you want by doing something like this.

Resource: MyComplexType
Id: my-complex-type
Parent: Resource
Title: "My Complex Type"
Description: "A complex type (I think)."
* ^baseDefinition = "http://hl7.org/fhir/StructureDefinition/Element"
* ^kind = #complex-type
* foo 0..* SU string "Foo" "Foo"
* bar 0..1 SU boolean "Bar" "Bar"

FSH Online.

There is an important caveat, in that the snapshot that SUSHI generates will contain some of the elements that are inherited from Resource (for example, meta). The differential should be correct. If you don't need/want the SUSHI-generated snapshot (or if you can get another tool to re-generate the snapshot for you), then you might be OK.

stefan-hubert-bl commented 2 years ago

Thanks @cmoesel for your prompt answer! (Being a beginner) having hard time to understand the consequences of what you say about the elements still inherited from Resource.

BTW: Here is what I experimented also with was using: Extension: MyComplexTypeB I found this also generates a StructureDefinition of kind "complex-type" (however using type "Extension"). It feels like I can use this now in my resouce definition like any other specific complex-type, which may be exactly what I want. However, I observe that here, instead of this as element definition "type": [ { "code": "my-complex-type-a" } I now see this: "type": [ { "code": "Extension", "profile": [ "http://example.org/StructureDefinition/my-complex-type-b" ] } I don't understand "Extensions" enough yet to understand what consequences this difference has, though.

FSH Online