← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20632: Analytics. Fixed bug related to program indicators/data items and financial year periods

 

------------------------------------------------------------
revno: 20632
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-12 13:46:32 +0200
message:
  Analytics. Fixed bug related to program indicators/data items and financial year periods
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-09-08 18:09:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-10-12 11:46:32 +0000
@@ -39,6 +39,8 @@
 import static org.hisp.dhis.system.util.MathUtils.getRounded;
 
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
@@ -337,7 +339,7 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Returns the count clause based on the output type.
+     * Returns the count clause based on value dimension and output type.
      * 
      * TODO include output type if aggregation type is count
      */
@@ -381,6 +383,38 @@
             }
         }
     }
+
+    /**
+     * Returns columns based on value dimension and output type.
+     */
+    private List<String> getAggregateColumns( EventQueryParams params )
+    {
+        EventOutputType outputType = params.getOutputType();
+        
+        if ( params.hasValueDimension() )
+        {
+            return Lists.newArrayList( statementBuilder.columnQuote( params.getValue().getUid() ) );
+        }
+        else if ( params.hasProgramIndicatorDimension() )
+        {
+            Set<String> uids = ProgramIndicator.getDataElementAndAttributeIdentifiers( params.getProgramIndicator().getExpression() );
+            
+            return uids.stream().map( uid -> statementBuilder.columnQuote( uid ) ).collect( Collectors.toList() );
+        }
+        else
+        {
+            if ( EventOutputType.TRACKED_ENTITY_INSTANCE.equals( outputType ) && params.isProgramRegistration() )
+            {
+                return Lists.newArrayList( "tei" );
+            }
+            else if ( EventOutputType.ENROLLMENT.equals( outputType ) )
+            {
+                return Lists.newArrayList( "pi" );
+            }
+        }
+        
+        return Lists.newArrayList();
+    }
     
     /**
      * Returns the dynamic select columns. Dimensions come first and query items
@@ -426,11 +460,13 @@
     
     private String getFromWhereMultiplePartitionsClause( EventQueryParams params, List<String> fixedColumns )
     {
+        List<String> aggregateCols = getAggregateColumns( params );
+        
         String sql = "from (";
         
         for ( String partition : params.getPartitions().getPartitions() )
         {
-            sql += "select " + getSelectString( fixedColumns ) + getSelectColumns( params );
+            sql += "select " + getSelectString( fixedColumns ) + getSelectString( aggregateCols ) + getSelectColumns( params );
             
             sql += " " + getFromWhereSinglePartitionClause( params, partition );