← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6642: local vn - Upgraded the category report in allowing to generate this report by vertical or horizo...

 

------------------------------------------------------------
revno: 6642
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-04-19 15:29:34 +0700
message:
  local vn - Upgraded the category report in allowing to generate this report by vertical or horizontal.
modified:
  local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportCategoryAction.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/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportCategoryAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportCategoryAction.java	2011-11-03 04:26:28 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportCategoryAction.java	2012-04-19 08:29:34 +0000
@@ -34,9 +34,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reportsheet.DataElementGroupOrder;
+import org.hisp.dhis.reportsheet.ExportItem;
 import org.hisp.dhis.reportsheet.ExportReport;
 import org.hisp.dhis.reportsheet.ExportReportCategory;
-import org.hisp.dhis.reportsheet.ExportItem;
 import org.hisp.dhis.reportsheet.exporting.AbstractGenerateExcelReportSupport;
 import org.hisp.dhis.reportsheet.utils.ExcelUtils;
 
@@ -65,7 +65,14 @@
 
             Collection<ExportItem> exportReportItems = exportReportInstance.getExportItemBySheet( sheetNo );
 
-            this.generateOutPutFile( exportReportInstance, exportReportItems, organisationUnit, sheet );
+            if ( isVerticalCategory( exportReportItems ) )
+            {
+                this.generateVerticalOutPutFile( exportReportInstance, exportReportItems, organisationUnit, sheet );
+            }
+            else
+            {
+                this.generateHorizontalOutPutFile( exportReportInstance, exportReportItems, organisationUnit, sheet );
+            }
         }
     }
 
@@ -73,8 +80,8 @@
     // Supportive method
     // -------------------------------------------------------------------------
 
-    private void generateOutPutFile( ExportReportCategory exportReport, Collection<ExportItem> exportReportItems,
-        OrganisationUnit organisationUnit, Sheet sheet )
+    private void generateVerticalOutPutFile( ExportReportCategory exportReport,
+        Collection<ExportItem> exportReportItems, OrganisationUnit organisationUnit, Sheet sheet )
     {
         for ( ExportItem reportItem : exportReportItems )
         {
@@ -158,4 +165,56 @@
             }
         }
     }
+
+    private void generateHorizontalOutPutFile( ExportReportCategory exportReport,
+        Collection<ExportItem> exportReportItems, OrganisationUnit organisationUnit, Sheet sheet )
+    {
+        for ( ExportItem reportItem : exportReportItems )
+        {
+            int colBegin = reportItem.getRow();
+
+            for ( DataElementGroupOrder dataElementGroup : exportReport.getDataElementOrders() )
+            {
+                for ( DataElement dataElement : dataElementGroup.getDataElements() )
+                {
+                    if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.DATAELEMENT ) )
+                    {
+                        ExportItem newReportItem = new ExportItem();
+                        newReportItem.setColumn( reportItem.getColumn() );
+                        newReportItem.setRow( reportItem.getRow() );
+                        newReportItem.setPeriodType( reportItem.getPeriodType() );
+                        newReportItem.setName( reportItem.getName() );
+                        newReportItem.setSheetNo( reportItem.getSheetNo() );
+                        newReportItem.setItemType( reportItem.getItemType() );
+
+                        String expression = reportItem.getExpression();
+                        expression = expression.replace( "*", String.valueOf( dataElement.getId() ) );
+                        newReportItem.setExpression( expression );
+
+                        double value = this.getDataValue( newReportItem, organisationUnit );
+
+                        ExcelUtils.writeValueByPOI( reportItem.getRow(), colBegin++, String.valueOf( value ),
+                            ExcelUtils.NUMBER, sheet, this.csNumber );
+                    }
+                }
+            }
+        }
+    }
+
+    private boolean isVerticalCategory( Collection<ExportItem> items )
+    {
+        Integer previousRow = null;
+
+        for ( ExportItem item : items )
+        {
+            if ( previousRow != null && previousRow != item.getRow() )
+            {
+                return false;
+            }
+
+            previousRow = item.getRow();
+        }
+
+        return true;
+    }
 }