use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing.
@Test
public void checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing() throws Exception {
// given
final PatientIdentifierType requiredIdentifierType = new PatientIdentifierType(12345);
requiredIdentifierType.setUuid("some type uuid");
requiredIdentifierType.setName("NameOfRequiredIdentifierType");
final PatientIdentifierType patientIdentifierType = new PatientIdentifierType(6789);
patientIdentifierType.setUuid("another type uuid");
patientIdentifierType.setName("NameOfPatientIdentifierType");
final List<PatientIdentifierType> requiredTypes = new ArrayList<>();
requiredTypes.add(requiredIdentifierType);
when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(requiredTypes);
final Patient patientWithIdentifiers = new Patient();
patientWithIdentifiers.addIdentifier(new PatientIdentifier("some identifier", patientIdentifierType, mock(Location.class)));
try {
// when
patientService.checkPatientIdentifiers(patientWithIdentifiers);
fail();
// then
} catch (MissingRequiredIdentifierException e) {
assertTrue(e.getMessage().contains("required"));
assertTrue(e.getMessage().contains("NameOfRequiredIdentifierType"));
} catch (Exception e) {
fail("Expecting MissingRequiredIdentifierException");
}
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method shouldCreatePatientWithValidatedIdentifier.
/**
* Tests creating patients with identifiers that are or are not validated.
*
* @throws Exception
*/
@Test
public void shouldCreatePatientWithValidatedIdentifier() throws Exception {
executeDataSet(CREATE_PATIENT_VALID_IDENT_XML);
Patient patient = createBasicPatient();
Patient patient2 = createBasicPatient();
PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
PatientIdentifier ident1 = new PatientIdentifier("123-1", pit, locationService.getLocation(1));
PatientIdentifier ident2 = new PatientIdentifier("123", pit, locationService.getLocation(1));
PatientIdentifier ident3 = new PatientIdentifier("123-0", pit, locationService.getLocation(1));
PatientIdentifier ident4 = new PatientIdentifier("123-A", pit, locationService.getLocation(1));
try {
ident1.setPreferred(true);
patient.addIdentifier(ident1);
patientService.savePatient(patient);
fail("Patient creation should have failed with identifier " + ident1.getIdentifier());
} catch (InvalidCheckDigitException ex) {
} catch (APIException e) {
if (!(e.getMessage() != null && e.getMessage().contains("failed to validate with reason: " + Context.getMessageSourceService().getMessage("PatientIdentifier.error.checkDigitWithParameter", new Object[] { ident1.getIdentifier() }, null)))) {
fail("Patient creation should have failed with identifier " + ident1.getIdentifier());
}
}
patient.removeIdentifier(ident1);
try {
ident2.setPreferred(true);
patient.addIdentifier(ident2);
patientService.savePatient(patient);
fail("Patient creation should have failed with identifier " + ident2.getIdentifier());
} catch (InvalidCheckDigitException ex) {
} catch (APIException e) {
if (!(e.getMessage() != null && e.getMessage().contains("failed to validate with reason: " + Context.getMessageSourceService().getMessage("PatientIdentifier.error.unallowedIdentifier", new Object[] { ident2.getIdentifier(), new LuhnIdentifierValidator().getName() }, null)))) {
fail("Patient creation should have failed with identifier " + ident2.getIdentifier());
}
}
patient.removeIdentifier(ident2);
try {
ident3.setPreferred(true);
patient.addIdentifier(ident3);
patientService.savePatient(patient);
patientService.purgePatient(patient);
patient.removeIdentifier(ident3);
ident4.setPreferred(true);
patient2.addIdentifier(ident4);
patientService.savePatient(patient2);
} catch (InvalidCheckDigitException ex) {
fail("Patient creation should have worked with identifiers " + ident3.getIdentifier() + " and " + ident4.getIdentifier());
}
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method purgePatientIdentifierType_shouldDeleteTypeFromDatabase.
/**
* @see PatientService#purgePatientIdentifierType(PatientIdentifierType)
*/
@Test
public void purgePatientIdentifierType_shouldDeleteTypeFromDatabase() throws Exception {
PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
patientIdentifierType.setName("testing");
patientIdentifierType.setDescription("desc");
patientIdentifierType.setRequired(false);
patientService.savePatientIdentifierType(patientIdentifierType);
PatientIdentifierType type = patientService.getPatientIdentifierType(patientIdentifierType.getId());
patientService.purgePatientIdentifierType(type);
assertNull(patientService.getPatientIdentifierType(patientIdentifierType.getId()));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId.
/**
* @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
*/
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId() throws Exception {
PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null);
patientIdentifier.setPatient(patientService.getPatient(2));
Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifierType_shouldCreateNewPatientIdentifierType.
/**
* @see PatientService#savePatientIdentifierType(PatientIdentifierType)
*/
@Test
public void savePatientIdentifierType_shouldCreateNewPatientIdentifierType() throws Exception {
PatientIdentifierType identifierType = new PatientIdentifierType();
identifierType.setName("test");
identifierType.setDescription("test description");
identifierType.setRequired(false);
Assert.assertNull(identifierType.getPatientIdentifierTypeId());
patientService.savePatientIdentifierType(identifierType);
PatientIdentifierType savedIdentifierType = patientService.getPatientIdentifierType(identifierType.getPatientIdentifierTypeId());
assertNotNull(savedIdentifierType);
}
Aggregations