=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java 2012-10-10 08:50:17 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java 2013-01-03 06:54:08 +0000 @@ -36,10 +36,7 @@ */ public interface CaseAggregateConditionSchedulingManager { - final String TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTHS = "aggregateLast12MonthsTask"; - final String TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTS = "aggregateLast6MonthsTask"; - final String TASK_AGGREGATE_QUERY_BUILDER_FROM_6_TO_12_MONTS = "aggregateFrom6To12MonthsTask"; - + final String TASK_AGGREGATE_QUERY_BUILDER = "aggregateQueryBuilder"; void scheduleTasks(); void scheduleTasks( Map keyCronMap ); === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java 2012-11-16 03:50:03 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java 2013-01-03 06:54:08 +0000 @@ -27,13 +27,8 @@ package org.hisp.dhis.patient.scheduling; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; import org.hisp.dhis.caseaggregation.CaseAggregationCondition; import org.hisp.dhis.caseaggregation.CaseAggregationConditionService; @@ -47,8 +42,8 @@ import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.CalendarPeriodType; import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.RelativePeriods; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.rowset.SqlRowSet; @@ -77,24 +72,6 @@ private DataSetService dataSetService; // ------------------------------------------------------------------------- - // Params - // ------------------------------------------------------------------------- - - private boolean last6Months; - - public void setLast6Months( boolean last6Months ) - { - this.last6Months = last6Months; - } - - private boolean last6To12Months; - - public void setLast6To12Months( boolean last6To12Months ) - { - this.last6To12Months = last6To12Months; - } - - // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -121,54 +98,46 @@ { Collection orgunits = organisationUnitService.getAllOrganisationUnits(); - // --------------------------------------------------------------------- - // Get Period list in system-setting - // --------------------------------------------------------------------- - Collection dataSets = dataSetService.getAllDataSets(); for ( DataSet dataSet : dataSets ) { - String periodType = dataSet.getPeriodType().getName(); - List periods = getPeriods( periodType ); - - String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid " - + "from caseaggregationcondition cagg inner join datasetmembers dm " - + "on cagg.aggregationdataelementid=dm.dataelementid " + "inner join dataset ds " - + "on ds.datasetid = dm.datasetid " + "inner join periodtype pt " - + "on pt.periodtypeid=ds.periodtypeid " + "where ds.datasetid = " + dataSet.getId(); - - SqlRowSet rs = jdbcTemplate.queryForRowSet( sql ); - - while ( rs.next() ) + Period period = getPeriod( dataSet.getPeriodType().getName() ); + + if ( period != null ) { - // ------------------------------------------------------------- - // Get formula, agg-dataelement and option-combo - // ------------------------------------------------------------- - - int dataelementId = rs.getInt( "aggregationdataelementid" ); - int optionComboId = rs.getInt( "optioncomboid" ); - - DataElement dElement = dataElementService.getDataElement( dataelementId ); - DataElementCategoryOptionCombo optionCombo = categoryService - .getDataElementCategoryOptionCombo( optionComboId ); - - CaseAggregationCondition aggCondition = aggregationConditionService.getCaseAggregationCondition( rs - .getInt( "caseaggregationconditionid" ) ); - - // --------------------------------------------------------------------- - // Aggregation - // --------------------------------------------------------------------- - - for ( OrganisationUnit orgUnit : orgunits ) + String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid " + + "from caseaggregationcondition cagg inner join datasetmembers dm " + + "on cagg.aggregationdataelementid=dm.dataelementid " + "inner join dataset ds " + + "on ds.datasetid = dm.datasetid " + "inner join periodtype pt " + + "on pt.periodtypeid=ds.periodtypeid " + "where ds.datasetid = " + dataSet.getId(); + + SqlRowSet rs = jdbcTemplate.queryForRowSet( sql ); + + while ( rs.next() ) { - for ( Period period : periods ) + // ------------------------------------------------------------- + // Get formula, agg-dataelement and option-combo + // ------------------------------------------------------------- + + int dataelementId = rs.getInt( "aggregationdataelementid" ); + int optionComboId = rs.getInt( "optioncomboid" ); + + DataElement dElement = dataElementService.getDataElement( dataelementId ); + DataElementCategoryOptionCombo optionCombo = categoryService + .getDataElementCategoryOptionCombo( optionComboId ); + + CaseAggregationCondition aggCondition = aggregationConditionService.getCaseAggregationCondition( rs + .getInt( "caseaggregationconditionid" ) ); + + // --------------------------------------------------------------------- + // Aggregation + // --------------------------------------------------------------------- + + for ( OrganisationUnit orgUnit : orgunits ) { DataValue dataValue = dataValueService.getDataValue( orgUnit, dElement, period, optionCombo ); - if ( dataValue != null && dataValue.getStoredBy().equals( STORED_BY_DHIS_SYSTEM ) ) - continue; - Integer resultValue = aggregationConditionService.parseConditition( aggCondition, orgUnit, period ); @@ -183,6 +152,7 @@ null, optionCombo ); dataValueService.addDataValue( dataValue ); } + // ----------------------------------------------------- // Update dataValue // ----------------------------------------------------- @@ -216,33 +186,14 @@ // Supportive methods // ------------------------------------------------------------------------- - private List getPeriods( String periodType ) + private Period getPeriod( String periodTypeName ) { - Set periodTypes = new HashSet(); - periodTypes.add( periodType ); - - List relatives = new ArrayList(); - - if ( last6Months ) - { - relatives.addAll( new RelativePeriods().getLast6Months( periodTypes ) ); - } - - if ( last6To12Months ) - { - relatives.addAll( new RelativePeriods().getLast6To12Months( periodTypes ) ); - } - - Iterator iter = relatives.iterator(); - Date currentDate = new Date(); - while ( iter.hasNext() ) - { - if ( currentDate.before( iter.next().getEndDate() ) ) - { - iter.remove(); - } - } - return relatives; + Date date = new Date(); + + CalendarPeriodType periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName( periodTypeName ); + + Period period = periodType.createPeriod( date ); + + return (period.getEndDate().equals( date ) || period.getEndDate().before( date )) ? period : null; } - } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-12-21 09:23:20 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-01-03 06:54:08 +0000 @@ -444,9 +444,7 @@ - - - + @@ -462,20 +460,8 @@ - - - - - - - - - - - + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java 2012-11-16 03:50:03 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java 2013-01-03 06:54:08 +0000 @@ -43,10 +43,6 @@ public class ScheduleCaseAggregateConditionAction implements Action { - private static final String STRATEGY_LAST_12_DAILY = "last12Daily"; - - private static final String STRATEGY_LAST_6_DAILY_6_TO_12_WEEKLY = "last6Daily6To12Weekly"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -68,13 +64,6 @@ { this.execute = execute; } - - private String aggQueryBuilderStrategy; - - public void setAggQueryBuilderStrategy( String aggQueryBuilderStrategy ) - { - this.aggQueryBuilderStrategy = aggQueryBuilderStrategy; - } // ------------------------------------------------------------------------- // Output @@ -107,7 +96,7 @@ schedulingManager.executeTasks(); } else - { + { if ( Scheduler.STATUS_RUNNING.equals( schedulingManager.getTaskStatus() ) ) { schedulingManager.stopTasks(); @@ -116,20 +105,8 @@ { Map keyCronMap = new HashMap(); - if ( STRATEGY_LAST_12_DAILY.equals( aggQueryBuilderStrategy ) ) - { - keyCronMap.put( - CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTHS, - Scheduler.CRON_DAILY_0AM ); - } - else if ( STRATEGY_LAST_6_DAILY_6_TO_12_WEEKLY.equals( aggQueryBuilderStrategy ) ) - { - keyCronMap.put( CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTS, - Scheduler.CRON_DAILY_0AM_EXCEPT_SUNDAY ); - keyCronMap.put( - CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_FROM_6_TO_12_MONTS, - Scheduler.CRON_WEEKLY_SUNDAY_0AM ); - } + keyCronMap.put( CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER, + Scheduler.CRON_DAILY_0AM ); schedulingManager.scheduleTasks( keyCronMap ); } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js 2012-11-16 03:50:03 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js 2013-01-03 06:54:08 +0000 @@ -46,8 +46,7 @@ function schedulingAggCondTasks() { $.post( 'scheduleCaseAggTasks.action',{ - execute:false, - aggQueryBuilderStrategy:getFieldValue("aggQueryBuilderStrategy") + execute:false }, function( json ){ var status = json.scheduleTasks.status; if( status=='not_started' ){ @@ -72,8 +71,7 @@ if ( ok ) { $.post( 'scheduleCaseAggTasks.action',{ - execute:true, - aggQueryBuilderStrategy:getFieldValue("aggQueryBuilderStrategy") + execute:true },function( json ){ setMessage(i18n_execute_success); }); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm 2012-11-16 03:50:03 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm 2013-01-03 06:54:08 +0000 @@ -17,26 +17,7 @@ - - - - - - - - - - - - - - - +
$i18n.getString( "aggregate_task_strategy" )
- -