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.controller;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import org.owasp.esapi.ESAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
import gov.va.med.pbm.ampl.configuration.FhirConfiguration;
import gov.va.med.pbm.ampl.constant.AmplConstants;
import gov.va.med.pbm.ampl.constant.RestUriConstants;
import gov.va.med.pbm.ampl.fhir.client.Dstu2Client;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallAllergyIntolerance;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallAppointment;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallCondition;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallDocumentReference;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallEncounter;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallImmunization;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallObservation;
import gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.UnmarshallPatient;
import gov.va.med.pbm.ampl.model.Allergy;
import gov.va.med.pbm.ampl.model.Appointment;
import gov.va.med.pbm.ampl.model.Consult;
import gov.va.med.pbm.ampl.model.Immunization;
import gov.va.med.pbm.ampl.model.Measurement;
import gov.va.med.pbm.ampl.model.Problem;
import gov.va.med.pbm.ampl.model.ProgressNote;
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.comparator.AmplComparator;
/**
*
* This Controller class consists exclusively of methods that support the RESTful service for a {@link Patient} retrieved from
* HL7 FHIR DSTU2.
*
* @author Ian Meinert
* @author Asli Goncer
* @since 1.0
*
*/
@RestController
@RequestMapping(value = "/dstu2/v1/patients", produces = { "application/json" })
public class Dstu2Controller implements IBaseController {
/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(Dstu2Controller.class);
@Autowired
private FhirConfiguration fhirConfiguration;
/**
* Get method mapped to return the {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_ROOT)
public ResponseEntity<Object> getPatientById(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Collection<PatientDetails> patientDetails = new ArrayList<PatientDetails>();
Dstu2Client client = new Dstu2Client(fhirConfiguration);
try {
UnmarshallPatient unmarshaller = new UnmarshallPatient();
unmarshaller = new UnmarshallPatient(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
patientDetails = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(patientDetails, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link PatientAllergy} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_ALLERGIES)
public ResponseEntity<Object> getAllergiesByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Allergy> allergies = new ArrayList<Allergy>();
try {
UnmarshallAllergyIntolerance unmarshaller = new UnmarshallAllergyIntolerance(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.sortAllergyAssessment();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
allergies = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(allergies, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link ProgressNote} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_PROGRESS_NOTES)
public ResponseEntity<Object> getProgressNotesByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<ProgressNote> progressNotes = new ArrayList<ProgressNote>();
try {
UnmarshallDocumentReference unmarshaller = new UnmarshallDocumentReference(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
progressNotes = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(progressNotes, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link Consult} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_CONSULTS)
public ResponseEntity<Object> getConsultsByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Consult> consults = new ArrayList<Consult>();
try {
UnmarshallEncounter unmarshaller = new UnmarshallEncounter(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
consults = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(consults, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link Immunization} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_IMMUNIZATIONS)
public ResponseEntity<Object> getImmunizationsByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Immunization> immunizations = new ArrayList<Immunization>();
try {
UnmarshallImmunization unmarshaller = new UnmarshallImmunization(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
immunizations = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(immunizations, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link Problem} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_PROBLEM_LIST)
public ResponseEntity<Object> getProblemListByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Problem> problem = new ArrayList<Problem>();
try {
UnmarshallCondition unmarshaller = new UnmarshallCondition(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.sortCommentsByDateDesc();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
problem = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(problem, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link Appointment} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_APPOINTMENTS)
public ResponseEntity<Object> getAppointmentsByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Appointment> appointment = new ArrayList<Appointment>();
try {
UnmarshallAppointment unmarshaller = new UnmarshallAppointment(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
appointment = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(appointment, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link } for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param sort Comma-delimited list of field[value] pairs to filter results
* @param search Comma-delimited list of field, {@link AmplComparator}, value string to filter results
* @param size number of results to return per page. Default is 25
* @param page For paging, the page of size results to return. Default is 1.
* @return
*/
@Override
@GetMapping(RestUriConstants.GET_MEASUREMENTS)
public ResponseEntity<Object> getMeasurementsByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("sort") Optional<String> sort, @RequestParam("search") Optional<String> search,
@RequestParam("size") Optional<Integer> size, @RequestParam("page") Optional<Integer> page) {
Collection<Measurement> measurements = new ArrayList<Measurement>();
Dstu2Client client = new Dstu2Client(fhirConfiguration);
try {
UnmarshallObservation unmarshaller = new UnmarshallObservation(client, patientId, search, sort);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.sort();
unmarshaller.setPage(page.isPresent() ? page : Optional.of(1));
unmarshaller.setSize(size.isPresent() ? size : Optional.of(AmplConstants.DEFAULT_PAGE_SIZE));
unmarshaller.paginate();
measurements = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(measurements, HttpStatus.OK);
}
/**
* Get method mapped to return a collection of {@link Measurement} for a {@link PatientDetails}.
*
* @param patientId ID of patient to return
* @param search the searchable field, {@link AmplComparator}, value
* @return ResponseEntity
*/
@Override
@GetMapping(RestUriConstants.GET_LAST_MEASURES)
public ResponseEntity<Object> getMeasurementsLastMeasureByPatientId(@PathVariable("patientId") String patientId,
@RequestParam("search") Optional<String> search) {
if (!search.isPresent()) {
return new ResponseEntity<Object>("Missing required parameters", HttpStatus.BAD_REQUEST);
}
Dstu2Client client = new Dstu2Client(fhirConfiguration);
Collection<Measurement> measurements = new ArrayList<Measurement>();
try {
UnmarshallObservation unmarshaller = new UnmarshallObservation(client, patientId, search, null);
unmarshaller.getAllPatientsById();
unmarshaller.search();
unmarshaller.getMeasuresLast();
measurements = unmarshaller.getCollection();
} catch (FhirClientConnectionException e) {
LOGGER.error("An error with the FHIR client connection occurred", e);
}
return new ResponseEntity<Object>(measurements, HttpStatus.OK);
}
}