← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2493: Implemented aggregatedindicatorvalue export

 

------------------------------------------------------------
revno: 2493
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: trunk
timestamp: Sat 2011-01-08 15:48:07 +0000
message:
  Implemented aggregatedindicatorvalue export
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-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.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-01-08 05:58:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java	2011-01-08 15:48:07 +0000
@@ -118,7 +118,7 @@
 
 
     /**
-     * Returns values for children of an orgunit at a particular level
+     * Returns agg data values for children of an orgunit at a particular level
      * @param orgunit the root organisationunit
      * @param level the level to retrieve values at
      * @param periods the periods to retrieve values for
@@ -192,6 +192,15 @@
      */
     int deleteAggregatedIndicatorValues();
 
+    /**
+     * Returns agg indicator values for children of an orgunit at a particular level
+     * @param orgunit the root organisationunit
+     * @param level the level to retrieve values at
+     * @param periods the periods to retrieve values for
+     * @return an iterator type object for retrieving the values
+     */
+    public StoreIterator<AggregatedIndicatorValue> getAggregateIndicatorValuesAtLevel(OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods);
+
     // ----------------------------------------------------------------------
     // AggregatedIndicatorMapValue
     // ----------------------------------------------------------------------

=== 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-08 05:58:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueStore.java	2011-01-08 15:48:07 +0000
@@ -92,6 +92,15 @@
      */
     int deleteAggregatedDataValues();
 
+        /**
+     * Returns values for children of an orgunit at a particular level
+     * @param orgunit the root organisationunit
+     * @param level the level to retrieve values at
+     * @param periods the period to retrieve values for
+     * @return an iterator type object for retrieving the values
+     */
+    public StoreIterator<AggregatedDataValue> getAggregatedDataValuesAtLevel(OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods);
+
     // ----------------------------------------------------------------------
     // AggregatedDataMapValue
     // ----------------------------------------------------------------------
@@ -166,7 +175,7 @@
      * @param periods the period to retrieve values for
      * @return an iterator type object for retrieving the values
      */
-    public StoreIterator<AggregatedDataValue> getAggregateDataValuesAtLevel(OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods);
+    public StoreIterator<AggregatedIndicatorValue> getAggregatedIndicatorValuesAtLevel(OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods);
 
 
     // ----------------------------------------------------------------------

=== 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-08 05:58:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/DefaultAggregatedDataValueService.java	2011-01-08 15:48:07 +0000
@@ -80,7 +80,7 @@
 
     public StoreIterator<AggregatedDataValue> getAggregateDataValuesAtLevel(OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods)
     {
-       return aggregatedDataValueStore.getAggregateDataValuesAtLevel(orgunit, level, periods);
+       return aggregatedDataValueStore.getAggregatedDataValuesAtLevel(orgunit, level, periods);
     }
 
     // -------------------------------------------------------------------------
@@ -126,6 +126,11 @@
         return aggregatedDataValueStore.deleteAggregatedIndicatorValues();
     }
 
+    @Override
+    public StoreIterator<AggregatedIndicatorValue> getAggregateIndicatorValuesAtLevel( OrganisationUnit orgunit, OrganisationUnitLevel level, Collection<Period> periods )
+    {
+        return aggregatedDataValueStore.getAggregatedIndicatorValuesAtLevel( orgunit, level, periods );
+    }
     // -------------------------------------------------------------------------
     // AggregatedIndicatorMapValue
     // -------------------------------------------------------------------------
@@ -163,4 +168,5 @@
     {
         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-01-08 14:25:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java	2011-01-08 15:48:07 +0000
@@ -156,7 +156,7 @@
     }
 
     @Override
-    public StoreIterator<AggregatedDataValue> getAggregateDataValuesAtLevel(OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods)
+    public StoreIterator<AggregatedDataValue> getAggregatedDataValuesAtLevel(OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods)
     {
         final StatementHolder holder = statementManager.getHolder();
 
@@ -188,7 +188,7 @@
         }
         catch ( SQLException ex )
         {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
+            throw new RuntimeException( "Failed to get aggregated data values", ex );
         }
         finally
         {
@@ -337,6 +337,47 @@
         return statementManager.getHolder().executeUpdate( "DELETE FROM aggregatedindicatorvalue" );
     }
 
