FHIR Chat · Invariant Definition · shorthand

Stream: shorthand

Topic: Invariant Definition


view this post on Zulip Diana_Ovelgoenne (Oct 05 2021 at 07:46):

Hi, I am struggling with the Invariants in FSH while using hasMember[Observation]. I am trying to build the logic for validating the existence of 2 different hasMember while the 3rd one then must not be present :
Profile: TestInvariants
Parent: Observation
Id: test-invariants
Title: "test invariants"
Description: "This Profile defines the different invariants"

  • code = http://dicom.nema.org/resources/ontology/DCM#121071 "Finding"
  • value[x] 0..0
  • hasMember ^slicing.discriminator.type = #profile
  • hasMember ^slicing.discriminator.path = "$this.resolve()"
  • hasMember ^slicing.rules = #open
  • hasMember ^slicing.ordered = true
  • hasMember contains
    Observation1 0..1 and
    Observation2 0..* and
    Observation3 0..1

  • hasMember[Observation1] only Reference(Observation1)

  • hasMember[Observation1] ^short = "Observation1"
  • hasMember[Observation1] ^definition = "This Profile defines the obs 1"

  • hasMember[Observation2] only Reference(Observation2)

  • hasMember[Observation2] ^short = "Observation2"
  • hasMember[Observation2] ^definition = "This Profile defines the obs 2"
  • hasMember[Observation3] only Reference(Observation3)
  • hasMember[Observation3] ^short = "Observation3"
  • hasMember[Observation3] ^definition = "This Profile defines the obs 3"

  • obeys test

Invariant: test
Description: "Observation1 and Observation2 SHALL be present Then Observation3 SHALL NOT exist"
Expression: "hasMember[Observation1].exists() and hasMember[Observation2].exists() and hasMember[Observation3].exists().not()"
Severity: #error

Instance: InvariantsExample
InstanceOf: TestInvariants
Usage: #example
Title: "Invariants Example"
Description: ""

Even if only Observation1 and Observation2 exist, I get a Failed status at the qa.html. I am not sure if the syntaxis I am using in FSH while defining the invariant is the correct one, or why is this failing? It isn't clear how to write it when referring to the existence of a contained profile.
Thanks!

view this post on Zulip Chris Moesel (Oct 06 2021 at 12:53):

Hi @Diana_Ovelgoenne. Unfortunately, FSH syntax does not work inside of invariant expressions (keyword Expression in the Invariant definition). Invariant expressions must be written using FHIRPath syntax (FHIRPath spec, FHIRPath in FHIR). You got some of the FHIRPath syntax right already (e.g., .exists(), .not()) -- but the approach to identifying slices was not correct. In FHIR-based FHIRPath, you use the slice to refer to slices (documented in the additional functions part of the spec). Using this approach, your FHIRPath would be:

Expression: "hasMember.slice('http://example.org/StructureDefinition/test-invariants', 'Observation1').exists()
    and hasMember.slice('http://example.org/StructureDefinition/test-invariants', 'Observation2').exists()
    and hasMember.slice('http://example.org/StructureDefinition/test-invariants', 'Observation3').exists().not()"

(assuming canonical URL http://example.org/StructureDefinition/test-invariants for your profile).

Unfortunately, however, if you run this through the IG Publisher and try to validate your example, the IG Publisher crashes with this exception:

Exception in thread "main" java.lang.Error: Not done yet (ValidatorHostServices.resolveFunction): slice
    at org.hl7.fhir.validation.instance.InstanceValidator$ValidatorHostServices.resolveFunction(InstanceValidator.java:228)
    at org.hl7.fhir.r5.utils.FHIRPathEngine.parseExpression(FHIRPathEngine.java:1042)

I think this means that support for the FHIRPath slice function is not yet implemented in the validator. Is that correct, @Grahame Grieve? If so, is there a way to still use the slice function in invariants without crashing the publisher?

view this post on Zulip Jose Costa Teixeira (Jan 18 2022 at 09:53):

Is this addressed in the meanwhile? I'm looking for guidance on how to add slices in invariants, and I cannot find it

view this post on Zulip Chris Moesel (Jan 18 2022 at 14:35):

Hi @Jose Costa Teixeira -- as noted above, the FHIRPath slice command is documented in the additional functions part of the FHIR spec's FHIRPath page here: http://hl7.org/fhir/R4/fhirpath.html#functions. As for whether or not the IG Publisher supports slice(...) yet, I don't know.


Last updated: Apr 12 2022 at 19:14 UTC