← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19075: Fixed bug - Zero data values are not saved after runing Manual Aggregate.

 

------------------------------------------------------------
revno: 19075
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-05-01 23:42:48 +0700
message:
  Fixed bug - Zero data values are not saved after runing Manual Aggregate.
modified:
  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-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js


--
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-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	2015-02-09 22:18:20 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2015-05-01 16:42:48 +0000
@@ -495,7 +495,7 @@
             DataElementCategoryOptionCombo attributeOptioncombo = categoryService.getDefaultDataElementCategoryOptionCombo();
             for( CaseAggregationCondition caseAggregationCondition : caseAggregationConditions )
             {
-                String sql = aggregationConditionStore.parseExpressionToSql(false, caseAggregationCondition, attributeOptioncombo.getId(), _orgunitIds );
+                String sql = aggregationConditionStore.parseExpressionToSql(true, caseAggregationCondition, attributeOptioncombo.getId(), _orgunitIds );
     
                 for ( Period period : periods )
                 {

=== 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	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2015-05-01 16:42:48 +0000
@@ -365,22 +365,23 @@
         String aggregateDeName, Integer optionComboId, String optionComboName,  int attributeOptioncomboId, Integer deSumId,
         Collection<Integer> orgunitIds )
     {
-        String sql = "SELECT '" + aggregateDeId + "' as dataelementid, '" + optionComboId
+        String select = "SELECT '" + aggregateDeId + "' as dataelementid, '" + optionComboId
             + "' as categoryoptioncomboid, '" + attributeOptioncomboId
             + "' as attributeoptioncomboid, ou.organisationunitid as sourceid, '" + PARAM_PERIOD_ID + "' as periodid,'"
             + CaseAggregationCondition.AUTO_STORED_BY + "' as storedby, ";
 
         if ( isInsert )
         {
-            sql = "INSERT INTO datavalue (dataelementid, categoryoptioncomboid, attributeoptioncomboid, sourceid, periodid, storedby, lastupdated, followup, created, value) "
-                + sql + " now(), false, now(), ";
+            select = "INSERT INTO datavalue (dataelementid, categoryoptioncomboid, attributeoptioncomboid, sourceid, periodid, storedby, lastupdated, followup, created, value) "
+                + select + " now(), false, now(), ";
         }
         else
         {
-            sql += "'" + PARAM_PERIOD_ISO_DATE + "' as periodIsoDate,'" + aggregateDeName + "' as dataelementname, '"
+            select += "'" + PARAM_PERIOD_ISO_DATE + "' as periodIsoDate,'" + aggregateDeName + "' as dataelementname, '"
                 + optionComboName + "' as categoryoptioncomboname, ou.name as organisationunitname, ";
         }
 
+        String sql = select + " ( select ";
         if ( operator.equals( CaseAggregationCondition.AGGRERATION_COUNT )
             || operator.equals( CaseAggregationCondition.AGGRERATION_SUM ) )
         {
@@ -408,23 +409,20 @@
                     sql += " programinstance as pi ";
                     sql += " INNER JOIN trackedentityinstance p on p.trackedentityinstanceid=pi.trackedentityinstanceid ";
                     sql += " INNER JOIN programstageinstance psi ON pi.programinstanceid=psi.programinstanceid ";
-                    sql += " INNER JOIN organisationunit ou ON ou.organisationunitid=psi.organisationunitid ";
                 }
                 else if ( hasEntityInstance )
                 {
                     sql += " programinstance as pi INNER JOIN trackedentityinstance p on p.trackedentityinstanceid=pi.trackedentityinstanceid ";
-                    sql += " INNER JOIN organisationunit ou ON ou.organisationunitid=p.organisationunitid ";
                 }
                 else
                 {
                     sql += " programinstance as pi ";
                     sql += " INNER JOIN programstageinstance psi ON pi.programinstanceid=psi.programinstanceid ";
-                    sql += " INNER JOIN organisationunit ou ON ou.organisationunitid=psi.organisationunitid ";
                 }
 
                 sql += " WHERE " + createSQL( caseExpression, operator, orgunitIds );
 
-                sql += "GROUP BY ou.organisationunitid, ou.name";
+                sql += "GROUP BY ou.organisationunitid ) from organisationunit ou where ou.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) ";
             }
         }
         else
