← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3770: Improving performance in TabularAnalysis-WORKINPROGRESS

 

------------------------------------------------------------
revno: 3770
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-05-27 16:55:15 +0530
message:
  Improving performance in TabularAnalysis-WORKINPROGRESS
modified:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java
  local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java
  local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/action/GetOrgUnitsAction.java
  local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/ta/action/GenerateTabularAnalysisResultAction.java
  local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/util/DashBoardService.java
  local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-dashboard/src/main/resources/struts.xml
  local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/javascript/ta.js
  local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/tabularAnalysisFront.vm
  local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ed/action/EDReportResultAction.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 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java	2011-05-18 11:56:37 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java	2011-05-27 11:25:15 +0000
@@ -128,19 +128,33 @@
     String getAggCountForTextData( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit );
     
     String getCountForTextData( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit );
-    
+
+    String getDataelementIds( List<Report_inDesign> reportDesignList );
+    
+    String getAggVal( String expression, Map<String, String> aggDeMap );
+
+    double getIndividualIndicatorValue( Indicator indicator, OrganisationUnit orgunit, Date startDate, Date endDate );
+    
+    Map<Integer, Integer> getOrgunitLevelMap( );
+    
+    String getDataelementIdsAsString( List<Indicator> indicatorList );
+
     String getResultDataValueFromAggregateTable( String formula, String periodIdsByComma, Integer orgunitId );
     
     Map<String, String> getResultDataValueFromAggregateTable( Integer orgunitId, String dataElmentIdsByComma, String periodIdsByComma );
     
     Map<String, String> getAggDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodsByComma );
-    
-    String getDataelementIds( List<Report_inDesign> reportDesignList );
-    
-    String getAggVal( String expression, Map<String, String> aggDeMap );
 
+    Map<String, String> getResultDataValueFromAggregateTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+    
     Map<String, List<String>> getIndicatorDataValueFromAggregateTable( Integer orgunitId, String indicatorIdsByComma, Integer periodId );
     
-    double getIndividualIndicatorValue( Indicator indicator, OrganisationUnit orgunit, Date startDate, Date endDate );
+    Map<String, String> getResultDataValueFromAggregateTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
 
+    Map<String, String> getAggDataFromDataValueTableByDeAndPeriodwise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+    
+    Map<String, String> getDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+    
+    Map<String, String> getDataFromDataValueTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+        
 }

=== modified file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java	2011-05-18 11:56:37 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java	2011-05-27 11:25:15 +0000
@@ -1802,7 +1802,74 @@
             throw new RuntimeException( "Illegal DataElement id", e );
         }
     }
+
+    public Map<String, String> getResultDataValueFromAggregateTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+    {
+        Map<String, String> aggDataMap = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue" +
+                           " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
+                           " organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
+                           " periodid IN (" + periodIdsByComma +") " +
+                           " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {
+                Integer ouId = rs.getInt( 1 );
+                Integer deId = rs.getInt( 2 );
+                Integer optionComId = rs.getInt( 3 );
+                Double aggregatedValue = rs.getDouble( 4 );
+                if( aggregatedValue != null )
+                {
+                    aggDataMap.put( ouId+":"+deId+":"+optionComId, ""+aggregatedValue );
+                }
+            }
+            
+            return aggDataMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }
+
     
+    public Map<String, String> getResultDataValueFromAggregateTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+    {
+        Map<String, String> aggDataMap = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT organisationunitid,dataelementid,categoryoptioncomboid,periodid,value FROM aggregateddatavalue " + 
+                            " WHERE organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
+                            " dataelementid IN ("+ dataElmentIdsByComma +") AND "+
+                            " periodid IN ("+ periodIdsByComma +")";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Integer deId = rs.getInt( 2 );
+                Integer optionComId = rs.getInt( 3 );
+                Integer periodId = rs.getInt( 4 );
+                Double aggregatedValue = rs.getDouble( 5 );
+                if( aggregatedValue != null )
+                {
+                    aggDataMap.put( orgUnitId+":"+deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+                }
+            }
+            
+            return aggDataMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }
+
     
     public Map<String, String> getAggDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
     {
@@ -1834,6 +1901,104 @@
             throw new RuntimeException( "Illegal DataElement id", e );
         }
     }
+
+    public Map<String, String> getAggDataFromDataValueTableByDeAndPeriodwise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+    {
+        Map<String, String> aggDataMap = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT dataelementid,categoryoptioncomboid,periodid,SUM(value) FROM datavalue " +
+                           " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
+                           " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
+                           " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid,periodid";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {
+                Integer deId = rs.getInt( 1 );
+                Integer optionComId = rs.getInt( 2 );
+                Integer periodId = rs.getInt( 3 );
+                Double aggregatedValue = rs.getDouble( 4 );
+                if( aggregatedValue != null )
+                {
+                    aggDataMap.put( deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+                }
+            }
+            
+            return aggDataMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }    
+
+    public Map<String, String> getDataFromDataValueTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+    {
+        Map<String, String> aggDataMap = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue " +
+                           " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
+                           " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
+                           " periodid IN (" + periodIdsByComma +") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Integer deId = rs.getInt( 2 );
+                Integer optionComId = rs.getInt( 3 );
+                Double aggregatedValue = rs.getDouble( 4 );
+                if( aggregatedValue != null )
+                {
+                    aggDataMap.put( orgUnitId+":"+deId+":"+optionComId, ""+aggregatedValue );
+                }
+            }
+            
+            return aggDataMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }    
+
+    public Map<String, String> getDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+    {
+        Map<String, String> aggDataMap = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT sourceid,dataelementid,categoryoptioncomboid,periodid,value FROM datavalue " +
+                           " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
+                           " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
+                           " periodid IN (" + periodIdsByComma +")";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Integer deId = rs.getInt( 2 );
+                Integer optionComId = rs.getInt( 3 );
+                Integer periodId = rs.getInt( 4 );
+                Double aggregatedValue = rs.getDouble( 5 );
+                if( aggregatedValue != null )
+                {
+                    aggDataMap.put( orgUnitId+":"+deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+                }
+            }
+            
+            return aggDataMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }    
+
     
     public String getResultDataValueFromAggregateTable( String formula, String periodIdsByComma, Integer orgunitId )
     {
@@ -2026,6 +2191,41 @@
         return ""+recordCount;
     }
     
+    public String getDataelementIdsAsString( List<Indicator> indicatorList )
+    {
+        String dataElmentIdsByComma = "-1";
+        for( Indicator indicator : indicatorList )
+        {
+            String formula = indicator.getNumerator() + " + " + indicator.getDenominator();
+            try
+            {
+                Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+                Matcher matcher = pattern.matcher( formula );
+                StringBuffer buffer = new StringBuffer();
+
+                while ( matcher.find() )
+                {
+                    String replaceString = matcher.group();
+
+                    replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+                    replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
+
+                    int dataElementId = Integer.parseInt( replaceString );
+                    dataElmentIdsByComma += "," + dataElementId;
+                    replaceString = "";
+                    matcher.appendReplacement( buffer, replaceString );
+                }
+            }
+            catch( Exception e )
+            {
+                
+            }
+        }
+        
+        return dataElmentIdsByComma;
+    }
+
     public String getDataelementIds( List<Report_inDesign> reportDesignList )
     {
         String dataElmentIdsByComma = "-1";
@@ -2149,8 +2349,8 @@
         {
             throw new RuntimeException( "Illegal DataElement id", e );
         }
-    }
-
+    }    
+    
     public double getIndividualIndicatorValue( Indicator indicator, OrganisationUnit orgunit, Date startDate, Date endDate ) 
     {
         String numeratorExp = indicator.getNumerator();
@@ -2201,4 +2401,29 @@
         return aggregatedValue;
     }
 
+    public Map<Integer, Integer> getOrgunitLevelMap( )
+    {
+        Map<Integer, Integer> orgUnitLevelMap = new HashMap<Integer, Integer>();
+        try
+        {
+            String query = "SELECT organisationunitid,level FROM _orgunitstructure";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            
+            while ( rs.next() )
+            {                
+                Integer orgUnitId = rs.getInt( 1 );
+                Integer level = rs.getInt( 2 );
+                
+                orgUnitLevelMap.put( orgUnitId, level );
+            }
+            
+            return orgUnitLevelMap;
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Illegal DataElement id", e );
+        }
+    }
+
 }

=== modified file 'local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/action/GetOrgUnitsAction.java'
--- local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/action/GetOrgUnitsAction.java	2011-01-13 09:39:35 +0000
+++ local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/action/GetOrgUnitsAction.java	2011-05-27 11:25:15 +0000
@@ -1,9 +1,15 @@
 package org.hisp.dhis.dataanalyser.action;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.reports.ReportService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -19,7 +25,14 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private ReportService reportService;
 
+    public void setReportService( ReportService reportService )
+    {
+        this.reportService = reportService;
+    }
+    
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
@@ -66,10 +79,6 @@
     public String execute()
         throws Exception
     {
-        /* OrganisationUnit */
-        
-     //   System.out.println("org Id is : " + orgUnitId );
-        
         if ( orgUnitId != null )
         {
             orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
@@ -77,12 +86,31 @@
         
         System.out.println(" orgUnit Id is : " + orgUnit.getId() + " , orgUnit Name is : " + orgUnit.getName() );
         orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
-        //orgUnitLevel = orgUnit.getLevel();
         maxOrgUnitLevel = organisationUnitService.getNumberOfOrganisationalLevels();
         
         // Hardcoded : if it is Tabular Analysis, Null Reporter
         if( type != null && type.equalsIgnoreCase( "ta" ) )
         {
+            
+            List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( orgUnit.getId() ) );
+            Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+        
+            maxOrgUnitLevel = 1;
+            Iterator<OrganisationUnit> ouIterator = orgUnitList.iterator();
+            while ( ouIterator.hasNext() )
+            {
+                OrganisationUnit orgU = ouIterator.next();
+                
+                Integer level = orgunitLevelMap.get( orgU.getId() );
+                if( level == null )
+                    level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+                if ( level > maxOrgUnitLevel )
+                {
+                    maxOrgUnitLevel = level;
+                }
+            }
+            
+            /*
             for( int i = orgUnitLevel+1; i <= maxOrgUnitLevel; i++ )
             {
                 Collection<OrganisationUnit> tempOrgUnitList = organisationUnitService.getOrganisationUnitsAtLevel( i, orgUnit );
@@ -92,6 +120,7 @@
                     break;
                 }
             }
+            */
         }
         
         return SUCCESS;

=== modified file 'local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/ta/action/GenerateTabularAnalysisResultAction.java'
--- local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/ta/action/GenerateTabularAnalysisResultAction.java	2011-04-15 11:34:10 +0000
+++ local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/ta/action/GenerateTabularAnalysisResultAction.java	2011-05-27 11:25:15 +0000
@@ -27,12 +27,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -40,6 +44,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import jxl.Workbook;
 import jxl.format.Alignment;
@@ -79,6 +85,8 @@
 import org.hisp.dhis.period.SixMonthlyPeriodType;
 import org.hisp.dhis.period.WeeklyPeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
+import org.hisp.dhis.reports.ReportService;
+import org.hisp.dhis.system.util.MathUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -91,6 +99,12 @@
     private final String ORGUNITGRP = "orgUnitGroupRadio";
 
     private final String ORGUNITLEVEL = "orgUnitLevelRadio";
+    
+    private final String GENERATEAGGDATA = "generateaggdata";
+
+    private final String USEEXISTINGAGGDATA = "useexistingaggdata";
+
+    private final String USECAPTUREDDATA = "usecaptureddata";
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -167,6 +181,13 @@
         this.dataValueService = dataValueService;
     }
 
+    private ReportService reportService;
+
+    public void setReportService( ReportService reportService )
+    {
+        this.reportService = reportService;
+    }
+
     private I18nFormat format;
 
     public void setFormat( I18nFormat format )
@@ -256,38 +277,55 @@
         this.periodLB = periodLB;
     }
 
-    private String ouRadio;
+    private String orgUnitSelListCB;
+    
+    public void setOrgUnitSelListCB(String orgUnitSelListCB) 
+    {
+        this.orgUnitSelListCB = orgUnitSelListCB;
+    }
 
-    public void setOuRadio( String ouRadio )
+    private String aggData;
+    
+    public void setAggData( String aggData )
     {
-        this.ouRadio = ouRadio;
+        this.aggData = aggData;
     }
 
     List<String> periodNames;
 
     private Map<OrganisationUnit, Integer> ouChildCountMap;
 
