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));
}
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));
}
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());
}
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"));
}
}
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());
}
Aggregations