Search in sources :

Example 31 with PersonMergeLog

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

Example 32 with PersonMergeLog

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

Example 33 with PersonMergeLog

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());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 34 with PersonMergeLog

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());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 35 with PersonMergeLog

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()));
}
Also used : User(org.openmrs.User) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PersonMergeLog (org.openmrs.person.PersonMergeLog)41 Test (org.junit.Test)37 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)37 Patient (org.openmrs.Patient)18 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)18 Person (org.openmrs.Person)9 PersonName (org.openmrs.PersonName)8 PersonMergeLogData (org.openmrs.person.PersonMergeLogData)8 Date (java.util.Date)6 BindException (org.springframework.validation.BindException)6 Errors (org.springframework.validation.Errors)6 GregorianCalendar (java.util.GregorianCalendar)4 Location (org.openmrs.Location)2 Obs (org.openmrs.Obs)2 PatientIdentifier (org.openmrs.PatientIdentifier)2 PersonAddress (org.openmrs.PersonAddress)2 PersonAttribute (org.openmrs.PersonAttribute)2 ArrayList (java.util.ArrayList)1 Encounter (org.openmrs.Encounter)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1