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());
}
}
}
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;
}
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;
}
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());
}
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());
}
Aggregations