Stream: fhirpath
Topic: Issue with a FHIRPath Expression
Joan Harper (Jan 14 2021 at 21:17):
I have created a Patient profile and I am trying to implement a constraint --> Must have [identifier of type JHN] or [address and phone]
I initially wrote the FHIRPath expression as:
(identifier.type.coding.code="JHN") or (address.exists() and telecom.exists()) --- the two test cases that should trigger the error (no JHN and no address, no JHN and no telecom) come back with success instead of fail.
I tried changing it to:
(identifier.type.coding.code="JHN") or ((address.exists()) and (telecom.exists())) --- I got the same result
If a resource is missing JHN, or address, or phone, the validation succeeds as expected.
If a resource is missing JHN and address, or JHN and phone, the validation succeeds when it should fail.
Does anyone have any idea what is wrong with this FHIRPath expression?
Appreciate any help.
Joanie
ryan moehrke (Jan 14 2021 at 21:21):
(identifier.type.coding.code='JHN') or ((address.exists()) and (telecom.exists())) seems to work as expected here https://hl7.github.io/fhirpath.js/
(note i had to change your double quotes to single quotes which may have been the underlying issue)
Joan Harper (Jan 14 2021 at 21:29):
Thanks Ryan.
I changed the double quotes to single quote and now the tests that were missing both JHN and address, or JHN and telecom work.
Now the test where telecom is missing fails and the test where address is missing fails. These tests should both succeed.
The new expression is (identifier.type.coding.code='JHN') or ((address.exists()) and (telecom.exists()))
I'm so confused by this expression. This should be pretty straightforward.
ryan moehrke (Jan 14 2021 at 21:38):
so what are you cases where you want to pass vs fail?
because how I read your expression it worked as I expected with varying inclusion of your code, an address, or a telecom
Joan Harper (Jan 14 2021 at 21:43):
if it is missing address but has JHN, it should pass - this is now failing
if it is missing telecom but has JHN, it should pass - this is now failing
if it missing a JHN identifier but has address and telecom, it should pass
if it is missing a JHN identifier and address, it should fail
it it is missing a JHN identifier and telecom, it should fail
ryan moehrke (Jan 14 2021 at 21:58):
can you send over what patient resource you are working off of? Maybe the JHN identifier is not being recognized correctly in the fhirpath
Joan Harper (Jan 14 2021 at 22:15):
After a bit of back and forth with Ryan, he helped me fix my issue, which was occurring because there was slicing of the identifier.
(identifier.where(type.coding.code='JHN').exists()) or ((address.exists()) and (telecom.exists()))
Ryan, thank you very very much :)
Joanie
ryan moehrke (Jan 14 2021 at 22:17):
yup, because there were multiple identifiers in your examples with different identifier types etc. the previous expression of identifier.type.coding.code='JHN' needed to be modified to make sure at least one identifier has a type of JHN so we used where() for that and then an exists() to make the existence/absence of a matching element into a boolean true/false for the rest of the expression
Last updated: Apr 12 2022 at 19:14 UTC