← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3045: Implemented web pivot table for data element data

 

------------------------------------------------------------
revno: 3045
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-03-16 00:26:14 +0100
message:
  Implemented web pivot table for data element data
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-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.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-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
  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/GetPivotTableOptionsAction.java
  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/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm


--
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-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<Integer> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Gets a collection of AggregatedDataValues.
@@ -126,6 +134,16 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, Collection<Integer> periodIds, Collection<Integer> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> 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<Integer> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Gets a collection of AggregatedDataValues.
@@ -102,6 +111,16 @@
      * @return a collection of AggregatedDataValues.
      */
     Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, Collection<Integer> periodIds, Collection<Integer> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> 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<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
     
-    private Collection<AggregatedIndicatorValue> indicatorValues = new ArrayList<AggregatedIndicatorValue>();
+    private Collection<? extends AggregatedValue> indicatorValues = new ArrayList<AggregatedIndicatorValue>();
 
     // -------------------------------------------------------------------------
     // Constructor
@@ -92,12 +93,12 @@
         this.organisationUnits = organisationUnits;
     }
 
-    public Collection<AggregatedIndicatorValue> getIndicatorValues()
+    public Collection<? extends AggregatedValue> getIndicatorValues()
     {
         return indicatorValues;
     }
 
-    public void setIndicatorValues( Collection<AggregatedIndicatorValue> indicatorValues )
+    public void setIndicatorValues( Collection<? extends AggregatedValue> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return aggregatedDataValueStore.getAggregatedDataValues( periodIds, organisationUnitIds );
+    }
+    
     public Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
         return aggregatedDataValueStore.getAggregatedDataValues( dataElementId, periodIds, organisationUnitIds );
     }
     
