use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceImplTest method createVoidedPatientIdentifier.
private PatientIdentifier createVoidedPatientIdentifier() {
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifierType(mock(PatientIdentifierType.class));
patientIdentifier.setVoided(true);
patientIdentifier.setVoidedBy(mock(User.class));
patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
return patientIdentifier;
}
use of org.openmrs.PatientIdentifier 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.PatientIdentifier 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.PatientIdentifier 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.PatientIdentifier 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));
}
Aggregations