=== 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-01-31 19:47:04 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java 2011-03-15 23:26:14 +0000 @@ -116,6 +116,14 @@ */ Double getAggregatedValue( int dataElement, int categoryOptionCombo, Collection periodIds, int organisationUnit ); + /** + * Gets a collection of AggregatedDataValues. + * + * @param periodIds the collection of Period identifiers. + * @param organisationUnitIds the collection of OrganisationUnit identifiers. + * @return a collection of AggregatedDataValues. + */ + Collection getAggregatedDataValues( Collection periodIds, Collection organisationUnitIds ); /** * Gets a collection of AggregatedDataValues. @@ -126,6 +134,16 @@ * @return a collection of AggregatedDataValues. */ Collection getAggregatedDataValues( int dataElementId, Collection periodIds, Collection organisationUnitIds ); + + /** + * Gets a collection of 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 getAggregatedDataValues( 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-01-31 19:47:04 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java 2011-03-15 23:26:14 +0000 @@ -92,6 +92,15 @@ * @return the aggregated value. */ Double getAggregatedDataValue( int dataElement, int categoryOptionCombo, Collection periodIds, int organisationUnit ); + + /** + * Gets a collection of AggregatedDataValues. + * + * @param periodIds the collection of Period identifiers. + * @param organisationUnitIds the collection of OrganisationUnit identifiers. + * @return a collection of AggregatedDataValues. + */ + Collection getAggregatedDataValues( Collection periodIds, Collection organisationUnitIds ); /** * Gets a collection of AggregatedDataValues. @@ -102,6 +111,16 @@ * @return a collection of AggregatedDataValues. */ Collection getAggregatedDataValues( int dataElementId, Collection periodIds, Collection organisationUnitIds ); + + /** + * Gets a collection of 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 getAggregatedDataValues( 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/pivottable/PivotTable.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java 2011-03-14 19:34:32 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java 2011-03-15 23:26:14 +0000 @@ -32,6 +32,7 @@ import java.util.List; import org.hisp.dhis.aggregation.AggregatedIndicatorValue; +import org.hisp.dhis.common.AggregatedValue; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; @@ -48,7 +49,7 @@ private List organisationUnits = new ArrayList(); - private Collection indicatorValues = new ArrayList(); + private Collection indicatorValues = new ArrayList(); // ------------------------------------------------------------------------- // Constructor @@ -92,12 +93,12 @@ this.organisationUnits = organisationUnits; } - public Collection getIndicatorValues() + public Collection getIndicatorValues() { return indicatorValues; } - public void setIndicatorValues( Collection indicatorValues ) + public void setIndicatorValues( Collection indicatorValues ) { this.indicatorValues = indicatorValues; } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java 2011-03-14 20:44:04 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java 2011-03-15 23:26:14 +0000 @@ -34,9 +34,13 @@ */ public interface PivotTableService { + final int DATA_TYPE_INDICATOR = 0; + final int DATA_TYPE_DATA_ELEMENT = 1; + /** * Returns a PivotTable object. * + * @param dataType the type of data, can be 1 for indicator and 2 for data element. * @param groupId the identifier of the IndicatorGroup. * @param periodTypeName the identifier of the PeriodType. * @param startDate the start date string. @@ -44,5 +48,5 @@ * @param level the OrganisationUnit level. * @return a PivotTable object. */ - PivotTable getPivotTable( int groupId, String periodTypeName, String startDate, String endDate, int level ); + PivotTable getPivotTable( int dataType, int groupId, String periodTypeName, String startDate, String endDate, int level ); } === 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-01-31 19:47:04 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java 2011-03-15 23:26:14 +0000 @@ -93,11 +93,21 @@ return aggregatedDataValueStore.getAggregatedDataValue( dataElement, categoryOption, period, organisationUnit ); } + public Collection getAggregatedDataValues( Collection periodIds, Collection organisationUnitIds ) + { + return aggregatedDataValueStore.getAggregatedDataValues( periodIds, organisationUnitIds ); + } + public Collection getAggregatedDataValues( int dataElementId, Collection periodIds, Collection organisationUnitIds ) { return aggregatedDataValueStore.getAggregatedDataValues( dataElementId, periodIds, organisationUnitIds ); } + public Collection getAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection organisationUnitIds ) + { + return aggregatedDataValueStore.getAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds ); + } + public int deleteAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection organisationUnitIds ) { return aggregatedDataValueStore.deleteAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds ); @@ -113,7 +123,6 @@ return aggregatedDataValueStore.getAggregatedDataValuesAtLevel(orgunit, level, periods); } - @Override public int countDataValuesAtLevel( OrganisationUnit orgunit, OrganisationUnitLevel level, Collection periods ) { return aggregatedDataValueStore.countDataValuesAtLevel( orgunit, level, periods ); @@ -162,11 +171,13 @@ { return aggregatedDataValueStore.getAggregatedIndicatorValues( indicatorIds, periodIds, organisationUnitIds ); } + public int deleteAggregatedIndicatorValues( Collection indicatorIds, Collection periodIds, Collection organisationUnitIds ) { return aggregatedDataValueStore.deleteAggregatedIndicatorValues( indicatorIds, periodIds, organisationUnitIds ); } + public int deleteAggregatedIndicatorValues() { return aggregatedDataValueStore.deleteAggregatedIndicatorValues(); @@ -183,7 +194,8 @@ { return aggregatedDataValueStore.countIndicatorValuesAtLevel( orgunit, level, periods ); } -// ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- // AggregatedIndicatorMapValue // ------------------------------------------------------------------------- === 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-02-17 15:37:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java 2011-03-15 23:26:14 +0000 @@ -143,7 +143,35 @@ return statementManager.getHolder().queryForDouble( sql ); } - + + public Collection getAggregatedDataValues( Collection periodIds, Collection organisationUnitIds ) + { + final StatementHolder holder = statementManager.getHolder(); + + final ObjectMapper mapper = new ObjectMapper(); + + try + { + final String sql = + "SELECT * " + + "FROM aggregateddatavalue " + + "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " + + "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )"; + + 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 ) { @@ -174,6 +202,35 @@ } } + public Collection getAggregatedDataValues( Collection dataElementIds, Collection periodIds, Collection organisationUnitIds ) + { + final StatementHolder holder = statementManager.getHolder(); + + final ObjectMapper mapper = new ObjectMapper(); + + try + { + final String sql = + "SELECT * " + + "FROM aggregateddatavalue " + + "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " + + "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " + + "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )"; + + 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 ) { === 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-03-14 20:44:04 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java 2011-03-15 23:26:14 +0000 @@ -36,9 +36,11 @@ import java.util.List; import org.hisp.dhis.aggregation.AggregatedDataValueService; -import org.hisp.dhis.aggregation.AggregatedIndicatorValue; +import org.hisp.dhis.common.AggregatedValue; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorService; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -79,8 +81,15 @@ public void setIndicatorService( IndicatorService indicatorService ) { this.indicatorService = indicatorService; - } - + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + private PeriodService periodService; public void setPeriodService( PeriodService periodService ) @@ -99,8 +108,8 @@ // PivotTableService implementation // ------------------------------------------------------------------------- - public PivotTable getPivotTable( int groupId, String periodTypeName, String startDate, String endDate, int organisationUnitId ) - { + public PivotTable getPivotTable( int dataType, int groupId, String periodTypeName, String startDate, String endDate, int organisationUnitId ) + { PeriodType periodType = PeriodType.getPeriodTypeByName( periodTypeName ); List periods = new ArrayList( @@ -109,25 +118,52 @@ List organisationUnits = new ArrayList( organisationUnitService.getOrganisationUnit( organisationUnitId ).getChildren() ); - List indicators = null; - Collection indicatorValues = null; + List indicators = null; + Collection aggregatedValues = null; - if ( groupId == -1 ) // -1 -> All - { - indicators = new ArrayList( indicatorService.getAllIndicators() ); - - indicatorValues = aggregatedDataValueService.getAggregatedIndicatorValues( - ConversionUtils.getIdentifiers( Period.class, periods ), - ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + if ( dataType == DATA_TYPE_INDICATOR ) + { + if ( groupId == -1 ) // All + { + indicators = new ArrayList( indicatorService.getAllIndicators() ); + + aggregatedValues = aggregatedDataValueService.getAggregatedIndicatorValues( + ConversionUtils.getIdentifiers( Period.class, periods ), + ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + } + else + { + indicators = new ArrayList( indicatorService.getIndicatorGroup( groupId ).getMembers() ); + + aggregatedValues = aggregatedDataValueService.getAggregatedIndicatorValues( + ConversionUtils.getIdentifiers( Indicator.class, indicators ), + ConversionUtils.getIdentifiers( Period.class, periods ), + ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + } + } + else if ( dataType == DATA_TYPE_DATA_ELEMENT ) + { + if ( groupId == -1 ) // All + { + indicators = new ArrayList( dataElementService.getAggregateableDataElements() ); + + aggregatedValues = aggregatedDataValueService.getAggregatedDataValues( + ConversionUtils.getIdentifiers( Period.class, periods ), + ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + } + else + { + indicators = new ArrayList( dataElementService.getDataElementGroup( groupId ).getMembers() ); + + aggregatedValues = aggregatedDataValueService.getAggregatedDataValues( + ConversionUtils.getIdentifiers( Indicator.class, indicators ), + ConversionUtils.getIdentifiers( Period.class, periods ), + ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + } } else { - indicators = new ArrayList( indicatorService.getIndicatorGroup( groupId ).getMembers() ); - - indicatorValues = aggregatedDataValueService.getAggregatedIndicatorValues( - ConversionUtils.getIdentifiers( Indicator.class, indicators ), - ConversionUtils.getIdentifiers( Period.class, periods ), - ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) ); + throw new IllegalArgumentException( "Illegal data type: " + dataType ); } PivotTable pivotTable = new PivotTable(); @@ -135,7 +171,7 @@ pivotTable.setIndicators( indicators ); pivotTable.setPeriods( periods ); pivotTable.setOrganisationUnits( organisationUnits ); - pivotTable.setIndicatorValues( indicatorValues ); + pivotTable.setIndicatorValues( aggregatedValues ); Collections.sort( pivotTable.getIndicators(), INDICATOR_COMPARATOR ); Collections.sort( pivotTable.getOrganisationUnits(), ORGUNIT_COMPARATOR ); === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-01 17:14:27 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-15 23:26:14 +0000 @@ -175,11 +175,13 @@ + ref="org.hisp.dhis.indicator.IndicatorService"/> + + ref="org.hisp.dhis.period.PeriodService"/> + ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/> === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java 2011-03-14 13:23:25 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java 2011-03-15 23:26:14 +0000 @@ -63,13 +63,20 @@ // Input // ------------------------------------------------------------------------- - private Integer indicatorGroupId; - - public void setIndicatorGroupId( Integer indicatorGroupId ) - { - this.indicatorGroupId = indicatorGroupId; - } - + private Integer dataType = 0; + + public void setDataType( Integer dataType ) + { + this.dataType = dataType; + } + + private Integer groupId = -1; + + public void setGroupId( Integer groupId ) + { + this.groupId = groupId; + } + private String periodTypeName; public void setPeriodTypeName( String periodTypeName ) @@ -91,7 +98,7 @@ this.endDate = endDate; } - private Integer organisationUnitId; + private Integer organisationUnitId = 0; public void setOrganisationUnitId( Integer organisationUnitId ) { @@ -115,7 +122,7 @@ public String execute() { - pivotTable = pivotTableService.getPivotTable( indicatorGroupId, periodTypeName, startDate, endDate, organisationUnitId ); + pivotTable = pivotTableService.getPivotTable( dataType, groupId, periodTypeName, startDate, endDate, organisationUnitId ); for ( Period period : pivotTable.getPeriods() ) { === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java 2011-01-21 18:49:34 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java 2011-03-15 23:26:14 +0000 @@ -31,6 +31,9 @@ import java.util.Collections; import java.util.List; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataelement.comparator.DataElementGroupNameComparator; import org.hisp.dhis.indicator.IndicatorGroup; import org.hisp.dhis.indicator.IndicatorService; import org.hisp.dhis.indicator.comparator.IndicatorGroupNameComparator; @@ -51,6 +54,13 @@ this.indicatorService = indicatorService; } + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + private List periodTypes = PeriodType.getAvailablePeriodTypes(); public List getPeriodTypes() @@ -65,13 +75,22 @@ return indicatorGroups; } + private List dataElementGroups = new ArrayList(); + + public List getDataElementGroups() + { + return dataElementGroups; + } + @Override public String execute() throws Exception { indicatorGroups = new ArrayList( indicatorService.getAllIndicatorGroups() ); + dataElementGroups = new ArrayList( dataElementService.getAllDataElementGroups() ); Collections.sort( indicatorGroups, new IndicatorGroupNameComparator() ); + Collections.sort( dataElementGroups, new DataElementGroupNameComparator() ); return SUCCESS; } === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-14 20:51:30 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-15 23:26:14 +0000 @@ -338,6 +338,8 @@ scope="prototype"> +