FHIR Chat · Searching for a field value for queried parameter · implementers

Stream: implementers

Topic: Searching for a field value for queried parameter


view this post on Zulip Mike C. (Aug 09 2019 at 14:36):

Good Day FHIR Folks,

I am having a bit of difficulty creating the correct endpoint for my GET request to our FHIR API,

My goal in a very general sense is to call for all Resources that are related to one other specific Resource's id, and only when a certain Element in that resource matches a certain value.

Specifically, I want to find all Encounter resources that are tied to one specific Patient, and only when those Encounters for that Patient were for a specific year (the Element object is "period" with two fields within it, "start" and "end").

I have tried the following endpoints to obtain this desired result, with no luck:

https://[Base URL]/Encounter?_patient=Patient/###########&?_period.start=2011-09-18T19:05:01-04:00

https://[Base URL]/Encounter?_patient=Patient/###########&?_period=2011-09-18T19:05:01-04:00

https://[Base URL]/Encounter?_patient=Patient/###########&period=2011-09-18T19:05:01-04:00

https://[Base URL]/Encounter?_patient=Patient/###########?given:contains=2011-09-18T19:05:01-04:00

https://[Base URL]/Encounter?_patient=Patient/###########?contains=2011-09-18T19:05:01-04:00

https://[Base URL]/Encounter?_patient=Patient/###########&period?given:contains=2011-09-18T19:05:01-04:00

When send a Get to these endpoints, I am not given the one value that I am testing for, but rather a bundle of all Encounters regardless of matching period-value.

I am looking on the HL7 documentation here for "search" but I can't seem to find what I need, any points in the right direction would be greatly appreciated!!

view this post on Zulip Michele Mottini (Aug 09 2019 at 15:53):

No underscore - ...Encounter?patient=....

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 15:54):

https://[Base URL]/Encounter?patient=123&period=2011-09-18

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 15:54):

So only ever one "?", multiple parameters separated by &

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 15:55):

:contains isn't an allowed qualifier for period

view this post on Zulip Mike C. (Aug 09 2019 at 16:18):

@Michele Mottini @Lloyd McKenzie Thank you for the replies gentlemen! I appreciate your help.

view this post on Zulip Mike C. (Aug 09 2019 at 17:23):

@Lloyd McKenzie @Michele Mottini

https://[Base URL]/Encounter?patient=123&period=2011-09-18

Understood - branching off this, my question would be: is it possible to search for only part of the value in the period field? Essentially, doing a "string slice" of the total value (2011-09-18T19:05:01-04:00 is how the dates are formatted in this field for every Encounter), such that I could search for only the first four characters of the period.start value?

Basically, I want to be able to search for all Encounter resources that begin with a certain year (the first four characters in that string). Since it's not practical, in my use-case, to search for the entire long dateTime object, I want to just search for the all Encounter objects based on a year input i.e. "2011"

I would think that the ':contains' parameter would be the logical solution to this, but I know you said that ':contains' is not an allowed qualifier for the period Element, so would there be any way of achieving this another way?

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 18:27):

You aren't searching against the characters, you're searching against the math :) Searches against periods are based on set math of the range of the search term (determined by its precision) and the range of the period (including its precision). So if you search for period=2011, that will find any records that have a period that overlap the period of 2011-01-01T00:00:00 to 2011-12-31T23:59:59.

view this post on Zulip Michele Mottini (Aug 09 2019 at 18:32):

...isn't it contains, not overlap?

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 18:35):

Overlap

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 18:35):

Something that started 2011-12-31T23:59:58 and lasted 10 days into 2012 would be returned by a query of period=2011

view this post on Zulip Mike C. (Aug 09 2019 at 18:52):

@Lloyd McKenzie , thanks for the suggestion. I tried to use period=2011 as a query parameter but Postman still returns all encounters, basically not filtering by year 2011. Am I missing something?

view this post on Zulip Lloyd McKenzie (Aug 09 2019 at 19:44):

Actually, looks like 'period' isn't a valid search parameter. It should be 'date'. (You can look at the 'self' link to see what query the server actually executed - any parameters not listed it doesn't support or might not even be valid.)

view this post on Zulip Mike C. (Aug 09 2019 at 20:57):

Thank you @Lloyd McKenzie , that's the ticket I needed. Appreciate your and @Michele Mottini 's help today. Have a great weekend.

view this post on Zulip Eric Haas (Aug 12 2019 at 00:39):

@Lloyd McKenzie I think the 'self' link section and handling errors appear related enough to be merged or at least adjacent? instead of at opposite ends of the page

view this post on Zulip Lloyd McKenzie (Aug 12 2019 at 03:06):

Change request :)

view this post on Zulip natus (Oct 19 2019 at 19:49):

@Lloyd McKenzie not sure why searching by date instead of period.start and period.end . Some client need to get all encounter fisnishing before and exact date. Searching by date looks quite unprecise.
Also there is no way to _sort by end/start.
Any thought ?

view this post on Zulip Lloyd McKenzie (Oct 20 2019 at 01:47):

Searching by date allows you to find elements that overlap a particular period. You can use le and/or ge to define the boundaries of the period you're looking for matches with and can then look for records that overlap with those boundaries. So far no one's mentioned the ability to sort by period - agree that's something that's a reasonable thing to want to do. @natus would you be willing to submit a change request?

view this post on Zulip natus (Oct 20 2019 at 09:23):

@Lloyd McKenzie I have two use cases:
- search for all encounter who have missing end-date, OR end-date between x and y
- sort them by start date.

Ok to submit a change request for both. but please discuss before the content of the change.

Proposal 1:

Encounter?period=2019 //equivalent to actual date
Encounter?period.start=2019
Encounter?period.start:lt=2020-02&period.end:gt=2017
Encounter?period.end:missing=true
Encounter?_sort=period.start

Proposal 2:

Encounter?date=2019 // no broken change
Encounter?start-date=2019
Encounter?start-date:lt=2020-02&start-date:gt=2017
Encounter?end-date:missing=false
Encounter?_sort=-start-date

view this post on Zulip Lloyd McKenzie (Oct 20 2019 at 16:04):

It would have to be the second. "." is used for chaining and isn't allowed in the names of a search criteria

view this post on Zulip natus (Oct 21 2019 at 19:35):

ok. I guess I did the request in hl7gforce. I am unsure because the process has been tricky

view this post on Zulip Lloyd McKenzie (Oct 21 2019 at 20:07):

Yup. GF#25037 looks good.


Last updated: Apr 12 2022 at 19:14 UTC