Stream: implementers
Topic: Writing Condition Expressions under Constraints
Krant (Sep 17 2021 at 19:50):
Is there a documentation / Help I can read through on writing Conditional Expressions to validate the values. For instance::
I have custom Structure Definition based on Observation resource. Using HAPI for the validation. Is there a way to validate the value combination?
Ex:
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "76536-2",
"display": "Mean Arterial Pressure, Cuff"
}
]
},
When this one is used, the unit of measure from the valueQuantity should have only corresponding values, not anything from the code valueset for unitofmeasure.
"valueQuantity": {
"value": 90,
"unit": "mm Hg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
In other words, for Mean Arial Pressure LOINC code, valueQuantity.code should not allow kg, for example.
Chris Moesel (Sep 17 2021 at 20:05):
Hi @Krant. I think the key operators you're looking for is implies. In other words, "LOINC code X implies quantity unit Y". See the FHIRPath spec for examples of its use. If you search the whole spec for the word "implies" then you'll see it is used in several examples.
Chris Moesel (Sep 17 2021 at 20:17):
Here's an example using the Observation from your question:
code.coding.where(code = '76536-2' and system = 'http://loinc.org').exists() implies valueQuantity.where(code = 'mm[Hg]' and system = 'http://unitsofmeasure.org').exists()
You can try that out on the fhirpath tester with this Observation:
resourceType: Observation
id: ExampleObservation
status: final
code:
coding:
- code: 76536-2
system: 'http://loinc.org'
display: 'Mean Arterial Pressure, Cuff'
valueQuantity:
value: 90
code: 'mm[Hg]'
system: 'http://unitsofmeasure.org'
unit: mm Hg
Play with the code and quantity to see how it affects the result on the right-hand side.
Chris Moesel (Sep 17 2021 at 20:19):
For more advanced stuff (like checking for value set inclusion) you can just modify the expressions on the left or right side of implies
as appropriate. Note however that the fhirpath tester linked above does not cover the whole FHIRPath spec, so some FHIRPath expressions won't work there.
Krant (Sep 17 2021 at 21:29):
Thank you.. Is this conditional expression should be specified only in snapshot or it can be specified in Differential too?
Krant (Sep 17 2021 at 21:31):
Also, how do I specify multiple AND or OR conditions in the same expression?
Chris Moesel (Sep 17 2021 at 21:43):
Hi @Krant -- I'd recommend you review the documentation on Differential vs Snapshot, but in short, if you're creating a profile, your changes always go in the differential. When the profile is processed by the IG Publisher (or whatever tooling you're using) it will generate the snapshot, which will reflect any changes you made in the differential.
Chris Moesel (Sep 17 2021 at 21:46):
As for AND and OR, you use the keywords and
and or
. If you need to group logical constructs, you can group them in (
)
. For more info on FHIRPath, I'd suggest reading the FHIRPath spec as well as the section on FHIRPath in the FHIR R4 spec. Both are fairly easy reads.
Last updated: Apr 12 2022 at 19:14 UTC