← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4431: Fixed bug with web pivot table. Values for multi-dimensional data elements were not calculated co...

 

------------------------------------------------------------
revno: 4431
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-08-24 22:25:14 +0200
message:
  Fixed bug with web pivot table. Values for multi-dimensional data elements were not calculated correctly.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.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-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java	2011-03-15 23:26:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java	2011-08-24 20:25:14 +0000
@@ -124,6 +124,17 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
+
+    /**
+     * Gets a collection of AggregatedDataValues where the value is the sum of
+     * all category option combos for the data element. 0 is set as 
+     * categoryoptioncombo identifier value on the AggregatedDataValues.
+     * 
+     * @param periodIds the collection of Period identifiers.
+     * @param organisationUnitIds the collection of OrganisationUnit identifiers.
+     * @return a collection of AggregatedDataValues.
+     */
+    Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Gets a collection of AggregatedDataValues.
@@ -144,6 +155,18 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
+
+    /**
+     * Gets a collection of AggregatedDataValues where the value is the sum of
+     * all category option combos for the data element. 0 is set as 
+     * categoryoptioncombo identifier value on the AggregatedDataValues.
+     * 
+     * @param dataElementIds the collection of DataElement identifiers.
+     * @param periodIds the collection of Period identifiers.
+     * @param organisationUnitIds the collection of OrganisationUnit identifiers.
+     * @return a collection of AggregatedDataValues.
+     */
+    Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Deletes AggregatedDataValues registered for the given parameters.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java	2011-03-15 23:26:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java	2011-08-24 20:25:14 +0000
@@ -101,6 +101,17 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
+
+    /**
+     * Gets a collection of AggregatedDataValues where the value is the sum of
+     * all category option combos for the data element. 0 is set as 
+     * categoryoptioncombo identifier value on the AggregatedDataValues.
+     * 
+     * @param periodIds the collection of Period identifiers.
+     * @param organisationUnitIds the collection of OrganisationUnit identifiers.
+     * @return a collection of AggregatedDataValues.
+     */
+    Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Gets a collection of AggregatedDataValues.
@@ -121,6 +132,18 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
+
+    /**
+     * Gets a collection of AggregatedDataValues where the value is the sum of
+     * all category option combos for the data element. 0 is set as 
+     * categoryoptioncombo identifier value on the AggregatedDataValues.
+     * 
+     * @param dataElementIds the collection of DataElement identifiers.
+     * @param periodIds the collection of Period identifiers.
+     * @param organisationUnitIds the collection of OrganisationUnit identifiers.
+     * @return a collection of AggregatedDataValues.
+     */
+    Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Deletes AggregatedDataValues registered for the given parameters.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java	2011-03-15 23:26:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java	2011-08-24 20:25:14 +0000
@@ -98,6 +98,11 @@
         return aggregatedDataValueStore.getAggregatedDataValues( periodIds, organisationUnitIds );
     }
     
+    public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return aggregatedDataValueStore.getAggregatedDataValueTotals( periodIds, organisationUnitIds );
+    }
+    
     public Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
         return aggregatedDataValueStore.getAggregatedDataValues( dataElementId, periodIds, organisationUnitIds );
@@ -107,6 +112,11 @@
     {
         return aggregatedDataValueStore.getAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds );
     }
+
+    public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return aggregatedDataValueStore.getAggregatedDataValueTotals( dataElementIds, periodIds, organisationUnitIds );
+    }
     
     public int deleteAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java	2011-04-10 10:59:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java	2011-08-24 20:25:14 +0000
@@ -171,6 +171,35 @@
             holder.close();
         }
     }
+    
+    public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+        
+        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
+        
+        try
+        {
+            final String sql = 
+                "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
+                "FROM aggregateddatavalue " +
+                "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
+                "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
+            
+            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
+            
+            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
+        }
+        catch ( SQLException ex )
+        {
+            throw new RuntimeException( "Failed to get aggregated data value", ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
 
     public Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, 
         Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
@@ -231,6 +260,36 @@
         }
     }
 
+    public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+        
+        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
+        
+        try
+        {
+            final String sql = 
+                "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
+                "FROM aggregateddatavalue " +
+                "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
+                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
+                "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
+            
+            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
+            
+            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
+        }
+        catch ( SQLException ex )
+        {
+            throw new RuntimeException( "Failed to get aggregated data value", ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
+
     @Override
     public StoreIterator<AggregatedDataValue> getAggregatedDataValuesAtLevel( OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods )
     {
@@ -250,8 +309,6 @@
                 " AND ous.idlevel" + rootlevel + "=" + rootOrgunit.getId() +
                 " AND adv.periodid IN (" + periodids + ") ";
 
-            log.info("sql: " + sql);
-
             Statement statement = holder.getStatement();
 
             statement.setFetchSize(FETCH_SIZE);

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java	2011-07-13 18:16:12 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java	2011-08-24 20:25:14 +0000
@@ -147,7 +147,7 @@
             {
                 indicators = new ArrayList<DataElement>( dataElementService.getAggregateableDataElements() );
                 
-                aggregatedValues = aggregatedDataValueService.getAggregatedDataValues( 
+                aggregatedValues = aggregatedDataValueService.getAggregatedDataValueTotals( 
                     ConversionUtils.getIdentifiers( Period.class, periods ), 
                     ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) );
             }
@@ -155,8 +155,8 @@
             {
                 indicators = new ArrayList<AbstractIdentifiableObject>( dataElementService.getDataElementGroup( groupId ).getMembers() );
                 
-                aggregatedValues = aggregatedDataValueService.getAggregatedDataValues(
-                    ConversionUtils.getIdentifiers( Indicator.class, indicators ),
+                aggregatedValues = aggregatedDataValueService.getAggregatedDataValueTotals(
+                    ConversionUtils.getIdentifiers( DataElement.class, indicators ),
                     ConversionUtils.getIdentifiers( Period.class, periods ), 
                     ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) );  
             }