Search in sources :

Example 41 with PatientIdentifierType

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

the class PatientServiceTest method retirePatientIdentifierType_shouldThrowAPIExceptionWhenNullReasonIsPassed.

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

Example 42 with PatientIdentifierType

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

the class PatientServiceTest method shouldGetPatientsByIdentifierAndIdentifierType.

/**
 * Test the PatientService.getPatients(String, String, List) method with both an identifier and
 * an identifiertype
 *
 * @throws Exception
 */
@Test
@SkipBaseSetup
public void shouldGetPatientsByIdentifierAndIdentifierType() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet(FIND_PATIENTS_XML);
    authenticate();
    updateSearchIndex();
    List<PatientIdentifierType> types = new ArrayList<>();
    types.add(new PatientIdentifierType(1));
    // make sure we get back only one patient
    List<Patient> patients = patientService.getPatients("1234", null, types, false);
    assertEquals(1, patients.size());
    // make sure we get back only one patient
    patients = patientService.getPatients("1234", null, null, false);
    assertEquals(1, patients.size());
    // make sure we can search a padded identifier
    patients = patientService.getPatients("00000001234", null, null, false);
    assertEquals(1, patients.size());
}
Also used : ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test) SkipBaseSetup(org.openmrs.test.SkipBaseSetup)

Example 43 with PatientIdentifierType

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

the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient.

/**
 * Regression test for http://dev.openmrs.org/ticket/1375
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setPatientId(2);
    // patient.setCreator(new User(1));
    // patient.setDateCreated date_created="2005-09-22 00:00:00.0"
    // changed_by="1" date_changed="2008-08-18 12:29:59.0"
    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);
    Context.getPatientService().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)

Example 44 with PatientIdentifierType

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique() throws Exception {
    PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
    Assert.assertNotNull(duplicateId.getLocation());
    PatientIdentifierType idType = duplicateId.getIdentifierType();
    idType.setUniquenessBehavior(UniquenessBehavior.UNIQUE);
    patientService.savePatientIdentifierType(idType);
    PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation());
    Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi));
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 45 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierTypes_shouldFetchPatientIdentifierTypesThatMatchGivenNameWithGivenFormat.

/**
 * @see PatientService#getPatientIdentifierTypes(String,String,Boolean,Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldFetchPatientIdentifierTypesThatMatchGivenNameWithGivenFormat() throws Exception {
    executeDataSet("org/openmrs/api/include/PatientServiceTest-createPatientIdentifierType.xml");
    List<PatientIdentifierType> patientIdentifierTypes = Context.getPatientService().getPatientIdentifierTypes("Test OpenMRS Identification Number", "java.lang.Integer", null, null);
    Assert.assertEquals(false, patientIdentifierTypes.isEmpty());
    for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) {
        Assert.assertEquals("Test OpenMRS Identification Number", patientIdentifierType.getName());
        Assert.assertEquals("java.lang.Integer", patientIdentifierType.getFormat());
    }
}
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