Search in sources :

Example 1 with RemotePatient

use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-mirebalais by PIH.

the class FindPatientPageController method saveToCache.

private void saveToCache(List<RemotePatient> remotePatients, HttpSession session) {
    Map<String, RemotePatient> mpiSearchResults = (Map<String, RemotePatient>) session.getAttribute(MirebalaisConstants.MPI_SEARCH_RESULTS);
    if (mpiSearchResults == null) {
        mpiSearchResults = new HashMap<String, RemotePatient>();
        session.setAttribute(MirebalaisConstants.MPI_SEARCH_RESULTS, mpiSearchResults);
    }
    if (remotePatients != null && remotePatients.size() > 0) {
        for (RemotePatient remotePatient : remotePatients) {
            mpiSearchResults.put(MirebalaisConstants.MPI_REMOTE_SERVER + ":" + remotePatient.getRemoteUuid(), remotePatient);
        }
    }
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RemotePatient

use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-mirebalais 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(MirebalaisConstants.MPI_SEARCH_RESULTS);
    if (mpiSearchResults != null && mpiSearchResults.size() > 0) {
        remotePatient = mpiSearchResults.get(MirebalaisConstants.MPI_REMOTE_SERVER + ":" + uuid);
    }
    return remotePatient;
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RemotePatient

use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-mirebalais by PIH.

the class FindPatientPageController method removeFromCache.

private RemotePatient removeFromCache(String uuid, HttpSession session) {
    RemotePatient remotePatient = null;
    Map<String, RemotePatient> mpiSearchResults = (Map<String, RemotePatient>) session.getAttribute(MirebalaisConstants.MPI_SEARCH_RESULTS);
    if (mpiSearchResults != null && mpiSearchResults.size() > 0) {
        String key = MirebalaisConstants.MPI_REMOTE_SERVER + ":" + uuid;
        remotePatient = mpiSearchResults.get(key);
        if (remotePatient != null) {
            mpiSearchResults.remove(key);
        }
    }
    return remotePatient;
}
Also used : RemotePatient(org.openmrs.module.importpatientfromws.RemotePatient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RemotePatient

use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-mirebalais 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 = MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.ZL_EMR_ID.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("mirebalais/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 5 with RemotePatient

use of org.openmrs.module.importpatientfromws.RemotePatient in project openmrs-module-pihcore by PIH.

the class FindPatientPageController method removeFromCache.

private RemotePatient removeFromCache(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) {
        String key = MPI_REMOTE_SERVER + ":" + uuid;
        remotePatient = mpiSearchResults.get(key);
        if (remotePatient != null) {
            mpiSearchResults.remove(key);
        }
    }
    return 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