← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10045: Error when to run scheduled aggregation.

 

------------------------------------------------------------
revno: 10045
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-07 21:25:42 +0700
message:
  Error when to run scheduled aggregation.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java


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

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file '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-02-21 03:39:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java	2013-03-07 14:25:42 +0000
@@ -30,8 +30,6 @@
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
 import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
@@ -39,7 +37,6 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -70,7 +67,7 @@
     private DataElementService dataElementService;
 
     private DataElementCategoryService categoryService;
-    
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -96,29 +93,26 @@
     {
         Collection<OrganisationUnit> orgunits = organisationUnitService.getAllOrganisationUnits();
 
-        Set<DataSet> dataSets = new HashSet<DataSet>();
-        
-        Collection<CaseAggregationCondition> aggConditions = aggregationConditionService
-            .getAllCaseAggregationCondition();
-
-        for ( CaseAggregationCondition aggCondition : aggConditions )
-        {
-            DataElement dataElement = aggCondition.getAggregationDataElement();
-
-            dataSets.addAll( dataElement.getDataSets() );
-        }
-        
-        for ( DataSet dataSet : dataSets )
-        {
-            Period period = getPeriod( dataSet.getPeriodType().getName() );
+        String datasetSQL = "select dm.datasetid as datasetid, pt.name as periodname";
+        datasetSQL += "      from caseaggregationcondition cagg inner join datasetmembers dm ";
+        datasetSQL += "            on cagg.aggregationdataelementid=dm.dataelementid inner join dataset ds ";
+        datasetSQL += "            on ds.datasetid = dm.datasetid inner join periodtype pt ";
+        datasetSQL += "            on pt.periodtypeid=ds.periodtypeid ";
+
+        SqlRowSet rsDataset = jdbcTemplate.queryForRowSet( datasetSQL );
+        while ( rsDataset.next() )
+        {
+            int datasetId = rsDataset.getInt( "datasetid" );
+
+            Period period = getPeriod( rsDataset.getString( "periodname" ) );
 
             if ( period != null )
             {
                 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();
+                    + "     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 = " + datasetId;
 
                 SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
 
@@ -185,6 +179,7 @@
                             dataValueService.deleteDataValue( dataValue );
                         }
                     }
+
                 }
             }
         }
@@ -196,14 +191,14 @@
 
     private Period getPeriod( String periodTypeName )
     {
-        Calendar today = Calendar.getInstance();  
-        
-        today.add(Calendar.DATE, -1);  
+        Calendar today = Calendar.getInstance();
+
+        today.add( Calendar.DATE, -1 );
 
         CalendarPeriodType periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName( periodTypeName );
 
         Period period = periodType.createPeriod( today );
 
-        return ( period.getEndDate().before( today.getTime() )) ? period : null;
+        return (period.getEndDate().before( today.getTime() )) ? period : null;
     }
 }