+    String dataElementIdsByComma;
+    
+    String periodIdsByComma;
+    
+    String orgUnitIdsByComma;
+    
+    List<DataElement> dataElementList;
+    List<Indicator> indicatorList;
+    List<String> serviceTypeList;
+    Map<Integer, List<Integer>> periodMap;
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
-    public String execute()
-        throws Exception
+    public String execute() throws Exception
     {
-
         /* Initialization */
         statementManager.initialise();
 
         selOUList = new ArrayList<OrganisationUnit>();
         selStartPeriodList = new ArrayList<Date>();
         selEndPeriodList = new ArrayList<Date>();
-
+        dataElementList = new ArrayList<DataElement>();
+        indicatorList = new ArrayList<Indicator>();
+        serviceTypeList = new ArrayList<String>();
+        periodMap = new HashMap<Integer, List<Integer>>();
         ouChildCountMap = new HashMap<OrganisationUnit, Integer>();
 
         String monthOrder[] = {  "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
         int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
         
-        
         /* Period Info */
 
         String startD = "";
@@ -296,11 +334,11 @@
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" );
        
         periodNames = new ArrayList<String>();
+
         // for weekly period
-        
         if ( periodTypeLB.equalsIgnoreCase( WeeklyPeriodType.NAME ) )
         {
-            System.out.println( " Inside  weekly" );
+            Integer pCount = 0;
             for ( String periodStr : periodLB )
             {
                 String  startWeekDate = periodStr.split( "To" )[0] ; //for start week
@@ -309,17 +347,23 @@
                 startD = startWeekDate.trim();
                 endD = endWeekDate.trim();
                 
-                selStartPeriodList.add( format.parseDate( startD ) );
-                selEndPeriodList.add( format.parseDate( endD ) );
+                Date sDate = format.parseDate( startD );
+                Date eDate = format.parseDate( endD );
+                selStartPeriodList.add( sDate );
+                selEndPeriodList.add( eDate );
+                
+                List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                periodMap.put( pCount, periodIds );
+                
+                pCount++;
                 
                 periodNames.add( periodStr );
-                //System.out.println( startD + " : " + endD );
             }
         }
-        
         else
         {
-            System.out.println( " Inside other than weekly" );
+            Integer pCount = 0;
             for ( String year : yearLB )
             {
                 int selYear = Integer.parseInt( year );
@@ -329,9 +373,17 @@
                     startD = "" + selYear + "-01-01";
                     endD = "" + selYear  + "-12-31";
                     
-                    selStartPeriodList.add( format.parseDate( startD ) );
-                    selEndPeriodList.add( format.parseDate( endD ) );
+                    Date sDate = format.parseDate( startD );
+                    Date eDate = format.parseDate( endD );
+                    selStartPeriodList.add( sDate );
+                    selEndPeriodList.add( eDate );
+
+                    List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                    List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                    periodMap.put( pCount, periodIds );
                     
+                    pCount++;
+
                     periodNames.add( "" + selYear );
         
                     continue;
@@ -352,8 +404,16 @@
                         {
                             endD = "" + selYear  + "-" + monthOrder[period] + "-" + ( monthDays[period] + 1 );
                         } 
-                        selStartPeriodList.add( format.parseDate( startD ) );
-                        selEndPeriodList.add( format.parseDate( endD ) );
+
+                        Date sDate = format.parseDate( startD );
+                        Date eDate = format.parseDate( endD );
+                        selStartPeriodList.add( sDate );
+                        selEndPeriodList.add( eDate );
+
+                        List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                        List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                        periodMap.put( pCount, periodIds );
+                        pCount++;
                         
                         periodNames.add( simpleDateFormat.format( format.parseDate( startD ) ) );
                     }
@@ -384,8 +444,17 @@
                             endD = "" + selYear + "-12-31";
                             periodNames.add( (selYear) + "-Q4" );
                         }
-                        selStartPeriodList.add( format.parseDate( startD ) );
-                        selEndPeriodList.add( format.parseDate( endD ) );
+                        
+                        Date sDate = format.parseDate( startD );
+                        Date eDate = format.parseDate( endD );
+                        selStartPeriodList.add( sDate );
+                        selEndPeriodList.add( eDate );
+
+                        List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                        List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                        periodMap.put( pCount, periodIds );
+                        pCount++;
+
                     }
                     else if ( periodTypeLB.equalsIgnoreCase( SixMonthlyPeriodType.NAME ) )
                     {
@@ -403,8 +472,15 @@
                             periodNames.add( selYear + "-HY2" );
                         }
                        
-                        selStartPeriodList.add( format.parseDate( startD ) );
-                        selEndPeriodList.add( format.parseDate( endD ) );
+                        Date sDate = format.parseDate( startD );
+                        Date eDate = format.parseDate( endD );
+                        selStartPeriodList.add( sDate );
+                        selEndPeriodList.add( eDate );
+
+                        List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                        List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                        periodMap.put( pCount, periodIds );
+                        pCount++;
                     }
                     else if ( periodTypeLB.equalsIgnoreCase( DailyPeriodType.NAME ) )
                     {
@@ -422,44 +498,652 @@
                        startD = selYear + "-" + month + "-" + date;
                        endD = selYear  + "-" + month + "-" + date;
                        
-                       selStartPeriodList.add( format.parseDate( startD ) );
-                       selEndPeriodList.add( format.parseDate( endD ) );
+                       Date sDate = format.parseDate( startD );
+                       Date eDate = format.parseDate( endD );
+                       selStartPeriodList.add( sDate );
+                       selEndPeriodList.add( eDate );
+
+                       List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                       List<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                       periodMap.put( pCount, periodIds );
+                       pCount++;
+
                        System.out.println( startD + " *** " + endD );
                        periodNames.add( startD );
                     }
                 }
             }
-      }
-        
-        
- // calling diffrent functions       
-    
-    
-    if ( ouRadio.equalsIgnoreCase( ORGUNITSELECTED ) )
-    {
-        System.out.println( "Report Generation Start Time is : \t" + new Date() );
-        generateOrgUnitSelected();
-
-    }
-    else if ( ouRadio.equalsIgnoreCase( ORGUNITGRP ) )
-    {
-        System.out.println( "Report Generation Start Time is : \t" + new Date() );
-        generateOrgUnitGroup();
-
-    }
-    else if ( ouRadio.equalsIgnoreCase( ORGUNITLEVEL ) )
-    {
-        System.out.println( "Report Generation Start Time is : \t" + new Date() );
-        generateOrgUnitLevel();
-
-    }
-
-    statementManager.destroy();
-    System.out.println( "Report Generation End Time is : \t" + new Date() );
-
-    return SUCCESS;
-    }
-
+        }
+
+        initialize();
+        
+        // calling diffrent functions       
+        if ( orgUnitSelListCB.equalsIgnoreCase( ORGUNITSELECTED ) )
+        {
+            System.out.println( ORGUNITSELECTED + " Report Generation Start Time is : \t" + new Date() );
+            if( aggData.equalsIgnoreCase( USECAPTUREDDATA ) && aggPeriodCB == null )
+            {
+                System.out.println("Inside generateSelectedOrgUnitData_UseCapturedData_Periodwise method");
+                generateSelectedOrgUnitData_UseCapturedData_Periodwise();
+            }
+            else if( aggData.equalsIgnoreCase( USECAPTUREDDATA ) && aggPeriodCB != null )
+            {
+                System.out.println("Inside generateSelectedOrgUnitData_UseCapturedData_AggPeriods method");
+                generateSelectedOrgUnitData_UseCapturedData_AggPeriods();
+            }
+            else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) && aggPeriodCB != null )
+            {
+                System.out.println("Inside generateSelectedOrgUnitData_GenerateAggregateData_AggPeriods method");
+                generateSelectedOrgUnitData_GenerateAggregateData_AggPeriods();
+            }
+            else
+            {
+                generateOrgUnitSelected();
+            }
+        }
+        else if ( orgUnitSelListCB.equalsIgnoreCase( ORGUNITGRP ) )
+        {
+            System.out.println( ORGUNITGRP + " Report Generation Start Time is : \t" + new Date() );
+            generateOrgUnitGroup();
+        }
+        else if ( orgUnitSelListCB.equalsIgnoreCase( ORGUNITLEVEL ) )
+        {
+            System.out.println( ORGUNITLEVEL + " Report Generation Start Time is : \t" + new Date() );
+            if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) && aggPeriodCB == null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_UseExisting_Periodwise method");
+                generateOrgUnitLevelData_UseExisting_Periodwise();
+            }
+            else if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) && aggPeriodCB != null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_UseExisting_AggPeriods method");
+                generateOrgUnitLevelData_UseExisting_AggPeriods();
+            }
+            else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) && aggPeriodCB == null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_GenerateAggregateData_Periodwise method");
+                generateOrgUnitLevelData_GenerateAggregateData_Periodwise();
+            }
+            else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) && aggPeriodCB != null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_GenerateAggregateData_AggPeriods method");
+                generateOrgUnitLevelData_GenerateAggregateData_AggPeriods();
+            }
+            else if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) && aggPeriodCB == null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_UseCapturedData_Periodwise method");
+                generateOrgUnitLevelData_UseCapturedData_Periodwise();
+            }
+            else if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) && aggPeriodCB != null )
+            {
+                System.out.println("Inside generateOrgUnitLevelData_UseCapturedData_AggPeriods method");
+                generateOrgUnitLevelData_UseCapturedData_AggPeriods();
+            }
+            else
+            {
+                generateOrgUnitLevel();
+            }
+        }
+    
+        statementManager.destroy();
+    
+        System.out.println( "Report Generation End Time is : \t" + new Date() );
+    
+        return SUCCESS;
+    }
+    
+    
+    public void initialize()
+    {
+        dataElementIdsByComma = "-1";
+        
+        List<Period> periods = new ArrayList<Period>();
+        int periodCount = 0;
+        for ( Date sDate : selStartPeriodList )
+        {
+            Date eDate = selEndPeriodList.get( periodCount );
+            List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+            
+            if( periodList != null && periodList.size() > 0 )
+                periods.addAll( periodList );
+            periodCount++;
+        }
+        Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periods ) );
+        periodIdsByComma = getCommaDelimitedString( periodIds );
+        
+        System.out.println("PeriodIds: "+ periodIdsByComma );
+        
+        for ( String service : selectedServices )
+        {
+            String partsOfService[] = service.split( ":" );
+            if ( partsOfService[0].equalsIgnoreCase( "D" ) )
+            {
+                dataElementIdsByComma += ","+partsOfService[1];
+                DataElement de = dataElementService.getDataElement( Integer.parseInt( partsOfService[1] ) );
+                dataElementList.add( de );
+                serviceTypeList.add( "D" );
+            }
+            else
+            {
+                Indicator indicator = indicatorService.getIndicator( Integer.parseInt( partsOfService[1] ) );
+                indicatorList.add( indicator );
+                serviceTypeList.add( "I" );
+            }
+        }
+        
+        String indicaotrDes = reportService.getDataelementIdsAsString( indicatorList );
+        dataElementIdsByComma += "," + indicaotrDes;
+    }
+
+    // -------------------------------------------------------------------------
+    // Method for getting Selected OrgUnit(s) data in Excel Sheet 
+    //     - UseCapturedData - Period Aggregation 
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_UseCapturedData_AggPeriods() throws Exception
+    {
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getDataFromDataValueTableByPeriodAgg( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + rowCount, ou.getName(), getCellFormat2() ) );
+
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                String tempStr = "";
+                Double indValue = 0.0;
+                Double dataValue = 0.0;
+                
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    Double numValue = 0.0;
+                    Double denValue = 0.0;
+
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, headerRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                    
+                    try
+                    {
+                        numValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getNumerator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        denValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getDenominator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        if( denValue != 0.0 )
+                        {
+                            indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                        }
+                        else
+                        {
+                            indValue = 0.0;
+                        }
+                    }
+                    catch( Exception e )
+                    {
+                        indValue = 0.0;
+                    }
+                    
+                    indValue = Math.round( indValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                        
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId() );
+                            if( tempStr != null )
+                            {
+                                try
+                                {
+                                    dataValue = Double.parseDouble( tempStr );
+                                }
+                                catch( Exception e )
+                                {
+                                    dataValue = 0.0;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                        List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                            {
+                                tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId() );
+                                if( tempStr != null )
+                                {
+                                    try
+                                    {
+                                        dataValue += Double.parseDouble( tempStr );
+                                    }
+                                    catch( Exception e )
+                                    {
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                }
+
+                if ( flag == 1 )
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, indValue, getCellFormat2() ) );
+                }
+                else
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, dataValue, getCellFormat2() ) );
+                }
+
+                colCount++;
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+
+    
+    // -------------------------------------------------------------------------
+    // Method for getting Selected OrgUnit(s) data in Excel Sheet 
+    //     - UseCapturedData - Period wise 
+    // -------------------------------------------------------------------------
+    public void generateSelectedOrgUnitData_UseCapturedData_Periodwise() throws Exception
+    {
+        int startRow = 0;
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.mergeCells( headerCol, headerRow, headerCol, headerRow + 1 );
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        for ( String ouStr : orgUnitListCB )
+        {
+            OrganisationUnit ou = organisationUnitService.getOrganisationUnit( Integer.parseInt( ouStr ) );
+            selOUList.add( ou );
+        }
+
+        int c1 = headerCol + 1;
+        sheet0.mergeCells( c1, headerRow, c1, headerRow + 1 );
+        sheet0.addCell( new Label( c1, headerRow, "Facility", getCellFormat1() ) );
+        c1++;
+        
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getDataFromDataValueTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println(ou.getName() + " : " +new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + 1 + rowCount, rowCount, getCellFormat2() ) );
+            sheet0.addCell( new Label( 1, rowCount + 1, ou.getName(), getCellFormat2() ) );
+
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                        sheet0.addCell( new Label( colCount, startRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                    }
+                }
+
+                int periodCount = 0;
+                for ( Date sDate : selStartPeriodList )
+                {
+                    Date eDate = selEndPeriodList.get( periodCount );
+                
+                    Collection<Integer> periodIds = new ArrayList<Integer>( periodMap.get( periodCount ) );
+
+                    double pwdvAggValue = 0.0;
+                    double pwdAggIndValue = 0.0;
+
+                    String tempStr = "";
+                    if ( flag == 1 )
+                    {
+                        Double numValue = 0.0;
+                        Double denValue = 0.0;
+                        Double indValue = 0.0;
+                        for( Integer periodId : periodIds )
+                        {
+                            try
+                            {
+                                numValue += Double.parseDouble( getAggVal( selIndicator.getNumerator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                            
+                            try
+                            {
+                                denValue += Double.parseDouble( getAggVal( selIndicator.getDenominator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                        }
+                        
+                        try
+                        {
+                            if( denValue != 0.0 )
+                            {
+                                indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                            }
+                            else
+                            {
+                                indValue = 0.0;
+                            }
+                        }
+                        catch( Exception e )
+                        {
+                            indValue = 0.0;
+                        }
+
+                        pwdAggIndValue = indValue;
+                        pwdAggIndValue = Math.round( pwdAggIndValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                        tempStr = "" + pwdAggIndValue;
+                    }
+                    else if ( flag == 2 )
+                    {
+                        if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                        {
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( Integer periodId : periodIds )
+                                {
+                                    tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId()+":"+periodId );
+                                    if( tempStr != null )
+                                    {
+                                        try
+                                        {
+                                            pwdvAggValue += Double.parseDouble( tempStr );
+                                        }
+                                        catch( Exception e )
+                                        {
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                if ( tempPeriod != null )
+                                {
+                                    DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, selDecoc );
+
+                                    if ( dataValue != null && dataValue.getValue() != null )
+                                    {
+                                        tempStr = dataValue.getValue();
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                                else
+                                {
+                                    tempStr = " ";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                                {
+                                    for( Integer periodId : periodIds )
+                                    {
+                                        tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId()+":"+periodId );
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                pwdvAggValue += Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                            }
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                while ( optionComboIterator.hasNext() )
+                                {
+                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator.next();
+
+                                    PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                    Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                    if( tempPeriod != null )
+                                    {
+                                        DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, decoc1 );
+
+                                        if ( dataValue != null )
+                                        {
+                                            tempStr += dataValue.getValue() + " : ";
+                                        }
+                                        else
+                                        {
+                                            tempStr = "  ";
+                                        }
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, startRow + 1, periodNames.get( periodCount ), getCellFormat1() ) );
+                    }
+
+                    if ( flag == 1 )
+                    {
+                        sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, pwdAggIndValue, getCellFormat2() ) );
+                    }
+                    else
+                    {
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, (int) pwdvAggValue, getCellFormat2() ) );
+                        }
+                        else
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, tempStr, getCellFormat2() ) );
+                        }
+                    }
+
+                    colCount++;
+                    periodCount++;
+                }// Period Loop
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+
+    
     // -------------------------------------------------------------------------
     // Methods for getting OrgUnitSelected wise List in Excel Sheet
     // -------------------------------------------------------------------------
@@ -469,11 +1153,9 @@
     {
 
         int startRow = 0;
-        // int startCol = 0;
         int headerRow = 0;
         int headerCol = 0;
 
-        System.out.println( "inside the generateOrgUnitSelected" );
 
         String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER )
             .getValue();
@@ -503,11 +1185,6 @@
         {
             sheet0.addCell( new Number( headerCol, headerRow + 1 + rowCount, rowCount, getCellFormat2() ) );
 
-            // System.out.println(colCount + " : " + minOULevel + " : " +
-            // organisationUnitService.getLevelOfOrganisationUnit( ou ));
-
-            // sheet0.mergeCells( colCount, headerRow+1+rowCount, colCount,
-            // headerRow+1+rowCount+ouChildCountMap.get( ou ));
             sheet0.addCell( new Label( 1, rowCount + 1, ou.getName(), getCellFormat2() ) );
 
             /* Service Info */
@@ -591,6 +1268,11 @@
                 for ( Date sDate : selStartPeriodList )
                 {
                     Date eDate = selEndPeriodList.get( periodCount );
+                    
+                    List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                    Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                    String periodIdsByComma = getCommaDelimitedString( periodIds );
+
                     double pwnumAggValue = 0.0;
                     double pwdenAggValue = 0.0;
                     double pwdvAggValue = 0.0;
@@ -625,8 +1307,33 @@
                         {
                             if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
                             {
-                                tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, selDecoc,
-                                    sDate, eDate, ou );
+                                tempAggVal = null;
+                                if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+                                {
+                                        
+                                }
+                                else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+                                {
+                                    tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, selDecoc, sDate, eDate, ou );
+                                }
+                                else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+                                {
+                                        Map<String, String> aggDeMap = new HashMap<String, String>();
+                                        aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( ou.getId(), ""+selDataElement.getId(), periodIdsByComma ) );
+                                        tempStr = aggDeMap.get(selDataElement.getId()+"."+selDecoc.getId());
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                tempAggVal = Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                                tempAggVal = null;
+                                            }
+                                        }
+                                }
+
                                 if ( tempAggVal == null )
                                     tempAggVal = 0.0;
                                 pwdvAggValue = tempAggVal;
@@ -664,17 +1371,43 @@
 
                             if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
                             {
-                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
-                                while ( optionComboIterator.hasNext() )
-                                {
-                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator
-                                        .next();
-
-                                    tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, decoc1,
-                                        sDate, eDate, ou );
-                                    if ( tempAggVal == null )
-                                        tempAggVal = 0.0;
-                                    pwdvAggValue += tempAggVal;
+                                if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+                                {
+                                        
+                                }
+                                else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+                                {
+                                    Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                    while ( optionComboIterator.hasNext() )
+                                    {
+                                        DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator
+                                            .next();
+
+                                        tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, decoc1,
+                                            sDate, eDate, ou );
+                                        if ( tempAggVal == null )
+                                            tempAggVal = 0.0;
+                                        pwdvAggValue += tempAggVal;
+                                    }
+                                }
+                                else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+                                {
+                                        Map<String, String> aggDeMap = new HashMap<String, String>();
+                                        aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( ou.getId(), ""+selDataElement.getId(), periodIdsByComma ) );
+                                        for( String aggDe : aggDeMap.keySet() )
+                                        {
+                                                String temp = aggDeMap.get( aggDe );
+                                                try
+                                                {
+                                                        tempAggVal = Double.parseDouble( temp );
+                                                }
+                                                catch( Exception e )
+                                                {
+                                                        tempAggVal = 0.0;
+                                                }
+                                                pwdvAggValue += tempAggVal;
+                                        }
+
                                 }
 
                                 tempStr = "" + (int) pwdvAggValue;
@@ -804,7 +1537,7 @@
 
         outputReportFile.deleteOnExit();
     }
