Search in sources :

Example 96 with PatientIdentifierType

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

the class PatientServiceTest method checkPatientIdentifiers_shouldThrowErrorGivenPatientIdentifierIsInvalid.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test
public void checkPatientIdentifiers_shouldThrowErrorGivenPatientIdentifierIsInvalid() throws Exception {
    // given
    Patient patient = new Patient();
    PatientIdentifier nonBlankIdentifierWithoutLocation = new PatientIdentifier();
    nonBlankIdentifierWithoutLocation.setVoided(false);
    nonBlankIdentifierWithoutLocation.setLocation(null);
    nonBlankIdentifierWithoutLocation.setIdentifier("an identifier");
    nonBlankIdentifierWithoutLocation.setIdentifierType(new PatientIdentifierType(21345));
    nonBlankIdentifierWithoutLocation.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
    patient.addIdentifier(nonBlankIdentifierWithoutLocation);
    assertEquals(1, patient.getIdentifiers().size());
    try {
        // when
        Context.getPatientService().checkPatientIdentifiers(patient);
        // then
        fail("should throw PatientIdentifierException");
    } catch (BlankIdentifierException e) {
        fail("should not throw BlankIdentifierException");
    } catch (PatientIdentifierException e) {
        assertEquals(1, 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 97 with PatientIdentifierType

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierContainsAPatientAndAnotherPatientHasThisId.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierContainsAPatientAndAnotherPatientHasThisId() throws Exception {
    PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
    PatientIdentifier patientIdentifier = new PatientIdentifier("7TU-8", pit, null);
    patientIdentifier.setPatient(patientService.getPatient(2));
    Assert.assertTrue(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 98 with PatientIdentifierType

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

the class PatientServiceTest method retirePatientIdentifierType_shouldThrowErrorWhenTryingToRetireAPatientIdentifierTypeWhilePatientIdentifierTypesAreLocked.

@Test(expected = PatientIdentifierTypeLockedException.class)
public void retirePatientIdentifierType_shouldThrowErrorWhenTryingToRetireAPatientIdentifierTypeWhilePatientIdentifierTypesAreLocked() throws Exception {
    PatientService ps = Context.getPatientService();
    createPatientIdentifierTypeLockedGPAndSetValue("true");
    PatientIdentifierType pit = ps.getPatientIdentifierType(1);
    ps.retirePatientIdentifierType(pit, "Retire test");
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 99 with PatientIdentifierType

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

the class PatientDAOTest method getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypes_OrderedByRequiredAndName.

/**
 * @see PatientDAO#getPatientIdentifierTypes(String, String, Boolean, Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypes_OrderedByRequiredAndName() {
    PatientIdentifierType openMRSIdNumber = dao.getPatientIdentifierType(1);
    PatientIdentifierType oldIdNumber = dao.getPatientIdentifierType(2);
    oldIdNumber.setRequired(true);
    dao.savePatientIdentifierType(oldIdNumber);
    PatientIdentifierType nationalIdNo = dao.getPatientIdentifierType(5);
    oldIdNumber.setRequired(true);
    dao.savePatientIdentifierType(nationalIdNo);
    PatientIdentifierType socialSecNumber = dao.getPatientIdentifierType(4);
    socialSecNumber.setName("ASecurityNumber");
    socialSecNumber.setRequired(true);
    socialSecNumber.setRetired(false);
    dao.savePatientIdentifierType(socialSecNumber);
    List<PatientIdentifierType> patientIdentifierTypes = dao.getPatientIdentifierTypes(null, null, null, null);
    Assert.assertArrayEquals(new Object[] { socialSecNumber, oldIdNumber, openMRSIdNumber, nationalIdNo }, patientIdentifierTypes.toArray());
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 100 with PatientIdentifierType

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

the class PatientDAOTest method getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypes_OrderedByRequiredNameAndTypeId.

/**
 * @see PatientDAO#getPatientIdentifierTypes(String, String, Boolean, Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypes_OrderedByRequiredNameAndTypeId() {
    PatientIdentifierType openMRSIdNumber = dao.getPatientIdentifierType(1);
    openMRSIdNumber.setName("IdNumber");
    openMRSIdNumber.setRequired(true);
    dao.savePatientIdentifierType(openMRSIdNumber);
    PatientIdentifierType oldIdNumber = dao.getPatientIdentifierType(2);
    oldIdNumber.setName("IdNumber");
    oldIdNumber.setRequired(true);
    dao.savePatientIdentifierType(oldIdNumber);
    PatientIdentifierType socialSecNumber = dao.getPatientIdentifierType(4);
    socialSecNumber.setRequired(true);
    socialSecNumber.setRetired(false);
    dao.savePatientIdentifierType(socialSecNumber);
    PatientIdentifierType nationalIdNo = dao.getPatientIdentifierType(5);
    oldIdNumber.setName("IdNumber");
    oldIdNumber.setRequired(true);
    dao.savePatientIdentifierType(nationalIdNo);
    List<PatientIdentifierType> patientIdentifierTypes = dao.getPatientIdentifierTypes(null, null, null, null);
    Assert.assertArrayEquals(new Object[] { openMRSIdNumber, oldIdNumber, socialSecNumber, nationalIdNo }, patientIdentifierTypes.toArray());
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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