← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13475: CCEI: work in progress Aggregation Engine

 

------------------------------------------------------------
revno: 13475
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-30 04:45:24 +0000
message:
  CCEI: work in progress Aggregation Engine
removed:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/AggregationService.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultAggregationService.java
added:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/CCEIAggregationService.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultCCEIAggregationService.java
  local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/RunAggregationQueryAction.java
  local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/runAggregationQueryForm.vm
modified:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/lookup/Lookup.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/AddAggregationQueryAction.java
  local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-maintenance-ccem/src/main/resources/struts.xml
  local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/addAggregationQuery.vm
  local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/menu.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
=== removed file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/AggregationService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/AggregationService.java	2013-12-27 12:29:39 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/AggregationService.java	1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
-package org.hisp.dhis.coldchain.aggregation;
-
-import java.util.Map;
-
-public interface AggregationService
-{
-    String ID = AggregationService.class.getName();  
-    
-    String getQueryTemplate(String lookupName, Map<String,String> params);
-}

=== added file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/CCEIAggregationService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/CCEIAggregationService.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/aggregation/CCEIAggregationService.java	2013-12-30 04:45:24 +0000
@@ -0,0 +1,21 @@
+package org.hisp.dhis.coldchain.aggregation;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.period.Period;
+
+public interface CCEIAggregationService
+{
+    String ID = CCEIAggregationService.class.getName();  
+    
+    String getQueryTemplate( String lookupName, Map<String,String> params );
+    
+    Map<String, Integer> calculateStorageCapacityData( DataElement dataElement, Set<OrganisationUnit> orgUnits, Set<OrganisationUnitGroup> orgUnitGroups );
+    
+    String importData( Map<String, Integer> aggregationResultMap, Period period );
+    
+}

=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/lookup/Lookup.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/lookup/Lookup.java	2013-12-27 12:29:39 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/lookup/Lookup.java	2013-12-30 04:45:24 +0000
@@ -12,6 +12,8 @@
     
     public static final String WS_REF_TYPE = "WS_REF_TYPE";
     
+    public static final String CCEI_AGG_TYPE_STORAGE_CAPACITY = "STORAGE CAPACITY";
+    
     private String type;
     
     private String value;

=== removed file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultAggregationService.java'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultAggregationService.java	2013-12-27 12:30:44 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultAggregationService.java	1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-package org.hisp.dhis.coldchain.aggregation;
-
-import java.util.Map;
-
-import org.hisp.dhis.lookup.Lookup;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class DefaultAggregationService implements AggregationService
-{
-	// -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-	
-	@Override
-	public String getQueryTemplate(String lookupName, Map<String,String> params) {
-		String tempQuery = null;
-		if(lookupName.equalsIgnoreCase(Lookup.WS_REF_TYPE))
-		{
-			String equipmenttypeid = params.get("equipmenttypeid");
-			String modelName = params.get("modelName");
-			String equipmentattributevalue = params.get("equipmentattributevalue");
-			tempQuery = "SELECT COUNT(*) FROM modelattributevalue "+
-						"INNER JOIN equipment ON modelattributevalue.modelid = equipment.modelid "+
-						"INNER JOIN equipmentattributevalue ON equipmentattributevalue.equipmentid = equipment.equipmentid"+
-						" WHERE " +
-                        " equipment.equipmenttypeid = "+equipmenttypeid+" AND " +
-                        " modelattributevalue.value = "+modelName+" AND " +
-                        " equipment.organisationunitid IN ( ? ) AND "+
-                        " equipmentattributevalue.value IN ( "+equipmentattributevalue+" )"+
-                        " GROUP BY modelattributevalue.value";					
-		}
-		return tempQuery;
-	}
-
-    
-
-  
-}

