Stream: fhirpath
Topic: Is code in a set of codes?
Jean Duteau (Jun 09 2021 at 18:09):
I'm trying to write an invariant where a code has to be in a set of codes depending on a condition:
If type = C43660, then serviceProvisionCode = C106443, C131710, C131708, and/or C131709.
I've tried writing this as:
type.coding.code != 'C43360' or serviceProvisionCode.where((coding.code in {'C106643','C131710','C131708','C131709'}).not()).count() = 0
OR
type.coding.code != 'C43360' or serviceProvisionCode.where(({'C106643','C131710','C131708','C131709'} contains coding.code).not()).count() = 0
Both of those fail with a "expecting a token name" error:
Problem processing expression type.coding.code != 'C43360' or serviceProvisionCode.where((coding.code in {'C106643','C131710','C131708','C131709'}).not()).count() = 0 in profile http://hl7.org/fhir/us/spl/StructureDefinition/LabelerBusinessOperation path HealthcareService: Error @1, 7: Found { expecting a token name
Problem processing expression type.coding.code != 'C43360' or serviceProvisionCode.where(({'C106643','C131710','C131708','C131709'} contains coding.code).not()).count() = 0 in profile http://hl7.org/fhir/us/spl/StructureDefinition/LabelerBusinessOperation path HealthcareService: Error @1, 5: Found { expecting a token name
I'm guessing that I'm not specifying the static collection correctly. Can someone lend me a hand?
Paul Lynch (Jun 09 2021 at 21:24):
where('C106643' | 'C131710'|'C131708' | 'C131709')
Bryn Rhodes (Jun 09 2021 at 21:46):
type.coding.where(code = 'C43360').exists() implies serviceProvisionCode.coding.where(code in ('C106643' | 'C131710' | 'C131708' | 'C131709')).exists()
Bryn Rhodes (Jun 09 2021 at 21:46):
Using implies makes it a little more readable, IMHO
Bryn Rhodes (Jun 09 2021 at 21:47):
This logic is also assuming system, which might be dangerous?
Jean Duteau (Jun 09 2021 at 22:27):
thanks to both. I can't find that syntax in the FHIRPath spec, so a pointer to it would be nice. As to assuming system, I've already got a required binding so I know the system is fixed.
Jean Duteau (Jun 09 2021 at 22:31):
@Bryn Rhodes I need to say that only those codes are allowed. I think what you wrote says that one of those codes has to be there, but that others could also be there?
Bryn Rhodes (Jun 09 2021 at 23:14):
Ah, yes:
type.coding.where(code = 'C43360').exists() implies serviceProvisionCode.coding.select(code = ('C106643' | 'C131710' | 'C131708' | 'C131709')).allTrue()
Bryn Rhodes (Jun 09 2021 at 23:16):
And the link to the union syntax: http://hl7.org/fhirpath/#unionother-collection
Bryn Rhodes (Jun 09 2021 at 23:17):
FHIRPath by design does not have a list-selector syntax, so constructing a list is effectively a chain of unions.
Jean Duteau (Jun 09 2021 at 23:28):
i bow to your fhirpath skills :)
Last updated: Apr 12 2022 at 19:14 UTC