Search in sources :

Example 86 with PatientIdentifier

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);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 87 with 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());
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 88 with PatientIdentifier

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());
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 89 with PatientIdentifier

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());
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 90 with PatientIdentifier

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()));
}
Also used : Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)116 Test (org.junit.Test)91 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 PatientIdentifierType (org.openmrs.PatientIdentifierType)57 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)27 PersonName (org.openmrs.PersonName)24 Date (java.util.Date)19 PersonAddress (org.openmrs.PersonAddress)12 ArrayList (java.util.ArrayList)10 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3