=== added file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultCCEIAggregationService.java'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultCCEIAggregationService.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/aggregation/DefaultCCEIAggregationService.java	2013-12-30 04:45:24 +0000
@@ -0,0 +1,374 @@
+package org.hisp.dhis.coldchain.aggregation;
+
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hisp.dhis.coldchain.reports.CCEMReport;
+import org.hisp.dhis.coldchain.reports.CCEMReportDesign;
+import org.hisp.dhis.coldchain.reports.CCEMReportManager;
+import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.constant.ConstantService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.lookup.Lookup;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.user.CurrentUserService;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DefaultCCEIAggregationService implements CCEIAggregationService
+{
+	// -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    private CCEMReportManager ccemReportManager;
+
+    public void setCcemReportManager( CCEMReportManager ccemReportManager )
+    {
+        this.ccemReportManager = ccemReportManager;
+    }
+
+    private ConstantService constantService;
+
+    public void setConstantService( ConstantService constantService )
+    {
+        this.constantService = constantService;
+    }
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+	// -------------------------------------------------------------------------
+    // 
+    // -------------------------------------------------------------------------    
+	@Override
+	public String getQueryTemplate(String lookupName, Map<String,String> params) 
+	{
+		String tempQuery = null;
+		
+		if(lookupName.equalsIgnoreCase(Lookup.WS_REF_TYPE))
+		{
+			String equipmenttypeid = params.get("equipmenttypeid");
+			String modelName = params.get("modelName");
+			String equipmentattributevalue = params.get("equipmentattributevalue");
+			tempQuery = "SELECT COUNT(*) FROM modelattributevalue "+
+						"INNER JOIN equipment ON modelattributevalue.modelid = equipment.modelid "+
+						"INNER JOIN equipmentattributevalue ON equipmentattributevalue.equipmentid = equipment.equipmentid"+
+						" WHERE " +
+                        " equipment.equipmenttypeid = "+equipmenttypeid+" AND " +
+                        " modelattributevalue.value = "+modelName+" AND " +
+                        " equipment.organisationunitid IN ( ? ) AND "+
+                        " equipmentattributevalue.value IN ( "+equipmentattributevalue+" )"+
+                        " GROUP BY modelattributevalue.value";					
+		}
+		
+		return tempQuery;
+	}
+
+    
+	public Map<String, Integer> calculateStorageCapacityData( DataElement dataElement, Set<OrganisationUnit> orgUnits, Set<OrganisationUnitGroup> orgUnitGroups )
+	{
+		Map<String, Integer> aggregationResultMap = new HashMap<String, Integer>();
+
+		/**
+		 * TODO need to get all parameters from lookup
+		 */
+		CCEMReport ccemReport = ccemReportManager.getCCEMReportByReportId( "22" );
+		Map<String, String> ccemSettingsMap = new HashMap<String, String>( ccemReportManager.getCCEMSettings() );
+        List<CCEMReportDesign> reportDesignList = new ArrayList<CCEMReportDesign>( ccemReportManager.getCCEMReportDesign( ccemReport.getXmlTemplateName() ) );
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime( new Date() );
+        String periodStartDate = "";
+        String periodEndDate = "";
+        Integer periodId = ccemReportManager.getPeriodId( periodStartDate, "Yearly" );
+
+        CCEMReportDesign ccemReportDesign1 = reportDesignList.get( 0 );
+        String 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] );
+        
+        Collection<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, orgUnits ) );
+        String orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+
+        Collection<Integer> orgUnitGroupIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnitGroup.class, orgUnitGroups ) );
+        String orgUnitGroupIdsByComma = getCommaDelimitedString( orgUnitGroupIds );
+
+        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( "--" );
+
+        // PART 1 - 4:47:+4C:48:Yes
+        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];
+
+        List<Integer> catalogIdsForRequirement = new ArrayList<Integer>( ccemReportManager.getCatalogIdsForRequirement( vsReqCatalogTypeId, vsReqStorageTempId, vsReqStorageTemp, vsReqNationalSupplyId, vsReqNationalSupply ) );
+
+        // PART 2 - 5
+        String dataelementIds = "" + partsOfCellContent[1];
+        Integer vsReqLiveBirthDeId = Integer.parseInt( dataelementIds.split( "," )[0] );
+        Map<String, String> dataElementDataForRequirement = new HashMap<String, String>( ccemReportManager.getDataElementDataForCatalogOptionsForRequirement( orgUnitIdsByComma, dataelementIds, periodId ) );
+
+        // PART 3 - VaccineVolumePerChild
+        String vvpcConstantName = "" + partsOfCellContent[2];
+        Constant constant = constantService.getConstantByName( vvpcConstantName );
+        Double vsReqVaccineVolumePerChildData = constant.getValue();
+
+        // PART 4 - 3,4
+        String orgUnitGroupAttribIds = partsOfCellContent[3];
+        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 : orgUnits )
+        {
+            Map<String, String> numberOfData = new HashMap<String, String>();
+
+            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 );
+            numberOfData.put( "Actual", vaccineActualValue + "" );
+
+            // Calculation for Requirement Column
+            String tempStr = null;
+            Double vaccineRequirement = 0.0;
+            Double vsReqLiveBirthData = 0.0;
+            tempStr = dataElementDataForRequirement.get( vsReqLiveBirthDeId + ":" + periodId + ":" + orgUnit.getId() );
+            if ( tempStr != null )
+            {
+                try
+                {
+                    vsReqLiveBirthData = Double.parseDouble( tempStr );
+                }
+                catch ( Exception e )
+                {
+                    vsReqLiveBirthData = 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;
+                }
+            }
+
+            System.out.println( vsReqLiveBirthData + " : " + vsReqVaccineVolumePerChildData + " : " + vsReqSupplyIntervalData + " : " + vsReqReserveStockData );
+            // Formula for calculating Requirement 
+            try
+            {
+            	vaccineRequirement = vsReqLiveBirthData * vsReqVaccineVolumePerChildData * ( (vsReqSupplyIntervalData + vsReqReserveStockData) / 52);
+            }
+            catch ( Exception e )
+            {
+                System.out.println( "Exception while calculating individualVaccineRequirement" );
+                vaccineRequirement = 0.0;
+            }
+
+            vaccineRequirement = Math.round( vaccineRequirement * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+            numberOfData.put( "Required", vaccineRequirement + "" );
+
+            Double diffVaccineReq = vaccineActualValue - vaccineRequirement;
+            diffVaccineReq = Math.round( diffVaccineReq * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+            numberOfData.put( "Difference", "" + diffVaccineReq );
+
+            Double diffPercentage = 0.0;
+            if( vaccineActualValue == 0 && diffVaccineReq == 0 )
+            {
+            	diffPercentage = 0.0;
+            }
+            else
+            {
+            	diffPercentage = (diffVaccineReq / vaccineActualValue) * 100;
+            }
+            
+            if ( diffPercentage < -30.0 )
+            {
+            	aggregationResultMap.put( orgUnit.getId() + ":" + dataElement.getId(), 1 );
+            }
+            else if ( diffPercentage >= -30.0 && diffPercentage < -10.0 )
+            {
+            	aggregationResultMap.put( orgUnit.getId() + ":" + dataElement.getId(), 1 );
+            }
+            else if ( diffPercentage >= -10.0 && diffPercentage < 10.0 )
+            {
+            }
+            else if ( diffPercentage >= 10.0 && diffPercentage < 30.0 )
+            {
+            }
+            else
+            {
+            }
+        }
+
+		return aggregationResultMap;
+	}
+ 
+	
+    public String importData( Map<String, Integer> aggregationResultMap, Period period )
+    {
+    	String importStatus = "";
+    			
+        Integer updateCount = 0;
+        Integer insertCount = 0;
+
+        String storedBy = currentUserService.getCurrentUsername();
+        if ( storedBy == null )
+        {
+            storedBy = "[unknown]";
+        }
+
+        long t;
+        Date d = new Date();
+        t = d.getTime();
+        java.sql.Date lastUpdatedDate = new java.sql.Date( t );
+
+        String query = "";
+        int insertFlag = 1;
+        String insertQuery = "INSERT IGNORE INTO datavalue ( dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
+        
+        try
+        {
+	        int count = 1;
+	        for ( String cellKey : aggregationResultMap.keySet() )
+	        {
+	            // Orgunit
+	            String[] oneRow = cellKey.split( ":" );
+	            Integer orgUnitId = Integer.parseInt( oneRow[0] );
+	            Integer deId = Integer.parseInt( oneRow[1] );
+	            Integer deCOCId = 1;
+	            Integer periodId = period.getId();
+	            String value = aggregationResultMap.get( cellKey )+"";
+	        
+	            query = "SELECT value FROM datavalue WHERE dataelementid = " + deId + " AND categoryoptioncomboid = " + deCOCId + " AND periodid = " + periodId + " AND sourceid = " + orgUnitId;
+	    		SqlRowSet sqlResultSet1 = jdbcTemplate.queryForRowSet( query );
+	    		if ( sqlResultSet1 != null && sqlResultSet1.next() )
+	    		{
+	    		    String updateQuery = "UPDATE datavalue SET value = '" + value + "', storedby = '" + storedBy
+	    						+ "',lastupdated='" + lastUpdatedDate + "' WHERE dataelementid = " + deId
+	    						+ " AND periodid = " + periodId + " AND sourceid = " + orgUnitId
+	    						+ " AND categoryoptioncomboid = " + deCOCId;		    
+	    		  
+	    		    jdbcTemplate.update( updateQuery );
+	    		    updateCount++;
+	    		}
+	    		else
+	    		{
+	                if( value != null && !value.trim().equals( "" ) ) 
+	                {
+	        			insertQuery += "( " + deId + ", " + periodId + ", " + orgUnitId + ", " + deCOCId + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "'), ";
+	        		    insertFlag = 2;
+	        		    insertCount++;
+	                }
+	    		}
+	            
+	            if ( count == 1000 )
+	            {
+	                count = 1;
+	
+	                if ( insertFlag != 1 )
+	                {
+	                    insertQuery = insertQuery.substring( 0, insertQuery.length() - 2 );
+	                    jdbcTemplate.update( insertQuery );
+	                }
+	
+	                insertFlag = 1;
+	
+	                insertQuery = "INSERT IGNORE INTO datavalue ( dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
+	            }
+	
+	            count++;
+	        }
+	
+	        if ( insertFlag != 1 )
+	        {
+	            insertQuery = insertQuery.substring( 0, insertQuery.length() - 2 );
+	            jdbcTemplate.update( insertQuery );
+	        }
+
+	        importStatus = "Successfully populated aggregated data for the period : " + period.getStartDateString();
+	        importStatus = "<br/> Total new records : "+ insertCount;
+	        importStatus = "<br/> Total updated records : "+ updateCount;
+
+        }
+        catch( Exception e )
+        {
+        	importStatus = "Exception occured while import, please check log for more details" + e.getMessage();
+        }
+        
+        
+        return importStatus;
+    }
+
+}

