← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2372: Completed organisation unit distribution report

 

------------------------------------------------------------
revno: 2372
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2010-12-14 12:36:39 +0100
message:
  Completed organisation unit distribution report
added:
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionChartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style/
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style/dhis-web-reporting.css
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionServiceTest.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.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/resources/struts.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.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/document/DocumentService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java	2010-12-13 15:18:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java	2010-12-14 11:36:39 +0000
@@ -29,8 +29,6 @@
 
 import java.util.Collection;
 
-import org.hisp.dhis.datamart.DataMartExport;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionService.java	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionService.java	2010-12-14 11:36:39 +0000
@@ -1,12 +1,45 @@
 package org.hisp.dhis.orgunitdistribution;
 
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.jfree.chart.JFreeChart;
 
+/**
+ * @author Lars Helge Overland
+ */
 public interface OrgUnitDistributionService
 {
     final String ID = OrgUnitDistributionService.class.getName();
     
-    Grid getOrganisationUnitDistribution( OrganisationUnitGroupSet groupSet, OrganisationUnit parent );
+    JFreeChart getOrganisationUnitDistributionChart( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit );
+    
+    Grid getOrganisationUnitDistribution( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit, boolean organisationUnitOnly );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2010-11-29 02:04:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2010-12-14 11:36:39 +0000
@@ -1,4 +1,30 @@
 package org.hisp.dhis.patientdatavalue;
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 import java.io.Serializable;
 import java.util.Date;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2010-12-13 16:32:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2010-12-14 11:36:39 +0000
@@ -30,7 +30,6 @@
 import java.util.Collection;
 
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.indicator.IndicatorGroupSet;
 
 /**
  * @author Lars Helge Overland

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2010-12-13 16:32:50 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2010-12-14 11:36:39 +0000
@@ -202,6 +202,7 @@
         CategoryPlot plot = getCategoryPlot( dataSet, getBarRenderer(), orientation, labelPositions );
 
         JFreeChart jFreeChart = getBasicJFreeChart( plot );
+        jFreeChart.setTitle( title );
 
         return jFreeChart;
     }
@@ -368,7 +369,7 @@
 
         return renderer;
     }
-
+    
     /**
      * Returns a JFreeChart of type defined in the chart argument.
      */
@@ -466,10 +467,8 @@
 
                         if ( chart.isDimension( DIMENSION_PERIOD ) )
                         {
-
                             regularDataSet.addValue( value != null ? value : 0, indicator.getShortName(), chart
                                 .getFormat().formatPeriod( period ) );
-
                         }
                         else
                         {
@@ -477,10 +476,10 @@
                                 chart.getFormat().formatPeriod( period ), indicator.getShortName() );
                         }
                         columnIndex++;
-
-                        if ( value != null && value != 0.0 ) // Omit missing
-                        // values and 0
-                        // from regression
+                        
+                        // Omit missing values and 0 from regression
+                        
+                        if ( value != null && value != 0.0 ) 
                         {
                             regression.addData( columnIndex, value );
                         }
