use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatient.
/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
*/
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatient() {
// There are two identifiers in the test database for patient with id 2
Patient patientWithId2 = Context.getPatientService().getPatient(2);
List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), Collections.singletonList(patientWithId2), null);
assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("101"), hasIdentifier("101-6")));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldEscapeAnAsterixCharacterInIdentifierPhrase.
/**
* @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
*/
@Test
public void getPatients_shouldEscapeAnAsterixCharacterInIdentifierPhrase() {
// Note that all tests for wildcard should be pass in 2s due to the behaviour of wildcards,
// that is we test for the size and actual patient object returned
Patient patient2 = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("*567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient2.addIdentifier(patientIdentifier);
patientService.savePatient(patient2);
// add closely matching identifier to a different patient
Patient patient6 = patientService.getPatient(6);
PatientIdentifier patientIdentifier6 = new PatientIdentifier("4567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patientIdentifier6.setPreferred(true);
patient6.addIdentifier(patientIdentifier6);
patientService.savePatient(patient6);
updateSearchIndex();
// we expect only one matching patient
int actualSize = dao.getPatients("*567", 0, null).size();
Assert.assertEquals(1, actualSize);
// if actually the search returned the matching patient
Patient actualPatient = dao.getPatients("*567", 0, null).get(0);
Assert.assertEquals(patient2, actualPatient);
}
use of org.openmrs.PatientIdentifier 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);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAnEmptyString.
@Test(expected = APIException.class)
public void savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAnEmptyString() throws Exception {
PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
patientIdentifier.setIdentifier("");
patientService.savePatientIdentifier(patientIdentifier);
}
use of org.openmrs.PatientIdentifier 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));
}
Aggregations