Search code examples
hl7-fhir

(How) Can I use FHIR Shorthand (SUSHI) to define a new FHIR complex-type?


Given one of the following potential use cases / contexts:

  1. I am a committee and want to define a proposal to be added as part of FHIR standard. For some use in diverse FHIR-Resource types I want to define a new reusable complex FHIR structure type (as of http://hl7.org/fhir/structure-definition-kind complex-type)
  2. I am some specific vendor of a Software and want to use mechanisms/language/tools from FHIR to model/define our internal inter sw-compoont communication data structures. In order to use the full feature set of FHIR modelling, I'd like to define our own private FHIR complex-types as of http://hl7.org/fhir/structure-definition-kind complex-type)

Background: I already read documentation/tutorials for FHIR, FHIR Shorthand and SUSHI and was experimenting with these. I found that FHIR Shorthand allows to declare FHIR StructureDefinition artefacts of kind "logical" and "resource" (using FSH Item Declarations like Resource: MyResouce and Logical: MyLogical). However I did not find a way to declare a new complex-type using FHIR Shorthand

Question 1: Is there a way in FHIR Shorthand to define a new complex type so I can re-use the definition in diverse FHIR resource definitions? If not, what alternatives do I have to achieve the same (maybe outside FHIR Shorthand)?

EDIT/ADDITON:

Generalized Question(s)

FSH (FHIR Shorthand) is a specially-designed language for defining the content of HL7 FHIR Implementation Guides (IGs)

(quote from https://fshschool.org/docs/)

Question 2: Now, does that mean that FSH is not meant to edit artefacts for (potential future) FHIR Specification, but only for FHIR Implementation Guides?

Question 3: Is it allowed in FHIR Implementation Guides (IGs) to define StructureDefinition of kind "complex-types" and this way make the definition it available in the same of other IG(s)?


Solution

  • As for question 1 (can you create complex types using FSH?): I've answered that in the SUSHI issue you submitted on GitHub here. I'll also repeat the answer below:

    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"
    

    See this on 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.

    As for question 2 (is FSH only for IGs but not the FHIR spec?): FSH was initially designed only for developing IGs. In FSH 2.0, we introduced the ability to create Resources, but it is a Trial-Use (non-normative) feature. We (the FSH authors) think that FSH could be a great way to author and maintain resources in the core FHIR spec, but no one has used it for that purpose yet (and the core FHIR build does not process FSH at the moment).

    As for question 3 (Can IGs define complex types?): No, IGs cannot define and distribute custom Resource types or complex types (or primitive types). When you put Resource definitions in your FSH code, SUSHI will generate the StructureDefinition, but it excludes it from the resource list passed on to the IG Publisher (since the IG Publisher won't allow it). You can, however, create and distribute Logical Models in an IG.