use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PersonMergeLogValidatorTest method validate_shouldFailValidationIfPersonMergeLogDataIsNull.
/**
* @see PersonMergeLogValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfPersonMergeLogDataIsNull() {
PersonMergeLog personMergeLog = new PersonMergeLog();
personMergeLog.setWinner(new Person());
personMergeLog.setLoser(new Person());
PersonMergeLogValidator validator = new PersonMergeLogValidator();
Errors errors = new BindException(personMergeLog, "personMergeLog");
validator.validate(personMergeLog, errors);
Assert.assertTrue(errors.hasFieldErrors("personMergeLogData"));
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedNames.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditCreatedNames() throws Exception {
// retrieve preferred patient
Patient preferred = patientService.getPatient(999);
// retrieve notPreferredPatient and save it with an added name
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
PersonName name = new PersonName("first1234", "middle", "last1234");
notPreferred.addName(name);
patientService.savePatient(notPreferred);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// find the UUID of the name that was added by the merge
String addedNameUuid = null;
preferred = patientService.getPatient(999);
for (PersonName n : preferred.getNames()) {
if (n.getFullName().equals(name.getFullName())) {
addedNameUuid = n.getUuid();
}
}
Assert.assertNotNull("expected new name was not found in the preferred patient after the merge", addedNameUuid);
Assert.assertTrue("person name creation not audited", isValueInList(addedNameUuid, audit.getPersonMergeLogData().getCreatedNames()));
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedAddresses.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditCreatedAddresses() throws Exception {
// retrieve preferred patient
Patient preferred = patientService.getPatient(999);
// retrieve notPreferredPatient and save it with a new address
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
PersonAddress address = new PersonAddress();
address.setAddress1("another address123");
address.setAddress2("another address234");
address.setCityVillage("another city");
address.setCountry("another country");
notPreferred.addAddress(address);
patientService.savePatient(notPreferred);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// find the UUID of the address that was added by the merge
String addedAddressUuid = null;
preferred = patientService.getPatient(999);
for (PersonAddress a : preferred.getAddresses()) {
if (a.getAddress1().equals(address.getAddress1())) {
addedAddressUuid = a.getUuid();
}
}
Assert.assertNotNull("expected new address was not found in the preferred patient after the merge", addedAddressUuid);
Assert.assertTrue("person address creation not audited", isValueInList(addedAddressUuid, audit.getPersonMergeLogData().getCreatedAddresses()));
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfBirthEstimated.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfBirthEstimated() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
Patient preferred = patientService.getPatient(999);
preferred.setBirthdate(cDate.getTime());
preferred.setBirthdateEstimated(true);
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 birth was not audited", audit.getPersonMergeLogData().isPriorDateOfBirthEstimated());
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedAttributes.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditCreatedAttributes() throws Exception {
// retrieve preferred patient
Patient preferred = patientService.getPatient(999);
// retrieve notPreferredPatient and save it with a new attribute
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
PersonAttribute attribute = new PersonAttribute(2);
attribute.setValue("5089");
attribute.setAttributeType(personService.getPersonAttributeType(1));
notPreferred.addAttribute(attribute);
patientService.savePatient(notPreferred);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// find the UUID of the attribute that was added by the merge
String addedAttributeUuid = null;
preferred = patientService.getPatient(999);
for (PersonAttribute a : preferred.getAttributes()) {
if (a.getValue().equals(attribute.getValue())) {
addedAttributeUuid = a.getUuid();
}
}
Assert.assertNotNull("expected new attribute was not found in the preferred patient after the merge", addedAttributeUuid);
Assert.assertTrue("person attribute creation not audited", isValueInList(addedAttributeUuid, audit.getPersonMergeLogData().getCreatedAttributes()));
}
Aggregations