← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19546: support program/programStatus in TEI query (hql)

 

------------------------------------------------------------
revno: 19546
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-07-06 12:46:44 +0700
message:
  support program/programStatus in TEI query (hql)
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2015-07-03 08:41:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2015-07-06 05:46:44 +0000
@@ -132,7 +132,7 @@
     {
         String hql = "from TrackedEntityInstance tei";
 
-        if ( params.hasTrackedEntity() || params.hasOrganisationUnits() || params.hasFilters() )
+        if ( params.hasTrackedEntity() || params.hasOrganisationUnits() || params.hasFilters() || params.hasProgram() )
         {
             hql += " where ";
         }
@@ -172,6 +172,34 @@
             }
         }
 
+        if ( params.hasProgram() )
+        {
+            hql += " and exists (from ProgramInstance pi where pi.entityInstance=tei";
+            hql += " and pi.program.uid = '" + params.getProgram().getUid() + "'";
+
+            if ( params.hasProgramStatus() )
+            {
+                hql += " and pi.status = " + PROGRAM_STATUS_MAP.get( params.getProgramStatus() );
+            }
+
+            if ( params.hasFollowUp() )
+            {
+                hql += " and pi.followup = " + params.getFollowUp() + " ";
+            }
+
+            if ( params.hasProgramStartDate() )
+            {
+                hql += " and pi.enrollmentdate >= '" + getMediumDateString( params.getProgramStartDate() ) + "' ";
+            }
+
+            if ( params.hasProgramEndDate() )
+            {
+                hql += "and pi.enrollmentdate <= '" + getMediumDateString( params.getProgramEndDate() ) + "' ";
+            }
+
+            hql += ")";
+        }
+
         return hql;
     }