@@ -433,8 +431,6 @@
             sql += "FROM trackedentitydatavalue pdv ";
             sql += "    INNER JOIN programstageinstance psi  ";
             sql += "            ON psi.programstageinstanceid = pdv.programstageinstanceid ";
-            sql += "    INNER JOIN organisationunit ou ";
-            sql += "            ON ou.organisationunitid=psi.organisationunitid ";
             sql += "WHERE executiondate >='" + PARAM_PERIOD_START_DATE + "'  ";
             sql += "    AND executiondate <='" + PARAM_PERIOD_END_DATE + "' AND pdv.dataelementid=" + deSumId;
 
@@ -443,10 +439,10 @@
                 sql += " AND " + createSQL( caseExpression, operator, orgunitIds );
             }
 
-            sql += "GROUP BY ou.organisationunitid, ou.name";
+            sql += "GROUP BY ou.organisationunitid ) from organisationunit ou where ou.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) ";
             
         }
-        
+      
         return sql;
     }
 
@@ -821,7 +817,7 @@
         
         sql = sql.replaceAll( CaseAggregationCondition.CURRENT_DATE, "now()");
         
-        return sql + " ) ";
+        return sql + " )  and psi.organisationunitid=ou.organisationunitid ";
     }
 
     /**

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm	2014-05-16 02:03:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm	2015-05-01 16:42:48 +0000
@@ -45,7 +45,11 @@
 						#elseif($velocityCount==7)
 							#set($periodid=$col)
 						#elseif($velocityCount==11)
-							#set($value=$col)
+							#if( $!col )
+								#set($value=$col)
+							#else
+								#set($value="0")
+							#end
 						#end
 					#end
 					#set($item=$dataelementid + '_' + $categoryoptioncomboid + '_' + $periodid + '_' + $organisationunitid + '_' + $value)
@@ -54,7 +58,14 @@
 					</td>
 					
 					#foreach( $col in $row )	
-						#if( $velocityCount > 7 )
+						#if($velocityCount==11)
+							#if( $!col )
+								#set($val=$col)
+							#else
+								#set($val="0")	
+							#end				
+							<td>$val</td> 
+						#elseif( $velocityCount > 7 )						
 							<td>$col</td> 
 						#end
 					#end

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2014-06-17 12:21:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2015-05-01 16:42:48 +0000
@@ -41,7 +41,7 @@
 	{
 		if( confirm(i18n_confirm_data_values_aggregated_saved_into_database_directly) )
 		{
-			runAggregate(autoSave);
+			previewAggregate(autoSave);
 		}
 	}
 	else
@@ -50,7 +50,7 @@
 	}
 }
 
-function runAggregate(autoSave)
+/* function runAggregate(autoSave)
 {
 	hideById('caseAggregationForm');
 	hideById('caseAggregationResult');
@@ -62,14 +62,14 @@
 			dataSetId: getFieldValue('dataSetId'),
 			startDate: getFieldValue('startDate'),
 			endDate: getFieldValue('endDate'),
-			autoSave: getFieldValue('autoSave')
+			autoSave: false
 		}
 		, function(){
 			$( "#loaderDiv" ).hide();
-			showById('caseAggregationForm');
+			showById('caseAggregationForm');			
 			setHeaderDelayMessage(i18n_aggregate_successfully);
 		});
-}
+} */
 
 function previewAggregate(autoSave)
 {
@@ -82,11 +82,17 @@
 			dataSetId: getFieldValue('dataSetId'),
 			startDate: getFieldValue('startDate'),
 			endDate: getFieldValue('endDate'),
-			autoSave: getFieldValue('autoSave')
+			autoSave: false
 		}
 		, function(){
 			$( "#loaderDiv" ).hide();
-			showById('caseAggregationResult');
+			if(autoSave=="true"){
+				showById('caseAggregationForm');
+				saveAggregateDataValues( true );
+			}
+			else{
+				showById('caseAggregationResult');
+			}
 		});
 }