use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-pihcore by PIH.
the class FindPatientPageController method post.
public String post(@RequestParam(required = false, value = "remoteServer") String remoteServer, @RequestParam("remoteUuid") String remoteUuid, UiUtils ui, HttpServletRequest request) {
if (StringUtils.isNotBlank(remoteUuid)) {
HttpSession session = request.getSession();
RemotePatient remotePatient = getFromCache(remoteUuid, session);
if (remotePatient != null) {
// import the patient
try {
Patient patient = remotePatient.getPatient();
PatientIdentifierType zlIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid(ZlConfigConstants.PATIENTIDENTIFIERTYPE_ZLEMRID_UUID);
if (zlIdentifierType != null && patient != null) {
PatientIdentifier patientIdentifier = patient.getPatientIdentifier(zlIdentifierType);
if (patientIdentifier != null) {
patientIdentifier.setPreferred(true);
}
}
patient = Context.getPatientService().savePatient(patient);
if (patient != null) {
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("mirebalais.mpi.import.success", ui.format(patient)));
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
removeFromCache(remoteUuid, session);
return "redirect:" + ui.pageLink("coreapps", "patientdashboard/patientDashboard?patientId=" + patient.getId().toString());
}
} catch (Exception e) {
log.error("failed to import patient", e);
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, ui.message("mirebalais.mpi.import.error", e.getMessage()));
}
}
}
return "redirect:" + ui.pageLink("pihcore/mpi", "findPatient");
}
use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-pihcore by PIH.
the class FindPatientPageController method getFromCache.
private RemotePatient getFromCache(String uuid, HttpSession session) {
RemotePatient remotePatient = null;
Map<String, RemotePatient> mpiSearchResults = (Map<String, RemotePatient>) session.getAttribute(MPI_SEARCH_RESULTS);
if (mpiSearchResults != null && mpiSearchResults.size() > 0) {
remotePatient = mpiSearchResults.get(MPI_REMOTE_SERVER + ":" + uuid);
}
return remotePatient;
}
use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-pihcore by PIH.
the class FindPatientPageController method saveToCache.
private void saveToCache(List<RemotePatient> remotePatients, HttpSession session) {
Map<String, RemotePatient> mpiSearchResults = (Map<String, RemotePatient>) session.getAttribute(MPI_SEARCH_RESULTS);
if (mpiSearchResults == null) {
mpiSearchResults = new HashMap<String, RemotePatient>();
session.setAttribute(MPI_SEARCH_RESULTS, mpiSearchResults);
}
if (remotePatients != null && remotePatients.size() > 0) {
for (RemotePatient remotePatient : remotePatients) {
mpiSearchResults.put(MPI_REMOTE_SERVER + ":" + remotePatient.getRemoteUuid(), remotePatient);
}
}
}
Aggregations