1

Currently, I am fetching the list of Immunization resources for a Patient using the below code. Is this efficient method of fetching the data from FHIR Server? How to use the FHIRPATH in this case?

        // Create a client
        IGenericClient client = ctx.newRestfulGenericClient("https://hapi.fhir.org/baseR4");

        // Read a patient with the given ID
        Patient patient = client.read().resource(Patient.class).withId(patientId).execute();

        String id = patient.getId();

        List<IBaseResource> immunizations = new ArrayList<IBaseResource>();
        Bundle bundle = client.search().forResource(Immunization.class).where(Immunization.PATIENT.hasId(id))
                .returnBundle(Bundle.class).execute();
        immunizations.addAll(BundleUtil.toListOfResources(ctx, bundle));

        // Load the subsequent pages
        while (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
            bundle = client.loadPage().next(bundle).execute();
            immunizations.addAll(BundleUtil.toListOfResources(ctx, bundle));
        }

        String fhirResource = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
user1700138
  • 35
  • 2
  • 7

0 Answers0