Search in sources :

Example 76 with PatientIdentifierType

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

the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing.

@Test
public void checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing() throws Exception {
    // given
    final PatientIdentifierType requiredIdentifierType = new PatientIdentifierType(12345);
    requiredIdentifierType.setUuid("some type uuid");
    requiredIdentifierType.setName("NameOfRequiredIdentifierType");
    final PatientIdentifierType patientIdentifierType = new PatientIdentifierType(6789);
    patientIdentifierType.setUuid("another type uuid");
    patientIdentifierType.setName("NameOfPatientIdentifierType");
    final List<PatientIdentifierType> requiredTypes = new ArrayList<>();
    requiredTypes.add(requiredIdentifierType);
    when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(requiredTypes);
    final Patient patientWithIdentifiers = new Patient();
    patientWithIdentifiers.addIdentifier(new PatientIdentifier("some identifier", patientIdentifierType, mock(Location.class)));
    try {
        // when
        patientService.checkPatientIdentifiers(patientWithIdentifiers);
        fail();
    // then
    } catch (MissingRequiredIdentifierException e) {
        assertTrue(e.getMessage().contains("required"));
        assertTrue(e.getMessage().contains("NameOfRequiredIdentifierType"));
    } catch (Exception e) {
        fail("Expecting MissingRequiredIdentifierException");
    }
}
Also used : MissingRequiredIdentifierException(org.openmrs.api.MissingRequiredIdentifierException) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) DuplicateIdentifierException(org.openmrs.api.DuplicateIdentifierException) APIException(org.openmrs.api.APIException) MissingRequiredIdentifierException(org.openmrs.api.MissingRequiredIdentifierException) InsufficientIdentifiersException(org.openmrs.api.InsufficientIdentifiersException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Example 77 with PatientIdentifierType

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

the class PatientServiceTest method shouldCreatePatientWithValidatedIdentifier.

/**
 * Tests creating patients with identifiers that are or are not validated.
 *
 * @throws Exception
 */
@Test
public void shouldCreatePatientWithValidatedIdentifier() throws Exception {
    executeDataSet(CREATE_PATIENT_VALID_IDENT_XML);
    Patient patient = createBasicPatient();
    Patient patient2 = createBasicPatient();
    PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
    PatientIdentifier ident1 = new PatientIdentifier("123-1", pit, locationService.getLocation(1));
    PatientIdentifier ident2 = new PatientIdentifier("123", pit, locationService.getLocation(1));
    PatientIdentifier ident3 = new PatientIdentifier("123-0", pit, locationService.getLocation(1));
    PatientIdentifier ident4 = new PatientIdentifier("123-A", pit, locationService.getLocation(1));
    try {
        ident1.setPreferred(true);
        patient.addIdentifier(ident1);
        patientService.savePatient(patient);
        fail("Patient creation should have failed with identifier " + ident1.getIdentifier());
    } catch (InvalidCheckDigitException ex) {
    } catch (APIException e) {
        if (!(e.getMessage() != null && e.getMessage().contains("failed to validate with reason: " + Context.getMessageSourceService().getMessage("PatientIdentifier.error.checkDigitWithParameter", new Object[] { ident1.getIdentifier() }, null)))) {
            fail("Patient creation should have failed with identifier " + ident1.getIdentifier());
        }
    }
    patient.removeIdentifier(ident1);
    try {
        ident2.setPreferred(true);
        patient.addIdentifier(ident2);
        patientService.savePatient(patient);
        fail("Patient creation should have failed with identifier " + ident2.getIdentifier());
    } catch (InvalidCheckDigitException ex) {
    } catch (APIException e) {
        if (!(e.getMessage() != null && e.getMessage().contains("failed to validate with reason: " + Context.getMessageSourceService().getMessage("PatientIdentifier.error.unallowedIdentifier", new Object[] { ident2.getIdentifier(), new LuhnIdentifierValidator().getName() }, null)))) {
            fail("Patient creation should have failed with identifier " + ident2.getIdentifier());
        }
    }
    patient.removeIdentifier(ident2);
    try {
        ident3.setPreferred(true);
        patient.addIdentifier(ident3);
        patientService.savePatient(patient);
        patientService.purgePatient(patient);
        patient.removeIdentifier(ident3);
        ident4.setPreferred(true);
        patient2.addIdentifier(ident4);
        patientService.savePatient(patient2);
    } catch (InvalidCheckDigitException ex) {
        fail("Patient creation should have worked with identifiers " + ident3.getIdentifier() + " and " + ident4.getIdentifier());
    }
}
Also used : LuhnIdentifierValidator(org.openmrs.patient.impl.LuhnIdentifierValidator) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 78 with PatientIdentifierType

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

the class PatientServiceTest method purgePatientIdentifierType_shouldDeleteTypeFromDatabase.

/**
 * @see PatientService#purgePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void purgePatientIdentifierType_shouldDeleteTypeFromDatabase() throws Exception {
    PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
    patientIdentifierType.setName("testing");
    patientIdentifierType.setDescription("desc");
    patientIdentifierType.setRequired(false);
    patientService.savePatientIdentifierType(patientIdentifierType);
    PatientIdentifierType type = patientService.getPatientIdentifierType(patientIdentifierType.getId());
    patientService.purgePatientIdentifierType(type);
    assertNull(patientService.getPatientIdentifierType(patientIdentifierType.getId()));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 79 with PatientIdentifierType

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId() throws Exception {
    PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
    PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null);
    patientIdentifier.setPatient(patientService.getPatient(2));
    Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 80 with PatientIdentifierType

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

the class PatientServiceTest method savePatientIdentifierType_shouldCreateNewPatientIdentifierType.

/**
 * @see PatientService#savePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void savePatientIdentifierType_shouldCreateNewPatientIdentifierType() throws Exception {
    PatientIdentifierType identifierType = new PatientIdentifierType();
    identifierType.setName("test");
    identifierType.setDescription("test description");
    identifierType.setRequired(false);
    Assert.assertNull(identifierType.getPatientIdentifierTypeId());
    patientService.savePatientIdentifierType(identifierType);
    PatientIdentifierType savedIdentifierType = patientService.getPatientIdentifierType(identifierType.getPatientIdentifierTypeId());
    assertNotNull(savedIdentifierType);
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) 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