+    @Override
+    public StoreIterator<AggregatedIndicatorValue> getAggregatedIndicatorValuesAtLevel(OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods)
+    {
+        final StatementHolder holder = statementManager.getHolder();
+
+        try
+        {
+            int rootlevel = rootOrgunit.getLevel();
+
+            String periodids = getCommaDelimitedString( getIdentifiers(Period.class, periods));
+
+            final String sql =
+                "SELECT aiv.* " +
+                "FROM aggregatedindicatorvalue AS aiv " +
+                "INNER JOIN _orgunitstructure AS ous on aiv.organisationunitid=ous.organisationunitid " +
+                "WHERE aiv.level = " + level.getLevel() +
+                " AND ous.idlevel" + rootlevel + "=" + rootOrgunit.getId() +
+                " AND aiv.periodid IN (" + periodids + ") ";
+
+            log.info("sql: " + sql);
+
+            Statement statement = holder.getStatement();
+
+            statement.setFetchSize(FETCH_SIZE);
+
+            final ResultSet resultSet = statement.executeQuery( sql );
+
+            RowMapper<AggregatedIndicatorValue> rm = new AggregatedIndicatorValueRowMapper();
+            return new JdbcStoreIterator<AggregatedIndicatorValue>(resultSet, holder, rm);
+        }
+        catch ( SQLException ex )
+        {
+            throw new RuntimeException( "Failed to get aggregated indicator values", ex );
+        }
+        finally
+        {
+            // holder.close();
+        }
+    }
+
+
     // -------------------------------------------------------------------------
     // AggregatedIndicatorMapValue
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-01-08 01:23:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-01-08 15:48:07 +0000
@@ -39,6 +39,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.aggregation.AggregatedDataValue;
 import org.hisp.dhis.aggregation.AggregatedDataValueService;
+import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
 import org.hisp.dhis.aggregation.StoreIterator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
@@ -124,10 +125,24 @@
 
         log.info( "Exporting for " + rootOrgUnit.getName() + " at level: " + orgUnitLevel.getName());
 
-        StoreIterator<AggregatedDataValue> advIterator
+        if (requestType == RequestType.DATAVALUE)
+        {
+            processDataValues(writer, rootOrgUnit , orgUnitLevel, periods );
+        }
+       else
+        {
+            processIndicatorValues(writer, rootOrgUnit , orgUnitLevel, periods );
+        }
+
+    }
+
+     void processDataValues(Writer writer, OrganisationUnit rootOrgUnit , OrganisationUnitLevel orgUnitLevel, Collection<Period> periods )
+         throws IOException
+     {
+        StoreIterator<AggregatedDataValue> Iterator
             = aggregatedDataValueService.getAggregateDataValuesAtLevel( rootOrgUnit , orgUnitLevel, periods );
 
-        AggregatedDataValue adv = advIterator.next();
+        AggregatedDataValue adv = Iterator.next();
 
         while (adv != null)
         {
@@ -141,10 +156,41 @@
             writer.write( adv.getCategoryOptionComboId() + ",");
             writer.write( adv.getValue() + "\n");
 
-            adv = advIterator.next();
-        }
-
-        writer.flush();
-    }
-
+            adv = Iterator.next();
+        }
+
+        writer.flush();
+
+     }
+
+
+     void processIndicatorValues(Writer writer, OrganisationUnit rootOrgUnit , OrganisationUnitLevel orgUnitLevel, Collection<Period> periods )
+         throws IOException
+     {
+        StoreIterator<AggregatedIndicatorValue> Iterator
+            = aggregatedDataValueService.getAggregateIndicatorValuesAtLevel( rootOrgUnit , orgUnitLevel, periods );
+
+        AggregatedIndicatorValue aiv = Iterator.next();
+
+        while (aiv != null)
+        {
+            // process adv ..
+            int periodId = aiv.getPeriodId();
+            String period = periodService.getPeriod( periodId).getIsoDate();
+
+            writer.write( period + ",");
+            writer.write( aiv.getOrganisationUnitId() + ",");
+            writer.write( aiv.getIndicatorId() + ",");
+            writer.write( aiv.getFactor() + ",");
+            writer.write( aiv.getNumeratorValue() + ",");
+            writer.write( aiv.getDenominatorValue() + ",");
+            writer.write( aiv.getAnnualized() + ",");
+            writer.write( aiv.getValue() + "\n");
+
+            aiv = Iterator.next();
+        }
+
+        writer.flush();
+
+     }
 }