Search in sources :

Example 61 with PatientIdentifier

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

the class IdCardFragmentController method recordSuccessfulPrintAttempt.

/**
 * This method takes in a patientId and an identifier and validates that this is a valid identifier for this patient
 * If it is valid, it will save an Observation to the patient record indicating that an id card was successfully printed
 * @return a SimpleObject containing a flag indicating success, and a message suitable for display
 */
public SimpleObject recordSuccessfulPrintAttempt(UiUtils ui, UiSessionContext uiSessionContext, @SpringBean EmrApiProperties emrApiProperties, @RequestParam("patientId") Patient patient, @RequestParam("identifier") String identifier) {
    StatusMessage status = new StatusMessage(false, ui.message("zl.registration.patient.idcard.invalidForPatient", identifier, ui.format(patient.getPersonName())));
    for (PatientIdentifier pi : patient.getIdentifiers()) {
        if (pi.getIdentifierType().getUuid().equals(emrApiProperties.getPrimaryIdentifierType().getUuid())) {
            if (pi.getIdentifier().equalsIgnoreCase(identifier)) {
                status = new StatusMessage(true, "");
                savePrintingStatusObs(patient, uiSessionContext.getSessionLocation(), true);
            }
        }
    }
    return SimpleObject.fromObject(status, ui, "success", "message");
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier)

Example 62 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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 63 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-module-coreapps by openmrs.

the class FindPatientFragmentController method simplify.

SimpleObject simplify(UiUtils ui, EmrApiProperties emrApiProperties, Patient patient) {
    PersonName name = patient.getPersonName();
    SimpleObject preferredName = SimpleObject.fromObject(name, ui, "givenName", "middleName", "familyName", "familyName2");
    preferredName.put("name", ui.format(name));
    PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
    List<PatientIdentifier> primaryIdentifiers = patient.getPatientIdentifiers(primaryIdentifierType);
    SimpleObject o = SimpleObject.fromObject(patient, ui, "patientId", "gender", "age", "birthdate", "birthdateEstimated");
    o.put("preferredName", preferredName);
    o.put("primaryIdentifiers", SimpleObject.fromCollection(primaryIdentifiers, ui, "identifier"));
    return o;
}
Also used : PersonName(org.openmrs.PersonName) SimpleObject(org.openmrs.ui.framework.SimpleObject) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 64 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceImpl method mergeIdentifiers.

private void mergeIdentifiers(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
    // (must be done after all calls to services above so hbm doesn't try to save things prematurely (hacky)
    for (PatientIdentifier pi : notPreferred.getActiveIdentifiers()) {
        PatientIdentifier tmpIdentifier = new PatientIdentifier();
        tmpIdentifier.setIdentifier(pi.getIdentifier());
        tmpIdentifier.setIdentifierType(pi.getIdentifierType());
        tmpIdentifier.setLocation(pi.getLocation());
        tmpIdentifier.setPatient(preferred);
        boolean found = false;
        for (PatientIdentifier preferredIdentifier : preferred.getIdentifiers()) {
            if (preferredIdentifier.getIdentifier() != null && preferredIdentifier.getIdentifier().equals(tmpIdentifier.getIdentifier()) && preferredIdentifier.getIdentifierType() != null && preferredIdentifier.getIdentifierType().equals(tmpIdentifier.getIdentifierType())) {
                found = true;
            }
        }
        if (!found) {
            tmpIdentifier.setIdentifierType(pi.getIdentifierType());
            tmpIdentifier.setCreator(Context.getAuthenticatedUser());
            tmpIdentifier.setDateCreated(new Date());
            tmpIdentifier.setVoided(false);
            tmpIdentifier.setVoidedBy(null);
            tmpIdentifier.setVoidReason(null);
            tmpIdentifier.setUuid(UUID.randomUUID().toString());
            // we don't want to change the preferred identifier of the preferred patient
            tmpIdentifier.setPreferred(false);
            preferred.addIdentifier(tmpIdentifier);
            mergedData.addCreatedIdentifier(tmpIdentifier.getUuid());
            log.debug("Merging identifier " + tmpIdentifier.getIdentifier() + " to " + preferred.getPatientId());
        }
    }
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date)

Example 65 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceImplTest method processDeath_shouldMapValuesAndSavePatient.

@Test
public void processDeath_shouldMapValuesAndSavePatient() throws Exception {
    // given
    final Date dateDied = new Date();
    final Concept causeOfDeath = new Concept(2);
    when(conceptServiceMock.getConcept(anyString())).thenReturn(new Concept());
    when(locationServiceMock.getDefaultLocation()).thenReturn(new Location());
    ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
    when(patientDaoMock.savePatient(argumentCaptor.capture())).thenReturn(new Patient());
    // when
    final Patient patient = new Patient();
    patient.addIdentifier(new PatientIdentifier("an identifier", new PatientIdentifierType(1234), new Location()));
    patientService.processDeath(patient, dateDied, causeOfDeath, "unknown");
    // then
    final Patient savedPatient = argumentCaptor.getValue();
    assertEquals(true, savedPatient.getDead());
    assertEquals(dateDied, savedPatient.getDeathDate());
    assertEquals(causeOfDeath, savedPatient.getCauseOfDeath());
}
Also used : Concept(org.openmrs.Concept) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)116 Test (org.junit.Test)91 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 PatientIdentifierType (org.openmrs.PatientIdentifierType)57 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)27 PersonName (org.openmrs.PersonName)24 Date (java.util.Date)19 PersonAddress (org.openmrs.PersonAddress)12 ArrayList (java.util.ArrayList)10 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3