diff --git a/api/src/main/java/org/openmrs/module/cohort/api/dao/AbstractGenericDao.java b/api/src/main/java/org/openmrs/module/cohort/api/dao/AbstractGenericDao.java index 42e2afd..b05ee0f 100644 --- a/api/src/main/java/org/openmrs/module/cohort/api/dao/AbstractGenericDao.java +++ b/api/src/main/java/org/openmrs/module/cohort/api/dao/AbstractGenericDao.java @@ -171,4 +171,9 @@ protected void includeDeletedObjects(Criteria criteria, boolean includeDeleted) } } } + + @Override + public Criteria createCriteria() { + return getCurrentSession().createCriteria(clazz); + } } diff --git a/api/src/main/java/org/openmrs/module/cohort/api/dao/GenericDao.java b/api/src/main/java/org/openmrs/module/cohort/api/dao/GenericDao.java index 61a2359..cc1ea48 100644 --- a/api/src/main/java/org/openmrs/module/cohort/api/dao/GenericDao.java +++ b/api/src/main/java/org/openmrs/module/cohort/api/dao/GenericDao.java @@ -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; @@ -49,4 +50,5 @@ public interface GenericDao { Collection findByAnd(Criterion... predicates); + Criteria createCriteria(); } diff --git a/api/src/main/java/org/openmrs/module/cohort/api/impl/CohortMemberServiceImpl.java b/api/src/main/java/org/openmrs/module/cohort/api/impl/CohortMemberServiceImpl.java index 04de6e6..ad604d1 100644 --- a/api/src/main/java/org/openmrs/module/cohort/api/impl/CohortMemberServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/cohort/api/impl/CohortMemberServiceImpl.java @@ -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; @@ -142,8 +144,11 @@ public void purgeCohortMemberAttribute(CohortMemberAttribute cohortMemberAttribu @Override @Transactional(readOnly = true) public Collection 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