Search in sources :

Example 1 with ReferenceClientParam

use of ca.uhn.fhir.rest.gclient.ReferenceClientParam in project loinc2hpo by monarch-initiative.

the class FhirResourceRetriever method retrieveObservationFromServer.

/**
 * @TODO: implement it
 * retrieve a patient's observations from FHIR server
 * @param patient
 * @return
 */
public static List<Observation> retrieveObservationFromServer(Patient patient) {
    List<Observation> observationList = new ArrayList<>();
    String id = patient.getId();
    if (id != null) {
        Bundle observationBundle = client.search().forResource(Observation.class).where(new ReferenceClientParam("subject").hasId(id)).prettyPrint().returnBundle(Bundle.class).execute();
        while (true) {
            observationBundle.getEntry().forEach(p -> observationList.add((Observation) p.getResource()));
            if (observationBundle.getLink(IBaseBundle.LINK_NEXT) != null) {
                observationBundle = client.loadPage().next(observationBundle).execute();
            } else {
                break;
            }
        }
    }
    return observationList;
}
Also used : IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList) ReferenceClientParam(ca.uhn.fhir.rest.gclient.ReferenceClientParam)

Aggregations

ReferenceClientParam (ca.uhn.fhir.rest.gclient.ReferenceClientParam)1 ArrayList (java.util.ArrayList)1 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)1