← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15855: Fixed bug - Category combination data elements not storing values generated by aggregate query bu...

 

------------------------------------------------------------
revno: 15855
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-25 23:13:15 +0800
message:
  Fixed bug - Category combination data elements not storing values generated by aggregate query builder.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.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-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2014-06-25 15:13:15 +0000
@@ -96,7 +96,7 @@
      * @param i18n
      */
     Grid getAggregateValue( CaseAggregationCondition caseAggregationCondition, Collection<Integer> orgunitIds,
-        Period period, I18nFormat format, I18n i18n );
+        Period period, int attributeOptioncomboId, I18nFormat format, I18n i18n );
 
     /**
      * Retrieve the details of each {@link DataValue} which are generated by a
@@ -119,8 +119,8 @@
      *        value
      * @param period The date range for aggregate data value
      */
-    void insertAggregateValue( String expression, String operator, Integer dataElementId, Integer optionComboId,
-        Integer deSumId, Collection<Integer> orgunitIds, Period period );
+    void insertAggregateValue( String expression, String operator, Integer dataElementId, Integer optionComboId, 
+        int attributeOptioncomboId, Integer deSumId, Collection<Integer> orgunitIds, Period period );
 
     /**
      * Return standard SQL from query builder formula
@@ -143,7 +143,7 @@
      * @param endDate End date
      */
     String parseExpressionToSql( boolean isInsert, String caseExpression, String operator, Integer aggregateDeId,
-        String aggregateDeName, Integer optionComboId, String optionComboName, Integer deSumId,
+        String aggregateDeName, Integer optionComboId, String optionComboName,  int attributeOptioncomboId, Integer deSumId,
         Collection<Integer> orgunitIds, Period period );
 
     /**
@@ -151,7 +151,7 @@
      * list
      * 
      */
