use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAWhiteSpace.
@Test(expected = APIException.class)
public void savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAWhiteSpace() 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 getPatientIdentifiers_shouldReturnOnlyNonVoidedPatientsAndPatientIdentifiers.
/**
* @see PatientService#getPatientIdentifiers(String,List,List,List,Boolean)
*/
@Test
public void getPatientIdentifiers_shouldReturnOnlyNonVoidedPatientsAndPatientIdentifiers() throws Exception {
// sanity check. make sure there is at least one voided patient
Patient patient = patientService.getPatient(999);
Assert.assertTrue("This patient should be voided", patient.getVoided());
Assert.assertFalse("This test expects the patient to be voided BUT the identifier to be NONvoided", ((PatientIdentifier) (patient.getIdentifiers().toArray()[0])).getVoided());
// now fetch all identifiers
List<PatientIdentifier> patientIdentifiers = patientService.getPatientIdentifiers(null, null, null, null, null);
for (PatientIdentifier patientIdentifier : patientIdentifiers) {
Assert.assertFalse("No voided identifiers should be returned", patientIdentifier.getVoided());
Assert.assertFalse("No identifiers of voided patients should be returned", patientIdentifier.getPatient().getVoided());
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method voidPatientIdentifier_shouldVoidGivenPatientIdentifierWithGivenReason.
/**
* @see PatientService#getPatientIdentifier(Integer patientId)
*/
@Test
public void voidPatientIdentifier_shouldVoidGivenPatientIdentifierWithGivenReason() throws Exception {
Patient patient = patientService.getPatientIdentifier(3).getPatient();
int oldActiveIdentifierSize = patient.getActiveIdentifiers().size();
PatientIdentifier patientIdentifierToVoid = patientService.getPatientIdentifier(3);
PatientIdentifier voidedIdentifier = patientService.voidPatientIdentifier(patientIdentifierToVoid, "Testing");
// was the void reason set
Assert.assertEquals("Testing", voidedIdentifier.getVoidReason());
// patient's active identifiers must have reduced by 1 if the identifier
// was successfully voided
Assert.assertEquals(oldActiveIdentifierSize - 1, patient.getActiveIdentifiers().size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldThrowErrorGivenPatientIdentifierIsInvalid.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test
public void checkPatientIdentifiers_shouldThrowErrorGivenPatientIdentifierIsInvalid() throws Exception {
// given
Patient patient = new Patient();
PatientIdentifier nonBlankIdentifierWithoutLocation = new PatientIdentifier();
nonBlankIdentifierWithoutLocation.setVoided(false);
nonBlankIdentifierWithoutLocation.setLocation(null);
nonBlankIdentifierWithoutLocation.setIdentifier("an identifier");
nonBlankIdentifierWithoutLocation.setIdentifierType(new PatientIdentifierType(21345));
nonBlankIdentifierWithoutLocation.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patient.addIdentifier(nonBlankIdentifierWithoutLocation);
assertEquals(1, patient.getIdentifiers().size());
try {
// when
Context.getPatientService().checkPatientIdentifiers(patient);
// then
fail("should throw PatientIdentifierException");
} catch (BlankIdentifierException e) {
fail("should not throw BlankIdentifierException");
} catch (PatientIdentifierException e) {
assertEquals(1, patient.getIdentifiers().size());
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedIdentifiers.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditCreatedIdentifiers() throws Exception {
// retrieve preferred patient
Patient preferred = patientService.getPatient(999);
// retrieve notPreferredPatient and save it with a new identifier
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientService.getPatientIdentifierType(5));
patientIdentifier.setLocation(new Location(1));
notPreferred.addIdentifier(patientIdentifier);
patientService.savePatient(notPreferred);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// find the UUID of the identifier that was added by the merge
String addedIdentifierUuid = null;
preferred = patientService.getPatient(999);
for (PatientIdentifier id : preferred.getIdentifiers()) {
if (id.getIdentifier().equals(patientIdentifier.getIdentifier())) {
addedIdentifierUuid = id.getUuid();
}
}
Assert.assertNotNull("expected new identifier was not found in the preferred patient after the merge", addedIdentifierUuid);
Assert.assertTrue("person identifier creation not audited", isValueInList(addedIdentifierUuid, audit.getPersonMergeLogData().getCreatedIdentifiers()));
}
Aggregations