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.
CodePudding user response:
I'm not a FHIRPath/clinical data expert but I think this should work for you
{
"resourceType": "StructureDefinition",
"url": "https://test.com/test",
"type": "Observation",
"status": "draft",
"baseDefinition": "http://hl7.org/fhir/StructureDefinition/Observation",
"snapshot": {
"element": [
{
"path": "Observation",
"id": "Observation",
"min": 0,
"max": "*",
"base": {
"min": 0,
"max": "*"
},
"constraint" : [{
"severity" : "error",
"expression": "code.coding.where(system = 'http://loinc.org' and code = '76536-2').exists() implies (value as Quantity).where(code='mm[Hg]' and system='http://unitsofmeasure.org').exists()"
}]
}
]
}
}
The first part of the condition determines where you have an Observation with the appropriate code. If so it will require that your value has the right unit.
EDIT: To add some more information about what's going on here.
We are using a FHIRPath constraint to express this more complicated validation rule.
The .where(...)
(docs) condition filters down a repeated/single field if it matches the condition, in this case that's the code/system combination that matches in LOINC code you care about.
.exists()
(docs) returns true if the collection is non-empty.
implies
(docs) evaluates the right-hand side condition only if the left-hand side is true.
And finally the (... as Quantity)
operator (docs) is used to convert the value[x]
field to a specific type, so more operations can be done on it.