Search in sources :

Example 26 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method savePatientIdentifier_shouldThrowAnAPIExceptionWhenOneOfTheRequiredFieldsIsNull.

@Test(expected = APIException.class)
public void savePatientIdentifier_shouldThrowAnAPIExceptionWhenOneOfTheRequiredFieldsIsNull() throws Exception {
    PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
    patientIdentifier.setIdentifier(null);
    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 27 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method shouldCreatePatient.

@Test
public void shouldCreatePatient() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    // patient.removeAddress(pAddress);
    patient.setBirthdateEstimated(true);
    patient.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept());
    patient.setGender("male");
    List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
    assertNotNull(patientIdTypes);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("123-0");
    patientIdentifier.setIdentifierType(patientIdTypes.get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setPreferred(true);
    Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
    patientIdentifiers.add(patientIdentifier);
    patient.setIdentifiers(patientIdentifiers);
    patientService.savePatient(patient);
    Patient createdPatient = patientService.getPatient(patient.getPatientId());
    assertNotNull(createdPatient);
    assertNotNull(createdPatient.getPatientId());
    Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
    assertNotNull(createdPatientById);
}
Also used : Concept(org.openmrs.Concept) LinkedHashSet(java.util.LinkedHashSet) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 28 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatients.

/**
 * Regression test for http://dev.openmrs.org/ticket/790
 *
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatients() throws Exception {
    {
        // patient 999 should be voided and have a non-voided identifier of
        // XYZ
        Patient p = patientService.getPatient(999);
        Assert.assertNotNull(p);
        Assert.assertTrue(p.getVoided());
        boolean found = false;
        for (PatientIdentifier id : p.getIdentifiers()) {
            if (id.getIdentifier().equals("XYZ") && id.getIdentifierType().getId() == 2) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }
    PatientIdentifierType pit = patientService.getPatientIdentifierType(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("XYZ", pit, null);
    Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier));
}
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 29 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method getPatients_shouldFindAPatientsWithAMatchingIdentifierWithNoDigits.

/**
 * @see PatientService#getPatients(String,Integer,Integer)
 */
@Test
public void getPatients_shouldFindAPatientsWithAMatchingIdentifierWithNoDigits() throws Exception {
    final String identifier = "XYZ";
    Patient patient = patientService.getPatient(2);
    Assert.assertEquals(0, patientService.getPatients(identifier, (Integer) null, (Integer) null).size());
    PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1));
    patient.addIdentifier(pId);
    patientService.savePatient(patient);
    updateSearchIndex();
    Assert.assertEquals(1, patientService.getPatients(identifier).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 30 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method mergePatients_shouldCopyNonvoidedIdentifiersToPreferredPatient.

/**
 * @see PatientService#mergePatients(Patient, Patient)
 */
@Test
public void mergePatients_shouldCopyNonvoidedIdentifiersToPreferredPatient() throws Exception {
    Patient preferred = patientService.getPatient(7);
    Patient notPreferred = patientService.getPatient(8);
    PatientIdentifier nonvoidedPI = null;
    PatientIdentifier voidedPI = null;
    for (PatientIdentifier patientIdentifier : notPreferred.getIdentifiers()) {
        if (patientIdentifier.getIdentifier().equals("7TU-8")) {
            nonvoidedPI = patientIdentifier;
        }
        if (patientIdentifier.getIdentifier().equals("ABC123")) {
            voidedPI = patientIdentifier;
        }
    }
    patientService.mergePatients(preferred, notPreferred);
    Assert.assertNotNull(nonvoidedPI);
    Assert.assertTrue(contains(new ArrayList<>(preferred.getIdentifiers()), nonvoidedPI.getIdentifier()));
    Assert.assertNotNull(voidedPI);
    Assert.assertFalse(contains(new ArrayList<>(preferred.getIdentifiers()), voidedPI.getIdentifier()));
}
Also used : ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)103 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)59 PatientIdentifierType (org.openmrs.PatientIdentifierType)51 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)26 PersonName (org.openmrs.PersonName)19 Date (java.util.Date)15 PersonAddress (org.openmrs.PersonAddress)10 ArrayList (java.util.ArrayList)9 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 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 Concept (org.openmrs.Concept)3