use of org.openmrs.PatientIdentifier 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));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldNotGetCloseIdentifiersWithWrongStartPhrase.
@Test
public void getPatients_shouldNotGetCloseIdentifiersWithWrongStartPhrase() {
String oldPropertyValue = globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START);
Patient patient = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("BAH409", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
// add closely matching identifier to a different patient
Patient patient2 = patientService.getPatient(6);
PatientIdentifier patientIdentifier6 = new PatientIdentifier("BAH509", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patientIdentifier6.setPreferred(true);
patient2.addIdentifier(patientIdentifier6);
patientService.savePatient(patient2);
updateSearchIndex();
// Check for partial identifier match
List<Patient> patients = dao.getPatients("BAH5", false, 0, null);
Assert.assertEquals(1, patients.size());
Assert.assertEquals("BAH509", patients.get(0).getPatientIdentifier(5).toString());
if (oldPropertyValue != null) {
globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, oldPropertyValue);
} else {
globalPropertiesTestHelper.purgeGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE);
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatients.
/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
*/
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatients() {
// There is one identifier[id=12345K] in the test database for patient with id 6
Patient patientWithId6 = Context.getPatientService().getPatient(6);
// There is one identifier[id=6TS-4] in the test database for patient with id 7
Patient patientWithId7 = Context.getPatientService().getPatient(7);
List<Patient> patientsList = Arrays.asList(patientWithId6, patientWithId7);
List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), patientsList, null);
assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("12345K"), hasIdentifier("6TS-4")));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldNotGetExcessPatientsOnIdentifierAndNameMatch.
/**
* @see HibernatePatientDAO#getPatients(String, Integer, Integer)
*/
@Test
public void getPatients_shouldNotGetExcessPatientsOnIdentifierAndNameMatch() {
Patient patient = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("alpha", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
updateSearchIndex();
List<Patient> patients = dao.getPatients("alpha", 0, null);
Assert.assertEquals(patient, patients.get(0));
Assert.assertEquals(3, patients.size());
List<Patient> first_patient = dao.getPatients("alpha", 0, 1);
Assert.assertEquals(patient, first_patient.get(0));
Assert.assertEquals(1, first_patient.size());
List<Patient> two_patients_only = dao.getPatients("alpha", 0, 2);
Assert.assertEquals(2, two_patients_only.size());
List<Patient> second_patient = dao.getPatients("alpha", 1, 1);
Assert.assertEquals(1, second_patient.size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatientIdentifiers_shouldNotGetVoidedPatientIdentifiers.
/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
*/
@Test
public void getPatientIdentifiers_shouldNotGetVoidedPatientIdentifiers() {
List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null);
// standartTestDataset.xml contains 5 non-voided identifiers
//
// plus 1 non-voided identifier from HibernatePatientDAOTest-patients.xml
Assert.assertEquals(8, patientIdentifiers.size());
for (PatientIdentifier patientIdentifier : patientIdentifiers) {
Assert.assertFalse(patientIdentifier.getVoided());
}
}
Aggregations