-    void runAggregate( Collection<Integer> orgunitIds, CaseAggregateSchedule dataSet, Collection<Period> periods );
+    void runAggregate( Collection<Integer> orgunitIds, CaseAggregateSchedule dataSet, Collection<Period> periods, int attributeOptioncomboId );
 
     /**
      * Convert an expression of {@link CaseAggregationCondition} to standard

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2014-05-17 11:40:23 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2014-06-25 15:13:15 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.common.Grid;
 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.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -64,6 +65,7 @@
 import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -95,6 +97,9 @@
     private PeriodService periodService;
 
     private I18nService i18nService;
+    
+    @Autowired
+    private DataElementCategoryService categoryService;
 
     // -------------------------------------------------------------------------
     // Getters && Setters
@@ -419,7 +424,9 @@
     {
         periodService.reloadPeriod( period );
 
-        return aggregationConditionStore.getAggregateValue( caseAggregationCondition, orgunitIds, period, format, i18n );
+        int attributeOptioncomboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
+        
+        return aggregationConditionStore.getAggregateValue( caseAggregationCondition, orgunitIds, period, attributeOptioncomboId, format, i18n );
     }
 
     @Override
@@ -439,9 +446,11 @@
         Integer deSumId = (caseAggregationCondition.getDeSum() == null) ? null : caseAggregationCondition.getDeSum()
             .getId();
 
+        int attributeOptioncomboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
+        
         aggregationConditionStore.insertAggregateValue( caseAggregationCondition.getAggregationExpression(),
             caseAggregationCondition.getOperator(), caseAggregationCondition.getAggregationDataElement().getId(),
-            caseAggregationCondition.getOptionCombo().getId(), deSumId, orgunitIds, period );
+            caseAggregationCondition.getOptionCombo().getId(), attributeOptioncomboId, deSumId, orgunitIds, period );
     }
 
     @Override
@@ -459,8 +468,10 @@
     {
         periodService.reloadPeriod( period );
 
+        int attributeOptioncomboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
+        
         return aggregationConditionStore.parseExpressionToSql( isInsert, caseExpression, operator, aggregateDeId,
-            aggregateDeName, optionComboId, optionComboName, deSumId, orgunitIds, period );
+            aggregateDeName, optionComboId, optionComboName, attributeOptioncomboId, deSumId, orgunitIds, period );
     }
 
     @Override
@@ -477,6 +488,8 @@
     private Future<?> aggregateValueManager( ConcurrentLinkedQueue<CaseAggregateSchedule> caseAggregateSchedule,
         String taskStrategy )
     {
+        int attributeOptioncomboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
+        
         taskLoop: while ( true )
         {
             CaseAggregateSchedule dataSet = caseAggregateSchedule.poll();
@@ -487,7 +500,7 @@
 
             Collection<Period> periods = aggregationConditionStore.getPeriods( dataSet.getPeriodTypeName(),
                 taskStrategy );
-            aggregationConditionStore.runAggregate( null, dataSet, periods );
+            aggregationConditionStore.runAggregate( null, dataSet, periods, attributeOptioncomboId );
         }
 
         return null;

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2014-06-22 01:52:26 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2014-06-25 15:13:15 +0000
@@ -63,7 +63,9 @@
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -75,6 +77,7 @@
 import org.hisp.dhis.system.grid.ListGrid;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.TextUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
@@ -124,7 +127,7 @@
     {
         this.dataElementService = dataElementService;
     }
-
+    
     // -------------------------------------------------------------------------
     // Implementation Methods
     // -------------------------------------------------------------------------
@@ -151,7 +154,7 @@
     }
 
     public Grid getAggregateValue( CaseAggregationCondition caseAggregationCondition, Collection<Integer> orgunitIds,
-        Period period, I18nFormat format, I18n i18n )
+        Period period, int attributeOptioncomboId, I18nFormat format, I18n i18n )
     {
         Collection<Integer> _orgunitIds = getServiceOrgunit();
         _orgunitIds.retainAll( orgunitIds );
@@ -177,7 +180,7 @@
             String sql = parseExpressionToSql( false, caseAggregationCondition.getAggregationExpression(),
                 caseAggregationCondition.getOperator(), caseAggregationCondition.getAggregationDataElement().getId(),
                 caseAggregationCondition.getAggregationDataElement().getDisplayName(), caseAggregationCondition
-                    .getOptionCombo().getId(), caseAggregationCondition.getOptionCombo().getDisplayName(), deSumId,
+                    .getOptionCombo().getId(), caseAggregationCondition.getOptionCombo().getDisplayName(), attributeOptioncomboId, deSumId,
                 _orgunitIds, period );
 
             SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
@@ -212,7 +215,7 @@
         return grid;
     }
 
-    public void insertAggregateValue( String expression, String operator, Integer dataElementId, Integer optionComboId,
+    public void insertAggregateValue( String expression, String operator, Integer dataElementId, Integer optionComboId, int attributeOptioncomboId, 
         Integer deSumId, Collection<Integer> orgunitIds, Period period )
     {
         // Delete all data value from this period which created from DHIS-system
@@ -254,17 +257,17 @@
         // insert data elements into database directly
 
         String sql = parseExpressionToSql( true, expression, operator, dataElementId, "dataelementname", optionComboId,
-            "optionComboname", deSumId, orgunitIds, period );
+            "optionComboname", attributeOptioncomboId, deSumId, orgunitIds, period );
         jdbcTemplate.execute( sql );
     }
 
     @Override
     public String parseExpressionToSql( boolean isInsert, String caseExpression, String operator,
-        Integer aggregateDeId, String aggregateDeName, Integer optionComboId, String optionComboName, Integer deSumId,
+        Integer aggregateDeId, String aggregateDeName, Integer optionComboId, String optionComboName, int attributeOptioncomboId, Integer deSumId,
         Collection<Integer> orgunitIds, Period period )
-    {
+    { 
         String sql = "SELECT '" + aggregateDeId + "' as dataelementid, '" + optionComboId
-            + "' as categoryoptioncomboid, '" + optionComboId
+            + "' as categoryoptioncomboid, '" + attributeOptioncomboId
             + "' as attributeoptioncomboid, ou.organisationunitid as sourceid, '" + period.getId() + "' as periodid,'"
             + CaseAggregationCondition.AUTO_STORED_BY + "' as storedby, ";
 
@@ -360,7 +363,7 @@
     }
 
     @Override
-    public void runAggregate( Collection<Integer> orgunitIds, CaseAggregateSchedule dataSet, Collection<Period> periods )
+    public void runAggregate( Collection<Integer> orgunitIds, CaseAggregateSchedule dataSet, Collection<Period> periods, int attributeOptioncomboId )
     {
         String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid, "
             + " cagg.aggregationexpression as caseexpression, cagg.operator as caseoperator, cagg.desum as desumid "
@@ -372,7 +375,7 @@
 
         SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
 
-        while ( rs.next() )
+         while ( rs.next() )
         {
             for ( Period period : periods )
             {
@@ -404,7 +407,7 @@
 
                 if ( !orgunitIds.isEmpty() )
                 {
-                    insertAggregateValue( caseExpression, caseOperator, dataelementId, optionComboId, deSumId,
+                    insertAggregateValue( caseExpression, caseOperator, dataelementId, optionComboId, attributeOptioncomboId, deSumId,
                         orgunitIds, period );
                 }
             }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-06-20 12:32:01 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-06-25 15:13:15 +0000
@@ -38,6 +38,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
 import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 import org.hisp.dhis.system.util.ValidationUtils;
@@ -75,6 +76,9 @@
 
     @Autowired
     private StatementBuilder statementBuilder;
+    
+    @Autowired
+    private DataElementCategoryService categoryService;
 
     // -------------------------------------------------------------------------
     // Action Implementation
@@ -279,6 +283,10 @@
         executeSql( "UPDATE programstageinstance SET status=1 WHERE completed=true" );
         executeSql( "ALTER TABLE programstageinstance DROP COLUMN completed" );
         
+        executeSql( "update program_attributes set mandatory = false where mandatory is null;" );
+        
+        int attributeoptioncomboid = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
+        executeSql( "update datavalue set attributeoptioncomboid=" + attributeoptioncomboid + " where storedby='aggregated_from_tracker' or comment='aggregated_from_tracker'" );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java	2014-06-17 14:11:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java	2014-06-25 15:13:15 +0000
@@ -127,12 +127,14 @@
             DataElement dataElement = dataElementService.getDataElement( dataElementId );
             DataElementCategoryOptionCombo optionCombo = categoryService
                 .getDataElementCategoryOptionCombo( optionComboId );
+           
+            DataElementCategoryOptionCombo attributeOptioncombo = categoryService.getDefaultDataElementCategoryOptionCombo();
             
             Period period = PeriodType.getPeriodFromIsoString( periodIsoId );
 
             OrganisationUnit orgunit = organisationUnitService.getOrganisationUnit( orgunitId );
 
-            DataValue dataValue = dataValueService.getDataValue( dataElement, period, orgunit, optionCombo , optionCombo );
+            DataValue dataValue = dataValueService.getDataValue( dataElement, period, orgunit, optionCombo , attributeOptioncombo );
 
             // -----------------------------------------------------------------
             // Save/Update/Delete data-values
@@ -142,7 +144,7 @@
             {
                 if ( dataValue == null )
                 {
-                    dataValue = new DataValue( dataElement, period, orgunit, optionCombo, optionCombo,
+                    dataValue = new DataValue( dataElement, period, orgunit, optionCombo, attributeOptioncombo,
                         "" + resultValue, CaseAggregationCondition.AUTO_STORED_BY, new Date(), null );
                     dataValueService.addDataValue( dataValue );
                 }