← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12516: Fixed bug in Aggregate Query Builder formulas.

 

------------------------------------------------------------
revno: 12516
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-09 09:47:12 +0700
message:
  Fixed bug in Aggregate Query Builder formulas.
modified:
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.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-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-10-08 17:16:47 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-10-09 02:47:12 +0000
@@ -358,11 +358,14 @@
 
                 if ( hasDataelement )
                 {
-                    sql += innerJoin + "programstageinstance as psi ";
-                    if ( !hasProgramInstances )
+                    if ( hasPatients || hasProgramInstances )
                     {
                         sql += " ON pi.programinstanceid=psi.programinstanceid ";
                     }
+                    else
+                    {
+                        sql += " INNER JOIN programinstance pi on pi.programinstanceid=pi.programinstanceid ";
+                    }
                     sql += "INNER JOIN organisationunit ou on ou.organisationunitid=psi.organisationunitid ";
                 }
 
@@ -454,7 +457,7 @@
         }
         else if ( (hasProgramInstances && !hasPatients) || operator.equals( CaseAggregationCondition.AGGRERATION_COUNT ) )
         {
-            sql += "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid ";
+            sql += innerJoin + " programinstance as pi ON pi.programinstanceid = psi.programinstanceid ";
             innerJoin = " INNER JOIN ";
         }
 
@@ -842,9 +845,8 @@
      */
     private String getConditionForPatientAttribute( int attributeId, Collection<Integer> orgunitIds )
     {
-        String sql = " EXISTS ( SELECT _pav.patientid FROM patientattributevalue _pav "
-            + "WHERE _pav.patientid = pi.patientid AND _pav.patientattributeid=" + attributeId
-            + "  AND p.organisationunitid in (" + TextUtils.getCommaDelimitedString( orgunitIds ) + ") AND _pav.value ";
+        String sql = " EXISTS ( SELECT * FROM patientattributevalue _pav "
+            + " WHERE _pav.patientid=pi.patientid AND _pav.patientattributeid=" + attributeId + "  AND _pav.value ";
 
         return sql;
     }