dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19436
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8468: Improve Aggregate Query Builder (WIP).
------------------------------------------------------------
revno: 8468
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-11 09:33:30 +0700
message:
Improve Aggregate Query Builder (WIP).
modified:
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/startup/TableAlteror.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-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-10-10 08:50:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java 2012-10-11 02:33:30 +0000
@@ -42,6 +42,8 @@
import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -49,6 +51,8 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.setting.SystemSettingManager;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
/**
* @author Chau Thu Tran
@@ -58,6 +62,8 @@
public class CaseAggregateConditionTask
implements Runnable
{
+ public static final String STORED_BY_DHIS_SYSTEM = "DHIS-System";
+
private OrganisationUnitService organisationUnitService;
private CaseAggregationConditionService aggregationConditionService;
@@ -66,6 +72,12 @@
private SystemSettingManager systemSettingManager;
+ private JdbcTemplate jdbcTemplate;
+
+ private DataElementService dataElementService;
+
+ private DataElementCategoryService categoryService;
+
// -------------------------------------------------------------------------
// Params
// -------------------------------------------------------------------------
@@ -97,12 +109,16 @@
public CaseAggregateConditionTask( OrganisationUnitService organisationUnitService,
CaseAggregationConditionService aggregationConditionService, DataValueService dataValueService,
- SystemSettingManager systemSettingManager )
+ SystemSettingManager systemSettingManager, JdbcTemplate jdbcTemplate, DataElementService dataElementService,
+ DataElementCategoryService categoryService )
{
this.organisationUnitService = organisationUnitService;
this.aggregationConditionService = aggregationConditionService;
this.dataValueService = dataValueService;
this.systemSettingManager = systemSettingManager;
+ this.jdbcTemplate = jdbcTemplate;
+ this.dataElementService = dataElementService;
+ this.categoryService = categoryService;
}
// -------------------------------------------------------------------------
@@ -137,9 +153,24 @@
{
for ( CaseAggregationCondition aggCondition : aggConditions )
{
- DataElementCategoryOptionCombo optionCombo = aggCondition.getOptionCombo();
-
- DataElement dElement = aggCondition.getAggregationDataElement();
+ // -------------------------------------------------------------
+ // Get agg-dataelement and option-combo
+ // -------------------------------------------------------------
+
+ String sql = "select aggregationdataelementid, optioncomboid from caseaggregationcondition where caseaggregationconditionid="
+ + aggCondition.getId();
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
+ rs.next();
+ int dataelementId = rs.getInt( "aggregationdataelementid" );
+ int optionComboId = rs.getInt( "optioncomboid" );
+
+ // -------------------------------------------------------------
+ // Get agg-dataelement and option-combo
+ // -------------------------------------------------------------
+
+ DataElement dElement = dataElementService.getDataElement( dataelementId );
+ DataElementCategoryOptionCombo optionCombo = categoryService
+ .getDataElementCategoryOptionCombo( optionComboId );
for ( Period period : periods )
{
@@ -152,7 +183,7 @@
// -----------------------------------------
// Add dataValue
// -----------------------------------------
-
+
if ( dataValue == null )
{
dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, "", new Date(),
@@ -166,10 +197,14 @@
{
dataValue.setValue( "" + resultValue );
dataValue.setTimestamp( new Date() );
- dataValueService.updateDataValue( dataValue );
+ sql = "UPDATE datavalue" + " SET value='" + resultValue + "',lastupdated='" + new Date() + "' where dataelementId="
+ + dataelementId + " and periodid=" + period.getId() + " and sourceid="
+ + orgUnit.getId() + " and categoryoptioncomboid=" + optionComboId + " and storedby='"
+ + STORED_BY_DHIS_SYSTEM + "'";
+ jdbcTemplate.execute( sql );
}
+ }
- }
// -----------------------------------------
// Delete dataValue
// -----------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-10-10 08:50:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-10-11 02:33:30 +0000
@@ -143,6 +143,10 @@
executeSql( "ALTER TABLE program DROP COLUMN maxDaysAllowedInputData");
executeSql( "ALTER TABLE programstage_dataelements DROP CONSTRAINT \"fkaf0e5fc634ee4761\" ");
+
+ executeSql( "ALTER TABLE period modify periodid int AUTO_INCREMENT");
+ executeSql( "CREATE SEQUENCE period_periodid_seq");
+ executeSql( "ALTER TABLE period ALTER COLUMN periodid SET DEFAULT NEXTVAL('period_periodid_seq')");
}
// -------------------------------------------------------------------------
=== 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-10-10 08:50:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-10-11 02:33:30 +0000
@@ -434,12 +434,13 @@
<bean id="abstractRunCaseAggregateConditionTask"
class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask">
- <constructor-arg
- ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
+ <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.organisationunit.OrganisationUnitService" />
<constructor-arg ref="org.hisp.dhis.setting.SystemSettingManager" />
+ <constructor-arg ref="jdbcTemplate" />
+ <constructor-arg ref="org.hisp.dhis.dataelement.DataElementService" />
+ <constructor-arg ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
<bean id="aggregateLast12MonthsTask" class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask"