Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.pbm.ampl.fhir.client;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.dstu2.resource.AllergyIntolerance;
import ca.uhn.fhir.model.dstu2.resource.Appointment;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Condition;
import ca.uhn.fhir.model.dstu2.resource.DocumentReference;
import ca.uhn.fhir.model.dstu2.resource.Encounter;
import ca.uhn.fhir.model.dstu2.resource.Immunization;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
import ca.uhn.fhir.rest.gclient.ICriterion;
import ca.uhn.fhir.rest.gclient.StringClientParam;
import gov.va.med.pbm.ampl.configuration.FhirConfiguration;
/**
* This is the HAPI Client used to query the DSTU2 specification of a FHIR server.
*
* @author Ian Meinert
* @author AJ Magdub
* @since 1.0
*/
public class Dstu2Client extends AbstractFhirClient implements IFhirClient {
/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(Dstu2Client.class);
/**
* The Dstu2Client default constructor which passes the server URI and FHIR context to the super class.
*
* @param fhirConfiguration the {@link FhirConfiguration}
* @throws IOException which was raised by the {@link AbstractFhirClient}
*/
public Dstu2Client(FhirConfiguration fhirConfiguration) {
super(FhirContext.forDstu2(), fhirConfiguration);
}
/**
* Searches the FHIR context for a {@link Patient} with a given id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchPatientById(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
// the RES_ID should be the patient ID
bundle = super.getClient().search().forResource(Patient.class).where(Patient.RES_ID.matches().value(id))
// These includes currently produce [HTTP 400 Bad Request: Invalid request URL parameter _include specified]
// .include(new Include("Patient:careprovider"))
// .include(new Include("Patient:link"))
// .include(new Include("Patient:organization"))
.where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link AllergyIntolerance} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchAllergiesByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(AllergyIntolerance.class)
.where(new StringClientParam("patient").matches().value(id)).include(new Include("AllergyIntolerance:patient"))
.include(new Include("AllergyIntolerance:recorder")).include(new Include("AllergyIntolerance:reporter"))
.where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link DocumentReference} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchProgressNotesByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(DocumentReference.class)
.where(new StringClientParam("patient").matches().value(id))
.include(new Include("DocumentReference:authenticator")).include(new Include("DocumentReference:author"))
.include(new Include("DocumentReference:custodian")).include(new Include("DocumentReference:encounter"))
.include(new Include("DocumentReference:patient")).include(new Include("DocumentReference:related-ref"))
.include(new Include("DocumentReference:relatesto")).include(new Include("DocumentReference:subject"))
.where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link Observation} with a given patient id.
* <p>
* This filters a {@link Bundle} of {@link Observation} not associated with vitals.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchMeasurementsByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(Observation.class)
.where(new StringClientParam("patient").matches().value(id)).include(new Include("Observation:device"))
.include(new Include("Observation:encounter")).include(new Include("Observation:patient"))
.include(new Include("Observation:performer")).include(new Include("Observation:related-target"))
.include(new Include("Observation:specimen")).include(new Include("Observation:subject")).where(criterion)
.returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link Encounter} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchConsultsByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(Encounter.class)
.where(new StringClientParam("patient").matches().value(id)).include(new Include("Encounter:condition"))
.include(new Include("Encounter:episodeofcare")).include(new Include("Encounter:incomingreferral"))
.include(new Include("Encounter:indication")).include(new Include("Encounter:location"))
.include(new Include("Encounter:part-of")).include(new Include("Encounter:participant"))
.include(new Include("Encounter:patient")).include(new Include("Encounter:practitioner"))
.include(new Include("Encounter:procedure"))
// .include(new Include("Encounter:serviceprovider")) XXX Has reference, but include not provided in DSTU2 API
.where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link Immunization} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchImmunizationsByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(Immunization.class)
.where(new StringClientParam("patient").matches().value(id)).include(new Include("Immunization:location"))
.include(new Include("Immunization:manufacturer")).include(new Include("Immunization:patient"))
.include(new Include("Immunization:performer")).include(new Include("Immunization:reaction"))
.include(new Include("Immunization:requester")).where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link Condition} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchProblemListByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(Condition.class)
.where(new StringClientParam("patient").matches().value(id)).include(new Include("Condition:asserter"))
.include(new Include("Condition:encounter")).include(new Include("Condition:patient")).where(criterion)
.returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
/**
* Searches the FHIR context for a {@link Patient} {@link Appointment} with a given patient id.
*
* @param id the patient id
* @return HAPI Bundle in a JSON string
*/
@Override
public Bundle searchAppointmentsByPatientId(String id) {
ICriterion<StringClientParam> criterion = super.generateSessionParameterMap();
Bundle bundle = new Bundle();
try {
bundle = super.getClient().search().forResource(Appointment.class)
.where(new StringClientParam("patient").matches().value(id))
.include(new Include("Appointment:actor"))
.include(new Include("Appointment:location"))
.include(new Include("Appointment:practitioner"))
.where(criterion).returnBundle(Bundle.class).execute();
} catch (FhirClientConnectionException e) {
LOGGER.error(e.getMessage());
}
return bundle;
}
}