=== 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-12-01 16:05:30 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java 2011-12-01 17:08:55 +0000 @@ -253,6 +253,15 @@ */ Collection getAggregatedDataMapValues( int dataElementId, int periodId, Collection organisationUnitIds ); + /** + * Retrieves the AggregatedDataMapValues for the given arguments. + * + * @param dataElementIds the set of DataElement identifiers. + * @param periodId the Period identifier. + * @param organisationUnitId the OrganisationUnit identifier. + */ + Collection getAggregatedDataMapValues( Collection dataElementIds, int periodId, int organisationUnitId ); + // ---------------------------------------------------------------------- // AggregatedIndicatorValue // ---------------------------------------------------------------------- === 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-12-01 16:05:30 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java 2011-12-01 17:08:55 +0000 @@ -221,6 +221,15 @@ */ Collection getAggregatedDataMapValues( int dataElementId, int periodId, Collection organisationUnitIds ); + /** + * Retrieves the AggregatedDataMapValues for the given arguments. + * + * @param dataElementIds the set of DataElement identifiers. + * @param periodId the Period identifier. + * @param organisationUnitId the OrganisationUnit identifier. + */ + Collection getAggregatedDataMapValues( Collection dataElementIds, int periodId, int organisationUnitId ); + // ---------------------------------------------------------------------- // AggregatedIndicatorValue // ---------------------------------------------------------------------- === 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-12-01 16:05:30 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java 2011-12-01 17:08:55 +0000 @@ -157,6 +157,11 @@ return aggregatedDataValueStore.getAggregatedDataMapValues( dataElementId, periodId, organisationUnitIds ); } + public Collection getAggregatedDataMapValues( Collection dataElementIds, int periodId, int organisationUnitId ) + { + return aggregatedDataValueStore.getAggregatedDataMapValues( dataElementIds, periodId, organisationUnitId ); + } + // ------------------------------------------------------------------------- // AggregatedIndicatorValue // ------------------------------------------------------------------------- @@ -235,5 +240,4 @@ { return aggregatedDataValueStore.getDataValueMap( periodId, sourceId ); } - } === 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-12-01 16:05:30 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java 2011-12-01 17:08:55 +0000 @@ -443,6 +443,30 @@ return jdbcTemplate.query( sql, new AggregatedDataMapValueRowMapper() ); } + public Collection getAggregatedDataMapValues( Collection dataElementIds, int periodId, int organisationUnitId ) + { + final String sql = + "SELECT d.name, a.value, a.periodid " + + "FROM aggregateddatavalue AS a " + + "JOIN dataelement AS d ON (a.dataelementid = d.dataelementid) " + + "WHERE a.dataelementid IN (" + getCommaDelimitedString( dataElementIds ) + ") " + + "AND a.periodid = " + periodId + " " + + "AND a.organisationunitid = " + organisationUnitId; + + return jdbcTemplate.query( sql, new org.springframework.jdbc.core.RowMapper() + { + public AggregatedMapValue mapRow( ResultSet resultSet, int rowNum ) + throws SQLException + { + AggregatedMapValue value = new AggregatedMapValue(); + value.setDataElementName( resultSet.getString( 1 ) ); + value.setValue( resultSet.getDouble( 2 ) ); + value.setPeriodId( resultSet.getInt( 3 ) ); + return value; + } + } ); + } + // ------------------------------------------------------------------------- // AggregatedIndicatorValue // ------------------------------------------------------------------------- @@ -626,7 +650,8 @@ { final String sql = "SELECT o.organisationunitid, o.name, a.value, a.periodid, a.factor, a.numeratorvalue, a.denominatorvalue " + - "FROM aggregatedindicatorvalue AS a, organisationunit AS o " + + "FROM aggregatedindicatorvalue AS a " + + "JOIN organisationunit AS o ON (a.organisationunitid=o.organisationunitid) " + "WHERE a.indicatorid = " + indicatorId + " " + "AND a.periodid = " + periodId + " " + "AND a.organisationunitid IN (" + getCommaDelimitedString( organisationUnitIds ) + ")"; === modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2011-12-01 16:08:37 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2011-12-01 17:08:55 +0000 @@ -242,32 +242,12 @@ if ( group == null ) { - group = dataElementService.getAllDataElementGroups().iterator().next(); - } - - Period period = periodService.getPeriod( periodId ); - - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); - - Collection values = new HashSet(); - - if ( group != null ) - { - for ( DataElement dataElement : group.getMembers() ) - { - Double value = aggregatedDataValueService.getAggregatedValue( dataElement, period, organisationUnit ); - - value = value != null ? value : 0; // TODO improve - - AggregatedMapValue mapValue = new AggregatedMapValue(); - mapValue.setDataElementName( dataElement.getShortName() ); - mapValue.setValue( value ); - - values.add( mapValue ); - } - } - - return values; + return new HashSet(); + } + + Collection dataElementIds = ConversionUtils.getIdentifiers( DataElement.class, group.getMembers() ); + + return aggregatedDataValueService.getAggregatedDataMapValues( dataElementIds, periodId, organisationUnitId ); } // -------------------------------------------------------------------------