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.unmarshall.dstu2;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
import gov.va.med.pbm.ampl.fhir.client.Dstu2Client;
import gov.va.med.pbm.ampl.fhir.unmarshall.AbstractUnmarshaller;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.unbundle.UnbundlePatient;
import gov.va.med.pbm.ampl.model.Consult;
import gov.va.med.pbm.ampl.model.patientdemographics.PatientDetails;
import gov.va.med.pbm.ampl.utility.ESAPIValidationType;
import gov.va.med.pbm.ampl.utility.ESAPIValidator;
import gov.va.med.pbm.ampl.utility.operations.SortOperation;
/**
* The UnmarshallPatient class marshals the FHIR Patient resource to a client readable JSON format.
*
* @author Ian Meinert
*
*/
public class UnmarshallPatient extends AbstractUnmarshaller<PatientDetails> {
private UnmarshallEncounter patientEncounters;
/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(UnmarshallPatient.class);
/**
* The default constructor for the UnmarshallPatient class.
*/
public UnmarshallPatient() {
super();
}
/**
* The overloaded constructor accepting the Dstu2Client, patient Id, search term, and sort term.
* <p>
* The constructor also passes these parameters to the super class, along with the PatientDetails class definition.
*
* @param client the DSTU2 client
* @param patientId the patient id
* @param searchTerm the search field, operation, and value
* @param sortTerm the field and direction to sort
*/
public UnmarshallPatient(Dstu2Client client, String patientId, Optional<String> searchTerm, Optional<String> sortTerm) {
super(client, patientId, searchTerm, sortTerm);
try {
// Task the Encounter unmarshaler to return the encounters
patientEncounters = new UnmarshallEncounter(client, patientId, Optional.of(new String()),
Optional.of(new String()));
patientEncounters.getAllPatientsById();
// sort the collection so the latest entry is first out.
SortOperation<Consult> sorter = new SortOperation<Consult>();
sorter.setSortParams("provisionalDiagnosisDate[DESC]");
patientEncounters.setCollection(sorter.sort(patientEncounters.getCollection()));
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
}
/**
* The overloaded constructor accepting the Dstu2Client, patient Id, search term, sort term, size, and page.
* <p>
* The constructor also passes these parameters to the super class, along with the class definition.
*
* @param client the DSTU2 client
* @param patientId the patient id
* @param searchTerm the search field, operation, and value
* @param sortTerm the field and direction to sort
* @param size the limit of the results per page
* @param page the page number for the results
*/
public UnmarshallPatient(Dstu2Client client, String patientId, Optional<String> searchTerm, Optional<String> sortTerm,
Optional<Integer> page, Optional<Integer> size) {
super(client, patientId, searchTerm, sortTerm, page, size);
try {
// Task the Encounter unmarshaler to return the allergies
patientEncounters = new UnmarshallEncounter(client, patientId, Optional.of(new String()),
Optional.of(new String()));
patientEncounters.getAllPatientsById();
// sort the collection so the latest entry is first out.
SortOperation<Consult> sorter = new SortOperation<Consult>();
sorter.setSortParams("provisionalDiagnosisDate[DESC]");
patientEncounters.setCollection(sorter.sort(patientEncounters.getCollection()));
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
}
/**
* This method queries the FHIR server for all patients that match the patient Id.
*/
@Override
public void getAllPatientsById() {
LOGGER.debug("Getting the PatientDetails from the Marshaled client");
Collection<PatientDetails> patientDetailsCollection = new ArrayList<PatientDetails>();
Collection<Consult> consults = patientEncounters.getCollection();
Optional<Bundle> optBundle = Optional.ofNullable(super.getClient().searchPatientById(ESAPIValidator.validateStringInput(this.getPatientId(), ESAPIValidationType.CROSS_SITE_SCRIPTING_REFLECTED)));
if (optBundle.isPresent()) {
List<Entry> entries = optBundle.get().getEntry();
UnbundlePatient unbundledPatient = new UnbundlePatient(entries);
patientDetailsCollection = unbundledPatient.getEntries(consults);
}
LOGGER.debug("Storing {} record(s)", patientDetailsCollection.size());
super.setCollection(patientDetailsCollection);
}
}