Search in sources :

Example 6 with PersonAuditInfoCohortDefinition

use of org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition in project openmrs-module-pihcore by PIH.

the class PersonAuditInfoCohortDefinitionEvaluator method evaluate.

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {
    PersonAuditInfoCohortDefinition cd = (PersonAuditInfoCohortDefinition) cohortDefinition;
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Patient.class);
    crit.setProjection(Projections.property("id"));
    if (!cd.isIncludeVoided()) {
        crit.add(Restrictions.eq("voided", false));
    }
    if (cd.getCreatedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateCreated", cd.getCreatedOnOrAfter()));
    }
    if (cd.getCreatedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateCreated", DateUtil.getEndOfDayIfTimeExcluded(cd.getCreatedOnOrBefore())));
    }
    if (cd.getCreatedByUsers() != null) {
        crit.add(Restrictions.in("creator", cd.getCreatedByUsers()));
    }
    if (cd.getChangedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateChanged", cd.getChangedOnOrAfter()));
    }
    if (cd.getChangedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateChanged", DateUtil.getEndOfDayIfTimeExcluded(cd.getChangedOnOrBefore())));
    }
    if (cd.getChangedByUsers() != null) {
        crit.add(Restrictions.in("changedBy", cd.getChangedByUsers()));
    }
    if (cd.getVoidedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateVoided", cd.getVoidedOnOrAfter()));
    }
    if (cd.getVoidedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateVoided", DateUtil.getEndOfDayIfTimeExcluded(cd.getVoidedOnOrBefore())));
    }
    if (cd.getVoidedByUsers() != null) {
        crit.add(Restrictions.in("voidedBy", cd.getVoidedByUsers()));
    }
    Cohort c = new Cohort();
    for (Integer personId : (List<Integer>) crit.list()) {
        c.addMember(personId);
    }
    return new EvaluatedCohort(c, cohortDefinition, context);
}
Also used : Cohort(org.openmrs.Cohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) List(java.util.List) PersonAuditInfoCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition) Criteria(org.hibernate.Criteria)

Aggregations

PersonAuditInfoCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition)6 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)6 Test (org.junit.Test)5 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)5 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)5 Date (java.util.Date)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 Cohort (org.openmrs.Cohort)1 Patient (org.openmrs.Patient)1 PersonName (org.openmrs.PersonName)1