Search in sources :

Example 6 with RemotePatient

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");
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HttpSession(javax.servlet.http.HttpSession) RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 7 with RemotePatient

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;
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with 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);
        }
    }
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RemotePatient (org.openmrs.module.importpatientfromws.RemotePatient)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 HttpSession (javax.servlet.http.HttpSession)2 Patient (org.openmrs.Patient)2 PatientIdentifier (org.openmrs.PatientIdentifier)2 PatientIdentifierType (org.openmrs.PatientIdentifierType)2