Skip to content

Commit

Permalink
COH-56 Cohort members with filled end dates should not be returned
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Nov 1, 2023
1 parent 4c38130 commit 539aea7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ protected void includeDeletedObjects(Criteria criteria, boolean includeDeleted)
}
}
}

@Override
public Criteria createCriteria() {
return getCurrentSession().createCriteria(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.openmrs.Auditable;
import org.openmrs.OpenmrsObject;
Expand Down Expand Up @@ -49,4 +50,5 @@ public interface GenericDao<W extends OpenmrsObject & Auditable> {

Collection<W> findByAnd(Criterion... predicates);

Criteria createCriteria();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import lombok.AccessLevel;
import lombok.Setter;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.cohort.CohortMember;
import org.openmrs.module.cohort.CohortMemberAttribute;
Expand Down Expand Up @@ -142,8 +144,11 @@ public void purgeCohortMemberAttribute(CohortMemberAttribute cohortMemberAttribu
@Override
@Transactional(readOnly = true)
public Collection<CohortMember> findCohortMembersByCohortUuid(String cohortUuid) {
return cohortMemberDao.findBy(
PropValue.builder().property("uuid").associationPath(Optional.of("cohort")).value(cohortUuid).build());
Criteria criteria = cohortMemberDao.createCriteria();
criteria.createAlias("cohort", "cohort");
criteria.add(Restrictions.eq("cohort.uuid", cohortUuid));
criteria.add(Restrictions.isNull("endDate"));
return criteria.list();
}

@Override
Expand Down

0 comments on commit 539aea7

Please sign in to comment.