Search in sources :

Example 81 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierTypes_shouldOrderAsDefaultComparator.

/**
 * @see PatientService#getPatientIdentifierTypes(String,String,Boolean,Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldOrderAsDefaultComparator() throws Exception {
    List<PatientIdentifierType> list = patientService.getPatientIdentifierTypes(null, null, false, null);
    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 82 with PatientIdentifierType

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

the class PatientServiceTest method getAllPatientIdentifierTypes_shouldFetchAllNonRetiredPatientIdentifierTypes.

/**
 * @see PatientService#getAllPatientIdentifierTypes()
 */
@Test
public void getAllPatientIdentifierTypes_shouldFetchAllNonRetiredPatientIdentifierTypes() throws Exception {
    Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes();
    Assert.assertNotNull("Should not return null", types);
    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 83 with PatientIdentifierType

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

the class PatientServiceTest method savePatientIdentifierType_shouldUpdateExistingPatientIdentifierType.

/**
 * @see PatientService#savePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void savePatientIdentifierType_shouldUpdateExistingPatientIdentifierType() throws Exception {
    PatientIdentifierType identifierType = Context.getPatientService().getAllPatientIdentifierTypes().get(0);
    Assert.assertNotNull(identifierType);
    Assert.assertNotNull(identifierType.getPatientIdentifierTypeId());
    Assert.assertEquals(2, identifierType.getPatientIdentifierTypeId().intValue());
    Assert.assertNotSame("test", identifierType.getName());
    // Change existing patient identifier
    identifierType.setName("test");
    identifierType.setDescription("test description");
    identifierType.setRequired(false);
    patientService.savePatientIdentifierType(identifierType);
    PatientIdentifierType savedIdentifierType = patientService.getPatientIdentifierType(2);
    assertNotNull(savedIdentifierType);
    Assert.assertEquals("test", identifierType.getName());
    assertTrue(savedIdentifierType.equals(identifierType));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 84 with PatientIdentifierType

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

the class PatientServiceTest method getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit.

/**
 * @see PatientService#getPatients(String, String, java.util.List, boolean)
 */
@Test
public void getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit() throws Exception {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_PATTERN, "@SEARCH@,0@SEARCH@,@SEARCH-1@-@CHECKDIGIT@,0@SEARCH-1@-@CHECKDIGIT@"));
    // "^(0*@SEARCH-1@-@CHECKDIGIT@)$"));
    PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
    identifier.setCreator(new User(1));
    identifier.setDateCreated(new Date());
    Patient patient = Context.getPatientService().getPatient(2);
    patient.addIdentifier(identifier);
    Context.getPatientService().savePatient(patient);
    updateSearchIndex();
    assertEquals(1, Context.getPatientService().getPatients("12344").size());
    assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
Also used : User(org.openmrs.User) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 85 with PatientIdentifierType

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

the class PatientServiceTest method savePatientIdentifierType_shouldCreateNewType.

/**
 * @see PatientService#savePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void savePatientIdentifierType_shouldCreateNewType() throws Exception {
    PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
    patientIdentifierType.setName("testing");
    patientIdentifierType.setDescription("desc");
    patientIdentifierType.setRequired(false);
    patientService.savePatientIdentifierType(patientIdentifierType);
    PatientIdentifierType newPatientIdentifierType = patientService.getPatientIdentifierType(patientIdentifierType.getPatientIdentifierTypeId());
    assertNotNull(newPatientIdentifierType);
}
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