Search in sources :

Example 71 with PatientIdentifierType

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

the class PatientSearchCriteriaTest method getSearchMode_shouldIdentifySearchByNameOrIdentifier.

/**
 * @see PatientSearchCriteria#getSearchMode(String, String, java.util.List, boolean)
 */
@Test
public void getSearchMode_shouldIdentifySearchByNameOrIdentifier() {
    List<PatientIdentifierType> patientIdentifierTypeList = new ArrayList<>();
    patientIdentifierTypeList.add(new PatientIdentifierType());
    // test cases where "name" is the only parameter that is non-empty and non-blank
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("name", null, null, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "", null, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "  \n\t", null, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("name", null, new ArrayList<>(), true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "", new ArrayList<>(), true));
    // test cases where "identifier" is the only parameter that is non-empty and non-blank
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode(null, "identifier", null, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("", "identifier", null, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("  \n\t", "identifier", null, true));
    // test cases where 'patientIdentifierTypeList' is the only parameter that is non-empty and non-blank
    // 
    // testing variations of empty or blank value for name
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode(null, null, patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("", null, patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("  \n\t", null, patientIdentifierTypeList, true));
    // testing variations of empty or blank value for identifier
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode(null, "", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode(null, "  \n\t", patientIdentifierTypeList, true));
    // testing variations of empty or blank values for name and identifier
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("", "", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("  \n\t", "", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("", "\n\t", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("  \n\t", "  \n\t", patientIdentifierTypeList, true));
    // test cases where 'name' is the only parameter that is empty or blank
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode(null, "identifier", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("", "identifier", patientIdentifierTypeList, true));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_OR_IDENTIFIER, patientSearchCriteria.getSearchMode("  \n\t", "identifier", patientIdentifierTypeList, true));
}
Also used : ArrayList(java.util.ArrayList) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 72 with PatientIdentifierType

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

the class PatientSearchCriteriaTest method getSearchMode_shouldIdentifySearchByNameAndIdentifier.

/**
 * @see PatientSearchCriteria#getSearchMode(String, String, java.util.List, boolean)
 */
@Test
public void getSearchMode_shouldIdentifySearchByNameAndIdentifier() {
    List<PatientIdentifierType> patientIdentifierTypeList = new ArrayList<>();
    patientIdentifierTypeList.add(new PatientIdentifierType());
    // test cases where "name" and "identifier" are the only parameters that are non-empty and non-blank
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "identifier", null, false));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "identifier", new ArrayList<>(), false));
    // test cases where "name" and 'identifierTypeList' are the only parameters that are non-empty and non-blank
    // 
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", null, patientIdentifierTypeList, false));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "", patientIdentifierTypeList, false));
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "  \n\t ", patientIdentifierTypeList, false));
    // test case where all parameters are non-empty and non-blank
    Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_NAME_AND_IDENTIFIER, patientSearchCriteria.getSearchMode("name", "identifier", patientIdentifierTypeList, false));
}
Also used : ArrayList(java.util.ArrayList) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 73 with PatientIdentifierType

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

the class PatientServiceImplTest method processDeath_shouldMapValuesAndSavePatient.

@Test
public void processDeath_shouldMapValuesAndSavePatient() throws Exception {
    // given
    final Date dateDied = new Date();
    final Concept causeOfDeath = new Concept(2);
    when(conceptServiceMock.getConcept(anyString())).thenReturn(new Concept());
    when(locationServiceMock.getDefaultLocation()).thenReturn(new Location());
    ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
    when(patientDaoMock.savePatient(argumentCaptor.capture())).thenReturn(new Patient());
    // when
    final Patient patient = new Patient();
    patient.addIdentifier(new PatientIdentifier("an identifier", new PatientIdentifierType(1234), new Location()));
    patientService.processDeath(patient, dateDied, causeOfDeath, "unknown");
    // then
    final Patient savedPatient = argumentCaptor.getValue();
    assertEquals(true, savedPatient.getDead());
    assertEquals(dateDied, savedPatient.getDeathDate());
    assertEquals(causeOfDeath, savedPatient.getCauseOfDeath());
}
Also used : Concept(org.openmrs.Concept) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Example 74 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType 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 75 with PatientIdentifierType

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

the class PatientServiceImplTest method getPatientIdentifierTypes_shouldReturnPatientIdentifierTypesFromDao.

@Test
public void getPatientIdentifierTypes_shouldReturnPatientIdentifierTypesFromDao() {
    // given
    final List<PatientIdentifierType> expectedIdentifierTypes = new ArrayList<>();
    expectedIdentifierTypes.add(new PatientIdentifierType(12345));
    when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(expectedIdentifierTypes);
    // when
    final List<PatientIdentifierType> actualIdentifierTypes = patientService.getPatientIdentifierTypes("a name", "a format", true, false);
    // then
    verify(patientDaoMock, times(1)).getPatientIdentifierTypes("a name", "a format", true, false);
    assertEquals(expectedIdentifierTypes.get(0).getPatientIdentifierTypeId(), actualIdentifierTypes.get(0).getPatientIdentifierTypeId());
}
Also used : ArrayList(java.util.ArrayList) PatientIdentifierType(org.openmrs.PatientIdentifierType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

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