=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java 2012-07-19 19:20:26 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java 2012-12-29 16:37:15 +0000 @@ -75,28 +75,31 @@ FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); - final String sql = rawData ? - "select dataelementid, categoryoptioncomboid, value " + - "from datavalue " + - "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + - "and periodid = " + period.getId() + " " + - "and sourceid = " + unit.getId() - : - "select dataelementid, categoryoptioncomboid, value " + - "from aggregateddatavalue " + - "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + - "and periodid = " + period.getId() + " " + - "and organisationunitid = " + unit.getId(); - - SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - - while ( rowSet.next() ) + if ( !dataElements.isEmpty() ) { - int dataElementId = rowSet.getInt( "dataelementid" ); - int categoryOptionComboId = rowSet.getInt( "categoryoptioncomboid" ); - Double value = rowSet.getDouble( "value" ); - - map.put( dataElementId + SEPARATOR + categoryOptionComboId, value ); + final String sql = rawData ? + "select dataelementid, categoryoptioncomboid, value " + + "from datavalue " + + "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + + "and periodid = " + period.getId() + " " + + "and sourceid = " + unit.getId() + : + "select dataelementid, categoryoptioncomboid, value " + + "from aggregateddatavalue " + + "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + + "and periodid = " + period.getId() + " " + + "and organisationunitid = " + unit.getId(); + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); + + while ( rowSet.next() ) + { + int dataElementId = rowSet.getInt( "dataelementid" ); + int categoryOptionComboId = rowSet.getInt( "categoryoptioncomboid" ); + Double value = rowSet.getDouble( "value" ); + + map.put( dataElementId + SEPARATOR + categoryOptionComboId, value ); + } } return map; @@ -111,25 +114,28 @@ DataElementCategoryCombo categoryCombo = section.getCategoryCombo(); Set dataElements = new HashSet( section.getDataElements() ); - for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) + if ( !dataElements.isEmpty() ) { - final String sql = - "select dataelementid, sum(value) as total " + - "from aggregateddatavalue " + - "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + - "and categoryoptioncomboid in (" + getCommaDelimitedString( getIdentifiers( DataElementCategoryOptionCombo.class, categoryOption.getCategoryOptionCombos() ) ) + ") " + - "and periodid = " + period.getId() + " " + - "and organisationunitid = " + unit.getId() + " " + - "group by dataelementid"; - - SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - - while ( rowSet.next() ) + for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) { - int dataElementId = rowSet.getInt( "dataelementid" ); - Double value = rowSet.getDouble( "total" ); - - map.put( dataElementId + SEPARATOR + categoryOption.getId(), value ); + final String sql = + "select dataelementid, sum(value) as total " + + "from aggregateddatavalue " + + "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + + "and categoryoptioncomboid in (" + getCommaDelimitedString( getIdentifiers( DataElementCategoryOptionCombo.class, categoryOption.getCategoryOptionCombos() ) ) + ") " + + "and periodid = " + period.getId() + " " + + "and organisationunitid = " + unit.getId() + " " + + "group by dataelementid"; + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); + + while ( rowSet.next() ) + { + int dataElementId = rowSet.getInt( "dataelementid" ); + Double value = rowSet.getDouble( "total" ); + + map.put( dataElementId + SEPARATOR + categoryOption.getId(), value ); + } } } } @@ -145,22 +151,25 @@ FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); - final String sql = - "select dataelementid, sum(value) as total " + - "from aggregateddatavalue " + - "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + - "and periodid = " + period.getId() + " " + - "and organisationunitid = " + unit.getId() + " " + - "group by dataelementid"; - - SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - - while ( rowSet.next() ) + if ( !dataElements.isEmpty() ) { - int dataElementId = rowSet.getInt( "dataelementid" ); - Double value = rowSet.getDouble( "total" ); + final String sql = + "select dataelementid, sum(value) as total " + + "from aggregateddatavalue " + + "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " + + "and periodid = " + period.getId() + " " + + "and organisationunitid = " + unit.getId() + " " + + "group by dataelementid"; + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - map.put( String.valueOf( dataElementId ), value ); + while ( rowSet.next() ) + { + int dataElementId = rowSet.getInt( "dataelementid" ); + Double value = rowSet.getDouble( "total" ); + + map.put( String.valueOf( dataElementId ), value ); + } } return map; @@ -172,22 +181,25 @@ Set indicators = new HashSet( dataSet.getIndicators() ); - final String sql = - "select indicatorid, sum(value) as total " + - "from aggregatedindicatorvalue " + - "where indicatorid in (" + getCommaDelimitedString( getIdentifiers( Indicator.class, indicators ) ) + ") " + - "and periodid = " + period.getId() + " " + - "and organisationunitid = " + unit.getId() + " " + - "group by indicatorid"; - - SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - - while ( rowSet.next() ) + if ( !indicators.isEmpty() ) { - int indicatorid = rowSet.getInt( "indicatorid" ); - Double value = rowSet.getDouble( "total" ); + final String sql = + "select indicatorid, sum(value) as total " + + "from aggregatedindicatorvalue " + + "where indicatorid in (" + getCommaDelimitedString( getIdentifiers( Indicator.class, indicators ) ) + ") " + + "and periodid = " + period.getId() + " " + + "and organisationunitid = " + unit.getId() + " " + + "group by indicatorid"; + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); - map.put( String.valueOf( indicatorid ), value ); + while ( rowSet.next() ) + { + int indicatorid = rowSet.getInt( "indicatorid" ); + Double value = rowSet.getDouble( "total" ); + + map.put( String.valueOf( indicatorid ), value ); + } } return map;