Skip to content

Commit

Permalink
Merge pull request #9 from phc007/patch-1
Browse files Browse the repository at this point in the history
Alter the SQL for findUniqueByDemographicId to yield the last non deleted instance of the prevention and not the first
  • Loading branch information
warrendennis authored Dec 5, 2024
2 parents e253ae1 + 20dbc03 commit 2188422
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/oscarehr/common/dao/PreventionDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public List<Prevention> findActiveByDemoId(Integer demoId) {

@Override
public List<Prevention> findUniqueByDemographicId(Integer demographicId) {
Query query = entityManager.createQuery("select x from "+modelClass.getSimpleName()+" x where demographicId=?1 and deleted='0' GROUP BY preventionType ORDER BY preventionDate DESC");
query.setParameter(1, demographicId);
Query query = entityManager.createNativeQuery("SELECT p1.* FROM preventions p1 left join preventions as p2 on p1.prevention_type = p2.prevention_type and p1.demographic_no = p2.demographic_no and p2.deleted='0' and (p1.prevention_date < p2.prevention_date OR (p1.prevention_date = p2.prevention_date and p1.id < p2.id)) where p1.demographic_no = :demographicId AND p1.deleted='0' AND p2.id is null ORDER BY p1.prevention_date DESC", Prevention.class);
query.setParameter("demographicId", demographicId);

@SuppressWarnings("unchecked")
List<Prevention> results = query.getResultList();
Expand Down

0 comments on commit 2188422

Please sign in to comment.