From 539aea7374a2a6ce084e86c58b62fa0ef658ce30 Mon Sep 17 00:00:00 2001 From: dkayiwa Date: Wed, 1 Nov 2023 14:04:01 +0300 Subject: [PATCH] COH-56 Cohort members with filled end dates should not be returned --- .../module/cohort/api/dao/AbstractGenericDao.java | 5 +++++ .../org/openmrs/module/cohort/api/dao/GenericDao.java | 2 ++ .../module/cohort/api/impl/CohortMemberServiceImpl.java | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) 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