Search in sources :

Example 16 with PersonMergeLog

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 17 with PersonMergeLog

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

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()));
}
Also used : PersonAddress(org.openmrs.PersonAddress) 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 19 with PersonMergeLog

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

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()));
}
Also used : Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PersonAttribute(org.openmrs.PersonAttribute) 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