=== modified file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/META-INF/dhis/beans.xml	2013-12-23 12:24:45 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/META-INF/dhis/beans.xml	2013-12-30 04:45:24 +0000
@@ -97,6 +97,15 @@
     </bean>		
 
 	<!-- Service definitions -->
+	<bean id="org.hisp.dhis.coldchain.aggregation.CCEIAggregationService"
+        class="org.hisp.dhis.coldchain.aggregation.DefaultCCEIAggregationService">
+		<property name="ccemReportManager" ref="org.hisp.dhis.coldchain.reports.CCEMReportManager" />
+		<property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
+		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
+		<property name="jdbcTemplate" ref="jdbcTemplate"/>
+    </bean>
+	
+	
 	<bean id="org.hisp.dhis.coldchain.model.ModelTypeAttributeOptionService"
         class="org.hisp.dhis.coldchain.model.DefaultModelTypeAttributeOptionService">
         <property name="modelTypeAttributeOptionStore" ref="org.hisp.dhis.coldchain.model.ModelTypeAttributeOptionStore"/>

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/AddAggregationQueryAction.java'
--- local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/AddAggregationQueryAction.java	2013-12-26 10:29:48 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/AddAggregationQueryAction.java	2013-12-30 04:45:24 +0000
@@ -1,7 +1,13 @@
 package org.hisp.dhis.ccem.aggregation.action;
 
