← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7330: CCEM Reports work in progress

 

------------------------------------------------------------
revno: 7330
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-06-19 11:18:55 +0100
message:
  CCEM Reports work in progress
modified:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReport.java
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReportManager.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/DefaultCCEMReportManager.java
  local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateCCEMReportAction.java
  local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/ccemReportOutput.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReport.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReport.java	2012-06-13 06:35:38 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReport.java	2012-06-19 10:18:55 +0000
@@ -10,6 +10,7 @@
     public static final String CATALOGTYPE_ATTRIBUTE_VALUE_AGE_GROUP = "CATALOGTYPE_ATTRIBUTE_VALUE_AGE_GROUP";
     public static final String ORGUNITGROUP_DATAVALUE = "ORGUNITGROUP_DATAVALUE";
     public static final String ORGUNIT_EQUIPMENT_ROUTINE_DATAVALUE = "ORGUNIT_EQUIPMENT_ROUTINE_DATAVALUE";
+    public static final String VACCINE_STORAGE_CAPACITY = "VACCINE_STORAGE_CAPACITY";
     
     public static final String LAST_YEAR = "LAST_YEAR";
     public static final String CURRENT_YEAR = "CURRENT_YEAR";

=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReportManager.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReportManager.java	2012-06-13 06:35:38 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/reports/CCEMReportManager.java	2012-06-19 10:18:55 +0000
@@ -26,4 +26,18 @@
     Integer getPeriodId( String startDate, String periodType );
     
     Map<String, Integer> getFacilityWiseEquipmentRoutineData( String orgUnitIdsByComma, String periodIdsByComma, String dataElementIdsByComma, String optComboIdsByComma );
+    
+    Map<Integer, Double> getCatalogDataSumByEquipmentData( String orgUnitIdsByComma, Integer inventoryTypeId, Integer catalogTypeAttributeId, Integer inventoryTypeAttributeId, String equipmentValue );
+    
+    Map<Integer, Double> getSumOfEquipmentDatabyInventoryType( String orgUnitIdsByComma, Integer inventoryTypeId, Integer inventoryTypeAttributeId, Double factor );
+    
+    Map<String, String> getOrgUnitGroupAttribDataForRequirement( String orgUnitGroupIdsByComma, String orgUnitGroupAttribIds );
+    
+    Map<String, String> getDataElementDataForCatalogOptionsForRequirement( String orgUnitIdsByComma, String catalogOption_DataelementIds, Integer periodId );
+    
+    Map<String, String> getCatalogDataForRequirement( Integer vsReqCatalogTypeId, Integer vsReqStorageTempId, String vsReqStorageTemp, Integer vsReqNationalSupplyId, String vsReqNationalSupply, String vsReqCatalogAttribIds );
+    
+    List<Integer> getCatalogIdsForRequirement( Integer vsReqCatalogTypeId, Integer vsReqStorageTempId, String vsReqStorageTemp, Integer vsReqNationalSupplyId, String vsReqNationalSupply );
+    
+    Map<Integer, String> getOrgunitAndOrgUnitGroupMap( String orgUnitGroupIdsByComma, String orgUnitIdsByComma );
 }

=== modified file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/DefaultCCEMReportManager.java'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/DefaultCCEMReportManager.java	2012-06-13 06:35:38 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/DefaultCCEMReportManager.java	2012-06-19 10:18:55 +0000
@@ -45,7 +45,235 @@
     // -------------------------------------------------------------------------
     // Implementation Methods
     // -------------------------------------------------------------------------
