Stream: fhirpath.js
Topic: Querying for resources of a specified type
Tim Harsch (Jun 10 2020 at 21:08):
Hi, I'm new to Zulip and the chat server. I'm trying to incorporate fhirpath.js into my code and am having trouble filtering resources by type. I'd appreciate a little guidance. I've tried Bundle.entry.resource.ofType(Observation)
and Bundle.entry.select(resource as Observation)
. The former returns empty collection and the latter returns error Error: No TypeExpression evaluator
Tim Harsch (Jun 10 2020 at 21:18):
Seems this also returns empty array: Bundle.entry.where(resourceType = Observation)
. If these are unexpected results I could post my test file and JSON document to a gist, if it helps.
Paul Lynch (Jun 10 2020 at 21:19):
ofType in fhirpath.js never got past types "integer" and "decimal", but I think the code to fully support it is nearly there. Please file raise an issue on the GitHub repository-- better to make separate requests for ofType and "as". One might be easier to complete than the other.
Paul Lynch (Jun 10 2020 at 21:23):
Bundle.entry.where(resourceType = 'Observation') should work. (You were missing the quotes for the string.)
Tim Harsch (Jun 10 2020 at 21:42):
will do. thanks
Tim Harsch (Jun 10 2020 at 21:47):
quoting Observation did not change the result. If you think that is an error perhaps then I'm willing to open a third github issue for it. Would you like to see my FHIR json document first?
Paul Lynch (Jun 10 2020 at 21:48):
Yes, please. My test of that form worked.
Tim Harsch (Jun 10 2020 at 21:48):
Also, is there a way to validate the syntax itself? something I can use a pre-check that would have told me about the missing quotes? In my hurried reading of the spec I thought I saw something to the effect that quotes were optional but I'm not sure
Tim Harsch (Jun 10 2020 at 21:52):
Paul Lynch said:
Yes, please. My test of that form worked.
https://gist.github.com/timharsch/80ebf952d4c784bbfa5542d9ca518b2d
Paul Lynch (Jun 10 2020 at 21:53):
Without the quotes, it is checking field resourceType against field "Observation" (which doesn't exist). So, I am not sure how this problem would have been caught. Also, note that "resourceType" is an artifact of the JSON encoding, and does not really exist in the FHIR resource. So, while it will work in fhirpath.js, it is kind of a hack. But, it might be your only option until ofType is implemented.
Paul Lynch (Jun 10 2020 at 21:57):
Tim Harsch said:
Paul Lynch said:
Yes, please. My test of that form worked.
https://gist.github.com/timharsch/80ebf952d4c784bbfa5542d9ca518b2d
Bundle.entry.resource.where(resourceType = 'Observation')
(.resource was missing)
Tim Harsch (Jun 10 2020 at 21:59):
Paul Lynch said:
Yes, please. My test of that form worked.
https://github.com/HL7/fhirpath.js/issues/50
Tim Harsch (Jun 10 2020 at 22:05):
Paul Lynch said:
better to make separate requests for ofType and "as". One might be easier to complete than the other.
https://github.com/HL7/fhirpath.js/issues/51
Tim Harsch (Jun 10 2020 at 22:08):
Thanks @Paul Lynch let me know what you think about Bundle.entry.where(resourceType = 'Observation')
(with the quotes) against my document. If you want me to file an issue on GitHub for it, I'd be happy too.
Paul Lynch (Jun 10 2020 at 22:08):
See above.
Paul Lynch (Jun 10 2020 at 22:09):
Paul Lynch (Jun 10 2020 at 22:10):
That link was not very specific. I'll repeat what I said above:
Bundle.entry.resource.where(resourceType = 'Observation')
(.resource was missing)
Tim Harsch (Jun 10 2020 at 22:16):
Paul Lynch said:
That link was not very specific. I'll repeat what I said above:
Bundle.entry.resource.where(resourceType = 'Observation')
(.resource was missing)
That worked for me. I got back 10 observations from my document.. Thank you!
Last updated: Apr 12 2022 at 19:14 UTC