Stream: implementers
Topic: OR queries across parameters?
Anthony Sute (Jun 08 2018 at 17:02):
The OR examples on the FHIR STU3 Search page show how to match on one or more values for a single parameter. However, we're trying to do ORs across different parameters such as:
http://.../fhir/baseDstu3/Patient?_id=218,_lastUpdated=gt2018-05-02
Is this supported in the FHIR search spec? The HAPI Server is giving inconsistent query results based on the ordering of the querystring parameters and I'm not sure if it's a HAPI issue.
Lloyd McKenzie (Jun 08 2018 at 18:07):
That's not legal FHIR syntax. If you want to do OR across search parameters you'll need to use _query or GraphQL, though neither are widely supported
Alexander Zautke (Jun 08 2018 at 18:29):
One other option would be to use _filter. Unfortunately, this is not that widely supported, too.
You could use OR searches in the following way:
[base]/Patient?_filter=_id eq 218 or _lastUpdated co 2018-05-02
Lloyd McKenzie (Jun 08 2018 at 19:15):
I'd actually meant to type _filter rather than _query :)
Anthony Sute (Jun 08 2018 at 19:35):
Thanks Lloyd. I'm curious if the syntax I showed might be something to consider in an upcoming spec to more easily express OR queries? I would think that the use of the comma to specify multiple values for a single parameter to OR against would be conceptually straightforward to extend to multiple parameters instead?
@James Agnew - HAPI doesn't raise an error for the OR syntax above that Lloyd indicated was illegal. Does HAPI attempt to parse OR queries across multiple parameters? Thanks in advance!
Lloyd McKenzie (Jun 08 2018 at 21:33):
I suspect it would be a parsing challenge. Also, we're trying to draw bounds over how complex we make RESTful query. But you're welcome to submit a change request
Grahame Grieve (Jun 08 2018 at 21:35):
but you should not. _filter is the only rational way to do this syntax. The fact that is not widely supported is not related to syntax but to complexity. We should not create additional syntaxes for the complexity
John Moehrke (Jun 11 2018 at 15:20):
The classic RESTful way to do OR is to do multiple GET... you don't get one result, but you do get your OR result
Christiaan Knaap (Jun 14 2018 at 11:53):
I think HAPI is correct not to report this as an error. You simple asked for a Patient having an _id of either '218' or '_lastUpdated=gt2018-05-02'. The latter will never yield a result though, since an _id is not allowed to have _ or = characters (see Resource Identity)
Last updated: Apr 12 2022 at 19:14 UTC