=== 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 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 params ); + + Map calculateStorageCapacityData( DataElement dataElement, Set orgUnits, Set orgUnitGroups ); + + String importData( Map 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 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 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 calculateStorageCapacityData( DataElement dataElement, Set orgUnits, Set orgUnitGroups ) + { + Map aggregationResultMap = new HashMap(); + + /** + * TODO need to get all parameters from lookup + */ + CCEMReport ccemReport = ccemReportManager.getCCEMReportByReportId( "22" ); + Map ccemSettingsMap = new HashMap( ccemReportManager.getCCEMSettings() ); + List reportDesignList = new ArrayList( 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 orgUnitIds = new ArrayList( getIdentifiers( OrganisationUnit.class, orgUnits ) ); + String orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds ); + + Collection orgUnitGroupIds = new ArrayList( getIdentifiers( OrganisationUnitGroup.class, orgUnitGroups ) ); + String orgUnitGroupIdsByComma = getCommaDelimitedString( orgUnitGroupIds ); + + Map equipmentSumByInventoryTypeMap = new HashMap( 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 catalogSumByEquipmentDataMap = new HashMap( 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 catalogIdsForRequirement = new ArrayList( ccemReportManager.getCatalogIdsForRequirement( vsReqCatalogTypeId, vsReqStorageTempId, vsReqStorageTemp, vsReqNationalSupplyId, vsReqNationalSupply ) ); + + // PART 2 - 5 + String dataelementIds = "" + partsOfCellContent[1]; + Integer vsReqLiveBirthDeId = Integer.parseInt( dataelementIds.split( "," )[0] ); + Map dataElementDataForRequirement = new HashMap( 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 orgUnitGroupAttribDataForRequirement = new HashMap( ccemReportManager.getOrgUnitGroupAttribDataForRequirement( orgUnitGroupIdsByComma, orgUnitGroupAttribIds ) ); + + Map orgUnitGroupMap = new HashMap( ccemReportManager.getOrgunitAndOrgUnitGroupMap( orgUnitGroupIdsByComma, orgUnitIdsByComma ) ); + + for ( OrganisationUnit orgUnit : orgUnits ) + { + Map numberOfData = new HashMap(); + + 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 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 = "
Total new records : "+ insertCount; + importStatus = "
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 @@ + + + + + + + + === 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 dataElements = new ArrayList(); + + public List getDataElements() + { + return dataElements; + } + + private String importStatus = ""; + + public String getImportStatus() + { + return importStatus; + } + + // ------------------------------------------------------------------------- + // Action + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + Map aggregationResultMap = new HashMap(); + + Set orgUnitList = new HashSet( selectionTreeManager.getReloadedSelectedOrganisationUnits() ); + + Set orgUnitGroups = new HashSet( organisationUnitGroupService.getAllOrganisationUnitGroups() ); + + List ouGroups = new ArrayList( 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 conditions = new HashSet( 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"> - - + + + + + + + + + + + + + + + + + + + \ 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 @@ /content.vm /dhis-web-maintenance-ccem/addAggregationParam.vm + + + aggregationQueryList.action + + + + /main.vm + /dhis-web-maintenance-ccem/runAggregationQueryForm.vm + /dhis-web-maintenance-ccem/menu.vm + + + + /main.vm + /dhis-web-maintenance-ccem/runAggregationQueryResult.vm + /dhis-web-maintenance-ccem/menu.vm + + \ 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 @@ === 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 @@

$i18n.getString( "aggregation_builder" )

$i18n.getString( "transfer" )

=== 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 @@ +

$i18n.getString( "manual_aggregation" )

+ +

$encoder.htmlEncode( $dataSet.displayName )

+ +
+ + + + + + + + +
+ #organisationUnitSelectionTree( false, true, false ) +
+ +
+ +