-
+    
     // -------------------------------------------------------------------------
     // Methods for getting OrgUnitGroup wise List in Excel Sheet
     // -------------------------------------------------------------------------
@@ -813,7 +1546,6 @@
         throws Exception
     {
         int startRow = 0;
-        // int startCol = 0;
         int headerRow = 0;
         int headerCol = 0;
 
@@ -1190,6 +1922,1798 @@
 
     }
 
+
+    // -------------------------------------------------------------------------
+    // Method for getting OrgUnit Level wise data in Excel Sheet 
+    //     - UseCapturedData - Period wise 
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_UseCapturedData_Periodwise() throws Exception
+    {
+        int startRow = 0;
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.mergeCells( headerCol, headerRow, headerCol, headerRow + 1 );
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.mergeCells( c1, headerRow, c1, headerRow + 1 );
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getDataFromDataValueTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + 1 + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, ou.getName(), getCellFormat2() ) );
+
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                        sheet0.addCell( new Label( colCount, startRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                    }
+                }
+
+                int periodCount = 0;
+                for ( Date sDate : selStartPeriodList )
+                {
+                    Date eDate = selEndPeriodList.get( periodCount );
+                
+                    Collection<Integer> periodIds = new ArrayList<Integer>( periodMap.get( periodCount ) );
+                    System.out.println( periodIds );
+
+                    double pwdvAggValue = 0.0;
+                    double pwdAggIndValue = 0.0;
+
+                    String tempStr = "";
+                    if ( flag == 1 )
+                    {
+                        Double numValue = 0.0;
+                        Double denValue = 0.0;
+                        Double indValue = 0.0;
+                        for( Integer periodId : periodIds )
+                        {
+                            try
+                            {
+                                numValue += Double.parseDouble( getAggVal( selIndicator.getNumerator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                            
+                            try
+                            {
+                                denValue += Double.parseDouble( getAggVal( selIndicator.getDenominator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                        }
+                        
+                        try
+                        {
+                            if( denValue != 0.0 )
+                            {
+                                indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                            }
+                            else
+                            {
+                                indValue = 0.0;
+                            }
+                        }
+                        catch( Exception e )
+                        {
+                            indValue = 0.0;
+                        }
+
+                        pwdAggIndValue = indValue;
+                        pwdAggIndValue = Math.round( pwdAggIndValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                        tempStr = "" + pwdAggIndValue;
+                    }
+                    else if ( flag == 2 )
+                    {
+                        if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                        {
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( Integer periodId : periodIds )
+                                {
+                                    tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId()+":"+periodId );
+                                    if( tempStr != null )
+                                    {
+                                        try
+                                        {
+                                            pwdvAggValue += Double.parseDouble( tempStr );
+                                        }
+                                        catch( Exception e )
+                                        {
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                if ( tempPeriod != null )
+                                {
+                                    DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, selDecoc );
+
+                                    if ( dataValue != null && dataValue.getValue() != null )
+                                    {
+                                        tempStr = dataValue.getValue();
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                                else
+                                {
+                                    tempStr = " ";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                                {
+                                    for( Integer periodId : periodIds )
+                                    {
+                                        tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId()+":"+periodId );
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                pwdvAggValue += Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                            }
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                while ( optionComboIterator.hasNext() )
+                                {
+                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator.next();
+
+                                    PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                    Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                    if( tempPeriod != null )
+                                    {
+                                        DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, decoc1 );
+
+                                        if ( dataValue != null )
+                                        {
+                                            tempStr += dataValue.getValue() + " : ";
+                                        }
+                                        else
+                                        {
+                                            tempStr = "  ";
+                                        }
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, startRow + 1, periodNames.get( periodCount ), getCellFormat1() ) );
+                    }
+
+                    if ( flag == 1 )
+                    {
+                        sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, pwdAggIndValue, getCellFormat2() ) );
+                    }
+                    else
+                    {
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, (int) pwdvAggValue, getCellFormat2() ) );
+                        }
+                        else
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, tempStr, getCellFormat2() ) );
+                        }
+                    }
+
+                    colCount++;
+                    periodCount++;
+                }// Period Loop
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+
+
+    // -------------------------------------------------------------------------
+    // Method for getting Selected OrgUnit(s) data in Excel Sheet 
+    //     - UseCapturedData - Aggregation of Periods 
+    // -------------------------------------------------------------------------
+    public void generateSelectedOrgUnitData_UseCapturedData_AggPeriods() throws Exception
+    {
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        for ( String ouStr : orgUnitListCB )
+        {
+            OrganisationUnit ou = organisationUnitService.getOrganisationUnit( Integer.parseInt( ouStr ) );
+            selOUList.add( ou );
+        }
+
+        int c1 = headerCol + 1;
+        sheet0.addCell( new Label( c1, headerRow, "Facility", getCellFormat1() ) );
+        c1++;
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getDataFromDataValueTableByPeriodAgg( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println(ou.getName() + " : "+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + rowCount, rowCount, getCellFormat2() ) );
+            sheet0.addCell( new Label( 1, rowCount, ou.getName(), getCellFormat2() ) );
+            
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                String tempStr = "";
+                Double indValue = 0.0;
+                Double dataValue = 0.0;
+                
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    Double numValue = 0.0;
+                    Double denValue = 0.0;
+
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, headerRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                    
+                    try
+                    {
+                        numValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getNumerator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        denValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getDenominator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        if( denValue != 0.0 )
+                        {
+                            indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                        }
+                        else
+                        {
+                            indValue = 0.0;
+                        }
+                    }
+                    catch( Exception e )
+                    {
+                        indValue = 0.0;
+                    }
+                    
+                    indValue = Math.round( indValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                        
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId() );
+                            if( tempStr != null )
+                            {
+                                try
+                                {
+                                    dataValue = Double.parseDouble( tempStr );
+                                }
+                                catch( Exception e )
+                                {
+                                    dataValue = 0.0;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                        List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                            {
+                                tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId() );
+                                if( tempStr != null )
+                                {
+                                    try
+                                    {
+                                        dataValue += Double.parseDouble( tempStr );
+                                    }
+                                    catch( Exception e )
+                                    {
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                }
+
+                if ( flag == 1 )
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, indValue, getCellFormat2() ) );
+                }
+                else
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, dataValue, getCellFormat2() ) );
+                }
+
+                colCount++;
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+
+    
+    // -------------------------------------------------------------------------
+    // Method for getting Selected OrgUnit(s) data in Excel Sheet 
+    //     - GenerateAggregatedData - Aggregation of Periods 
+    // -------------------------------------------------------------------------
+    public void generateSelectedOrgUnitData_GenerateAggregateData_AggPeriods() throws Exception
+    {
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        for ( String ouStr : orgUnitListCB )
+        {
+            OrganisationUnit ou = organisationUnitService.getOrganisationUnit( Integer.parseInt( ouStr ) );
+            selOUList.add( ou );
+        }
+
+        int c1 = headerCol + 1;
+        sheet0.addCell( new Label( c1, headerRow, "Facility", getCellFormat1() ) );
+        c1++;
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + rowCount, rowCount, getCellFormat2() ) );
+            sheet0.addCell( new Label( 1, headerRow + rowCount, ou.getName(), getCellFormat2() ) );
+            
+            List<OrganisationUnit> ouChildList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( ou.getId() ) );
+            List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, ouChildList ) );
+            orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+            Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getAggDataFromDataValueTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+            
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                String tempStr = "";
+                Double indValue = 0.0;
+                Double dataValue = 0.0;
+                
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    Double numValue = 0.0;
+                    Double denValue = 0.0;
+
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, headerRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                    
+                    try
+                    {
+                        numValue = Double.parseDouble( reportService.getAggVal( selIndicator.getNumerator(), aggDataMap ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        denValue = Double.parseDouble( reportService.getAggVal( selIndicator.getDenominator(), aggDataMap ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        if( denValue != 0.0 )
+                        {
+                            indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                        }
+                        else
+                        {
+                            indValue = 0.0;
+                        }
+                    }
+                    catch( Exception e )
+                    {
+                        indValue = 0.0;
+                    }
+                    
+                    indValue = Math.round( indValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                        
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            tempStr = aggDataMap.get( selDataElement.getId()+"."+selDecoc.getId() );
+                            if( tempStr != null )
+                            {
+                                try
+                                {
+                                    dataValue = Double.parseDouble( tempStr );
+                                }
+                                catch( Exception e )
+                                {
+                                    dataValue = 0.0;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                        List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                            {
+                                tempStr = aggDataMap.get( selDataElement.getId()+"."+optionCombo.getId() );
+                                if( tempStr != null )
+                                {
+                                    try
+                                    {
+                                        dataValue += Double.parseDouble( tempStr );
+                                    }
+                                    catch( Exception e )
+                                    {
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                }
+
+                if ( flag == 1 )
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, indValue, getCellFormat2() ) );
+                }
+                else
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, dataValue, getCellFormat2() ) );
+                }
+
+                colCount++;
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();    
+    }
+
+    
+    // -------------------------------------------------------------------------
+    // Method for getting OrgUnit Level wise data in Excel Sheet 
+    //     - GenerateAggregatedData - Aggregation of Periods 
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_GenerateAggregateData_AggPeriods() throws Exception
+    {
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        System.out.println( "Before getting orgunitlevelmap "+new Date() );
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+        System.out.println( "After getting orgunitlevelmap "+new Date() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + rowCount, ou.getName(), getCellFormat2() ) );
+
+            List<OrganisationUnit> ouChildList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( ou.getId() ) );
+            List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, ouChildList ) );
+            orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+            Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getAggDataFromDataValueTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+            
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                String tempStr = "";
+                Double indValue = 0.0;
+                Double dataValue = 0.0;
+                
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    Double numValue = 0.0;
+                    Double denValue = 0.0;
+
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, headerRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                    
+                    try
+                    {
+                        numValue = Double.parseDouble( reportService.getAggVal( selIndicator.getNumerator(), aggDataMap ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        denValue = Double.parseDouble( reportService.getAggVal( selIndicator.getDenominator(), aggDataMap ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        if( denValue != 0.0 )
+                        {
+                            indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                        }
+                        else
+                        {
+                            indValue = 0.0;
+                        }
+                    }
+                    catch( Exception e )
+                    {
+                        indValue = 0.0;
+                    }
+                    
+                    indValue = Math.round( indValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                        
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            tempStr = aggDataMap.get( selDataElement.getId()+"."+selDecoc.getId() );
+                            if( tempStr != null )
+                            {
+                                try
+                                {
+                                    dataValue = Double.parseDouble( tempStr );
+                                }
+                                catch( Exception e )
+                                {
+                                    dataValue = 0.0;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                        List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                            {
+                                tempStr = aggDataMap.get( selDataElement.getId()+"."+optionCombo.getId() );
+                                if( tempStr != null )
+                                {
+                                    try
+                                    {
+                                        dataValue += Double.parseDouble( tempStr );
+                                    }
+                                    catch( Exception e )
+                                    {
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                }
+
+                if ( flag == 1 )
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, indValue, getCellFormat2() ) );
+                }
+                else
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, dataValue, getCellFormat2() ) );
+                }
+
+                colCount++;
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();    
+    }
+
+    // -------------------------------------------------------------------------
+    // Method for getting OrgUnit Level wise data in Excel Sheet 
+    //     - GenerateAggregatedData - Periodwise 
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_GenerateAggregateData_Periodwise() throws Exception
+    {
+        int startRow = 0;
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.mergeCells( headerCol, headerRow, headerCol, headerRow + 1 );
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.mergeCells( c1, headerRow, c1, headerRow + 1 );
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println( ou.getName() +" : "+ new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + 1 + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, ou.getName(), getCellFormat2() ) );
+
+            List<OrganisationUnit> ouChildList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( ou.getId() ) );
+            List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, ouChildList ) );
+            orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+            Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getAggDataFromDataValueTableByDeAndPeriodwise( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+            
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                        sheet0.addCell( new Label( colCount, startRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                    }
+                }
+
+                int periodCount = 0;
+                for ( Date sDate : selStartPeriodList )
+                {
+                    Date eDate = selEndPeriodList.get( periodCount );
+                
+                    Collection<Integer> periodIds = new ArrayList<Integer>( periodMap.get( periodCount ) );
+
+                    double pwdvAggValue = 0.0;
+                    double pwdAggIndValue = 0.0;
+
+                    String tempStr = "";
+                    if ( flag == 1 )
+                    {
+                        Double numValue = 0.0;
+                        Double denValue = 0.0;
+                        Double indValue = 0.0;
+                        for( Integer periodId : periodIds )
+                        {
+                            try
+                            {
+                                numValue += Double.parseDouble( getAggValByPeriod( selIndicator.getNumerator(), aggDataMap, periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                            
+                            try
+                            {
+                                denValue += Double.parseDouble( getAggValByPeriod( selIndicator.getDenominator(), aggDataMap, periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                        }
+                        
+                        try
+                        {
+                            if( denValue != 0.0 )
+                            {
+                                indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                            }
+                            else
+                            {
+                                indValue = 0.0;
+                            }
+                        }
+                        catch( Exception e )
+                        {
+                            indValue = 0.0;
+                        }
+
+                        pwdAggIndValue = indValue;
+                        pwdAggIndValue = Math.round( pwdAggIndValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                        tempStr = "" + pwdAggIndValue;
+                    }
+                    else if ( flag == 2 )
+                    {
+                        if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                        {
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( Integer periodId : periodIds )
+                                {
+                                    tempStr = aggDataMap.get( selDataElement.getId()+":"+selDecoc.getId()+":"+periodId );
+                                    if( tempStr != null )
+                                    {
+                                        try
+                                        {
+                                            pwdvAggValue += Double.parseDouble( tempStr );
+                                        }
+                                        catch( Exception e )
+                                        {
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                if ( tempPeriod != null )
+                                {
+                                    DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, selDecoc );
+
+                                    if ( dataValue != null && dataValue.getValue() != null )
+                                    {
+                                        tempStr = dataValue.getValue();
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                                else
+                                {
+                                    tempStr = " ";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                                {
+                                    for( Integer periodId : periodIds )
+                                    {
+                                        tempStr = aggDataMap.get( selDataElement.getId()+":"+optionCombo.getId()+":"+periodId );
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                pwdvAggValue += Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                            }
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                while ( optionComboIterator.hasNext() )
+                                {
+                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator.next();
+
+                                    PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                    Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                    if( tempPeriod != null )
+                                    {
+                                        DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, decoc1 );
+
+                                        if ( dataValue != null )
+                                        {
+                                            tempStr += dataValue.getValue() + " : ";
+                                        }
+                                        else
+                                        {
+                                            tempStr = "  ";
+                                        }
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, startRow + 1, periodNames.get( periodCount ), getCellFormat1() ) );
+                    }
+
+                    if ( flag == 1 )
+                    {
+                        sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, pwdAggIndValue, getCellFormat2() ) );
+                    }
+                    else
+                    {
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, (int) pwdvAggValue, getCellFormat2() ) );
+                        }
+                        else
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, tempStr, getCellFormat2() ) );
+                        }
+                    }
+
+                    colCount++;
+                    periodCount++;
+                }// Period Loop
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+    
+
+    // -------------------------------------------------------------------------
+    // Method for getting OrgUnit Level wise data in Excel Sheet 
+    //     - UseExistingData - Periodwise 
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_UseExisting_Periodwise() throws Exception
+    {
+        int startRow = 0;
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.mergeCells( headerCol, headerRow, headerCol, headerRow + 1 );
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        System.out.println( "Before getting orgunitlevelmap "+new Date() );
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+        System.out.println( "After getting orgunitlevelmap "+new Date() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.mergeCells( c1, headerRow, c1, headerRow + 1 );
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        System.out.println( "Before getting aggdatamap "+new Date() );
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getResultDataValueFromAggregateTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+        System.out.println( "Before getting aggdatamap "+new Date() );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + 1 + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, ou.getName(), getCellFormat2() ) );
+
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                        sheet0.addCell( new Label( colCount, startRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.mergeCells( colCount, startRow, colCount + selStartPeriodList.size() - 1, startRow );
+                            sheet0.addCell( new Label( colCount, startRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                    }
+                }
+
+                int periodCount = 0;
+                for ( Date sDate : selStartPeriodList )
+                {
+                    Date eDate = selEndPeriodList.get( periodCount );
+                
+                    Collection<Integer> periodIds = new ArrayList<Integer>( periodMap.get( periodCount ) );
+                    System.out.println( periodIds );
+
+                    double pwdvAggValue = 0.0;
+                    double pwdAggIndValue = 0.0;
+
+                    String tempStr = "";
+                    if ( flag == 1 )
+                    {
+                        Double numValue = 0.0;
+                        Double denValue = 0.0;
+                        Double indValue = 0.0;
+                        for( Integer periodId : periodIds )
+                        {
+                            try
+                            {
+                                numValue += Double.parseDouble( getAggVal( selIndicator.getNumerator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                            
+                            try
+                            {
+                                denValue += Double.parseDouble( getAggVal( selIndicator.getDenominator(), aggDataMap, ou.getId(), periodId ) );
+                            }
+                            catch( Exception e )
+                            {
+                            }
+                        }
+                        
+                        try
+                        {
+                            if( denValue != 0.0 )
+                            {
+                                indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                            }
+                            else
+                            {
+                                indValue = 0.0;
+                            }
+                        }
+                        catch( Exception e )
+                        {
+                            indValue = 0.0;
+                        }
+
+                        pwdAggIndValue = indValue;
+                        pwdAggIndValue = Math.round( pwdAggIndValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                        tempStr = "" + pwdAggIndValue;
+                    }
+                    else if ( flag == 2 )
+                    {
+                        if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                        {
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( Integer periodId : periodIds )
+                                {
+                                    tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId()+":"+periodId );
+                                    if( tempStr != null )
+                                    {
+                                        try
+                                        {
+                                            pwdvAggValue += Double.parseDouble( tempStr );
+                                        }
+                                        catch( Exception e )
+                                        {
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                if ( tempPeriod != null )
+                                {
+                                    DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, selDecoc );
+
+                                    if ( dataValue != null && dataValue.getValue() != null )
+                                    {
+                                        tempStr = dataValue.getValue();
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                                else
+                                {
+                                    tempStr = " ";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+
+                            if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                                {
+                                    for( Integer periodId : periodIds )
+                                    {
+                                        tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId()+":"+periodId );
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                pwdvAggValue += Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                            }
+                                        }
+                                    }
+                                }
+                                tempStr = "" + (int) pwdvAggValue;
+                            }
+                            else
+                            {
+                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                while ( optionComboIterator.hasNext() )
+                                {
+                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator.next();
+
+                                    PeriodType periodType = periodService.getPeriodTypeByName( periodTypeLB );
+                                    Period tempPeriod = periodService.getPeriod( sDate, eDate, periodType );
+                                    if( tempPeriod != null )
+                                    {
+                                        DataValue dataValue = dataValueService.getDataValue( ou, selDataElement, tempPeriod, decoc1 );
+
+                                        if ( dataValue != null )
+                                        {
+                                            tempStr += dataValue.getValue() + " : ";
+                                        }
+                                        else
+                                        {
+                                            tempStr = "  ";
+                                        }
+                                    }
+                                    else
+                                    {
+                                        tempStr = " ";
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, startRow + 1, periodNames.get( periodCount ), getCellFormat1() ) );
+                    }
+
+                    if ( flag == 1 )
+                    {
+                        sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, pwdAggIndValue, getCellFormat2() ) );
+                    }
+                    else
+                    {
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            sheet0.addCell( new Number( colCount, headerRow + 1 + rowCount, (int) pwdvAggValue, getCellFormat2() ) );
+                        }
+                        else
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow + 1 + rowCount, tempStr, getCellFormat2() ) );
+                        }
+                    }
+
+                    colCount++;
+                    periodCount++;
+                }// Period Loop
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();
+    }
+
+    
+    // -------------------------------------------------------------------------
+    // Method for getting OrgUnit Level wise data in Excel Sheet 
+    //     - UseExistingData - Aggregation of Periods
+    // -------------------------------------------------------------------------
+    public void generateOrgUnitLevelData_UseExisting_AggPeriods() throws Exception
+    {
+        int headerRow = 0;
+        int headerCol = 0;
+
+        String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+        String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+        WritableSheet sheet0 = outputReportWorkbook.createSheet( "TabularAnalysis", 0 );
+
+        sheet0.addCell( new Label( headerCol, headerRow, "Sl.No.", getCellFormat1() ) );
+
+        selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
+        selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+
+        System.out.println( "Before getting orgunitlevelmap "+new Date() );
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+        System.out.println( "After getting orgunitlevelmap "+new Date() );
+    
+        Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
+        while ( ouIterator.hasNext() )
+        {
+            OrganisationUnit orgU = ouIterator.next();
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
+            {
+                ouIterator.remove();
+            }
+        }
+
+        int minOULevel = 1;
+        int maxOuLevel = 1;
+        if ( selOUList != null && selOUList.size() > 0 )
+        {
+            minOULevel = organisationUnitService.getLevelOfOrganisationUnit( selOUList.get( 0 ) );
+        }
+        maxOuLevel = orgUnitLevelCB;
+
+        int c1 = headerCol + 1;
+        for ( int i = minOULevel; i <= maxOuLevel; i++ )
+        {
+            sheet0.addCell( new Label( c1, headerRow, "Level " + i, getCellFormat1() ) );
+            c1++;
+        }
+
+        /* Service Info */
+        Indicator selIndicator = new Indicator();
+        DataElement selDataElement = new DataElement();
+        DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
+        int flag = 0;
+
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        System.out.println( "Before getting aggdatamap "+new Date() );
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getResultDataValueFromAggregateTableByPeriodAgg( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+        System.out.println( "After getting aggdatamap "+new Date() );
+    
+        /* Calculation Part */
+        int rowCount = 1;
+        int colCount = 0;
+        for( OrganisationUnit ou : selOUList )
+        {
+            System.out.println("Entered into orgunitloop :"+new Date());
+            sheet0.addCell( new Number( headerCol, headerRow + rowCount, rowCount, getCellFormat2() ) );
+            
+            Integer level = orgunitLevelMap.get( ou.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            colCount = 1 + level - minOULevel;
+            sheet0.addCell( new Label( colCount, headerRow + rowCount, ou.getName(), getCellFormat2() ) );
+
+            colCount = c1;
+            int deListCount = 0;
+            int indListCount = 0;
+            int serviceListCount = 0;
+            for( String serviceType : serviceTypeList )
+            {
+                String tempStr = "";
+                Double indValue = 0.0;
+                Double dataValue = 0.0;
+                
+                if ( serviceType.equalsIgnoreCase( "I" ) )
+                {
+                    Double numValue = 0.0;
+                    Double denValue = 0.0;
+
+                    flag = 1;
+                    selIndicator = indicatorList.get( indListCount );
+                    indListCount++;
+                    if ( rowCount == 1 )
+                    {
+                        sheet0.addCell( new Label( colCount, headerRow, selIndicator.getName(), getCellFormat1() ) );
+                    }
+                    
+                    try
+                    {
+                        numValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getNumerator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        denValue = Double.parseDouble( getAggValByOrgUnit( selIndicator.getDenominator(), aggDataMap, ou.getId() ) );
+                    }
+                    catch( Exception e )
+                    {
+                    }
+                    
+                    try
+                    {
+                        if( denValue != 0.0 )
+                        {
+                            indValue = ( numValue / denValue ) * selIndicator.getIndicatorType().getFactor();
+                        }
+                        else
+                        {
+                            indValue = 0.0;
+                        }
+                    }
+                    catch( Exception e )
+                    {
+                        indValue = 0.0;
+                    }
+                    
+                    indValue = Math.round( indValue * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+                }
+                else
+                {
+                    flag = 2;
+                    selDataElement = dataElementList.get( deListCount );
+                    deListCount++;
+                    if ( deSelection.equalsIgnoreCase( "optioncombo" ) )
+                    {
+                        selDecoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( selectedServices.get( serviceListCount ).split( ":" )[2] ) );
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName() + "-" + selDecoc.getName(), getCellFormat1() ) );
+                        }
+                        
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId() );
+                            if( tempStr != null )
+                            {
+                                try
+                                {
+                                    dataValue = Double.parseDouble( tempStr );
+                                }
+                                catch( Exception e )
+                                {
+                                    dataValue = 0.0;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                    else
+                    {
+                        if ( rowCount == 1 )
+                        {
+                            sheet0.addCell( new Label( colCount, headerRow, selDataElement.getName(), getCellFormat1() ) );
+                        }
+                        List<DataElementCategoryOptionCombo> optionCombos = new ArrayList<DataElementCategoryOptionCombo>( selDataElement.getCategoryCombo().getOptionCombos() );
+                        if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
+                        {
+                            for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                            {
+                                tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId() );
+                                if( tempStr != null )
+                                {
+                                    try
+                                    {
+                                        dataValue += Double.parseDouble( tempStr );
+                                    }
+                                    catch( Exception e )
+                                    {
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            dataValue = 0.0;
+                        }
+                    }
+                }
+
+                if ( flag == 1 )
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, indValue, getCellFormat2() ) );
+                }
+                else
+                {
+                    sheet0.addCell( new Number( colCount, headerRow + rowCount, dataValue, getCellFormat2() ) );
+                }
+
+                colCount++;
+                serviceListCount++;
+            }// Service loop end
+            rowCount++;
+        }// Orgunit loop end
+        
+        outputReportWorkbook.write();
+        outputReportWorkbook.close();
+
+        fileName = "TabularAnalysis.xls";
+        File outputReportFile = new File( outputReportPath );
+        inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+    
+        outputReportFile.deleteOnExit();    
+    }
+
+    
     // -------------------------------------------------------------------------
     // Method for getting OrgUnit Level wise List in Excel Sheet
     // -------------------------------------------------------------------------
@@ -1211,11 +3735,19 @@
         selOrgUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitListCB.get( 0 ) ) );
         selOUList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
 
+        System.out.println( "Before getting orgunitlevelmap "+new Date() );
+        Map<Integer, Integer> orgunitLevelMap = new HashMap<Integer, Integer>( reportService.getOrgunitLevelMap() );
+        System.out.println( "After getting orgunitlevelmap "+new Date() );
+        
         Iterator<OrganisationUnit> ouIterator = selOUList.iterator();
         while ( ouIterator.hasNext() )
         {
             OrganisationUnit orgU = ouIterator.next();
-            if ( organisationUnitService.getLevelOfOrganisationUnit( orgU ) > orgUnitLevelCB )
+            
+            Integer level = orgunitLevelMap.get( orgU.getId() );
+            if( level == null )
+                level = organisationUnitService.getLevelOfOrganisationUnit( orgU );
+            if ( level > orgUnitLevelCB )
             {
                 ouIterator.remove();
             }
@@ -1243,6 +3775,13 @@
         DataElementCategoryOptionCombo selDecoc = new DataElementCategoryOptionCombo();
         int flag = 0;
 
+        List<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, selOUList ) );
+        orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        System.out.println( "Before getting aggdatamap "+new Date() );
+        Map<String, String> aggDataMap = new HashMap<String, String>( reportService.getResultDataValueFromAggregateTable( orgUnitIdsByComma, dataElementIdsByComma, periodIdsByComma ) );
+        System.out.println( "Before getting aggdatamap "+new Date() );
+        
         /* Calculation Part */
         int rowCount = 1;
         int colCount = 0;
@@ -1320,6 +3859,11 @@
                 for ( Date sDate : selStartPeriodList )
                 {
                     Date eDate = selEndPeriodList.get( periodCount );
+                    
+                    List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+                    Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+                    //String periodIdsByComma = getCommaDelimitedString( periodIds );
+
                     double pwnumAggValue = 0.0;
                     double pwdenAggValue = 0.0;
                     double pwdvAggValue = 0.0;
@@ -1354,7 +3898,53 @@
                         {
                             if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
                             {
-                                tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, selDecoc, sDate, eDate, ou );
+                                tempAggVal = null;
+                                if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+                                {
+                                        
+                                }
+                                else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+                                {
+                                    tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, selDecoc, sDate, eDate, ou );
+                                }
+                                else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+                                {
+                                    tempAggVal = 0.0;
+                                    for( Integer periodId : periodIds )
+                                    {
+                                        tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+selDecoc.getId()+":"+periodId );
+                                        if( tempStr != null )
+                                        {
+                                            try
+                                            {
+                                                tempAggVal += Double.parseDouble( tempStr );
+                                            }
+                                            catch( Exception e )
+                                            {
+                                               
+                                            }
+                                        }
+                                    }
+                                    
+                                    /*
+                                    Map<String, String> aggDeMap = new HashMap<String, String>();
+                                    aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( ou.getId(), ""+selDataElement.getId(), periodIdsByComma ) );
+                                    tempStr = aggDeMap.get(selDataElement.getId()+"."+selDecoc.getId());
+                                    
+                                    if( tempStr != null )
+                                    {
+                                        try
+                                        {
+                                            tempAggVal = Double.parseDouble( tempStr );
+                                        }
+                                        catch( Exception e )
+                                        {
+                                            tempAggVal = null;
+                                        }
+                                    }
+                                    */
+                                }
+
                                 if ( tempAggVal == null )
                                     tempAggVal = 0.0;
                                 pwdvAggValue = tempAggVal;
@@ -1391,17 +3981,67 @@
 
                             if ( selDataElement.getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
                             {
-                                Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
-                                while ( optionComboIterator.hasNext() )
-                                {
-                                    DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator
-                                        .next();
+                                if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+                                {
+                                        
+                                }
+                                else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+                                {
+                                    Iterator<DataElementCategoryOptionCombo> optionComboIterator = optionCombos.iterator();
+                                    while ( optionComboIterator.hasNext() )
+                                    {
+                                        DataElementCategoryOptionCombo decoc1 = (DataElementCategoryOptionCombo) optionComboIterator
+                                            .next();
 
-                                    tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, decoc1,
-                                        sDate, eDate, ou );
-                                    if ( tempAggVal == null )
-                                        tempAggVal = 0.0;
+                                        tempAggVal = aggregationService.getAggregatedDataValue( selDataElement, decoc1,
+                                            sDate, eDate, ou );
+                                        if ( tempAggVal == null )
+                                            tempAggVal = 0.0;
+                                        pwdvAggValue += tempAggVal;
+                                    }
+                                }
+                                else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+                                {
+                                    tempAggVal = 0.0;
+                                    for( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                                    {
+                                        for( Integer periodId : periodIds )
+                                        {
+                                            tempStr = aggDataMap.get( ou.getId()+":"+selDataElement.getId()+":"+optionCombo.getId()+":"+periodId );
+                                            if( tempStr != null )
+                                            {
+                                                try
+                                                {
+                                                    tempAggVal += Double.parseDouble( tempStr );
+                                                }
+                                                catch( Exception e )
+                                                {
+                                                   
+                                                }
+                                            }
+                                        }
+                                    }
                                     pwdvAggValue += tempAggVal;
+                                    System.out.println( ou.getName()+" : "+selDataElement.getName()+" : "+pwdvAggValue );
+                                    /*
+                                    Map<String, String> aggDeMap = new HashMap<String, String>();
+                                        System.out.println(ou.getId()+ " : " + selDataElement.getName() + periodIdsByComma );
+                                        aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( ou.getId(), ""+selDataElement.getId(), periodIdsByComma ) );
+                                        for( String aggDe : aggDeMap.keySet() )
+                                        {
+                                                String temp = aggDeMap.get( aggDe );
+                                                try
+                                                {
+                                                        tempAggVal = Double.parseDouble( temp );
+                                                }
+                                                catch( Exception e )
+                                                {
+                                                        tempAggVal = 0.0;
+                                                }
+                                                pwdvAggValue += tempAggVal;
+                                        }
+                                        */
+
                                 }
 
                                 tempStr = "" + (int) pwdvAggValue;
@@ -1531,30 +4171,7 @@
         outputReportFile.deleteOnExit();
     }
 
-    // Returns the OrgUnitTree for which Root is the orgUnit
-    public List<OrganisationUnit> getChildOrgUnitTree( OrganisationUnit orgUnit )
-    {
-        List<OrganisationUnit> orgUnitTree = new ArrayList<OrganisationUnit>();
-        orgUnitTree.add( orgUnit );
-
-        List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
-
-        ouChildCountMap.put( orgUnit, children.size() );
-
-        Collections.sort( children, new OrganisationUnitNameComparator() );
-
-        Iterator<OrganisationUnit> childIterator = children.iterator();
-        OrganisationUnit child;
-        while ( childIterator.hasNext() )
-        {
-            child = (OrganisationUnit) childIterator.next();
-            orgUnitTree.addAll( getChildOrgUnitTree( child ) );
-        }
-        return orgUnitTree;
-    }// getChildOrgUnitTree end
-
-    public WritableCellFormat getCellFormat1()
-        throws Exception
+    public WritableCellFormat getCellFormat1() throws Exception
     {
         WritableCellFormat wCellformat = new WritableCellFormat();
         
@@ -1566,8 +4183,7 @@
         return wCellformat;
     }
 
-    public WritableCellFormat getCellFormat2()
-        throws Exception
+    public WritableCellFormat getCellFormat2() throws Exception
     {
         WritableCellFormat wCellformat = new WritableCellFormat();
 
@@ -1577,5 +4193,169 @@
 
         return wCellformat;
     }
-
+    
+    public String getAggVal( String expression, Map<String, String> aggDataMap, Integer orgUnitId, Integer periodId )
+    {
+        try
+        {
+            Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+            Matcher matcher = pattern.matcher( expression );
+            StringBuffer buffer = new StringBuffer();
+
+            String resultValue = "";
+
+            while ( matcher.find() )
+            {
+                String replaceString = matcher.group();
+
+                replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+                String keyString = orgUnitId + ":" + replaceString.replaceAll( "\\.", ":" ) + ":" + periodId;
+                
+                replaceString = aggDataMap.get( keyString );
+                
+                if( replaceString == null )
+                {
+                    replaceString = "0";
+                }
+                
+                matcher.appendReplacement( buffer, replaceString );
+
+                resultValue = replaceString;
+            }
+
+            matcher.appendTail( buffer );
+            
+            double d = 0.0;
+            try
+            {
+                d = MathUtils.calculateExpression( buffer.toString() );
+            }
+            catch ( Exception e )
+            {
+                d = 0.0;
+                resultValue = "";
+            }
+            
+            resultValue = "" + (double) d;
+
+            return resultValue;
+        }
+        catch ( NumberFormatException ex )
+        {
+            throw new RuntimeException( "Illegal DataElement id", ex );
+        }
+    }
+
+
+    public String getAggValByPeriod( String expression, Map<String, String> aggDataMap, Integer periodId )
+    {
+        try
+        {
+            Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+            Matcher matcher = pattern.matcher( expression );
+            StringBuffer buffer = new StringBuffer();
+
+            String resultValue = "";
+
+            while ( matcher.find() )
+            {
+                String replaceString = matcher.group();
+
+                replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+                String keyString = replaceString.replaceAll( "\\.", ":" ) + ":" + periodId;
+                
+                replaceString = aggDataMap.get( keyString );
+                
+                if( replaceString == null )
+                {
+                    replaceString = "0";
+                }
+                
+                matcher.appendReplacement( buffer, replaceString );
+
+                resultValue = replaceString;
+            }
+
+            matcher.appendTail( buffer );
+            
+            double d = 0.0;
+            try
+            {
+                d = MathUtils.calculateExpression( buffer.toString() );
+            }
+            catch ( Exception e )
+            {
+                d = 0.0;
+                resultValue = "";
+            }
+            
+            resultValue = "" + (double) d;
+
+            return resultValue;
+        }
+        catch ( NumberFormatException ex )
+        {
+            throw new RuntimeException( "Illegal DataElement id", ex );
+        }
+    }
+
+    public String getAggValByOrgUnit( String expression, Map<String, String> aggDataMap, Integer orgUnitId )
+    {
+        try
+        {
+            Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+            Matcher matcher = pattern.matcher( expression );
+            StringBuffer buffer = new StringBuffer();
+
+            String resultValue = "";
+
+            while ( matcher.find() )
+            {
+                String replaceString = matcher.group();
+
+                replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+                String keyString = orgUnitId + ":" + replaceString.replaceAll( "\\.", ":" );
+                
+                replaceString = aggDataMap.get( keyString );
+                
+                if( replaceString == null )
+                {
+                    replaceString = "0";
+                }
+                
+                matcher.appendReplacement( buffer, replaceString );
+
+                resultValue = replaceString;
+            }
+
+            matcher.appendTail( buffer );
+            
+            double d = 0.0;
+            try
+            {
+                d = MathUtils.calculateExpression( buffer.toString() );
+            }
+            catch ( Exception e )
+            {
+                d = 0.0;
+                resultValue = "";
+            }
+            
+            resultValue = "" + (double) d;
+
+            return resultValue;
+        }
+        catch ( NumberFormatException ex )
+        {
+            throw new RuntimeException( "Illegal DataElement id", ex );
+        }
+    }
+
+    
 }// class end

=== modified file 'local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/util/DashBoardService.java'
--- local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/util/DashBoardService.java	2011-03-01 09:39:28 +0000
+++ local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dataanalyser/util/DashBoardService.java	2011-05-27 11:25:15 +0000
@@ -103,14 +103,6 @@
         this.organisationUnitService = organisationUnitService;
     }
     
-    /*
-    private DBConnection dbConnection;
-
-    public void setDbConnection( DBConnection dbConnection )
-    {
-        this.dbConnection = dbConnection;
-    }
-*/
 
     public List<Period> getMonthlyPeriods( Date start, Date end )
     {

=== modified file 'local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml	2011-05-24 08:25:51 +0000
+++ local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml	2011-05-27 11:25:15 +0000
@@ -1079,14 +1079,11 @@
     </bean>
 	
     <bean
-		id="org.hisp.dhis.dataanalyser.ta.action.GenerateTabularAnalysisResultAction"
-		class="org.hisp.dhis.dataanalyser.ta.action.GenerateTabularAnalysisResultAction"
-		scope="prototype">
-        <property name="statementManager" ref="statementManager"/>
-		
-        <property name="aggregationService">
-            <ref bean="org.hisp.dhis.aggregation.AggregationService"/>
-        </property>
+        id="org.hisp.dhis.dataanalyser.ta.action.GenerateTabularAnalysisResultAction"
+        class="org.hisp.dhis.dataanalyser.ta.action.GenerateTabularAnalysisResultAction"
+        scope="prototype">
+        <property name="statementManager" ref="statementManager"/>      
+        <property name="aggregationService" ref="org.hisp.dhis.aggregation.AggregationService" />
         <property name="dataElementService">
             <ref bean="org.hisp.dhis.dataelement.DataElementService"/>
         </property>
@@ -1111,9 +1108,9 @@
         <property name="organisationUnitGroupService">
             <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
         </property>
+        <property name="reportService" ref="org.hisp.dhis.reports.ReportService" />
     </bean>
 	
-	<!-- OrganisationUnit Profile -->
 	
 	<!-- Ajax -->
 	<!-- GetWeekly Period List for Tabular Analysis -->
@@ -1184,9 +1181,8 @@
     <bean id="org.hisp.dhis.dataanalyser.action.GetOrgUnitsAction"
 		class="org.hisp.dhis.dataanalyser.action.GetOrgUnitsAction"
 		scope="prototype">
-        <property name="organisationUnitService">
-            <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
-        </property>
+        <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		<property name="reportService" ref="org.hisp.dhis.reports.ReportService" />
     </bean>
 	
     <bean id="org.hisp.dhis.dataanalyser.action.GetPeriodsAction"
@@ -1283,11 +1279,7 @@
     <bean id="org.hisp.dhis.dataanalyser.action.ExportToExcelAction"
 		class="org.hisp.dhis.dataanalyser.action.ExportToExcelAction"
 		scope="prototype">
- <!--   <property name="locationManager">
-            <ref bean="org.hisp.dhis.external.location.LocationManager"/>
-        </property>-->
-		<property name="configurationService" ref="org.hisp.dhis.config.ConfigurationService">
-		</property>
+		<property name="configurationService" ref="org.hisp.dhis.config.ConfigurationService" />
     </bean>
 	
     <bean id="org.hisp.dhis.dataanalyser.action.GetSortedDataAction"

=== modified file 'local/in/dhis-web-dashboard/src/main/resources/struts.xml'
--- local/in/dhis-web-dashboard/src/main/resources/struts.xml	2011-05-24 08:25:51 +0000
+++ local/in/dhis-web-dashboard/src/main/resources/struts.xml	2011-05-27 11:25:15 +0000
@@ -749,7 +749,6 @@
 			class="org.hisp.dhis.dataanalyser.action.GetOrgUnitsAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-dashboard/responseOrgUnit.vm</result>
-			<!--<interceptor-ref name="transactionStack"/>-->
 			<param name="onExceptionReturn">plainTextError</param>
 		</action>
 		

=== modified file 'local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/javascript/ta.js'
--- local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/javascript/ta.js	2011-04-29 13:45:23 +0000
+++ local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/javascript/ta.js	2011-05-27 11:25:15 +0000
@@ -1,13 +1,26 @@
 
 
+function ouListSelection()
+{
+	var orgUnitSelListCB = document.getElementById( "orgUnitSelListCB" );
+	var orgUnitSelListCBVal = orgUnitSelListCB.options[ orgUnitSelListCB.selectedIndex ].value;
+
+	if( orgUnitSelListCBVal == "orgUnitGroupRadio" )
+	{
+		getOrgUnitGroups();
+	}
+	else if( orgUnitSelListCBVal == "orgUnitSelectedRadio" )
+	{
+		ouSelCBChange();
+	}
+	else
+	{
+		ouLevelSelected();
+	}
+}
+/*
 function ouradioSelection( evt )
 {
-	//var ouSelCBId = document.getElementById( "ouSelCB" );
-	//if( ouSelCBId.checked )
-	//{
-	//	return;
-	//}
-	
 	var excelItems = byId('ouRadio');
 	
 	if(excelItems.checked && excelItems.getAttribute('value') == "orgUnitGroupRadio")
@@ -23,6 +36,7 @@
 		ouLevelSelected();
 	}
 }
+*/
 
 function getOrgUnitGroups()
 {
@@ -32,19 +46,17 @@
   
 	for(var i=0; i < orgUnitGroupIds.length; i++)
 	{
-            
-            var option = document.createElement("option");
-            option.value = orgUnitGroupIds[i];
-            option.text = orgUnitGroupNames[i];
-            option.title = orgUnitGroupNames[i];
-            ouLevelId.add(option, null);
+        var option = document.createElement("option");
+        option.value = orgUnitGroupIds[i];
+        option.text = orgUnitGroupNames[i];
+        option.title = orgUnitGroupNames[i];
+        ouLevelId.add(option, null);
 	}
 }
 
 
 function ouSelCBChange()
 {
-    //var ouSelCBId = document.getElementById( "ouSelCB" );
     var ouListCDId = document.getElementById( "orgUnitListCB" );
     var ouLevelId = document.getElementById( "orgUnitLevelCB" );
 	
@@ -68,9 +80,7 @@
     if( selOrgUnitId != null && selOrgUnitId != "NONE" && selOrgUnitId != "")
     {
         getOUDeatilsForTA( selOrgUnitId );
-    }
-    
-	
+    }	
 }
 
 function ouLevelSelected()
@@ -240,17 +250,6 @@
     
     if ( dataElementGroupId != null )
     {
-        /* //var url = "getDataElementsForTA.action?id=" + dataElementGroupId + "&deOptionValue=" + deOptionValue;
-        var request = new Request();
-        request.setResponseTypeXML('dataElement');
-        request.setCallbackSuccess(getDataElementsReceived);
-        //request.send(url);
-
-        var requestString = "getDataElementsForTA.action";
-        var params = "id=" + dataElementGroupId + "&deOptionValue=" + deOptionValue;
-        request.sendAsPost( params );
-        request.send( requestString ); */
-		
 		$.post("getDataElementsForTA.action",
 		{
 			id:dataElementGroupId,
@@ -296,18 +295,6 @@
 	
     if ( indicatorGroupId != null )
     {
-        /* //var url = "getIndicators.action?id=" + indicatorGroupId;
-		
-        var request = new Request();
-        request.setResponseTypeXML( 'indicator' );
-        request.setCallbackSuccess( getIndicatorsReceived );
-        //request.send( url );
-
-        var requestString = "getIndicators.action";
-        var params = "id=" + indicatorGroupId;
-        request.sendAsPost( params );
-        request.send( requestString ); */
-		
 		$.post("getIndicators.action",
 		{
 			id:indicatorGroupId
@@ -341,10 +328,8 @@
             availableIndicators.add( option, null );
         }
     }
-	
-// If the list of available indicators is empty, an empty placeholder will be added
-//addOptionPlaceHolder( availableIndicators );
 }
+
 // getting period List
 function getPeriods()
 {
@@ -353,8 +338,6 @@
 	
     var yearLB = document.getElementById("yearLB");
     
-    
-   // alert( periodTypeId );
     var periodLB = document.getElementById( "periodLB" );
 	
     periodLB.disabled = false;
@@ -371,8 +354,6 @@
     
     else if( periodTypeId == dailyPeriodTypeName )
     {
-       // alert( monthDays.length );
-    	//alert( days.length );
     	for( i= 0; i < days.length; i++ )
         {
             periodLB.options[i] = new Option(days[i],days[i],false,false);
@@ -399,8 +380,6 @@
     
     else if( periodTypeId == weeklyPeriodTypeName )
     {
-    	//alert(periodTypeId);
-    	
         if( yearLB.selectedIndex < 0 ) 
         {
             alert("Please select Year(s) First");
@@ -410,15 +389,10 @@
         {
         	getWeeks();
         }
-        /*
-    	for( i= 0; i < weeks.length; i++ )
-        {
-    		periodLB.options[i] = new Option(weeks[i],weeks[i],false,false);
-        }
-    	getWeeks();*/
     }
 
 }
+
 //getting weekly Period
 function getWeeklyPeriod()
 {
@@ -431,34 +405,12 @@
     }
     
 }
-//singleSelectionOption yearList
-/*
-function selectSingleOptionYearList()
-{
-	var periodTypeObj = document.getElementById( 'periodTypeLB' );
-	
-    var periodTypeVal = periodTypeObj.options[ periodTypeObj.selectedIndex ].value;
-    if( periodTypeVal == weeklyPeriodTypeName  )
-    {
-        var yearListObj = document.getElementById('yearLB');
-	
-        for( var i = 0; i < yearListObj.length; i++ )
-        {
-            if( i != yearListObj.selectedIndex )
-            {
-            	yearListObj.options[i].selected = false;
-            }
-        }
-    }
-}
-*/
+
 //get week period Ajax calling
 function getWeeks()
 {
-	//var periodTypeName = weeklyPeriodTypeName;
 	var yearListObj = document.getElementById('yearLB');
 	var yearListval = yearListObj.options[ yearListObj.selectedIndex ].value;
-	//alert(yearListval); 
 	var year = yearListval.split( "-" )[0] ;
 	var yearList = "" ;
 	
@@ -469,13 +421,10 @@
     	{
     		yearList += yearLB.options[k].value + ";" ;
     	}
-     //yearLB.add[yearLB.selectedIndex];
     }
-    // alert( "Year List is : " +yearList );
 	
 	$.post("getWeeklyPeriod.action",
 			{
-			 //periodTypeName:weeklyPeriodTypeName,
 				yearList:yearList
 			},
 			function (data)
@@ -483,11 +432,10 @@
 				getWeeklyPeriodReceived(data);
 			},'xml');
 }
+
 // week rang received
 function getWeeklyPeriodReceived( xmlObject )
 {	
-	//alert("Inside Result");
-	
 	var periodList = document.getElementById( "periodLB" );
 	
 	clearList( periodList );
@@ -498,37 +446,14 @@
 	{
 	    var weeklyPeriodName = weeklyperiodList[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
 		
-	        var option = document.createElement( "option" );
-	        option.value = weeklyPeriodName;
-	        option.text = weeklyPeriodName;
-	        option.title = weeklyPeriodName;
-	        periodList.add( option, null );
-	}
-}	
-/*
-function getPeriods()
-{
-	var periodTypeList = document.getElementById( "periodTypeLB" );
-	var periodTypeId = periodTypeList.options[ periodTypeList.selectedIndex ].value;
-	var startDateList = document.getElementById( "sDateLB" );
-	var endDateList = document.getElementById( "eDateLB" );
-	
-	if ( periodTypeId != "NA" )
-	{		
-		var url = "getPeriods.action?id=" + periodTypeId;
-		
-		var request = new Request();
-	    request.setResponseTypeXML( 'period' );
-	    request.setCallbackSuccess( getPeriodsReceived );
-	    request.send( url );
-	}
-	else
-	{
-	    clearList( startDateList );
-	    clearList( endDateList );
+        var option = document.createElement( "option" );
+        option.value = weeklyPeriodName;
+        option.text = weeklyPeriodName;
+        option.title = weeklyPeriodName;
+        periodList.add( option, null );
 	}
 }
-*/
+
 function getPeriodsReceived( xmlObject )
 {	
     var startDateList = document.getElementById( "sDateLB" );
@@ -572,25 +497,16 @@
 		{
 			getOUDetailsForTARecevied(data);
 		},'xml');
-
-	/*
-    var request = new Request();
-    request.setResponseTypeXML( 'orgunit' );
-    request.setCallbackSuccess( getOUDetailsForTARecevied );
-
-    var requestString = "getOrgUnitDetails.action";
-    var params = "orgUnitId=" + orgUnitIds+"&type=ta";
-    request.sendAsPost( params );
-    request.send( requestString );
-    */ 
 }
 
 function getOUDetailsForTARecevied(xmlObject)
 {
     var ouListCDId = document.getElementById( "orgUnitListCB" );
     var ouLevelId = document.getElementById( "orgUnitLevelCB" );
-    var ouRadioVal = $( "input[name='ouRadio']:checked" ).val();
-		
+    //var ouRadioVal = $( "input[name='ouRadio']:checked" ).val();
+	var orgUnitSelListCB = document.getElementById( "orgUnitSelListCB" );
+	var ouRadioVal = orgUnitSelListCB.options[ orgUnitSelListCB.selectedIndex ].value;
+
     var orgUnits = xmlObject.getElementsByTagName("orgunit");
 
     for ( var i = 0; i < orgUnits.length; i++ )
@@ -628,8 +544,8 @@
             clearList( ouListCDId );
     		
             ouListCDId.options[ouListCDId.options.length] = new Option(orgUnitName,id,false,false);
-            var selouRadioButton = $( "input[name='ouRadio']:checked" ).val();
-            if( selouRadioButton == "orgUnitGroupRadio" )
+            //var selouRadioButton = $( "input[name='ouRadio']:checked" ).val();
+            if( ouRadioVal == "orgUnitGroupRadio" )
             {
             	getOrgUnitGroups();
             }
@@ -663,7 +579,6 @@
     if( j == 0 )
     {
     	document.getElementById( "ViewReport" ).disabled = true;
-    	
     }
     else
     {
@@ -691,7 +606,6 @@
     var selectedServices = document.getElementById("selectedServices");
     var orgUnitListCB = document.getElementById("orgUnitListCB");
     var selOUListLength = document.tabularAnalysisForm.orgUnitListCB.options.length;
-   // alert(selOUListLength);
     var orgUnitLevelCB = document.getElementById("orgUnitLevelCB");
     var yearLB = document.getElementById("yearLB");
     var periodLB = document.getElementById("periodLB");
@@ -699,8 +613,9 @@
     var aggPeriodCB = document.getElementById("aggPeriodCB");
     var periodTypeList = document.getElementById( "periodTypeLB" );
     var periodTypeId = periodTypeList.options[ periodTypeList.selectedIndex ].value;
-    var ouRadioVal = $( "input[name='ouRadio']:checked" ).val();
-  
+	var orgUnitSelListCB = document.getElementById( "orgUnitSelListCB" );
+	var ouRadioVal = orgUnitSelListCB.options[ orgUnitSelListCB.selectedIndex ].value;
+
     var k=0;
     if( selectedServices.options.length <= 0 ) 
     {
@@ -732,21 +647,11 @@
 	
     if( ouRadioVal == "orgUnitSelectedRadio" )
     {
-        //if( orgUnitListCB.selectedIndex < 0 ) 
     	if( selOUListLength <= 0 )
         {
             alert( "Please select OrgUnit(s)" );
             return false;
         }
-    	/*
-        else
-        {
-        	for(k=0;k<selOUListLength;k++)
-        	{
-        		document.tabularAnalysisForm.orgUnitListCB.options[k].selected = true;
-        	}
-    	}
-    	*/
     }
     else if( ouRadioVal == "orgUnitGroupRadio" ) 
     { 

=== modified file 'local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/tabularAnalysisFront.vm'
--- local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/tabularAnalysisFront.vm	2010-12-03 11:30:11 +0000
+++ local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/tabularAnalysisFront.vm	2011-05-27 11:25:15 +0000
@@ -1,44 +1,44 @@
 <style>
-#overlay {
-z-index:9998;
-position:absolute;
-top:0;
-bottom:0;
-left:0;
-width:100%;
-background:#000;
-opacity:0.45;
--moz-opacity:0.45;
-filter:alpha(opacity=45);
-visibility:hidden;
-}
-#overlayImg{ width: 50px; height: 50px; z-index: 9999; position: absolute; left:50%}
+    #overlay {
+    z-index:9998;
+    position:absolute;
+    top:0;
+    bottom:0;
+    left:0;
+    width:100%;
+    background:#000;
+    opacity:0.45;
+    -moz-opacity:0.45;
+    filter:alpha(opacity=45);
+    visibility:hidden;
+    }
+    #overlayImg{ width: 50px; height: 50px; z-index: 9999; position: absolute; left:50%}
 </style>
 <div id="overlay">
-<div id="overlayImg"><img  width="50" height="50" src="images/ajax-loader.gif" /></div>
+    <div id="overlayImg"><img  width="50" height="50" src="images/ajax-loader.gif" /></div>
 </div>
 
 <script>
-	
-	// Global Variables
-	var dailyPeriodTypeName = '$dailyPeriodTypeName';
-	var weeklyPeriodTypeName = '$weeklyPeriodTypeName';
-	var monthlyPeriodTypeName = '$monthlyPeriodTypeName';
-	var quarterlyPeriodTypeName = '$quarterlyPeriodTypeName';
-	var sixmonthPeriodTypeName = '$sixMonthPeriodTypeName';
-	var yearlyPeriodTypeName = '$yearlyPeriodTypeName';
-	
-	var maxOrgUnitLevels = $maxOrgUnitLevels;
-	var selOrgUnitId="NONE";
-	
-	var days = new Array();
-	
-	var monthDays = new Array(31,29,31,30,31,30,31,31,30,31,30,31); // for daily Period
-	//var monthNames = new Array("Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar");
-	
-	var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
-	var quarterNames = new Array("Q1","Q2","Q3","Q4");
-	var halfYearNames = new Array("HY1","HY2");
+    
+    // Global Variables
+    var dailyPeriodTypeName = '$dailyPeriodTypeName';
+    var weeklyPeriodTypeName = '$weeklyPeriodTypeName';
+    var monthlyPeriodTypeName = '$monthlyPeriodTypeName';
+    var quarterlyPeriodTypeName = '$quarterlyPeriodTypeName';
+    var sixmonthPeriodTypeName = '$sixMonthPeriodTypeName';
+    var yearlyPeriodTypeName = '$yearlyPeriodTypeName';
+    
+    var maxOrgUnitLevels = $maxOrgUnitLevels;
+    var selOrgUnitId="NONE";
+    
+    var days = new Array();
+    
+    var monthDays = new Array(31,29,31,30,31,30,31,31,30,31,30,31); // for daily Period
+    //var monthNames = new Array("Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar");
+    
+    var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
+    var quarterNames = new Array("Q1","Q2","Q3","Q4");
+    var halfYearNames = new Array("HY1","HY2");
 
     k = 0;
 
@@ -74,207 +74,226 @@
     }
 
     var orgUnitGroupIds = new Array();
-	var orgUnitGroupNames = new Array();
+    var orgUnitGroupNames = new Array();
 
-	#set( $count1 = 0 );
-	#foreach( $orgUnitGroup in $orgUnitGroups )
-	   orgUnitGroupIds[$count1] = $orgUnitGroup.id;
-	   orgUnitGroupNames[$count1] = '$orgUnitGroup.name';
-	   #set( $count1 = $count1 + 1 );
-	#end
-	
-	
-	
+    #set( $count1 = 0 );
+    #foreach( $orgUnitGroup in $orgUnitGroups )
+       orgUnitGroupIds[$count1] = $orgUnitGroup.id;
+       orgUnitGroupNames[$count1] = '$orgUnitGroup.name';
+       #set( $count1 = $count1 + 1 );
+    #end
+    
+    
+    
 </script>
 
 
 <h1>Tabular Analysis Form</h1>
 <hr />
 
-<form id="tabularAnalysisForm" name="tabularAnalysisForm" action="tabularAnalysisResult.action" method="post" onsubmit="return formValidations()" target="_blank">	
-	<table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="0" width="100%" border=0>
-		<colgroup>
-        	<col width="40%">
-  		    <col width="20%">
- 		    <col width="40%">
-  	    </colgroup>
+<form id="tabularAnalysisForm" name="tabularAnalysisForm" action="tabularAnalysisResult.action" method="post" onsubmit="return formValidations()" target="_blank">  
+    <table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="0" width="100%" border=0>
+        <colgroup>
+            <col width="40%">
+            <col width="20%">
+            <col width="40%">
+        </colgroup>
 
-		<tr>
-			<td class="NormalB">$i18n.getString( "ga_filter_by_degroup" )<br>
-		   		<select id="dataElementGroupId" name="dataElementGroupId" style="width:350px" onchange="getDataElements()">
-                	<option value="0">[ Select DataElementGroup / All ]</option>				                    
-            			#foreach ( $degroup in $dataElementGroups )
-            			<option value="$degroup.id" title="$degroup.name">$degroup.name</option>        			
-     		        #end
-     		    </select>
+        <tr>
+            <td class="NormalB">$i18n.getString( "ga_filter_by_degroup" )<br>
+                <select id="dataElementGroupId" name="dataElementGroupId" style="width:350px" onchange="getDataElements()">
+                    <option value="0">[ Select DataElementGroup / All ]</option>                                    
+                        #foreach ( $degroup in $dataElementGroups )
+                        <option value="$degroup.id" title="$degroup.name">$degroup.name</option>                    
+                    #end
+                </select>
             </td>   
             <td class="NormalB">&nbsp;</td>
             <td class="NormalB">$i18n.getString( "compare_view" )<br>
-            	<select id="deSelection" name="deSelection" style="width:350px" onchange="deSelectionChangeFuntion( 'availableDataElements', 'selectedServices' )">
-                	<option value="dataelement" selected>DataElements</option>
+                <select id="deSelection" name="deSelection" style="width:350px" onchange="deSelectionChangeFuntion( 'availableDataElements', 'selectedServices' )">
+                    <option value="dataelement" selected>DataElements</option>
                     <option value="optioncombo">Options in DataElements</option>
                 </select>
             </td>
-    	</tr>
+        </tr>
         
         <tr>
-			<td class="NormalB">&nbsp;</td>   
-			<td class="NormalB">&nbsp;</td>
-			<td class="NormalB">&nbsp;</td>
-		</tr>
-                			
-		<tr>
-			<td class="NormalB">$i18n.getString( "ga_available_delist" )<br>
-				<select multiple size="5" id="availableDataElements" name="availableDataElements" style="width:350px; height:85px" ondblclick="moveSelectedById( 'availableDataElements', 'selectedServices' )">					
-					#foreach ( $element in $dataElements )
-						<option value="D:$element.id" title="$element.name">$element.name</option>					
-				    #end
-				</select>
-			</td>
-    		<td class="NormalB" align="center">
-    			<br />
-    			<input type="button" value="&gt;" style="width:40px" onclick="moveSelectedById( 'availableDataElements', 'selectedServices' )"><br>
+            <td class="NormalB">&nbsp;</td>   
+            <td class="NormalB">&nbsp;</td>
+            <td class="NormalB">&nbsp;</td>
+        </tr>
+                            
+        <tr>
+            <td class="NormalB">$i18n.getString( "ga_available_delist" )<br>
+                <select multiple size="5" id="availableDataElements" name="availableDataElements" style="width:350px; height:85px" ondblclick="moveSelectedById( 'availableDataElements', 'selectedServices' )">                    
+                    #foreach ( $element in $dataElements )
+                        <option value="D:$element.id" title="$element.name">$element.name</option>                  
+                    #end
+                </select>
+            </td>
+            <td class="NormalB" align="center">
+                <br />
+                <input type="button" value="&gt;" style="width:40px" onclick="moveSelectedById( 'availableDataElements', 'selectedServices' )"><br>
                 <input type="button" value="&lt;" style="width:40px" onclick="moveSelectedServices( 'selectedServices', 'availableDataElements', 'availableIndicators' )"><br>
-			</td>
-			<td class="NormalB" rowspan="5">    			
-    			<table>
-    				<tr>
-    					<td class="NormalB">
-							$i18n.getString( "ta_selected_servicelist" )<br />
-							<select multiple id="selectedServices" name="selectedServices" style="width:350px; height:250px" ondblclick="moveSelectedServices( 'selectedServices', 'availableDataElements', 'availableIndicators' )">                           
-							</select>    						
-					    </td>
-					    <td>
-							<a href="javascript:moveup('selectedServices')"><img src="../images/move_up.png" alt="$i18n.getString( "move_up" )"></a><br><br>
-							<a href="javascript:movedown('selectedServices')"><img src="../images/move_down.png" alt="$i18n.getString( "move_down" )"></a>
-    					</td>
-				    </tr>
-			    </table>
-			</td>
-		</tr>
-  		
-		<tr>
-			<td class="NormalB">&nbsp;<br/></td>   
-			<td class="NormalB">&nbsp;<br/></td>
-		</tr>
-
-		<tr>
-			<td class="NormalB">$i18n.getString( "ga_filter_by_indicatorgroup" )<br>
-				<select id="indicatorGroupId" name="indicatorGroupId" style="width:350px" onchange="getIndicators()">
-					<option value="0">[ Select IndicatorGroup / All ]</option>                    
-                    	#foreach ( $group in $indicatorGroups )
-                    		<option value="$group.id">$group.name</option>
-				    	#end
-				</select>
-			</td>   
-			<td class="NormalB">&nbsp;</td>
-		</tr>
-
-		<tr>
-			<td class="NormalB">&nbsp;</td>   
-			<td class="NormalB">&nbsp;</td>
-		</tr>
-                			
-		<tr>
-			<td class="NormalB">$i18n.getString( "ga_available_indicatorlist" )<br>
-				<select multiple size="5" id="availableIndicators" name="availableIndicators" style="width:350px; height:85px" ondblclick="moveSelectedById( 'availableIndicators', 'selectedServices' )">					
-					#foreach ( $indicator in $indicators )
-						<option value="I:$indicator.id">$indicator.name</option>
-				    #end
-				</select>
-			</td>
-			<td class="NormalB" align="center">
-				<br />
-				<input type="button" value="&gt;" style="width:40px" onclick="moveSelectedById( 'availableIndicators', 'selectedServices' )"><br>
-				<input type="button" value="&lt;" style="width:40px" onclick="moveSelectedServices( 'selectedServices', 'availableDataElements', 'availableIndicators' )"><br>		
-			</td>
-		</tr>
-		<tr>
-			<td class="NormalB">&nbsp;</td>   
-			<td class="NormalB">&nbsp;</td>
-			<td class="NormalB">&nbsp;</td>
-		</tr>
-		<tr>
-			<td class="NormalB">
-				<table>
-
-                    <tr>
-                        <td class="NormalB" colspan="3"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitSelectedRadio" onclick="ouradioSelection(event)" > Selected
-                        &nbsp;&nbsp; <input type="radio" id="ouRadio" name="ouRadio" value="orgUnitGroupRadio"  onclick="ouradioSelection(event)" > OrgUnitGroups
-                        &nbsp;&nbsp;<input type="radio" id="ouRadio" name="ouRadio" value="orgUnitLevelRadio" onclick="ouradioSelection(event)" checked> OrgUnit Levels</td>
+            </td>
+            <td class="NormalB" rowspan="5">                
+                <table>
+                    <tr>
+                        <td class="NormalB">
+                            $i18n.getString( "ta_selected_servicelist" )<br />
+                            <select multiple id="selectedServices" name="selectedServices" style="width:350px; height:250px" ondblclick="moveSelectedServices( 'selectedServices', 'availableDataElements', 'availableIndicators' )">                           
+                            </select>                           
+                        </td>
+                        <td>
+                            <a href="javascript:moveup('selectedServices')"><img src="../images/move_up.png" alt="$i18n.getString( "move_up" )"></a><br><br>
+                            <a href="javascript:movedown('selectedServices')"><img src="../images/move_down.png" alt="$i18n.getString( "move_down" )"></a>
+                        </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+        
+        <tr>
+            <td class="NormalB">&nbsp;<br/></td>   
+            <td class="NormalB">&nbsp;<br/></td>
+        </tr>
+
+        <tr>
+            <td class="NormalB">$i18n.getString( "ga_filter_by_indicatorgroup" )<br>
+                <select id="indicatorGroupId" name="indicatorGroupId" style="width:350px" onchange="getIndicators()">
+                    <option value="0">[ Select IndicatorGroup / All ]</option>                    
+                        #foreach ( $group in $indicatorGroups )
+                            <option value="$group.id">$group.name</option>
+                        #end
+                </select>
+            </td>   
+            <td class="NormalB">&nbsp;</td>
+        </tr>
+
+        <tr>
+            <td class="NormalB">&nbsp;</td>   
+            <td class="NormalB">&nbsp;</td>
+        </tr>
+                            
+        <tr>
+            <td class="NormalB">$i18n.getString( "ga_available_indicatorlist" )<br>
+                <select multiple size="5" id="availableIndicators" name="availableIndicators" style="width:350px; height:85px" ondblclick="moveSelectedById( 'availableIndicators', 'selectedServices' )">                  
+                    #foreach ( $indicator in $indicators )
+                        <option value="I:$indicator.id">$indicator.name</option>
+                    #end
+                </select>
+            </td>
+            <td class="NormalB" align="center">
+                <br />
+                <input type="button" value="&gt;" style="width:40px" onclick="moveSelectedById( 'availableIndicators', 'selectedServices' )"><br>
+                <input type="button" value="&lt;" style="width:40px" onclick="moveSelectedServices( 'selectedServices', 'availableDataElements', 'availableIndicators' )"><br>      
+            </td>
+        </tr>
+        <tr>
+            <td class="NormalB">&nbsp;</td>   
+            <td class="NormalB">&nbsp;</td>
+            <td class="NormalB">&nbsp;</td>
+        </tr>
+        <tr>
+            <td class="NormalB">
+                <table>
+                    <tr>
+                        <td class="NormalB">
+                            <select name="orgUnitSelListCB" id="orgUnitSelListCB" style="width: 150px;" onchange="ouListSelection()" >
+                                <option value="orgUnitLevelRadio">OrgUnit Levels</option>
+                                <option value="orgUnitSelectedRadio">Selected</option>
+                                <option value="orgUnitGroupRadio">OrgUnitGroups</option>
+                            </select>
+                        </td>
+                        <td class="NormalB">&nbsp;</td>  
+                        <td class="NormalB">
+                            <select id="aggData" name="aggData" style="width:150px">
+                                <option value="generateaggdata">$i18n.getString( "generate_agg_data" )</option>
+                                <option value="useexistingaggdata">$i18n.getString( "use_existing_agg_data" )</option>
+                                <option value="usecaptureddata">$i18n.getString( "use_captured_data" )</option>
+                            </select>
+                        </td>
+                    </tr>
+<!--                    
+                    <tr>
+                        <td class="NormalB" colspan="3">
+                            <input type="radio" id="ouRadio" name="ouRadio" value="orgUnitSelectedRadio" onclick="ouradioSelection(event)" > Selected&nbsp;&nbsp; 
+                            <input type="radio" id="ouRadio" name="ouRadio" value="orgUnitGroupRadio"  onclick="ouradioSelection(event)" > OrgUnitGroups&nbsp;&nbsp;
+                            <input type="radio" id="ouRadio" name="ouRadio" value="orgUnitLevelRadio" onclick="ouradioSelection(event)" checked> OrgUnit Levels
+                        </td>
+                    </tr>
+-->                 
+    <!--                    
+                    <tr>
+                        <td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitSelectedRadio" onclick="ouradioSelection(event)" > Selected</td>
+                        <td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitGroupRadio"  onclick="ouradioSelection(event)" > OrgUnitGroups</td>
+                        <td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitLevelRadio" onclick="ouradioSelection(event)" checked> OrgUnit Levels</td>
                     </tr>   
-					
-<!--					
-					<tr>
-						<td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitSelectedRadio" onclick="ouradioSelection(event)" > Selected</td>
-						<td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitGroupRadio"  onclick="ouradioSelection(event)" > OrgUnitGroups</td>
-						<td class="NormalB"><input type="radio" id="ouRadio" name="ouRadio" value="orgUnitLevelRadio" onclick="ouradioSelection(event)" checked> OrgUnit Levels</td>
-					</tr>	
 -->
-					<tr>
-						<td class="NormalB">$i18n.getString( "ga_orgunit" )<br>
-							<select name="orgUnitListCB" id="orgUnitListCB" multiple size="7" style="width: 150px;" ondblclick="remOUFunction()" disabled >
-							</select>						
-						</td>
-						<td class="NormalB">&nbsp;</td>  
-						<td class="NormalB">OrgUnitGroups/Level<br>
-							<select name="orgUnitLevelCB" id="orgUnitLevelCB" size="7" style="width: 150px;">
-							</select>
-						</td>
-					</tr>
-				</table>
-			</td>
-			<td class="NormalB" align="center">&nbsp;</td>
-			<td class="NormalB" align="center">
-				<table>
-					<tr>
-						<td class="NormalB">
-							PeriodType: <br>
-							<select id="periodTypeLB" name="periodTypeLB" onchange="getPeriods()" style="width: 150px;">								
-								#foreach ( $periodType in $periodTypes )
-									<option value="$periodType.name" #if($periodType.name==$monthlyPeriodTypeName) selected #end>$periodType.name</option>								
-                         	    #end
-                         	</select>
+                    <tr>
+                        <td class="NormalB">$i18n.getString( "ga_orgunit" )<br>
+                            <select name="orgUnitListCB" id="orgUnitListCB" multiple size="7" style="width: 150px;" ondblclick="remOUFunction()" disabled >
+                            </select>                       
+                        </td>
+                        <td class="NormalB">&nbsp;</td>  
+                        <td class="NormalB">OrgUnitGroups/Level<br>
+                            <select name="orgUnitLevelCB" id="orgUnitLevelCB" size="7" style="width: 150px;">
+                            </select>
+                        </td>
+                    </tr>
+                </table>
+            </td>
+            <td class="NormalB" align="center">&nbsp;</td>
+            <td class="NormalB" align="center">
+                <table>
+                    <tr>
+                        <td class="NormalB">
+                            PeriodType: <br>
+                            <select id="periodTypeLB" name="periodTypeLB" onchange="getPeriods()" style="width: 150px;">                                
+                                #foreach ( $periodType in $periodTypes )
+                                    <option value="$periodType.name" #if($periodType.name==$monthlyPeriodTypeName) selected #end>$periodType.name</option>                              
+                                #end
+                            </select>
                             <br /><br />                        
-						</td>
-						<td>&nbsp;</td>
-						<td align="right" class="NormalB">
-							<input type="checkbox" id="aggPeriodCB" name="aggPeriodCB" value="ON"> Aggregate By Period<br>
-						</td>
-					</tr>                       			    
-					<tr>
-						<td class="NormalB">
-							Year : <br>
-							<select id="yearLB" name="yearLB" onchange="getWeeklyPeriod()"  size="5" multiple style="width: 150px;">																				
-								#foreach($periodName in $periodNameList)
-									<option value="$periodName">$periodName</option>								
-							    #end
-							</select>
-						</td>
-						<td>&nbsp;</td>
-						<td class="NormalB">
-							Period : <br>
-							<select id="periodLB" name="periodLB" size="5" multiple style="width: 175px;">								
-							</select>
-						</td>
-					</tr>
-					<tr>
-						<td>&nbsp;</td>
-						<td>&nbsp;</td>
-						<td>&nbsp;</td>
-					</tr>                    			                   			        
-					<tr>
-						<td>
-							<input type="submit" id="ViewReport" name="ViewReport" value="$i18n.getString( 'ta_generatereport' )" style="width: 120; height: 25; font-family:Arial; font-weight:bold; color:#000000">
-						</td>
-						<td>&nbsp;</td>
-						<td align="right">&nbsp;</td>
-					</tr>                            
-					<input type="hidden" name="selectedButton" id="selectedButton">
-				</table>    
-			</td>
-		</tr>
-	</table>							
+                        </td>
+                        <td>&nbsp;</td>
+                        <td align="right" class="NormalB">
+                            <input type="checkbox" id="aggPeriodCB" name="aggPeriodCB" value="ON"> Aggregate By Period<br>
+                        </td>
+                    </tr>                                       
+                    <tr>
+                        <td class="NormalB">
+                            Year : <br>
+                            <select id="yearLB" name="yearLB" onchange="getWeeklyPeriod()"  size="5" multiple style="width: 150px;">                                                                                
+                                #foreach($periodName in $periodNameList)
+                                    <option value="$periodName">$periodName</option>                                
+                                #end
+                            </select>
+                        </td>
+                        <td>&nbsp;</td>
+                        <td class="NormalB">
+                            Period : <br>
+                            <select id="periodLB" name="periodLB" size="5" multiple style="width: 175px;">                              
+                            </select>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td>&nbsp;</td>
+                        <td>&nbsp;</td>
+                        <td>&nbsp;</td>
+                    </tr>                                                                   
+                    <tr>
+                        <td>
+                            <input type="submit" id="ViewReport" name="ViewReport" value="$i18n.getString( 'ta_generatereport' )" style="width: 120; height: 25; font-family:Arial; font-weight:bold; color:#000000">
+                        </td>
+                        <td>&nbsp;</td>
+                        <td align="right">&nbsp;</td>
+                    </tr>                            
+                    <input type="hidden" name="selectedButton" id="selectedButton">
+                </table>    
+            </td>
+        </tr>
+    </table>                            
 </form>
 
 <script>

=== modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ed/action/EDReportResultAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ed/action/EDReportResultAction.java	2011-05-18 11:56:37 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ed/action/EDReportResultAction.java	2011-05-27 11:25:15 +0000
@@ -362,11 +362,11 @@
                     {
                         if( denValue != 0.0 )
                         {
-                                indValue = ( numValue / denValue ) * indicator.getIndicatorType().getFactor();
+                            indValue = ( numValue / denValue ) * indicator.getIndicatorType().getFactor();
                         }
                         else
                         {
-                                indValue = 0.0;
+                            indValue = 0.0;
                         }
                     }
                     catch( Exception e )