=== 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 getAggregatedDataValues( Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection periodIds, Collection organisationUnitIds ); /** * Gets a collection of AggregatedDataValues. @@ -144,6 +155,18 @@ * @return a collection of AggregatedDataValues. */ Collection getAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection dataElementIds, Collection periodIds, Collection 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 getAggregatedDataValues( Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection periodIds, Collection organisationUnitIds ); /** * Gets a collection of AggregatedDataValues. @@ -121,6 +132,18 @@ * @return a collection of AggregatedDataValues. */ Collection getAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection dataElementIds, Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection periodIds, Collection organisationUnitIds ) + { + return aggregatedDataValueStore.getAggregatedDataValueTotals( periodIds, organisationUnitIds ); + } + public Collection getAggregatedDataValues( int dataElementId, Collection periodIds, Collection organisationUnitIds ) { return aggregatedDataValueStore.getAggregatedDataValues( dataElementId, periodIds, organisationUnitIds ); @@ -107,6 +112,11 @@ { return aggregatedDataValueStore.getAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds ); } + + public Collection getAggregatedDataValueTotals( Collection dataElementIds, Collection periodIds, Collection organisationUnitIds ) + { + return aggregatedDataValueStore.getAggregatedDataValueTotals( dataElementIds, periodIds, organisationUnitIds ); + } public int deleteAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection 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 getAggregatedDataValueTotals( Collection periodIds, Collection organisationUnitIds ) + { + final StatementHolder holder = statementManager.getHolder(); + + final ObjectMapper mapper = new ObjectMapper(); + + 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 getAggregatedDataValues( int dataElementId, Collection periodIds, Collection organisationUnitIds ) @@ -231,6 +260,36 @@ } } + public Collection getAggregatedDataValueTotals( Collection dataElementIds, Collection periodIds, Collection organisationUnitIds ) + { + final StatementHolder holder = statementManager.getHolder(); + + final ObjectMapper mapper = new ObjectMapper(); + + 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 getAggregatedDataValuesAtLevel( OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection 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( 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( 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 ) ); }