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);
}
Aggregations