← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19224: Fixed bug when to run Aggregate Query Builder expression with interger tracked entity attribute.

 

------------------------------------------------------------
revno: 19224
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-01 19:26:30 +0700
message:
  Fixed bug when to run Aggregate Query Builder expression with interger tracked entity attribute.
modified:
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.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/hibernate/HibernateCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2015-05-28 15:04:54 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2015-06-01 12:26:30 +0000
@@ -87,6 +87,8 @@
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.grid.ListGrid;
 import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.util.TextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -150,6 +152,10 @@
     @Autowired
     private DataElementCategoryService categoryService;
     
+
+    @Autowired
+    private TrackedEntityAttributeService attributeService;
+    
     // -------------------------------------------------------------------------
     // Implementation Methods
     // -------------------------------------------------------------------------
@@ -445,7 +451,7 @@
             sql += "GROUP BY ou.organisationunitid ) from organisationunit ou where ou.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) ";
             
         }
-      
+System.out.println("\n\n " + sql + "\n\n");
         return sql;
     }
 
@@ -812,7 +818,17 @@
         
         sql = sql.replaceAll( CaseAggregationCondition.CURRENT_DATE, "now()");
         
-        return sql + " )  and psi.organisationunitid=ou.organisationunitid ";
+        sql += " ) ";
+        if( hasDataelementCriteria( caseExpression ) )
+        {
+            sql += " and psi.organisationunitid=ou.organisationunitid ";
+        }
+        else
+        {
+            sql += " and pi.organisationunitid=ou.organisationunitid ";
+        }
+        
+        return sql;
     }
 
     /**
@@ -896,7 +912,15 @@
 
             if ( isExist )
             {
-                sql += " AND _pav.value ";
+                TrackedEntityAttribute attribute =attributeService.getTrackedEntityAttribute( Integer.parseInt( attributeId ) );
+                if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_NUMBER ) )
+                {
+                    sql += " AND cast( _pav.value as " + statementBuilder.getDoubleColumnType() + " )  ";
+                }
+                else
+                {
+                    sql += " AND _pav.value ";
+                }
             }
         }
 
@@ -953,7 +977,7 @@
         String sql = " EXISTS ( SELECT * FROM programinstance as _pi inner join trackedentityinstance _p on _p.trackedentityinstanceid=_pi.trackedentityinstanceid "
             + "WHERE _pi.trackedentityinstanceid=pi.trackedentityinstanceid AND _pi.programid="
             + programId
-            + " AND _p.organisationunitid in ("
+            + " AND _pi.organisationunitid in ("
             + TextUtils.getCommaDelimitedString( orgunitIds )
             + ") AND _pi.enrollmentdate >= '"
             + PARAM_PERIOD_START_DATE