FHIR Chat · How to dynamically specify client search criteria? · hapi

Stream: hapi

Topic: How to dynamically specify client search criteria?


view this post on Zulip Volker Wick (Aug 21 2020 at 05:01):

I am implementing a FHIR server where I need to delegate a patient search query to another server backend. The server function that implements this search is called with three parameters family, given (both StringParam) and a birthday (DateParam)

My delegation code I have envisioned looks something like this ...

return fhirContext.newRestfulGenericClient(backendInstance)
    .search()
    .forResource(Patient.class)
    .where(criteria)   // ??? can't use .where(Patient.FAMILY.matches().value(family.getValue()))
    .execute();

However, I am not sure about how to fill the criteria parameter. Depending on whether family, given and birthday are present, criteria should be set accordingly. (That's why I can't use Patient.FAMILY.matches() ... or other similar functions here)

I did not get very far with the implementation of where() that accepts an ICriterion<...> object and was considering the alternative where() that takes a Map<String, List<IQueryParameterType>>

Here is the code that sets up the criteria HashMap as I would guess how it might work. Unfortunately I am probably missing something as my code does not yield any results (unless my search criteria are all empty):

    // family is a StringParam
    Map<String, List<IQueryParameterType>> criteria = new HashMap<>();
    if (family != null && !family.isEmpty()) {
        criteria.put("family",  Arrays.asList(family));
    }

Can somebody point me in the right direction or post a documentation link that clears this up?

view this post on Zulip Volker Wick (Aug 21 2020 at 12:02):

Ok, so it turns out it works pretty much as I had outlined it in my question. A bug in my test backend had sent me on a wild goose chase and the approach was ok all along.

One additional point to note is that the string keys in the criteria map must match the corresponding search parameters, i.e. "family", "given" and "birthdate".


Last updated: Apr 12 2022 at 19:14 UTC