Search in sources :

Example 66 with PersonName

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

the class PatientServiceImpl method mergeNames.

private void mergeNames(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 (PersonName newName : notPreferred.getNames()) {
        boolean containsName = false;
        for (PersonName currentName : preferred.getNames()) {
            containsName = currentName.equalsContent(newName);
            if (containsName) {
                break;
            }
        }
        if (!containsName) {
            PersonName tmpName = constructTemporaryName(newName);
            preferred.addName(tmpName);
            mergedData.addCreatedName(tmpName.getUuid());
            log.debug("Merging name " + newName.getGivenName() + " to " + preferred.getPatientId());
        }
    }
}
Also used : PersonName(org.openmrs.PersonName)

Example 67 with PersonName

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

the class PatientServiceImpl method constructTemporaryName.

private PersonName constructTemporaryName(PersonName newName) {
    PersonName tmpName = PersonName.newInstance(newName);
    tmpName.setPersonNameId(null);
    tmpName.setVoided(false);
    tmpName.setVoidedBy(null);
    tmpName.setVoidReason(null);
    // we don't want to change the preferred name of the preferred patient
    tmpName.setPreferred(false);
    tmpName.setUuid(UUID.randomUUID().toString());
    return tmpName;
}
Also used : PersonName(org.openmrs.PersonName)

Example 68 with PersonName

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

the class PersonServiceImpl method parsePersonName.

/**
 * @see org.openmrs.api.PersonService#parsePersonName(java.lang.String)
 */
@Override
public PersonName parsePersonName(String name) throws APIException {
    // strip beginning/ending whitespace
    name = name.trim();
    // trim off all trailing commas
    while (name.endsWith(",")) {
        name = name.substring(0, name.length() - 1);
    }
    String firstName = name;
    String middleName = "";
    String lastName = "";
    String lastName2 = null;
    if (name.contains(",")) {
        String[] names = name.split(",");
        // trim whitespace on each part of the name
        for (int x = 0; x < names.length; x++) {
            names[x] = names[x].trim();
        }
        String[] firstNames = names[1].split(" ");
        if (firstNames.length == 2) {
            // user entered "Smith, John Adam"
            lastName = names[0];
            firstName = firstNames[0];
            middleName = firstNames[1];
        } else {
            // user entered "Smith, John"
            firstName = names[1];
            lastName = names[0];
        }
    } else if (name.contains(" ")) {
        String[] names = name.split(" ");
        if (names.length == 4) {
            // user entered "John Adam Smith"
            firstName = names[0];
            middleName = names[1];
            lastName = names[2];
            lastName2 = names[3];
        } else if (names.length == 3) {
            // user entered "John Adam Smith"
            firstName = names[0];
            middleName = names[1];
            lastName = names[2];
        } else {
            // user entered "John Smith"
            firstName = names[0];
            lastName = names[1];
        }
    }
    PersonName pn = new PersonName(firstName, middleName, lastName);
    pn.setFamilyName2(lastName2);
    return pn;
}
Also used : PersonName(org.openmrs.PersonName)

Example 69 with PersonName

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

the class PatientServiceTest method mergePatients_shouldAuditPriorCauseOfDeath.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldAuditPriorCauseOfDeath() throws Exception {
    // retrieve preferred patient and set a cause of death
    Patient preferred = patientService.getPatient(999);
    preferred.setCauseOfDeath(Context.getConceptService().getConcept(3));
    preferred.setDeathDate(new Date());
    preferred.setDead(true);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    // merge with not preferred
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertEquals("prior cause of death was not audited", Context.getConceptService().getConcept(3).getUuid(), audit.getPersonMergeLogData().getPriorCauseOfDeath());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 70 with PersonName

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

the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfDeathEstimated.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldAuditPriorDateOfDeathEstimated() throws Exception {
    // retrieve preferred patient and set a date of death
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    Patient preferred = patientService.getPatient(999);
    preferred.setDeathDate(cDate.getTime());
    preferred.setDeathdateEstimated(true);
    preferred.setCauseOfDeath(Context.getConceptService().getConcept(3));
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertTrue("prior estimated date of death was not audited", audit.getPersonMergeLogData().getPriorDateOfDeathEstimated());
}
Also used : PersonName(org.openmrs.PersonName) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PersonName (org.openmrs.PersonName)108 Test (org.junit.Test)81 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)57 Patient (org.openmrs.Patient)41 Person (org.openmrs.Person)39 Date (java.util.Date)26 PatientIdentifier (org.openmrs.PatientIdentifier)19 PersonAddress (org.openmrs.PersonAddress)19 User (org.openmrs.User)17 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)17 PatientIdentifierType (org.openmrs.PatientIdentifierType)13 Location (org.openmrs.Location)12 ArrayList (java.util.ArrayList)9 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)9 PersonMergeLog (org.openmrs.person.PersonMergeLog)8 PersonAttribute (org.openmrs.PersonAttribute)7 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)6 Provider (org.openmrs.Provider)5