use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfBirth.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfBirth() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
// milliseconds are not serialized into the database. they will be ignored in the test
cDate.set(Calendar.MILLISECOND, 0);
Patient preferred = patientService.getPatient(999);
preferred.setBirthdate(cDate.getTime());
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.assertEquals("prior date of birth was not audited", cDate.getTime(), audit.getPersonMergeLogData().getPriorDateOfBirth());
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfDeath.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfDeath() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
// milliseconds are not serialized into the database. they will be ignored in the test
cDate.set(Calendar.MILLISECOND, 0);
Patient preferred = patientService.getPatient(999);
preferred.setDeathDate(cDate.getTime());
preferred.setDead(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.assertEquals("prior date of death was not audited", cDate.getTime(), audit.getPersonMergeLogData().getPriorDateOfDeath());
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorGender.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorGender() throws Exception {
// retrieve preferred patient and set gender
Patient preferred = patientService.getPatient(999);
preferred.setGender("M");
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 gender was not audited", "M", audit.getPersonMergeLogData().getPriorGender());
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers() throws Exception {
List<Location> locations = Context.getLocationService().getAllLocations();
Assert.assertTrue(CollectionUtils.isNotEmpty(locations));
// check if we have patient identifiers already
PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierType(5);
Assert.assertNotNull(patientIdentifierType);
// retrieve preferred patient and set gender
Patient preferred = patientService.getPatient(999);
// create new identifier for the preferred patient
PatientIdentifier preferredIdentifier = new PatientIdentifier();
preferredIdentifier.setIdentifier("9999-4");
preferredIdentifier.setIdentifierType(patientIdentifierType);
preferredIdentifier.setLocation(locations.get(0));
preferred.addIdentifier(preferredIdentifier);
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
// merge with not preferred
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
// create identifier with the same values for the non preferred patient
PatientIdentifier nonPreferredIdentifier = new PatientIdentifier();
nonPreferredIdentifier.setIdentifier("9999-4");
nonPreferredIdentifier.setIdentifierType(patientIdentifierType);
nonPreferredIdentifier.setLocation(locations.get(0));
notPreferred.addIdentifier(nonPreferredIdentifier);
patientService.savePatient(notPreferred);
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// should not copy the duplicate identifier to the winner
Assert.assertEquals(notPreferred.getIdentifiers().size() - 1, audit.getPersonMergeLogData().getCreatedIdentifiers().size());
}
use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditMovedUsers.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditMovedUsers() throws Exception {
// retrieve patients
Patient preferred = patientService.getPatient(999);
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
User user = Context.getUserService().getUser(501);
user.setPerson(notPreferred);
Context.getUserService().saveUser(user);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
Assert.assertTrue("user association change not audited", isValueInList(Context.getUserService().getUser(501).getUuid(), audit.getPersonMergeLogData().getMovedUsers()));
}
Aggregations