0

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

Rasoul
  • 167
  • 1
  • 2
  • 9
  • The request http://localhost:9090/organId/Patient/12345/$everything isn't a search, it's a separate operation https://hl7.org/fhir/patient-operation-everything.html. What FHIR client are you using? It should have a way of performing this request. – Nik Klassen Oct 27 '22 at 16:13
  • Thanks Nik. I’m using Hapi fhir client – Rasoul Oct 27 '22 at 16:22

1 Answers1

0

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();
Rasoul
  • 167
  • 1
  • 2
  • 9