Search in sources :

Example 51 with Patient

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

the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
 */
@Test
public void getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    executeDataSet(CREATE_RELATIONSHIP_XML);
    // TODO use xml imported in BaseContextSensitiveTest#baseSetupWithStandardDataAndAuthentication()
    Patient patient = createTestPatient();
    List<Relationship> rels = createTestDatedRelationships(ps.getPatient(2), patient, personService.getRelationshipType(4));
    // Get relationships effective between 1987-01-01 and 1988-01-01
    List<Relationship> res = personService.getRelationships(ps.getPatient(2), patient, null, df.parse("1987-01-01"), df.parse("1988-01-01"));
    // Verify # of results and which results we have received
    assertEquals(5, res.size());
    for (Relationship rr : res) {
        if (!rr.equals(rels.get(0)) && !rr.equals(rels.get(2)) && !rr.equals(rels.get(3)) && !rr.equals(rels.get(7)) && !rr.equals(rels.get(8))) {
            if (rr.equals(rels.get(1))) {
                fail("unexpected relationship 1 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(4))) {
                fail("unexpected relationship 4 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(5))) {
                fail("unexpected relationship 5 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(6))) {
                fail("unexpected relationship 6 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else {
                fail("unrecognized unexpected relationship in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 52 with Patient

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

the class CohortServiceTest method addPatientToCohort_shouldAddAPatientAndSaveTheCohort.

/**
 * @see CohortService#addPatientToCohort(Cohort,Patient)
 */
@Test
public void addPatientToCohort_shouldAddAPatientAndSaveTheCohort() {
    executeDataSet(COHORT_XML);
    // make a patient, add it using the method
    Patient patientToAdd = Context.getPatientService().getPatient(3);
    service.addPatientToCohort(service.getCohort(2), patientToAdd);
    // proof of "save the cohort": see if the patient is in the cohort
    assertTrue(service.getCohort(2).contains(3));
}
Also used : Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 53 with Patient

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

the class CohortServiceTest method removePatientFromCohort_shouldSaveCohortAfterRemovingPatient.

@Test
public void removePatientFromCohort_shouldSaveCohortAfterRemovingPatient() {
    executeDataSet(COHORT_XML);
    Cohort cohort = service.getCohort(2);
    Integer patientId = cohort.getMemberships().iterator().next().getPatientId();
    Patient patient = Context.getPatientService().getPatient(patientId);
    service.removePatientFromCohort(cohort, patient);
    assertFalse(cohort.contains(patientId));
}
Also used : Cohort(org.openmrs.Cohort) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 54 with Patient

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

the class CohortServiceTest method patientVoided_shouldVoidMemberships.

@Test
public void patientVoided_shouldVoidMemberships() {
    executeDataSet(COHORT_XML);
    Cohort cohort = Context.getCohortService().getCohort(2);
    Patient voidedPatient = new Patient(7);
    voidedPatient.setVoided(true);
    voidedPatient.setDateVoided(new Date());
    voidedPatient.setVoidedBy(Context.getAuthenticatedUser());
    voidedPatient.setVoidReason("Voided as a result of the associated patient getting voided");
    CohortMembership newMemberContainingVoidedPatient = new CohortMembership(voidedPatient.getPatientId());
    cohort.addMembership(newMemberContainingVoidedPatient);
    assertTrue(cohort.contains(voidedPatient.getPatientId()));
    assertEquals(1, service.getCohortsContainingPatientId(voidedPatient.getId()).size());
    service.notifyPatientVoided(voidedPatient);
    assertTrue(newMemberContainingVoidedPatient.getVoided());
    assertEquals(newMemberContainingVoidedPatient.getDateVoided(), voidedPatient.getDateVoided());
    assertEquals(newMemberContainingVoidedPatient.getVoidedBy(), voidedPatient.getVoidedBy());
    assertEquals(newMemberContainingVoidedPatient.getVoidReason(), voidedPatient.getVoidReason());
}
Also used : Cohort(org.openmrs.Cohort) Patient(org.openmrs.Patient) Date(java.util.Date) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with Patient

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

the class CohortValidator method validate.

@Override
public void validate(Object obj, Errors errors) {
    if (obj == null || !(obj instanceof Cohort)) {
        throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + Cohort.class);
    }
    Cohort cohort = (Cohort) obj;
    if (!cohort.getVoided()) {
        Collection<CohortMembership> members = cohort.getMemberships();
        if (!CollectionUtils.isEmpty(members)) {
            for (CohortMembership member : members) {
                Patient p = Context.getPatientService().getPatient(member.getPatientId());
                int dateCompare = OpenmrsUtil.compareWithNullAsLatest(member.getStartDate(), member.getEndDate());
                if (p != null && p.getVoided() && !member.getVoided()) {
                    String message = "Patient " + p.getPatientId() + " is voided, cannot add voided members to a cohort";
                    errors.rejectValue("memberships", "Cohort.patientAndMemberShouldBeVoided", message);
                }
                if (dateCompare == 1) {
                    String message = "Start date is null or end date is before start date";
                    errors.rejectValue("memberships", "Cohort.startDateShouldNotBeNullOrBeforeEndDate", message);
                }
            }
        }
    }
}
Also used : Cohort(org.openmrs.Cohort) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28