-
+    
+    public Map<Integer, String> getOrgunitAndOrgUnitGroupMap( String orgUnitGroupIdsByComma, String orgUnitIdsByComma )
+    {
+        Map<Integer, String> orgUnitGroupMap = new HashMap<Integer, String>();
+        int prevOrgUnitId = 0;
+        try
+        {
+            String query = "SELECT organisationunitid, orgunitgroup.name FROM orgunitgroupmembers " +
+            		        " INNER JOIN orgunitgroup ON orgunitgroupmembers.orgunitgroupid = orgunitgroup.orgunitgroupid "+
+            		        " WHERE " +
+            		            " orgunitgroup.orgunitgroupid IN ("+ orgUnitGroupIdsByComma +") AND " +
+            		            " organisationunitid IN ("+ orgUnitIdsByComma +") ORDER BY organisationunitid"; 
+                                        
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );            
+            while ( rs.next() )
+            {
+                Integer orgUnitID = rs.getInt( 1 );
+                String ouGroupName = rs.getString( 2 );
+
+                if( prevOrgUnitId == orgUnitID )
+                {
+                    String temp = orgUnitGroupMap.get( orgUnitID );
+                    if( temp == null ) temp = "";
+                    temp += "," +ouGroupName;
+                    orgUnitGroupMap.put( orgUnitID, temp );
+                }
+                else
+                {
+                    orgUnitGroupMap.put( orgUnitID, ouGroupName );
+                }
+                
+                prevOrgUnitId = orgUnitID;
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return orgUnitGroupMap;
+    }
+
+    
+    public Map<String, String> getOrgUnitGroupAttribDataForRequirement( String orgUnitGroupIdsByComma, String orgUnitGroupAttribIds )
+    {
+        Map<String, String> orgUnitGroupAttribDataForRequirement = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT orgunitgroupmembers.organisationunitid, attributevalue.attributeid, value FROM attributevalue "+
+                                " INNER JOIN orgunitgroupattributevalues ON attributevalue.attributevalueid = orgunitgroupattributevalues.attributevalueid "+ 
+                                " INNER JOIN orgunitgroupmembers ON orgunitgroupmembers.orgunitgroupid = orgunitgroupattributevalues.orgunitgroupid "+
+                                " WHERE "+
+                                    " attributeid IN ("+orgUnitGroupAttribIds+") AND " +
+                                    " orgunitgroupattributevalues.orgunitgroupid IN ("+ orgUnitGroupIdsByComma +")";
+                        
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer orgUnitID = rs.getInt( 1 );
+                Integer attribId = rs.getInt( 2 );
+                String value = rs.getString( 3 );
+
+                orgUnitGroupAttribDataForRequirement.put( orgUnitID+":"+attribId, value );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return orgUnitGroupAttribDataForRequirement;
+    }
+
+    
+    public Map<String, String> getDataElementDataForCatalogOptionsForRequirement( String orgUnitIdsByComma, String catalogOption_DataelementIds, Integer periodId )
+    {
+        Map<String, String> dataElementDataForRequirement = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT dataelementid, periodid, sourceid, value FROM datavalue " +
+                                " WHERE " +
+                                    " dataelementid IN ( "+ catalogOption_DataelementIds +") AND " +
+                                    " sourceid IN ( " + orgUnitIdsByComma + " ) AND " +
+                                    " periodid = "+periodId; 
+                        
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer deId = rs.getInt( 1 );
+                Integer pId = rs.getInt( 2 );
+                Integer sourceId = rs.getInt( 3 );
+                String value = rs.getString( 4 );
+                
+                dataElementDataForRequirement.put( deId+":"+pId+":"+sourceId, value );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return dataElementDataForRequirement;
+    }
+
+    
+    public Map<String, String> getCatalogDataForRequirement( Integer vsReqCatalogTypeId, Integer vsReqStorageTempId, String vsReqStorageTemp, Integer vsReqNationalSupplyId, String vsReqNationalSupply, String vsReqCatalogAttribIds )
+    {
+        Map<String, String> catalogDataForRequirement = new HashMap<String, String>();
+        try
+        {
+            String query = "SELECT catalog.catalogid, catalogtypeattributeid, value FROM catalogdatavalue " +
+            		        " INNER JOIN catalog ON catalog.catalogid = catalogdatavalue.catalogid "+
+            		        " WHERE " +
+            		            " catalog.catalogid IN " +
+            		                "( SELECT cd1.catalogid FROM catalogdatavalue AS cd1 INNER JOIN catalogdatavalue AS cd2 ON cd1.catalogid = cd2.catalogid " +
+            		                    " WHERE cd1.catalogtypeattributeid = "+vsReqNationalSupplyId+" AND cd1.value = '"+vsReqNationalSupply+"' AND cd2.catalogtypeattributeid = "+vsReqStorageTempId+" AND cd2.value = '"+ vsReqStorageTemp +"') " + 
+            		            " AND catalogtypeattributeid IN ("+vsReqCatalogAttribIds+") AND " +
+            		            " catalog.catalogtypeid = "+vsReqCatalogTypeId;
+                        
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer catalogId = rs.getInt( 1 );
+                Integer catalogTypeAttribId = rs.getInt( 2 );
+                String value = rs.getString( 3 );
+                
+                catalogDataForRequirement.put( catalogId+":"+catalogTypeAttribId, value );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return catalogDataForRequirement;
+    }
+
+    public List<Integer> getCatalogIdsForRequirement( Integer vsReqCatalogTypeId, Integer vsReqStorageTempId, String vsReqStorageTemp, Integer vsReqNationalSupplyId, String vsReqNationalSupply )
+    {
+        List<Integer> catalogIdsForRequirement = new ArrayList<Integer>();
+        try
+        {
+            String query = "SELECT DISTINCT(catalog.catalogid) FROM catalogdatavalue " +
+                                " INNER JOIN catalog ON catalog.catalogid = catalogdatavalue.catalogid "+
+                                " WHERE " +
+                                    " catalog.catalogid IN " +
+                                        "( SELECT cd1.catalogid FROM catalogdatavalue AS cd1 INNER JOIN catalogdatavalue AS cd2 ON cd1.catalogid = cd2.catalogid " +
+                                            " WHERE cd1.catalogtypeattributeid = "+vsReqNationalSupplyId+" AND cd1.value = '"+vsReqNationalSupply+"' AND cd2.catalogtypeattributeid = "+vsReqStorageTempId+" AND cd2.value = '"+ vsReqStorageTemp +"') " + 
+                                    " AND catalog.catalogtypeid = "+vsReqCatalogTypeId;
+                        
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer catalogId = rs.getInt( 1 );
+                
+                catalogIdsForRequirement.add( catalogId );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return catalogIdsForRequirement;
+    }
+    
+    public Map<Integer, Double> getSumOfEquipmentDatabyInventoryType( String orgUnitIdsByComma, Integer inventoryTypeId, Integer inventoryTypeAttributeId, Double factor )
+    {
+        Map<Integer, Double> equipmentSumByInventoryTypeMap = new HashMap<Integer, Double>();
+        try
+        {
+            String query = "SELECT organisationunitid, SUM(value*"+factor+") FROM equipment " +
+                                " INNER JOIN equipmentinstance on equipment.equipmentinstanceid = equipmentinstance.equipmentinstanceid " +
+                                " WHERE " + 
+                                    " equipmentinstance.working = 1 AND "+
+                                    " equipmentinstance.inventorytypeid =  "+ inventoryTypeId +" AND "+       
+                                    " equipmentinstance.organisationunitid in (" + orgUnitIdsByComma +") AND "+
+                                    " equipment.inventorytypeattributeid = "+ inventoryTypeAttributeId +" "+
+                                    " GROUP BY organisationunitid";                  
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Double catalogDataValueSum = rs.getDouble( 2 );
+                equipmentSumByInventoryTypeMap.put( orgUnitId, catalogDataValueSum );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return equipmentSumByInventoryTypeMap;
+    }
+
+    
+    public Map<Integer, Double> getCatalogDataSumByEquipmentData( String orgUnitIdsByComma, Integer inventoryTypeId, Integer catalogTypeAttributeId, Integer inventoryTypeAttributeId, String equipmentValue )
+    {
+        Map<Integer, Double> catalogSumByEquipmentDataMap = new HashMap<Integer, Double>();
+        try
+        {
+            String query =  "SELECT equipmentinstance.organisationunitid, sum(catalogdatavalue.value) FROM catalogdatavalue " +  
+                            " INNER JOIN equipmentinstance on catalogdatavalue.catalogid = equipmentinstance.catalogid " +  
+                            " WHERE " + 
+                                " equipmentinstance.working = 1 AND " +
+                                " equipmentinstance.inventorytypeid =  " + inventoryTypeId + " AND " + 
+                                " catalogdatavalue.catalogtypeattributeid =  " + catalogTypeAttributeId + " AND " +
+                                " equipmentinstance.organisationunitid in ("+ orgUnitIdsByComma +") AND " +
+                                " equipmentinstance.equipmentinstanceid in " +
+                                    "( SELECT equipmentinstanceid FROM equipment WHERE inventorytypeattributeid = "+ inventoryTypeAttributeId +" AND equipment.value IN ('"+ equipmentValue +"') ) "+
+                                " GROUP BY equipmentinstance.organisationunitid";
+
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Double catalogDataValueSum = rs.getDouble( 2 );
+                catalogSumByEquipmentDataMap.put( orgUnitId, catalogDataValueSum );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( "Exception: ", e );
+        }
+        
+        return catalogSumByEquipmentDataMap;
+    }
+    
     public Map<String, Integer> getFacilityWiseEquipmentRoutineData( String orgUnitIdsByComma, String periodIdsByComma, String dataElementIdsByComma, String optComboIdsByComma )
     {
         Map<String, Integer> equipmentDataValueMap = new HashMap<String, Integer>();

=== modified file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateCCEMReportAction.java'
--- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateCCEMReportAction.java	2012-06-13 06:35:38 +0000
+++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateCCEMReportAction.java	2012-06-19 10:18:55 +0000
@@ -12,8 +12,6 @@
 import java.util.List;
 import java.util.Map;
 
-import jxl.write.Label;
-
 import org.hisp.dhis.coldchain.reports.CCEMReport;
 import org.hisp.dhis.coldchain.reports.CCEMReportDesign;
 import org.hisp.dhis.coldchain.reports.CCEMReportManager;
@@ -597,10 +595,392 @@
             ccemReportOutput.setTableHeadings( tableHeadings );
             ccemReportOutput.setTableSubHeadings( tableSubHeadings );
         }
-        
+        else if( ccemReport.getReportType().equals( CCEMReport.VACCINE_STORAGE_CAPACITY ) )
+        {
+
+            ccemReportOutput = new CCEMReportOutput();
+            List<String> tableHeadings = new ArrayList<String>();
+            List<List<String>> tableSubHeadings = new ArrayList<List<String>>();
+            List<String> oneSubHeadingRow = new ArrayList<String>();
+            List<List<String>> tableData = new ArrayList<List<String>>();
+
+            List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit>();
+            List<OrganisationUnit> orgUnitGroupMembers = new ArrayList<OrganisationUnit>();
+            
+            String orgUnitGroupIdsByComma = "-1";
+            
+            Integer periodId = 0;
+            Date date = new Date();
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime( date );
+            String periodStartDate = "";
+            
+            periodStartDate = calendar.get( Calendar.YEAR ) + "-01-01";
+           
+            periodId = ccemReportManager.getPeriodId( periodStartDate, "Yearly" );
+            
+            if( periodId == 0 )
+            {
+                ccemReportOutput.setReportHeading( "No Period Exists" );
+                return SUCCESS;
+            }
+            
+            tableHeadings.add( "OrgUnit Hierarchy" );
+            oneSubHeadingRow.add( " " );
+            tableHeadings.add( "OrgUnit" );
+            oneSubHeadingRow.add( " " );
+            tableHeadings.add( "OrgUnit Code" );
+            oneSubHeadingRow.add( " " );
+            tableHeadings.add( "OrgUnit Type" );
+            oneSubHeadingRow.add( " " );
+            tableHeadings.add( "Net Storage" );
+            oneSubHeadingRow.add( "Actual" );
+            tableHeadings.add( " " );
+            oneSubHeadingRow.add( "Required" );
+            tableHeadings.add( " " );
+            oneSubHeadingRow.add( "Difference" );
+            tableHeadings.add( "Surplus" );
+            oneSubHeadingRow.add( ">30%" );
+            tableHeadings.add( " " );
+            oneSubHeadingRow.add( "10-30%" );
+            tableHeadings.add( "Match" );
+            oneSubHeadingRow.add( "+/- 10%" );
+            tableHeadings.add( "Shortage" );
+            oneSubHeadingRow.add( "10-30%" );
+            tableHeadings.add( " " );
+            oneSubHeadingRow.add( ">30%" );
+            
+            tableSubHeadings.add( oneSubHeadingRow );
+            
+            CCEMReportDesign ccemReportDesign1 = reportDesignList.get( 0 );
+            String ccemCellContent1 = ccemSettingsMap.get( ccemReportDesign1.getContent() );
+            if( ccemCellContent1.equals( "ALL" ) )
+            {
+                for( Integer orgUnitGroupId : orgunitGroupList )
+                {
+                    OrganisationUnitGroup orgUnitGroup = organisationUnitGroupService.getOrganisationUnitGroup( orgUnitGroupId );
+                    orgUnitGroupMembers.addAll( orgUnitGroup.getMembers() );
+                    orgUnitGroupIdsByComma += "," + orgUnitGroupId;
+                }
+            }
+            else
+            {
+                String orgUnitGroupIds[] = ccemReportDesign1.getContent().split( "," );
+                
+                for( Integer orgUnitGroupId : orgunitGroupList )
+                {
+                    int flag = 0;
+                    for( String ouGroupId : orgUnitGroupIds )
+                    {
+                        if( Integer.parseInt( ouGroupId ) == orgUnitGroupId ) 
+                        {
+                            orgUnitGroupIdsByComma += "," + orgUnitGroupId;
+                            flag=1;
+                            break;
+                        }
+                    }
+                    
+                    if( flag == 0 ) continue;
+                    
+                    OrganisationUnitGroup orgUnitGroup = organisationUnitGroupService.getOrganisationUnitGroup( orgUnitGroupId );
+                    orgUnitGroupMembers.addAll( orgUnitGroup.getMembers() );
+                }
+            }
+            
+            for( Integer orgUnitId : selOrgUnitList )
+            {
+                orgUnitList.addAll( organisationUnitService.getOrganisationUnitWithChildren( orgUnitId ) );
+            }
+            
+            orgUnitList.retainAll( orgUnitGroupMembers );
+            Collection<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers(OrganisationUnit.class, orgUnitList ) );
+            orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+
+            //Calculations for Actual Column
+            ccemReportDesign1 = reportDesignList.get( 1 );
+            ccemCellContent1 = ccemSettingsMap.get( ccemReportDesign1.getContent() );
+            
+            String[] partsOfCellContent = ccemCellContent1.split( "-" );
+            Integer vscrActualInventoryTypeId = Integer.parseInt( partsOfCellContent[0].split(":" )[0] );
+            Integer vscrActualInventoryTypeAttributeId = Integer.parseInt( partsOfCellContent[0].split(":" )[1] );
+            Double factor = Double.parseDouble( partsOfCellContent[0].split(":" )[2] );;
+
+            Map<Integer, Double> equipmentSumByInventoryTypeMap = new HashMap<Integer, Double>( ccemReportManager.getSumOfEquipmentDatabyInventoryType( orgUnitIdsByComma, vscrActualInventoryTypeId, vscrActualInventoryTypeAttributeId, factor ) );
+            
+            String[] partsOfVSRActualCellContent = partsOfCellContent[1].split( ":" );
+            Integer vsrActualInventoryTypeId = Integer.parseInt( partsOfVSRActualCellContent[0] );
+            Integer vsrActualCatalogTypeAttributeId = Integer.parseInt( partsOfVSRActualCellContent[1] );
+            Integer vsrActualInventoryTypeAttributeId = Integer.parseInt( partsOfVSRActualCellContent[2] );
+            String vsrActualEquipmentValue = partsOfVSRActualCellContent[3];
+            
+            Map<Integer, Double> catalogSumByEquipmentDataMap = new HashMap<Integer, Double>( ccemReportManager.getCatalogDataSumByEquipmentData( orgUnitIdsByComma, vsrActualInventoryTypeId, vsrActualCatalogTypeAttributeId, vsrActualInventoryTypeAttributeId, vsrActualEquipmentValue ) );
+            
+            //Calculations for Required Column
+            ccemReportDesign1 = reportDesignList.get( 2 );
+            ccemCellContent1 = ccemSettingsMap.get( ccemReportDesign1.getContent() );
+            partsOfCellContent = ccemCellContent1.split( "--" );
+            
+            String[] catalogDataParts = partsOfCellContent[0].split( ":" );
+            Integer vsReqCatalogTypeId = Integer.parseInt( catalogDataParts[0] );
+            Integer vsReqStorageTempId = Integer.parseInt( catalogDataParts[1] );
+            String vsReqStorageTemp = catalogDataParts[2];
+            Integer vsReqNationalSupplyId = Integer.parseInt( catalogDataParts[3] );
+            String vsReqNationalSupply = catalogDataParts[4];
+            String vsReqCatalogAttribIds = catalogDataParts[5];
+            
+            Integer vsReqPackedVol = Integer.parseInt( vsReqCatalogAttribIds.split( "," )[0] );
+            Integer vsReqDoses = Integer.parseInt( vsReqCatalogAttribIds.split( "," )[1] );
+            Integer vsReqTargetPopCat= Integer.parseInt( vsReqCatalogAttribIds.split( "," )[2] );
+            Integer vsReqUsage = Integer.parseInt( vsReqCatalogAttribIds.split( "," )[3] );
+            Integer vsReqWastage = Integer.parseInt( vsReqCatalogAttribIds.split( "," )[4] );
+
+            List<Integer> catalogIdsForRequirement = new ArrayList<Integer>( ccemReportManager.getCatalogIdsForRequirement( vsReqCatalogTypeId, vsReqStorageTempId, vsReqStorageTemp, vsReqNationalSupplyId, vsReqNationalSupply ) );
+            
+            Map<String, String> catalogDataForRequirement = new HashMap<String, String>( ccemReportManager.getCatalogDataForRequirement( vsReqCatalogTypeId, vsReqStorageTempId, vsReqStorageTemp, vsReqNationalSupplyId, vsReqNationalSupply, vsReqCatalogAttribIds ) );
+            
+            String[] dataelementDataParts = partsOfCellContent[1].split( "," );
+            Map<String, Integer> catalogOption_DataelementMap = new HashMap<String, Integer>();
+            String catalogOption_DataelementIds = "-1";
+            
+            for( String de_catalogOption : dataelementDataParts )
+            {
+                catalogOption_DataelementMap.put( de_catalogOption.split( ":" )[1], Integer.parseInt( de_catalogOption.split( ":" )[0] ) );
+                catalogOption_DataelementIds += "," + Integer.parseInt( de_catalogOption.split( ":" )[0] );
+            }
+
+            Map<String, String> dataElementDataForRequirement = new HashMap<String, String>( ccemReportManager.getDataElementDataForCatalogOptionsForRequirement( orgUnitIdsByComma, catalogOption_DataelementIds, periodId ) );
+
+            String orgUnitGroupAttribIds = partsOfCellContent[2];
+            Integer vsReqSupplyInterval = Integer.parseInt( orgUnitGroupAttribIds.split( "," )[0] );
+            Integer vsReqReserveStock = Integer.parseInt( orgUnitGroupAttribIds.split( "," )[1] );
+            
+            
+            Map<String, String> orgUnitGroupAttribDataForRequirement = new HashMap<String, String>( ccemReportManager.getOrgUnitGroupAttribDataForRequirement( orgUnitGroupIdsByComma, orgUnitGroupAttribIds ) );
+            
+            Map<Integer, String> orgUnitGroupMap = new HashMap<Integer, String>( ccemReportManager.getOrgunitAndOrgUnitGroupMap( orgUnitGroupIdsByComma, orgUnitIdsByComma ) );
+            
+            for( OrganisationUnit orgUnit : orgUnitList )
+            {
+                List<String> oneTableDataRow = new ArrayList<String>();
+                String orgUnitBranch = "";
+                if( orgUnit.getParent() != null )
+                {
+                    orgUnitBranch = getOrgunitBranch( orgUnit.getParent() );
+                }
+                else
+                {
+                    orgUnitBranch = " ";
+                }
+                
+                oneTableDataRow.add( orgUnitBranch );
+                oneTableDataRow.add( orgUnit.getName() );
+                oneTableDataRow.add( orgUnit.getCode() );
+                String orgUnitGroupName = orgUnitGroupMap.get( orgUnit.getId() );
+                if( orgUnitGroupName == null )
+                {
+                    oneTableDataRow.add( " " );
+                }
+                else
+                {
+                    oneTableDataRow.add( orgUnitGroupName );
+                }
+                
+                Double vsrActualValue = catalogSumByEquipmentDataMap.get( orgUnit.getId() );
+                if( vsrActualValue == null ) vsrActualValue = 0.0;
+
+                Double vscrActualValue = equipmentSumByInventoryTypeMap.get( orgUnit.getId() );
+                if( vscrActualValue == null ) vscrActualValue = 0.0;
+
+                Double vaccineActualValue = vsrActualValue + vscrActualValue;
+                vaccineActualValue = Math.round( vaccineActualValue * Math.pow( 10, 1 ) )/ Math.pow( 10, 1 );
+                oneTableDataRow.add( ""+vaccineActualValue );
+                
+                // Calculation for Requirement Column
+                String tempStr = null;
+                Double vaccineRequirement = 0.0;
+                for( Integer catalogId : catalogIdsForRequirement )
+                {
+                    Double vsReqUsageData = 0.0;
+                    tempStr = catalogDataForRequirement.get( catalogId+":"+vsReqUsage );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqUsageData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqUsageData = 0.0;
+                        }
+                    }
+                    
+                    Double vsReqTargetPopData = 0.0;
+                    String vsReqTargetPopCatData = catalogDataForRequirement.get( catalogId+":"+vsReqTargetPopCat );
+                    if( vsReqTargetPopCatData != null )
+                    {
+                        Integer deId = catalogOption_DataelementMap.get( vsReqTargetPopCatData );
+                        tempStr = dataElementDataForRequirement.get( deId+":"+periodId+":"+orgUnit.getId() );
+                        if( tempStr != null )
+                        {
+                            try
+                            {
+                                vsReqTargetPopData = Double.parseDouble( tempStr );
+                            }
+                            catch( Exception e )
+                            {
+                                vsReqTargetPopData = 0.0;
+                            }
+                        }
+                    }
+                    
+                    Double vsReqDosesData = 0.0;
+                    tempStr = catalogDataForRequirement.get( catalogId+":"+vsReqDoses );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqDosesData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqDosesData = 0.0;
+                        }
+                    }
+                    
+                    Double vsReqPackedVolData = 0.0;
+                    tempStr = catalogDataForRequirement.get( catalogId+":"+vsReqPackedVol );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqPackedVolData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqPackedVolData = 0.0;
+                        }
+                    }
+                    
+                    Double vsReqWastageData = 0.0;
+                    tempStr = catalogDataForRequirement.get( catalogId+":"+vsReqWastage );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqWastageData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqWastageData = 0.0;
+                        }
+                    }
+                    
+                    Double vsReqSupplyIntervalData = 0.0;
+                    tempStr = orgUnitGroupAttribDataForRequirement.get( orgUnit.getId()+":"+vsReqSupplyInterval );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqSupplyIntervalData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqSupplyIntervalData = 0.0;
+                        }
+                    }
+                    
+                    Double vsReqReserveStockData = 0.0;
+                    tempStr = orgUnitGroupAttribDataForRequirement.get( orgUnit.getId()+":"+vsReqReserveStock );
+                    if( tempStr != null )
+                    {
+                        try
+                        {
+                            vsReqReserveStockData = Double.parseDouble( tempStr );
+                        }
+                        catch( Exception e )
+                        {
+                            vsReqReserveStockData = 0.0;
+                        }
+                    }
+                    
+                    //Formula for calculating Requirement for individual vaccine
+                    Double individualVaccineRequirement = 0.0;
+                    try
+                    {
+                        individualVaccineRequirement = ( ( vsReqUsageData * vsReqTargetPopData ) / 100 ) * vsReqDosesData * vsReqPackedVolData * ( 1 / ( 1 - ( vsReqWastageData /100 ) ) ) * ( ( (vsReqSupplyIntervalData + vsReqReserveStockData)/52 ) / 1000 );
+                    }
+                    catch( Exception e )
+                    {
+                        System.out.println( "Exception while calculating individualVaccineRequirement");
+                        individualVaccineRequirement = 0.0;
+                    }
+                    
+                    //System.out.println( vsReqUsageData +":"+vsReqTargetPopData +":"+vsReqDosesData +":"+vsReqPackedVolData +":"+ vsReqWastageData +":"+ vsReqSupplyIntervalData +":"+ vsReqReserveStockData );
+                   
+                    vaccineRequirement += individualVaccineRequirement;
+                    
+                }
+                
+                vaccineRequirement = Math.round( vaccineRequirement * Math.pow( 10, 1 ) )/ Math.pow( 10, 1 );
+                oneTableDataRow.add( ""+vaccineRequirement );
+                
+                Double diffVaccineReq = vaccineActualValue - vaccineRequirement;
+                diffVaccineReq = Math.round( diffVaccineReq * Math.pow( 10, 1 ) )/ Math.pow( 10, 1 );                
+                oneTableDataRow.add( ""+diffVaccineReq );
+                
+                Double diffPercentage = ( diffVaccineReq / vaccineActualValue ) * 100;
+                if( diffPercentage < -30.0 )
+                {
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "1" );
+                }
+                else if( diffPercentage >= -30.0 && diffPercentage < -10.0 )
+                {
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "1" );
+                    oneTableDataRow.add( "0" );
+                }
+                else if( diffPercentage >= -10.0 && diffPercentage < 10.0 )
+                {
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "1" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                }
+                else if( diffPercentage >= 10.0 && diffPercentage < 30.0 )
+                {
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "1" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                }
+                else
+                {
+                    oneTableDataRow.add( "1" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                    oneTableDataRow.add( "0" );
+                }
+                    
+                tableData.add( oneTableDataRow );
+            }
+            
+            ccemReportOutput.setTableData( tableData );
+            ccemReportOutput.setTableHeadings( tableHeadings );
+            ccemReportOutput.setTableSubHeadings( tableSubHeadings );            
+        }
+
         return SUCCESS;
     }
-    
+
     private String getOrgunitBranch( OrganisationUnit orgunit )
     {
         String hierarchyOrgunit = orgunit.getName();

=== modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/ccemReportOutput.vm'
--- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/ccemReportOutput.vm	2012-06-13 06:35:38 +0000
+++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/ccemReportOutput.vm	2012-06-19 10:18:55 +0000
@@ -29,7 +29,6 @@
 				<th>$tableHeading</th>
 			#end
 		</tr>
-		
 		#foreach( $oneSubHeadingRow in $tableSubHeadings )
 		<tr>
 			#foreach( $oneSubHeadingCellData in $oneSubHeadingRow )
@@ -46,7 +45,7 @@
 			#end
 		</tr>
 		#set( $mark = !$mark)	
-		#end		
+		#end
 	</table>
 </div>