+import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
 import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
+import org.hisp.dhis.coldchain.aggregation.CCEIAggregationService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.lookup.Lookup;
+import org.hisp.dhis.lookup.LookupService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -25,18 +31,70 @@
 		this.dataElementService = dataElementService;
 	}
     
+    private LookupService lookupService;
+    
+    public void setLookupService(LookupService lookupService) 
+    {
+		this.lookupService = lookupService;
+	}
+    
+    private CCEIAggregationService cceiAggregationService;
+    
+	public void setCceiAggregationService( CCEIAggregationService cceiAggregationService) 
+	{
+		this.cceiAggregationService = cceiAggregationService;
+	}
+    
+	private DataElementCategoryService dataElementCategoryService;
+	
+	public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService) 
+	{
+		this.dataElementCategoryService = dataElementCategoryService;
+	}
+	
     // -------------------------------------------------------------------------
     // Input/ Output
     // -------------------------------------------------------------------------
 
-    // -------------------------------------------------------------------------
+	private String name;
+    
+    private String aggType;
+    
+    private Integer dataElementId;
+    
+    public void setName(String name) 
+    {
+		this.name = name;
+	}
+
+	public void setAggType(String aggType) 
+	{
+		this.aggType = aggType;
+	}
+
+	public void setDataElementId(Integer dataElementId) 
+	{
+		this.dataElementId = dataElementId;
+	}
+
+	// -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 	public String execute()
         throws Exception
     {
-    	//aggregationConditionService.addCaseAggregationCondition(arg0);
-        
+		DataElement dataElement = dataElementService.getDataElement( dataElementId );
+		
+		/**
+		 * TODO support for category option combo
+		 */
+		if( aggType.equals( Lookup.CCEI_AGG_TYPE_STORAGE_CAPACITY ) )
+		{
+			CaseAggregationCondition condition = new CaseAggregationCondition( name, aggType, "NONE", dataElement, dataElementCategoryService.getDefaultDataElementCategoryOptionCombo() );
+			
+			aggregationConditionService.addCaseAggregationCondition( condition );
+		}
+
         return SUCCESS;
     }
 