@@ -497,11 +496,10 @@
                         for ( Period period : chart.getAllPeriods() )
                         {
                             final double value = regression.predict( columnIndex++ );
-
-                            if ( !Double.isNaN( value ) ) // Enough values
-                            // must
-                            // exist for
-                            // regression
+                            
+                            // Enough values must exist for regression
+                            
+                            if ( !Double.isNaN( value ) ) 
                             {
                                 regressionDataSet.addValue( value, TREND_PREFIX + indicator.getShortName(), chart
                                     .getFormat().formatPeriod( period ) );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java	2010-12-14 05:15:06 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java	2010-12-14 11:36:39 +0000
@@ -1,12 +1,43 @@
 package org.hisp.dhis.orgunitdistribution.impl;
 
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.collections.CollectionUtils;
+import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
@@ -16,14 +47,25 @@
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService;
 import org.hisp.dhis.system.grid.ListGrid;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.CategoryLabelPositions;
+import org.jfree.chart.plot.PlotOrientation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
+/**
+ * @author Lars Helge Overland
+ */
 public class DefaultOrgUnitDistributionService
     implements OrgUnitDistributionService
 {
     private static final Comparator<OrganisationUnit> ORGUNIT_COMPARATOR = new OrganisationUnitNameComparator();
     private static final Comparator<OrganisationUnitGroup> ORGUNIT_GROUP_COMPARATOR = new OrganisationUnitGroupNameComparator();
-    
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
     private OrganisationUnitService organisationUnitService;
     
     public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
@@ -31,15 +73,46 @@
         this.organisationUnitService = organisationUnitService;
     }
     
+    private ChartService chartService;
+    
+    public void setChartService( ChartService chartService )
+    {
+        this.chartService = chartService;
+    }
+
+    // -------------------------------------------------------------------------
+    // OrgUnitDistributionService implementation
+    // -------------------------------------------------------------------------
+
+    public JFreeChart getOrganisationUnitDistributionChart( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit )
+    {
+        Map<String, Double> categoryValues = new HashMap<String, Double>();
+                
+        Grid grid = getOrganisationUnitDistribution( groupSet, organisationUnit, true );
+        
+        Assert.isTrue( grid != null && grid.getHeight() == 2 );
+        
+        for ( int i = 1; i < grid.getWidth(); i++ ) // Skip name column
+        {
+            categoryValues.put( grid.getRow( 0 ).get( i ), Double.valueOf( grid.getRow( 1 ).get( i ) ) );
+        }
+        
+        String title = groupSet.getName() + " - " + organisationUnit.getName();
+        
+        JFreeChart chart = chartService.getJFreeChart( title, PlotOrientation.VERTICAL, CategoryLabelPositions.DOWN_45, categoryValues );
+        
+        return chart;
+    }
+    
     @Override
     @Transactional
     @SuppressWarnings("unchecked")
-    public Grid getOrganisationUnitDistribution( OrganisationUnitGroupSet groupSet, OrganisationUnit parent )
+    public Grid getOrganisationUnitDistribution( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit, boolean organisationUnitOnly  )
     {
         Grid grid = new ListGrid();
         grid.nextRow();
         
-        List<OrganisationUnit> units = new ArrayList<OrganisationUnit>( parent.getChildren() );
+        List<OrganisationUnit> units = organisationUnitOnly ? Arrays.asList( organisationUnit ) : new ArrayList<OrganisationUnit>( organisationUnit.getChildren() );
         List<OrganisationUnitGroup> groups = new ArrayList<OrganisationUnitGroup>( groupSet.getOrganisationUnitGroups() );
         
         Collections.sort( units, 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	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-12-14 11:36:39 +0000
@@ -271,6 +271,8 @@
   	class="org.hisp.dhis.orgunitdistribution.impl.DefaultOrgUnitDistributionService">
     <property name="organisationUnitService" 
         ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+    <property name="chartService"
+      ref="org.hisp.dhis.chart.ChartService"/>
   </bean>
     
   <!-- DeletionHandler -->

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionServiceTest.java	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/orgunitdistribution/OrgUnitDistributionServiceTest.java	2010-12-14 11:36:39 +0000
@@ -59,7 +59,7 @@
         
         organisationUnitGroupService.addOrganisationUnitGroupSet( groupSet );
         
-        Grid grid = distributionService.getOrganisationUnitDistribution( groupSet, unitA );
+        Grid grid = distributionService.getOrganisationUnitDistribution( groupSet, unitA, false );
         assertNotNull( grid );
         assertEquals( 3, grid.getWidth() );
         assertEquals( 3, grid.getHeight() );

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2010-12-14 03:45:27 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2010-12-14 11:36:39 +0000
@@ -1279,3 +1279,8 @@
 {
 	return isNumber( value ) && parseFloat( value ) == 0;
 }
+
+function getRandomNumber()
+{
+	return Math.floor( 1000000 * Math.random() );
+}

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java	2010-12-14 11:36:39 +0000
@@ -133,7 +133,7 @@
             
             log.info( "Get distribution for group set: " + selectedGroupSet + " and organisation unit: " + selectedOrganisationUnit );
         
-            distribution = distributionService.getOrganisationUnitDistribution( selectedGroupSet, selectedOrganisationUnit );
+            distribution = distributionService.getOrganisationUnitDistribution( selectedGroupSet, selectedOrganisationUnit, false );
         }
         
         return SUCCESS;

=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionChartAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionChartAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionChartAction.java	2010-12-14 11:36:39 +0000
@@ -0,0 +1,119 @@
+package org.hisp.dhis.reporting.orgunitdistribution.action;
+
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.jfree.chart.JFreeChart;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GetOrgUnitDistributionChartAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+    
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    private OrgUnitDistributionService distributionService;
+
+    public void setDistributionService( OrgUnitDistributionService distributionService )
+    {
+        this.distributionService = distributionService;
+    }
+    
+    private SelectionTreeManager selectionTreeManager;
+
+    public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+    {
+        this.selectionTreeManager = selectionTreeManager;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer groupSetId;
+
+    public void setGroupSetId( Integer groupSetId )
+    {
+        this.groupSetId = groupSetId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private JFreeChart chart;
+
+    public JFreeChart getChart()
+    {
+        return chart;
+    }
+
+    private int width = 700;
+
+    public int getWidth()
+    {
+        return width;
+    }
+
+    private int height = 400;
+
+    public int getHeight()
+    {
+        return height;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        OrganisationUnitGroupSet groupSet = organisationUnitGroupService.getOrganisationUnitGroupSet( groupSetId );
+        OrganisationUnit unit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
+        
+        chart = distributionService.getOrganisationUnitDistributionChart( groupSet, unit );
+        
+        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	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-12-14 11:36:39 +0000
@@ -530,4 +530,14 @@
       ref="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
   </bean>
   
+  <bean id="org.hisp.dhis.reporting.orgunitdistribution.action.GetOrgUnitDistributionChartAction"
+  	class="org.hisp.dhis.reporting.orgunitdistribution.action.GetOrgUnitDistributionChartAction"
+  	scope="prototype">
+    <property name="organisationUnitGroupService"
+      ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
+    <property name="distributionService"
+      ref="org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService"/>
+    <property name="selectionTreeManager"
+      ref="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
+  </bean>
 </beans>

=== 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	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2010-12-14 11:36:39 +0000
@@ -284,7 +284,7 @@
 intro_pivot_table = Browse pivot tables, which can be pivoted on any of the indicator, organisation unit and period dimensions.
 intro_report_table = Add and generate report tables. Report tables are highly customizable database tables which can be used as basis for reports.
 intro_data_completeness = Browse the submission rates of data sets. This can be viewed by organisation unit and period, and later reported to PDF and Workbook.
-intro_orgunit_distribution_report = Browse the organisation unit distribution report.
+intro_orgunit_distribution_report = Browse the organisation unit distribution report based on the organisation unit group sets and its groups.
 orgunit_distribution_report = Organisation Unit Distribution Report
 add_indicator_chart = Add indicator chart
 create_period_by_indicator_chart = Create period by indicator chart
@@ -296,4 +296,6 @@
 distribution_report = Distribution Report
 select_group_set = Select group set
 orgunit_distribution = Organisation unit distribution report
-get_report = Get report
\ No newline at end of file
+get_report = Get report
+get_chart = Get chart
+group_set = Group set
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2010-12-14 11:36:39 +0000
@@ -418,17 +418,21 @@
       <param name="bufferSize">1024</param>
       </result>
     </action>
-    
-    
+        
     <!-- Organisation Unit Distribution -->
   
     <action name="displayOrgUnitDistribution" class="org.hisp.dhis.reporting.orgunitdistribution.action.GetOrgUnitDistributionAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-reporting/viewOrgUnitDistribution.vm</param>
       <param name="menu">/dhis-web-reporting/menu.vm</param>
-      <param name="javascripts">../dhis-web-commons/oust/oust.js</param>
+      <param name="javascripts">../dhis-web-commons/oust/oust.js,javascript/orgUnitDistribution.js</param>
+      <param name="stylesheets">style/dhis-web-reporting.css</param>
       <interceptor-ref name="organisationUnitTreeStack" />
     </action>
 	
+	<action name="getOrgUnitDistributionChart" class="org.hisp.dhis.reporting.orgunitdistribution.action.GetOrgUnitDistributionChartAction">
+	  <result name="success" type="chart"></result>
+    </action>
+	
   </package>
 </struts>

=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js	2010-12-14 11:36:39 +0000
@@ -0,0 +1,9 @@
+
+function displayOrgUnitDistributionChart() {
+	$( "#chartDiv" ).show();
+	$( "#tableDiv" ).hide();
+	var groupSetId = $( "#groupSetId" ).val();
+	var random = getRandomNumber();
+	var source = "getOrgUnitDistributionChart.action?groupSetId=" + groupSetId + "&r=" + random;
+	$( "#chartImg" ).attr( "src", source );
+}

=== added directory 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style'
=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style/dhis-web-reporting.css'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style/dhis-web-reporting.css	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/style/dhis-web-reporting.css	2010-12-14 11:36:39 +0000
@@ -0,0 +1,6 @@
+
+.oud
+{
+  text-align: center;
+  width: 150px;
+}

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm	2010-12-13 21:21:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm	2010-12-14 11:36:39 +0000
@@ -1,37 +1,59 @@
 
 <h3>$i18n.getString( "orgunit_distribution" )</h3>
 
-<div id="selectionTree" style="width:325px; height:200px"></div>
-
-<script type="text/javascript">
-selectionTreeSelection.setMultipleSelectionAllowed( false );
-selectionTree.buildSelectionTree();	
-</script>
+<!-- Criteria -->
 
 <form action="displayOrgUnitDistribution.action" method="get">
-<p>
-<select id="groupSetId" name="groupSetId" style="width:325px">
+
+<table>
+
+<tr><th>$i18n.getString( "criteria" )</th></tr>
+
+<tr>
+<td><div id="selectionTree" style="width:325px; height:200px"></div></td>
+</tr>
+
+<tr>
+<td><select id="groupSetId" name="groupSetId" style="width:325px">
 <option value="0">[ $i18n.getString( "select_group_set" ) ]</option>
 #foreach( $groupSet in $groupSets )
 <option value="$groupSet.id"
 #if( $selectedGroupSet.id && $groupSet.id == $selectedGroupSet.id ) selected="selected"#end
 >$!encoder.htmlEncode( $groupSet.name )</option>
 #end
-</select>
-</p>
-
-<p><input type="submit" value="$i18n.getString( 'get_report' )" style="width:100px"></p>
-
-<br>
+</select></td>
+</tr>
+
+<tr>
+<td><input type="submit" value="$i18n.getString( 'get_report' )" style="width:100px">
+<input type="button" value="$i18n.getString( 'get_chart' )" style="width:100px" onclick="displayOrgUnitDistributionChart()"></td>
+</tr>
+
+<tr><td style="height:15px"></td></tr>
+
+</table>
+
+</form>
+
+<script type="text/javascript">
+selectionTreeSelection.setMultipleSelectionAllowed( false );
+selectionTree.buildSelectionTree();	
+</script>
+
+<!-- Table -->
 
 #if( $distribution )
 
+<div id="tableDiv">
+
 <table class="listTable">
 
 <thead>
+<tr>
 #foreach( $col in $distribution.getRow( 0 ) )
-<th>$encoder.htmlEncode( $col )</th>
+<th class="oud">$encoder.htmlEncode( $col )</th>
 #end
+</tr>
 </thead>
 
 <tbody>
@@ -39,7 +61,7 @@
 #if( $velocityCount > 1 )
 <tr>
 #foreach( $col in $row )
-<td>${col}</td>
+<td #if( $velocityCount > 1 )class="oud"#end>${col}</td>
 #end
 </tr>
 #end 
@@ -48,4 +70,10 @@
 
 </table>
 
-#end
\ No newline at end of file
+</div>
+
+#end
+
+<!-- Chart -->
+
+<div id="chartDiv" style="display:none"><img src="" id="chartImg"></div>