Search in sources :

Example 86 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientServiceTest method getAllPatientIdentifierTypes_shouldOrderAsDefaultComparator.

/**
 * @see PatientService#getAllPatientIdentifierTypes(boolean)
 */
@Test
public void getAllPatientIdentifierTypes_shouldOrderAsDefaultComparator() throws Exception {
    List<PatientIdentifierType> list = patientService.getAllPatientIdentifierTypes();
    List<PatientIdentifierType> sortedList = new ArrayList<>(list);
    sortedList.sort(new PatientIdentifierTypeDefaultComparator());
    Assert.assertEquals(sortedList, list);
}
Also used : PatientIdentifierTypeDefaultComparator(org.openmrs.comparator.PatientIdentifierTypeDefaultComparator) ArrayList(java.util.ArrayList) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 87 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientServiceTest method checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test
public void checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank() throws Exception {
    // given
    Patient patient = new Patient();
    PatientIdentifier blankPatientIdentifier = new PatientIdentifier();
    blankPatientIdentifier.setIdentifier("");
    blankPatientIdentifier.setIdentifierType(new PatientIdentifierType(21345));
    blankPatientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
    patient.addIdentifier(blankPatientIdentifier);
    assertEquals(1, patient.getIdentifiers().size());
    try {
        // when
        Context.getPatientService().checkPatientIdentifiers(patient);
        // then
        fail("should throw BlankIdentifierException");
    } catch (BlankIdentifierException e) {
        assertEquals(0, patient.getIdentifiers().size());
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 88 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientServiceTest method getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesExcludingRetiredWhenIncludeRetiredIsFalse.

/**
 * @see PatientService#getAllPatientIdentifierTypes(null)
 */
@Test
public void getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesExcludingRetiredWhenIncludeRetiredIsFalse() throws Exception {
    Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes(false);
    for (PatientIdentifierType type : types) {
        if (type.getRetired()) {
            Assert.fail("Should not return retired patient identifier types");
        }
    }
    Assert.assertEquals("Should be exactly three patient identifier types in the dataset", 3, types.size());
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 89 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception {
    PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
    Assert.assertNotNull(duplicateId.getLocation());
    PatientIdentifierType idType = duplicateId.getIdentifierType();
    idType.setUniquenessBehavior(UniquenessBehavior.LOCATION);
    patientService.savePatientIdentifierType(idType);
    Location idLocation = locationService.getLocation(2);
    // sanity check
    Assert.assertNotSame(idLocation, duplicateId.getLocation());
    PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation);
    Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi));
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 90 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375.

/**
 * Regression test for ticket #1375: org.hibernate.NonUniqueObjectException caused by
 * PatientIdentifierValidator Manually construct a patient with a correctly-matching patientId
 * and patient identifier with validator. Calling PatientService.savePatient on that patient
 * leads to a call to PatientIdentifierValidator.validateIdentifier which used to load the
 * Patient for that identifier into the hibernate session, leading to a NonUniqueObjectException
 * when the calling saveOrUpdate on the manually constructed Patient.
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375() {
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setPatientId(2);
    patient.addName(new PersonName("This", "Isa", "Test"));
    PatientIdentifier patientIdentifier = new PatientIdentifier("101-6", new PatientIdentifierType(1), new Location(1));
    patientIdentifier.setPreferred(true);
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PatientIdentifierType (org.openmrs.PatientIdentifierType)131 Test (org.junit.Test)99 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)88 PatientIdentifier (org.openmrs.PatientIdentifier)56 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)53 Patient (org.openmrs.Patient)37 Location (org.openmrs.Location)29 ArrayList (java.util.ArrayList)20 BindException (org.springframework.validation.BindException)17 Errors (org.springframework.validation.Errors)14 Date (java.util.Date)13 PersonName (org.openmrs.PersonName)13 User (org.openmrs.User)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Concept (org.openmrs.Concept)6 Person (org.openmrs.Person)5 HashMap (java.util.HashMap)4 PersonAddress (org.openmrs.PersonAddress)4 PatientServiceTest (org.openmrs.api.PatientServiceTest)4 HL7Exception (ca.uhn.hl7v2.HL7Exception)3