use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method getAllPatientIdentifierTypes_shouldOrderAsDefaultComparator.
/**
* @see PatientService#getAllPatientIdentifierTypes(boolean)
*/
@Test
public void getAllPatientIdentifierTypes_shouldOrderAsDefaultComparator() throws Exception {
List<PatientIdentifierType> list = patientService.getAllPatientIdentifierTypes();
List<PatientIdentifierType> sortedList = new ArrayList<>(list);
sortedList.sort(new PatientIdentifierTypeDefaultComparator());
Assert.assertEquals(sortedList, list);
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test
public void checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank() throws Exception {
// given
Patient patient = new Patient();
PatientIdentifier blankPatientIdentifier = new PatientIdentifier();
blankPatientIdentifier.setIdentifier("");
blankPatientIdentifier.setIdentifierType(new PatientIdentifierType(21345));
blankPatientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patient.addIdentifier(blankPatientIdentifier);
assertEquals(1, patient.getIdentifiers().size());
try {
// when
Context.getPatientService().checkPatientIdentifiers(patient);
// then
fail("should throw BlankIdentifierException");
} catch (BlankIdentifierException e) {
assertEquals(0, patient.getIdentifiers().size());
}
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesExcludingRetiredWhenIncludeRetiredIsFalse.
/**
* @see PatientService#getAllPatientIdentifierTypes(null)
*/
@Test
public void getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesExcludingRetiredWhenIncludeRetiredIsFalse() throws Exception {
Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes(false);
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());
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation.
/**
* @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
*/
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception {
PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
Assert.assertNotNull(duplicateId.getLocation());
PatientIdentifierType idType = duplicateId.getIdentifierType();
idType.setUniquenessBehavior(UniquenessBehavior.LOCATION);
patientService.savePatientIdentifierType(idType);
Location idLocation = locationService.getLocation(2);
// sanity check
Assert.assertNotSame(idLocation, duplicateId.getLocation());
PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation);
Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375.
/**
* Regression test for ticket #1375: org.hibernate.NonUniqueObjectException caused by
* PatientIdentifierValidator Manually construct a patient with a correctly-matching patientId
* and patient identifier with validator. Calling PatientService.savePatient on that patient
* leads to a call to PatientIdentifierValidator.validateIdentifier which used to load the
* Patient for that identifier into the hibernate session, leading to a NonUniqueObjectException
* when the calling saveOrUpdate on the manually constructed Patient.
*
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375() {
Patient patient = new Patient();
patient.setGender("M");
patient.setPatientId(2);
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);
patientService.savePatient(patient);
}
Aggregations