Search in sources :

Example 66 with PatientIdentifier

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

the class PatientServiceImplTest method createVoidedPatientIdentifier.

private PatientIdentifier createVoidedPatientIdentifier() {
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifierType(mock(PatientIdentifierType.class));
    patientIdentifier.setVoided(true);
    patientIdentifier.setVoidedBy(mock(User.class));
    patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
    return patientIdentifier;
}
Also used : User(org.openmrs.User) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType)

Example 67 with PatientIdentifier

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

the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers.

@Test
public void checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers() throws Exception {
    // given
    final Integer equalIdentifierTypeId = 12345;
    final String equalIdentifierTypeName = "TypeName";
    final String equalIdentifier = "Identifier1";
    final PatientIdentifierType identifierType = new PatientIdentifierType(equalIdentifierTypeId);
    identifierType.setName(equalIdentifierTypeName);
    final PatientIdentifierType sameIdentifierType = new PatientIdentifierType(equalIdentifierTypeId);
    sameIdentifierType.setName(equalIdentifierTypeName);
    when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(new ArrayList<>());
    final Patient patientWithIdentifiers = new Patient();
    final PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", identifierType, mock(Location.class));
    patientIdentifier.setIdentifier(equalIdentifier);
    patientWithIdentifiers.addIdentifier(patientIdentifier);
    final PatientIdentifier patientIdentifierSameType = new PatientIdentifier("some identifier", sameIdentifierType, mock(Location.class));
    patientIdentifierSameType.setIdentifier(equalIdentifier);
    patientWithIdentifiers.addIdentifier(patientIdentifierSameType);
    // when
    try {
        patientService.checkPatientIdentifiers(patientWithIdentifiers);
        // then
        fail();
    } catch (DuplicateIdentifierException e) {
        assertNotNull(e.getPatientIdentifier());
        assertTrue(e.getMessage().contains("Identifier1 id type #: 12345"));
    }
}
Also used : DuplicateIdentifierException(org.openmrs.api.DuplicateIdentifierException) Patient(org.openmrs.Patient) Matchers.anyString(org.mockito.Matchers.anyString) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Example 68 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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 69 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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 70 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)116 Test (org.junit.Test)91 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 PatientIdentifierType (org.openmrs.PatientIdentifierType)57 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)27 PersonName (org.openmrs.PersonName)24 Date (java.util.Date)19 PersonAddress (org.openmrs.PersonAddress)12 ArrayList (java.util.ArrayList)10 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3