0

I cannot filter an Appointment from start and end date using the google healthcare API.

I am trying to recreate the query below:

Appointment?date=ge2023-02-03T04:00:00.000Z&date=le2023-02-05T04:00:00.000Z

This is my javascript code using the library:

const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

const params = {
   parent,
   resourceType,
   date: `le${end}`,
   date: `ge${start}`,
};

const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.search(params);

date: `ge${start}` is ignored because you cannot duplicate the same key.
Is there any other way I can achieve this.
Thanks!

Jorge Luis
  • 13
  • 3
  • What method are you trying to call exactly? – Linda Lawton - DaImTo Feb 05 '23 at 21:53
  • Just a search using this method. healthcare.projects.locations.datasets.fhirStores.fhir.search(params); https://cloud.google.com/healthcare-api/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/search – Jorge Luis Feb 05 '23 at 22:01
  • what happends if you remove date: `le${end}`, date: `ge${start}`, – Linda Lawton - DaImTo Feb 05 '23 at 22:09
  • If I remove the dates, I'll get all the appointments from the database. ![Search without Filter - google healthcare query builder](https://i.ibb.co/cCxcCMq/image.png). ![Search with Filters](https://i.ibb.co/wc96sk5/image.png). – Jorge Luis Feb 05 '23 at 22:18
  • Hello @LindaLawton-DaImTo, I was able to make it work (see the answer below). Thanks for the quick replies I appreciate it. – Jorge Luis Feb 05 '23 at 22:58
  • I had an idea it was something like that I have used Fhir before just not googles version. Fhir is pretty standard with its error messages. Glad you got it working. – Linda Lawton - DaImTo Feb 06 '23 at 08:09

2 Answers2

1

I was able to make it work.

const params = {
   parent,
   resourceType,
   "date:end": `le${end}`,
   "date:start": `ge${start}`,
};

Just change "date" to "date:start" and "date:end"

Jorge Luis
  • 13
  • 3
0

I see that you were able to make this work, but there's a better way. What you essentially want to do here is specify multiple date parameters. The solution that you've come up with does this, but by using non-existent modifiers, :start and :end. By default the FHIR store drop modifiers it does not recognize, so your query as the same as date=le...&date=ge..., which is the end result you want. But if you were using the header Prefer: handling=strict, or set defaultSearchHandlingStrict in your FHIR store config, you'll get an error back from this search.

So what's the correct thing to do? If you want to specify multiple query parameters to be ANDed together (with the Node API), all you need to do is specify an array. In the future, if you wanted to OR them together you would use a single parameter with a comma separated list. So your code becomes

  const params = {
    parent,
    resourceType,
    date: [`le${end}`, `ge${start}`],
  };

As a side note, the behaviour of search with the resourceType parameter is undefined, the method you want is searchType. These look the same due to the way the code is generated, but they function slightly differently.

Nik Klassen
  • 681
  • 8
  • 16
  • Thanks, Nik! I have changed my code with your suggestion and it works great. Thanks for this detailed answer. – Jorge Luis Feb 07 '23 at 09:14