Stream: implementers
Topic: FHIRPath complex extensions
Kevin Mayfield (Jun 21 2021 at 12:26):
Should FHIRPath work on complex extensions?
Have this extension https://simplifier.net/ukdigitalmedicine/extension-dm-controlleddrug used by MedicationRequest.
believe the expression would be in the profile not the extension.
What I want to say is:
is schedule is A or B then controlledDrugs words must not be null.
Something like this
((extension.where(url = 'https://fhir.nhs.uk/StructureDefinition/Extension-DM-ControlledDrug')).extension.where(url='quantityWords').exists())
This bit works but not having much luck checking for codes.
Grahame Grieve (Jun 21 2021 at 13:05):
checking for codes?
Kevin Mayfield (Jun 21 2021 at 13:39):
Yes something like
((extension.where(url = 'https://fhir.nhs.uk/StructureDefinition/Extension-DM-ControlledDrug')).extension.where(url='schedule').valueCoding.code='CD2')
Grahame Grieve (Jun 21 2021 at 13:49):
don't you need a where at the end? What are you trying to achieve?
Kevin Mayfield (Jun 21 2021 at 14:23):
To check the code is equal to CD2 <- not working
and then check another extension is present <- works
Have tried a few combinations with where at the end but they always come back as true (in fhirpath tester)
Kevin Mayfield (Jun 21 2021 at 14:26):
E.g. this always comes back as true
((extension.where(url = 'https://fhir.nhs.uk/StructureDefinition/Extension-DM-ControlledDrug')).extension.where(url='schedule')).valueCoding.where(code='CD2')
Kevin Mayfield (Jun 21 2021 at 14:27):
<extension url="https://fhir.nhs.uk/StructureDefinition/Extension-DM-ControlledDrug">
<extension url="schedule">
<valueCoding>
<system value="https://fhir.nhs.uk/CodeSystem/medicationrequest-controlled-drug" />
<code value="CD2 not true" />
<display value="Schedule 2" />
</valueCoding>
</extension>
</extension>
Brian Postlethwaite (Jun 21 2021 at 22:18):
Shouldn't that be value.code
, not valueCoding.code
Kevin Mayfield (Jun 22 2021 at 07:41):
Ah ha..... all is now clear. Many thanks
Kevin Mayfield (Jun 22 2021 at 09:02):
Validated fine also.... noticed a difference in behavior between fhirpath tester and FHIR Validation
fhirPath evaluates
expr1 or or expr2
but for fhir validation (hapi) this needs to be changed to
(expr1 or or expr2)
opening and closing brackets.
Grahame Grieve (Jun 22 2021 at 10:24):
that doesn't make sense
Kevin Mayfield (Jun 22 2021 at 10:38):
which one my comment or fhirtester?
Grahame Grieve (Jun 22 2021 at 10:38):
that you need the brackets
Kevin Mayfield (Jun 22 2021 at 10:39):
ah ok
Brian Postlethwaite (Jun 23 2021 at 06:14):
Also note that there is a shortcut syntax for extensions so
extension.where(url='schedule')
can be written as
extension('schedule')
Kevin Mayfield (Jun 24 2021 at 11:47):
Does hapi use same fhirpath library. I seem to be having problems on extensions.
Grahame Grieve (Jun 24 2021 at 11:55):
same as what?
Kevin Mayfield (Jun 24 2021 at 12:00):
Same as the one used in FHIRPath Tester.
Presuming its different as extensions test ok in but fail in HAPI
Grahame Grieve (Jun 24 2021 at 12:02):
I don't know what the FHIR Path tester is, but the HAPI one is the one used in the validator. What expression doesn't work? Add it to the FHIRPath test cases at https://github.com/FHIR/fhir-test-cases/blob/master/r5/fhirpath/tests-fhir-r5.xml
Kevin Mayfield (Jun 24 2021 at 12:12):
argh! Spotted an error - deleted
Kevin Mayfield (Jun 24 2021 at 17:17):
Many thanks.
The test scripts were very useful.
Problem was with the FHIRPathTester behaving differently to hapi.
if an extension dosen't exist FHIRTester would true for this expression
(extension('https://fhir.nhs.uk/StructureDefinition/Extension-DM-ResponsiblePractitioner').value.reference.exists() or extension('https://fhir.nhs.uk/StructureDefinition/Extension-DM-ResponsiblePractitioner').value.system.exists())
hapi would return false. Solution was to add check for existence
or extension('https://fhir.nhs.uk/StructureDefinition/Extension-DM-ResponsiblePractitioner').exists().not()
hapi version seems to make more sense.
Brian Postlethwaite (Jun 25 2021 at 01:43):
As an extract, or as a validate? FhirPathTester does both ways.
Brian Postlethwaite (Jun 25 2021 at 01:44):
I put that expression into fptester here and it returns false - interesting.
Kevin Mayfield (Jun 25 2021 at 03:43):
Is the latest version on windows store? It was a couple of years old.
Brian Postlethwaite (Jun 25 2021 at 03:47):
Yes the one on the windows store is current.
(as at 4.0.0 - don't think I updated it for 4.0.1 as yet)
Brian Postlethwaite (Jun 25 2021 at 03:48):
(But is on my list of things to do - need a local build of the fhir client, not the nuget ones due to an appstore limitation on reflection/emit - or at least did for the 1.4 libs)
Last updated: Apr 12 2022 at 19:14 UTC