Search code examples
searchhl7-fhirhapi-fhir

How to use fhir client search to include all resources i.e. ($everything)


How would you search for all resources for a given patient e.g. encounter, appointment, consent?

I know you could search for it via postman request http://localhost:9090/organId/Patient/12345/$everything and get the result. But I want to be able to execute the search query from my java program.

This is what I have so far, but I know the include part is not good and not working. Googling didn't return any result.

Bundle bundle = myFhirClient
                .search()
                .forResource(Patient.class)
                .returnBundle(Bundle.class)
                .where(new NumberClientParam(Patient.SP_RES_ID).exactly().number(patientId)).include(new Include("$everything"))
                .sort(new SortSpec().setOrder(SortOrderEnum.DESC).setParamName(Patient.SP_RES_ID))
                .execute();

Any help is much appreciated


Solution

  • I had to use Fhir Client operation instead of search. This will return all the reference resources for the given patientId.

    Parameters outParams = myFhirClient
                        .operation()
                        .onInstance(new IdType("Patient", patientId))
                        .named("$everything")
                        .withNoParameters(Parameters.class) // No input parameters
                        .execute();