=== added file 'local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/RunAggregationQueryAction.java'
--- local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/RunAggregationQueryAction.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/aggregation/action/RunAggregationQueryAction.java	2013-12-30 04:45:24 +0000
@@ -0,0 +1,138 @@
+package org.hisp.dhis.ccem.aggregation.action;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
+import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
+import org.hisp.dhis.coldchain.aggregation.CCEIAggregationService;
+import org.hisp.dhis.coldchain.equipment.EquipmentAttributeValue;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.lookup.Lookup;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+
+import com.opensymphony.xwork2.Action;
+
+public class RunAggregationQueryAction implements Action 
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SelectionTreeManager selectionTreeManager;
+
+    public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+    {
+        this.selectionTreeManager = selectionTreeManager;
+    }
+
+    private OrganisationUnitService organisationUnitService;
+    
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    private CaseAggregationConditionService aggregationConditionService;
+
+    public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
+    {
+        this.aggregationConditionService = aggregationConditionService;
+    }
+
+    private CCEIAggregationService cceiAggregationService;
+    
+    public void setCceiAggregationService( CCEIAggregationService cceiAggregationService) 
+    {
+		this.cceiAggregationService = cceiAggregationService;
+	}
+    
+    private PeriodService periodService;
+    
+    public void setPeriodService(PeriodService periodService) 
+    {
+		this.periodService = periodService;
+	}
+
+	// -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+	private List<DataElement> dataElements = new ArrayList<DataElement>();
+    
+    public List<DataElement> getDataElements() 
+    {
+		return dataElements;
+	}
+
+    private String importStatus = "";
+    
+	public String getImportStatus() 
+	{
+		return importStatus;
+	}
+    
+    // -------------------------------------------------------------------------
+    // Action
+    // -------------------------------------------------------------------------
+
+	public String execute()
+        throws Exception
+    {
+		Map<String, Integer> aggregationResultMap = new HashMap<String, Integer>();
+		
+		Set<OrganisationUnit> orgUnitList = new HashSet<OrganisationUnit>( selectionTreeManager.getReloadedSelectedOrganisationUnits() );
+
+    	Set<OrganisationUnitGroup> orgUnitGroups = new HashSet<OrganisationUnitGroup>( organisationUnitGroupService.getAllOrganisationUnitGroups() );
+    	
+    	List<OrganisationUnitGroup> ouGroups = new ArrayList<OrganisationUnitGroup>( organisationUnitGroupService.getOrganisationUnitGroupByName( EquipmentAttributeValue.HEALTHFACILITY ) ); 
+        
+    	OrganisationUnitGroup ouGroup = ouGroups.get( 0 );				
+       
+        if ( ouGroup != null )
+        {
+            orgUnitList.retainAll( ouGroup.getMembers() );
+        }
+        
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyyMM");
+        String curMonth = simpleDateFormat.format( new Date() );
+        Period period = PeriodType.getPeriodFromIsoString( curMonth );
+        period = periodService.reloadPeriod( period );
+        
+        Set<CaseAggregationCondition> conditions = new HashSet<CaseAggregationCondition>( aggregationConditionService.getAllCaseAggregationCondition() );
+        for( CaseAggregationCondition condition : conditions )
+        {
+        	DataElement dataElement = condition.getAggregationDataElement();
+        	if( condition.getOperator().equals( Lookup.CCEI_AGG_TYPE_STORAGE_CAPACITY) )
+        	{
+        		aggregationResultMap.putAll( cceiAggregationService.calculateStorageCapacityData( dataElement, orgUnitList, orgUnitGroups ) );
+        	}
+        	
+        	dataElements.add( dataElement );
+        }
+        
+        importStatus = cceiAggregationService.importData(aggregationResultMap, period);
+        
+        return SUCCESS;
+    }
+
+}

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml	2013-12-27 12:32:48 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml	2013-12-30 04:45:24 +0000
@@ -739,13 +739,24 @@
         class="org.hisp.dhis.ccem.aggregation.action.AggregationQueryListAction"
         scope="prototype">
         <property name="aggregationConditionService" ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
