dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21790
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10413: Improve Schedule automated aggregation.
------------------------------------------------------------
revno: 10413
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-03-25 11:56:23 +0700
message:
Improve Schedule automated aggregation.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
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/program/DefaultProgramStageInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
--
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-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-03-25 04:02:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-03-25 04:56:23 +0000
@@ -127,4 +127,5 @@
int averageNumberCompletedProgramInstance( Program program , Collection<Integer> orgunitIds, Date startDate, Date endDate, Boolean completed );
Collection<Integer> getOrganisationUnitIds ( Date startDate, Date endDate );
+
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-03-25 04:02:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-03-25 04:56:23 +0000
@@ -124,6 +124,6 @@
int averageNumberCompleted( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
Boolean completed );
- Collection<Integer> getOrgunitIds ( Date startDate, Date endDate );
+ Collection<Integer> getOrgunitIds( Date startDate, Date endDate );
}
=== 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-10 04:16:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java 2013-03-25 04:56:23 +0000
@@ -50,6 +50,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.setting.SystemSettingManager;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
@@ -64,8 +65,6 @@
{
public static final String STORED_BY_DHIS_SYSTEM = "DHIS-System";
- private OrganisationUnitService organisationUnitService;
-
private CaseAggregationConditionService aggregationConditionService;
private DataValueService dataValueService;
@@ -78,22 +77,27 @@
private SystemSettingManager systemSettingManager;
+ private ProgramStageInstanceService programStageInstanceService;
+
+ private OrganisationUnitService organisationUnitService;
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
- public CaseAggregateConditionTask( OrganisationUnitService organisationUnitService,
- CaseAggregationConditionService aggregationConditionService, DataValueService dataValueService,
- JdbcTemplate jdbcTemplate, DataElementService dataElementService, DataElementCategoryService categoryService,
- SystemSettingManager systemSettingManager )
+ public CaseAggregateConditionTask( CaseAggregationConditionService aggregationConditionService,
+ DataValueService dataValueService, JdbcTemplate jdbcTemplate, DataElementService dataElementService,
+ DataElementCategoryService categoryService, SystemSettingManager systemSettingManager,
+ ProgramStageInstanceService programStageInstanceService, OrganisationUnitService organisationUnitService )
{
- this.organisationUnitService = organisationUnitService;
this.aggregationConditionService = aggregationConditionService;
this.dataValueService = dataValueService;
this.jdbcTemplate = jdbcTemplate;
this.dataElementService = dataElementService;
this.categoryService = categoryService;
this.systemSettingManager = systemSettingManager;
+ this.programStageInstanceService = programStageInstanceService;
+ this.organisationUnitService = organisationUnitService;
}
// -------------------------------------------------------------------------
@@ -106,8 +110,6 @@
String taskStrategy = (String) systemSettingManager.getSystemSetting(
KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY, DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY );
- Collection<OrganisationUnit> orgunits = organisationUnitService.getAllOrganisationUnits();
-
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 ";
@@ -121,7 +123,7 @@
Collection<Period> periods = getPeriod( rsDataset.getString( "periodname" ), taskStrategy );
- for( Period period : periods )
+ for ( Period period : periods )
{
String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid "
+ " from caseaggregationcondition cagg inner join datasetmembers dm "
@@ -131,6 +133,9 @@
SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
+ Collection<Integer> orgunitIds = programStageInstanceService.getOrganisationUnitIds(
+ period.getStartDate(), period.getEndDate() );
+
while ( rs.next() )
{
// -------------------------------------------------------------
@@ -151,8 +156,9 @@
// Aggregation
// ---------------------------------------------------------------------
- for ( OrganisationUnit orgUnit : orgunits )
+ for ( Integer orgUnitId : orgunitIds )
{
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
DataValue dataValue = dataValueService.getDataValue( orgUnit, dElement, period, optionCombo );
Integer resultValue = aggregationConditionService.parseConditition( aggCondition, orgUnit,
@@ -163,7 +169,7 @@
// -----------------------------------------------------
// Add dataValue
// -----------------------------------------------------
-
+
if ( dataValue == null )
{
dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, "", new Date(),
@@ -206,34 +212,34 @@
// -------------------------------------------------------------------------
private Collection<Period> 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 ) )
+ 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 ) )
+ 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 ) )
+ else if ( TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTH.equals( taskStrategy ) )
{
calStartDate.add( Calendar.MONTH, -12 );
}
Date startDate = calStartDate.getTime();
-
+
Calendar calEndDate = Calendar.getInstance();
-
+
Date endDate = calEndDate.getTime();
CalendarPeriodType periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName( periodTypeName );
- return periodType.generatePeriods( startDate , endDate ) ;
+ return periodType.generatePeriods( startDate, endDate );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-03-25 04:02:33 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-03-25 04:56:23 +0000
@@ -507,5 +507,5 @@
{
return programStageInstanceStore.getOrgunitIds( startDate, endDate );
}
-
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-03-25 04:02:33 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-03-25 04:56:23 +0000
@@ -1954,7 +1954,7 @@
Projections.property( "orgunit.id" ), "orgunitid" ) ) );
return criteria.list();
}
-
+
// ---------------------------------------------------------------------
// Get orgunitIds
// ---------------------------------------------------------------------
=== 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-21 04:37:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-25 04:56:23 +0000
@@ -484,6 +484,7 @@
<constructor-arg ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
<constructor-arg ref="org.hisp.dhis.datavalue.DataValueService" />
<constructor-arg ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <constructor-arg ref="org.hisp.dhis.program.ProgramStageInstanceService" />
<constructor-arg ref="jdbcTemplate" />
<constructor-arg ref="org.hisp.dhis.dataelement.DataElementService" />
<constructor-arg ref="org.hisp.dhis.dataelement.DataElementCategoryService" />