Google Healthcare API Nodejs - Filter Appointment using start and end date

201 Views Asked by At

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!

2

There are 2 best solutions below

1
On BEST ANSWER

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.

0
On

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"