-    </bean>   
-     <bean id="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryFormAction"
+    </bean>
+    
+    <bean id="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryFormAction"
         class="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryFormAction"
         scope="prototype">
         <property name="lookupService" ref="org.hisp.dhis.lookup.LookupService" />
         <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
     </bean> 
+
+    <bean id="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryAction"
+        class="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryAction"
+        scope="prototype">
+        <property name="lookupService" ref="org.hisp.dhis.lookup.LookupService" />
+        <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+        <property name="aggregationConditionService" ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
+        <property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+        <property name="cceiAggregationService" ref="org.hisp.dhis.coldchain.aggregation.CCEIAggregationService" />
+    </bean> 
       
 	<bean id="org.hisp.dhis.ccem.aggregation.action.GetAggregationParameterAction"
         class="org.hisp.dhis.ccem.aggregation.action.GetAggregationParameterAction"
@@ -755,5 +766,16 @@
         <property name="modelTypeAttributeService" ref="org.hisp.dhis.coldchain.model.ModelTypeAttributeService" />
         <property name="modelAttributeValueService" ref="org.hisp.dhis.coldchain.model.ModelAttributeValueService" />
     </bean>
+
+	<bean id="org.hisp.dhis.ccem.aggregation.action.RunAggregationQueryAction"
+        class="org.hisp.dhis.ccem.aggregation.action.RunAggregationQueryAction"
+        scope="prototype">
+        <property name="aggregationConditionService" ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
+        <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+        <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+        <property name="cceiAggregationService" ref="org.hisp.dhis.coldchain.aggregation.CCEIAggregationService" />
+        <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
+        <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+    </bean>
     
 </beans>
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/resources/struts.xml'
--- local/in/dhis-web-maintenance-ccem/src/main/resources/struts.xml	2013-12-27 12:32:48 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/resources/struts.xml	2013-12-30 04:45:24 +0000
@@ -684,5 +684,22 @@
         <result name="success" type="velocity">/content.vm</result>
         <param name="page">/dhis-web-maintenance-ccem/addAggregationParam.vm</param>            
     </action>
