Search in sources :

Example 36 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PatientServiceTest method mergePatients_shouldAuditCreatedIdentifiers.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldAuditCreatedIdentifiers() throws Exception {
    // retrieve preferred patient
    Patient preferred = patientService.getPatient(999);
    // retrieve notPreferredPatient and save it with a new identifier
    Patient notPreferred = patientService.getPatient(2);
    voidOrders(Collections.singleton(notPreferred));
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("123-0");
    patientIdentifier.setIdentifierType(patientService.getPatientIdentifierType(5));
    patientIdentifier.setLocation(new Location(1));
    notPreferred.addIdentifier(patientIdentifier);
    patientService.savePatient(notPreferred);
    // merge the two patients and retrieve the audit object
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    // find the UUID of the identifier that was added by the merge
    String addedIdentifierUuid = null;
    preferred = patientService.getPatient(999);
    for (PatientIdentifier id : preferred.getIdentifiers()) {
        if (id.getIdentifier().equals(patientIdentifier.getIdentifier())) {
            addedIdentifierUuid = id.getUuid();
        }
    }
    Assert.assertNotNull("expected new identifier was not found in the preferred patient after the merge", addedIdentifierUuid);
    Assert.assertTrue("person identifier creation not audited", isValueInList(addedIdentifierUuid, audit.getPersonMergeLogData().getCreatedIdentifiers()));
}
Also used : Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 37 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidatorTest method validate_shouldFailValidationIfWinnerIsNull.

/**
 * @see PersonMergeLogValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfWinnerIsNull() {
    PersonMergeLog personMergeLog = new PersonMergeLog();
    personMergeLog.setLoser(new Person());
    personMergeLog.setPersonMergeLogData(new PersonMergeLogData());
    PersonMergeLogValidator validator = new PersonMergeLogValidator();
    Errors errors = new BindException(personMergeLog, "personMergeLog");
    validator.validate(personMergeLog, errors);
    Assert.assertTrue(errors.hasFieldErrors("winner"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PersonMergeLogValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    PersonMergeLog personMergeLog = new PersonMergeLog();
    personMergeLog.setWinner(new Person());
    personMergeLog.setLoser(new Person());
    personMergeLog.setPersonMergeLogData(new PersonMergeLogData());
    personMergeLog.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    PersonMergeLogValidator validator = new PersonMergeLogValidator();
    Errors errors = new BindException(personMergeLog, "personMergeLog");
    validator.validate(personMergeLog, errors);
    Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 39 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see PersonMergeLogValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    PersonMergeLog personMergeLog = new PersonMergeLog();
    personMergeLog.setWinner(new Person());
    personMergeLog.setLoser(new Person());
    personMergeLog.setPersonMergeLogData(new PersonMergeLogData());
    personMergeLog.setVoidReason("voidReason");
    PersonMergeLogValidator validator = new PersonMergeLogValidator();
    Errors errors = new BindException(personMergeLog, "personMergeLog");
    validator.validate(personMergeLog, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 40 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonServiceTest method getAllPersonMergeLogs_shouldRetrieveAllPersonMergeLogsAndDeserializeThem.

/**
 * @see PersonService#getAllPersonMergeLogs(boolean)
 */
@Test
public void getAllPersonMergeLogs_shouldRetrieveAllPersonMergeLogsAndDeserializeThem() throws Exception {
    PersonMergeLog personMergeLog = getTestPersonMergeLog();
    Context.getPersonService().savePersonMergeLog(personMergeLog);
    List<PersonMergeLog> result = Context.getPersonService().getAllPersonMergeLogs(true);
    Assert.assertEquals("could not retrieve expected number of PersonMergeLog objects", 1, result.size());
    Assert.assertNotNull("PersonMergeLog at index 0 is null", result.get(0));
    Assert.assertNotNull("PersonMergeLog data has not been deserialized", result.get(0).getPersonMergeLogData());
}
Also used : PersonMergeLog(org.openmrs.person.PersonMergeLog) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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