=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2012-04-03 22:10:58 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2013-03-09 15:25:42 +0000 @@ -73,6 +73,9 @@ final String KEY_PHONE_NUMBER_AREA_CODE = "phoneNumberAreaCode"; final String KEY_MULTI_ORGANISATION_UNIT_FORMS = "multiOrganisationUnitForms"; final String KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASKS = "scheduleAggregateQueryBuilder"; + final String KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "scheduleAggregateQueryBuilderTackStrategy"; + final String DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "lastMonth"; + final String KEY_CONFIGURATION = "keyConfig"; final String KEY_ACCOUNT_RECOVERY = "keyAccountRecovery"; === 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 2013-01-03 06:54:08 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java 2013-03-09 15:25:42 +0000 @@ -37,6 +37,11 @@ public interface CaseAggregateConditionSchedulingManager { final String TASK_AGGREGATE_QUERY_BUILDER = "aggregateQueryBuilder"; + final String TASK_AGGREGATE_QUERY_BUILDER_LAST_MONTH = "lastMonth"; + final String TASK_AGGREGATE_QUERY_BUILDER_LAST_3_MONTH = "last3Month"; + final String TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTH = "last6Month"; + final String TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTH = "last12Month"; + 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 2013-03-07 14:25:42 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java 2013-03-09 15:25:42 +0000 @@ -27,9 +27,18 @@ package org.hisp.dhis.patient.scheduling; +import static org.hisp.dhis.patient.scheduling.CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTH; +import static org.hisp.dhis.patient.scheduling.CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_3_MONTH; +import static org.hisp.dhis.patient.scheduling.CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTH; +import static org.hisp.dhis.patient.scheduling.CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_MONTH; +import static org.hisp.dhis.setting.SystemSettingManager.DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY; +import static org.hisp.dhis.setting.SystemSettingManager.KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY; + +import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Date; +import java.util.List; import org.hisp.dhis.caseaggregation.CaseAggregationCondition; import org.hisp.dhis.caseaggregation.CaseAggregationConditionService; @@ -43,6 +52,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.CalendarPeriodType; import org.hisp.dhis.period.Period; +import org.hisp.dhis.setting.SystemSettingManager; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.rowset.SqlRowSet; @@ -68,13 +78,16 @@ private DataElementCategoryService categoryService; + private SystemSettingManager systemSettingManager; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- public CaseAggregateConditionTask( OrganisationUnitService organisationUnitService, CaseAggregationConditionService aggregationConditionService, DataValueService dataValueService, - JdbcTemplate jdbcTemplate, DataElementService dataElementService, DataElementCategoryService categoryService ) + JdbcTemplate jdbcTemplate, DataElementService dataElementService, DataElementCategoryService categoryService, + SystemSettingManager systemSettingManager ) { this.organisationUnitService = organisationUnitService; this.aggregationConditionService = aggregationConditionService; @@ -82,6 +95,7 @@ this.jdbcTemplate = jdbcTemplate; this.dataElementService = dataElementService; this.categoryService = categoryService; + this.systemSettingManager = systemSettingManager; } // ------------------------------------------------------------------------- @@ -91,6 +105,9 @@ @Override public void run() { + String taskStrategy = (String) systemSettingManager.getSystemSetting( + KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY, DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY ); + Collection orgunits = organisationUnitService.getAllOrganisationUnits(); String datasetSQL = "select dm.datasetid as datasetid, pt.name as periodname"; @@ -104,9 +121,9 @@ { int datasetId = rsDataset.getInt( "datasetid" ); - Period period = getPeriod( rsDataset.getString( "periodname" ) ); + List periods = getPeriod( rsDataset.getString( "periodname" ), taskStrategy ); - if ( period != null ) + for( Period period : periods ) { String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid " + " from caseaggregationcondition cagg inner join datasetmembers dm " @@ -148,6 +165,7 @@ // ----------------------------------------------------- // Add dataValue // ----------------------------------------------------- + if ( dataValue == null ) { dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, "", new Date(), @@ -189,16 +207,39 @@ // Supportive methods // ------------------------------------------------------------------------- - private Period getPeriod( String periodTypeName ) - { - Calendar today = Calendar.getInstance(); + private List getPeriod( String periodTypeName, String taskStrategy ) + { + Calendar calStartDate = Calendar.getInstance(); + + if ( TASK_AGGREGATE_QUERY_BUILDER_LAST_MONTH.equals( taskStrategy ) ) + { + calStartDate.add( Calendar.MONTH, -1 ); + } + else if ( TASK_AGGREGATE_QUERY_BUILDER_LAST_3_MONTH.equals( taskStrategy ) ) + { + calStartDate.add( Calendar.MONTH, -3 ); + } + else if ( TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTH.equals( taskStrategy ) ) + { + calStartDate.add( Calendar.MONTH, -6 ); + } + else if ( TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTH.equals( taskStrategy ) ) + { + calStartDate.add( Calendar.MONTH, -12 ); + } - today.add( Calendar.DATE, -1 ); + Date startDate = calStartDate.getTime(); + + Calendar calEndDate = Calendar.getInstance(); + + Date endDate = calEndDate.getTime(); CalendarPeriodType periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName( periodTypeName ); - Period period = periodType.createPeriod( today ); - - return (period.getEndDate().before( today.getTime() )) ? period : null; + List periods = new ArrayList(); + + periods.addAll( periodType.generatePeriods( startDate , endDate ) ); + + return periods; } } === 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 2013-03-08 09:15:27 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-09 15:25:42 +0000 @@ -483,6 +483,7 @@ + keyCronMap = new HashMap(); keyCronMap.put( CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER, === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-08 13:27:22 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-09 15:25:42 +0000 @@ -1033,6 +1033,9 @@ scope="prototype"> + + + + + + \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-03-01 14:09:05 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-03-09 15:25:42 +0000 @@ -361,4 +361,9 @@ insert_data_elements = Insert data elements only_enroll_once = Only enroll one insert_a_due_date = Please insert a due-date -capture_coordinates = Capture coordinates \ No newline at end of file +capture_coordinates = Capture coordinates +task_stragely = Task stragely +last_month = Last month +last_3_month = Last 3 month +last_6_month = Last 6 month +last_12_month = Last 12 month \ No newline at end of file === 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 2013-01-03 06:54:08 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js 2013-03-09 15:25:42 +0000 @@ -1,3 +1,4 @@ + // ----------------------------------------------------------------------- // Schedule Messages // ----------------------------------------------------------------------- @@ -46,6 +47,7 @@ function schedulingAggCondTasks() { $.post( 'scheduleCaseAggTasks.action',{ + taskStrategy:getFieldValue('taskStrategy'), execute:false }, function( json ){ var status = json.scheduleTasks.status; @@ -71,6 +73,7 @@ if ( ok ) { $.post( 'scheduleCaseAggTasks.action',{ + taskStrategy:getFieldValue('taskStrategy'), 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 2013-01-07 09:11:47 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm 2013-03-09 15:25:42 +0000 @@ -17,7 +17,20 @@ - + + + + + + +
$i18n.getString("task_stragely")
+ +