+
+    <action name="addAggregationQuery" class="org.hisp.dhis.ccem.aggregation.action.AddAggregationQueryAction">
+        <result name="success" type="redirect">aggregationQueryList.action</result>
+    </action>
+
+    <action name="runAggregationQueryForm" class="org.hisp.dhis.ccem.action.NoAction">
+        <result name="success" type="velocity">/main.vm</result>
+        <param name="page">/dhis-web-maintenance-ccem/runAggregationQueryForm.vm</param>
+        <param name="menu">/dhis-web-maintenance-ccem/menu.vm</param>
+    </action>
+
+    <action name="runAggregationQuery" class="org.hisp.dhis.ccem.aggregation.action.RunAggregationQueryAction">
+        <result name="success" type="velocity">/main.vm</result>
+        <param name="page">/dhis-web-maintenance-ccem/runAggregationQueryResult.vm</param>
+        <param name="menu">/dhis-web-maintenance-ccem/menu.vm</param>
+    </action>
+
 </package>
 </struts>
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/addAggregationQuery.vm'
--- local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/addAggregationQuery.vm	2013-12-27 12:32:48 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/addAggregationQuery.vm	2013-12-30 04:45:24 +0000
@@ -42,7 +42,7 @@
 				<select style='width:100%; margin-bottom:-5px;' id="aggType" name="aggType" onchange="getParameters()">
                     <option value="-1" >Please Select</option>
 					#foreach( $lookup in $lookups )
-						<option value="$lookup.id">$lookup.value</option>
+						<option value="$lookup.value">$lookup.value</option>
 					#end
 				</select>
 			</td>

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/menu.vm'
--- local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/menu.vm	2013-12-24 12:32:37 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/menu.vm	2013-12-30 04:45:24 +0000
@@ -11,6 +11,7 @@
 <h2>$i18n.getString( "aggregation_builder" )</h2>
 <ul>
     <li><a href="aggregationQueryList.action">$i18n.getString( "aggregation_query_list" )</a></li>
+	<li><a href="runAggregationQueryForm.action">$i18n.getString( "manual_aggregation" )</a></li>
 </ul>
 
 <h2>$i18n.getString( "transfer" )</h2>

=== added file 'local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/runAggregationQueryForm.vm'
--- local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/runAggregationQueryForm.vm	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/webapp/dhis-web-maintenance-ccem/runAggregationQueryForm.vm	2013-12-30 04:45:24 +0000
@@ -0,0 +1,20 @@
+<h3>$i18n.getString( "manual_aggregation" )</h3>
+
+<h4>$encoder.htmlEncode( $dataSet.displayName )</h4>
+
+<form id="runAggregationQueryForm" action="runAggregationQuery.action" method="post">
+  
+  <table id="selectionTable">
+	<tr>
+	  <td>
+		#organisationUnitSelectionTree( false, true, false )
+	  </td>
+    </tr>
+    <tr>
+      <td>
+        <input type="submit" id="submitButton" value="$i18n.getString( 'aggregate_values' )" style="width:10em"/>
+	  </td>
+    </tr>
+  </table>
+
+</form>