+    public Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return aggregatedDataValueStore.getAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds );
+    }
+    
     public int deleteAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> 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<Period> periods )
     {
         return aggregatedDataValueStore.countDataValuesAtLevel( orgunit, level, periods );
@@ -162,11 +171,13 @@
     {
         return aggregatedDataValueStore.getAggregatedIndicatorValues( indicatorIds, periodIds, organisationUnitIds );
     }
+    
     public int deleteAggregatedIndicatorValues( Collection<Integer> indicatorIds, Collection<Integer> periodIds,
         Collection<Integer> 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<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+        
+        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
+        
+        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<AggregatedDataValue> getAggregatedDataValues( int dataElementId, 
         Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
@@ -174,6 +202,35 @@
         }
     }
 
+    public Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+        
+        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
+        
+        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<AggregatedDataValue> getAggregatedDataValuesAtLevel( OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> 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<Period> periods = new ArrayList<Period>( 
@@ -109,25 +118,52 @@
         List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( 
             organisationUnitService.getOrganisationUnit( organisationUnitId ).getChildren() );
          
-        List<? extends Indicator> indicators = null;
-        Collection<AggregatedIndicatorValue> indicatorValues = null;
+        List<? extends IdentifiableObject> indicators = null;
+        Collection<? extends AggregatedValue> aggregatedValues = null;
         
-        if ( groupId == -1 ) // -1 -> All
-        {
-            indicators = new ArrayList<Indicator>( 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<Indicator>( indicatorService.getAllIndicators() );
+                
+                aggregatedValues = aggregatedDataValueService.getAggregatedIndicatorValues(
+                    ConversionUtils.getIdentifiers( Period.class, periods ), 
+                    ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) );
+            }
+            else
+            {
+                indicators = new ArrayList<Indicator>( 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<DataElement>( dataElementService.getAggregateableDataElements() );
+                
+                aggregatedValues = aggregatedDataValueService.getAggregatedDataValues( 
+                    ConversionUtils.getIdentifiers( Period.class, periods ), 
+                    ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnits ) );
+            }
+            else
+            {
+                indicators = new ArrayList<IdentifiableObject>( 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<Indicator>( 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 @@
 	<property name="aggregatedDataValueService"
 	  ref="org.hisp.dhis.aggregation.AggregatedDataValueService"/>
     <property name="indicatorService" 
-        ref="org.hisp.dhis.indicator.IndicatorService"/>
+      ref="org.hisp.dhis.indicator.IndicatorService"/>
+    <property name="dataElementService"
+      ref="org.hisp.dhis.dataelement.DataElementService"/>
     <property name="periodService" 
-        ref="org.hisp.dhis.period.PeriodService"/>
+      ref="org.hisp.dhis.period.PeriodService"/>
     <property name="organisationUnitService" 
-        ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+      ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
   </bean>
   
   <!-- DataSetReport -->

=== 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<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
     
     public List<PeriodType> getPeriodTypes()
@@ -65,13 +75,22 @@
         return indicatorGroups;
     }
 
+    private List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>(); 
+    
+    public List<DataElementGroup> getDataElementGroups()
+    {
+        return dataElementGroups;
+    }
+
     @Override
     public String execute()
         throws Exception
     {
         indicatorGroups = new ArrayList<IndicatorGroup>( indicatorService.getAllIndicatorGroups() );
+        dataElementGroups = new ArrayList<DataElementGroup>( 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">
     <property name="indicatorService"
       ref="org.hisp.dhis.indicator.IndicatorService"/>
+    <property name="dataElementService"
+      ref="org.hisp.dhis.dataelement.DataElementService"/>
   </bean>
   
   <bean id="org.hisp.dhis.reporting.pivottable.action.GetPivotTableAction"

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-02-28 02:42:12 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-03-15 23:26:14 +0000
@@ -323,4 +323,7 @@
 none = None
 ascending = Low to high
 descending = High to low
-top_limit = Top limit
\ No newline at end of file
+top_limit = Top limit
+data_type = Data type
+indicator = Indicator
+data_element_group = Data element group
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js	2011-01-21 18:49:34 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js	2011-03-15 23:26:14 +0000
@@ -3,6 +3,12 @@
 // Public methods
 // -------------------------------------------------------------------------
 
+function toggleDataType()
+{	
+  $( "#indicatorGroupDiv" ).toggle();
+  $( "#dataElementGroupDiv" ).toggle();
+}
+
 function showCriteria()
 {
   $( "div#criteria" ).show( "fast" );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js	2011-01-21 18:49:34 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js	2011-03-15 23:26:14 +0000
@@ -20,6 +20,10 @@
 
 var organisationUnitId = -1;
 
+var DATA_TYPE_INDICATOR = 0;
+var DATA_TYPE_DATA_ELEMENT = 1;
+var currentDataType = DATA_TYPE_INDICATOR;
+
 // -----------------------------------------------------------------------------
 // Public methods
 // -----------------------------------------------------------------------------
@@ -40,7 +44,9 @@
 {
   clearGlobalVariables();
   
+  var dataType = $( "#dataType" ).val();
   var indicatorGroupId = $( "#indicatorGroup" ).val();
+  var dataElementGroupId = $( "#dataElementGroup" ).val();
   var startDate = $( "#startDate" ).val();
   var endDate = $( "#endDate" ).val();
   var periodTypeName = $( "#periodType" ).val();
@@ -50,6 +56,10 @@
   
   var url = "getPivotTable.action";
   
+  var groupId = dataType == DATA_TYPE_INDICATOR ? indicatorGroupId : dataElementGroupId;
+  
+  currentDataType = dataType;
+  
   hideDivs();
   
   showLoader();
@@ -57,7 +67,8 @@
   $.getJSON(
     url,
     {
-      "indicatorGroupId": indicatorGroupId, 
+      "dataType": dataType,
+      "groupId": groupId,
       "periodTypeName": periodTypeName, 
       "startDate": startDate, 
       "endDate": endDate, 
@@ -172,11 +183,14 @@
  */
 function viewChartMenu( indicatorId, periodId, orgunitId )
 {
-  currentIndicator = indicatorId;
-  currentPeriod = periodId;
-  currentOrgunit = orgunitId;
+  if ( currentDataType == DATA_TYPE_INDICATOR ) // Currently indicators only supported
+  {
+    currentIndicator = indicatorId;
+    currentPeriod = periodId;
+    currentOrgunit = orgunitId;
   
-  showDropDown( "pivotMenu" );
+    showDropDown( "pivotMenu" );
+  }
 }
 
 /**
@@ -184,8 +198,7 @@
  */
 function loadListeners()
 {
-  var table = document.getElementById( "pivotTable" );
-  
+  var table = document.getElementById( "pivotTable" ); 
   table.addEventListener( "click", setPosition, false );
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm	2011-03-15 04:00:28 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm	2011-03-15 23:26:14 +0000
@@ -26,7 +26,7 @@
 {
 #set( $size = $pivotTable.indicatorValues.size() )
 #foreach( $value in $pivotTable.indicatorValues )
-"${value.indicatorId}-${value.periodId}-${value.organisationUnitId}":"${value.value}"#if( $velocityCount < $size ),#end
+"${value.elementId}-${value.periodId}-${value.organisationUnitId}":"${value.value}"#if( $velocityCount < $size ),#end
 #end } ] 
 }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm	2011-01-21 18:49:34 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm	2011-03-15 23:26:14 +0000
@@ -15,7 +15,7 @@
   position: relative;
   left: 2px;
   width: 265px;
-  height: 470px;
+  height: 500px;
   border: 1px solid #b0b0b0;
   background-color: #d9ece1;
   padding-left: 20px;
@@ -34,6 +34,12 @@
   margin-bottom: 6px;
 }
 
+div.inputSection
+{
+  padding-top: 7px;
+  padding-bottom: 5px;
+}
+
 td.column
 {
   background-color: #dae6f8;
@@ -72,7 +78,15 @@
 
 <div id="criteria" style="display:none">
 
-<p>
+<div class="inputSection">
+<label>$i18n.getString( "data_type" )</label>
+<select id="dataType" style="width:250px" onchange="toggleDataType()">
+  <option value="0">$i18n.getString( "indicator" )</option>
+  <option value="1">$i18n.getString( "data_element" )</option>
+</select>
+</div>
+
+<div id="indicatorGroupDiv" class="inputSection">
 <label>$i18n.getString( "indicator_group" )</label>
 <select id="indicatorGroup" style="width:250px">
   <option value="-1">[ All ]</option>
@@ -80,35 +94,43 @@
   <option value="${group.id}">$encoder.htmlEncode( $group.name )</option>
   #end
 </select>
-</p>
-
-<p>
+</div>
+
+<div id="dataElementGroupDiv" class="inputSection" style="display:none">
+<label>$i18n.getString( "data_element_group" )</label>
+<select id="dataElementGroup" style="width:250px">
+  <option value="-1">[ All ]</option>
+  #foreach( $group in $dataElementGroups )
+  <option value="${group.id}">$encoder.htmlEncode( $group.name )</option>
+  #end
+</select>
+</div>
+
+<div class="inputSection">
 <label>$i18n.getString( "start_date" ) ($i18n.getString( "format.date.label" ))</label><br>
 <input type="text" id="startDate" style="width:210px">
-</p>
+</div>
 
-<p>
+<div class="inputSection">
 <label>$i18n.getString( "end_date" ) ($i18n.getString( "format.date.label" ))</label><br>
 <input type="text" id="endDate" style="width:210px">
-</p>
+</div>
 
-<p>
+<div class="inputSection">
 <label>$i18n.getString( "period_type" )</label>
 <select id="periodType" style="width:250px">
   #foreach( $type in $periodTypes )
   <option value="${type.name}" #if( $type.name == "Monthly" )selected="selected"#end>$encoder.htmlEncode( $type.name )</option>
   #end
 </select>
-</p>
+</div>
 
-<p>
 <div id="selectionTree" style="width:250px; height:200px"></div>
-</p>
 
-<p>
+<div class="inputSection">
 <input type="button" value='$i18n.getString( "get_data" )' style="width:80px" onclick="getData()">
 <input type="button" value='$i18n.getString( "cancel" )' style="width:80px" onclick="hideDivs()">
-</p>
+</div>
 
 </div>
  
@@ -116,7 +138,7 @@
 
 <div id="pivot" style="display:none">
 
-<p>
+<div class="inputSection">
 <table>
   <tr>
     <td><label>$i18n.getString( "indicators" )</label></td>
@@ -131,12 +153,12 @@
     <td><input type="checkbox" id="orgunitBox"></td>
   </tr>
 </table>
-</p>
+</div>
 
-<p>
+<div class="inputSection">
 <input type="button" value='$i18n.getString( "pivot" )' style="width:80px" onclick="pivotData()">
 <input type="button" value='$i18n.getString( "cancel" )' style="width:80px" onclick="hideDivs()">
-</p>
+</div>
 
 </div>