← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3554: Completed front-end of indicators (calculated fields) in data entry. One will first have to creat...

 

------------------------------------------------------------
revno: 3554
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-05-10 10:58:10 +0200
message:
  Completed front-end of indicators (calculated fields) in data entry. One will first have to create indicators, then assign them to the dataset, then insert them into custom forms with the custom form designer.
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.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-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2011-04-22 21:04:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2011-05-10 08:58:10 +0000
@@ -195,7 +195,7 @@
     // -------------------------------------------------------------------------
 
     @Test
-    public void testExplodeExpression()
+    public void testExplodeExpressionA()
     {
         categoryService.generateOptionCombos( categoryCombo );
         
@@ -212,6 +212,13 @@
     }
 
     @Test
+    public void testExplodeExpressionB()
+    {
+        assertEquals( "1", expressionService.explodeExpression( "1" ) );
+        assertEquals( "2+6/4", expressionService.explodeExpression( "2+6/4" ) );
+    }
+
+    @Test
     public void testGetExpressionValue()
     {
         Expression expression = new Expression( expressionA, descriptionA, dataElements );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2011-03-16 20:50:40 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2011-05-10 08:58:10 +0000
@@ -294,7 +294,10 @@
         
         for ( Double value : values )
         {
-            sum += value;
+            if ( value != null )
+            {
+                sum += value;
+            }
         }
         
         return sum;

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java	2010-11-24 20:34:35 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java	2011-05-10 08:58:10 +0000
@@ -4,12 +4,15 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.de.state.SelectedStateManager;
+import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.period.Period;
 
 import com.opensymphony.xwork2.Action;
@@ -41,6 +44,13 @@
     {
         this.format = format;
     }
+    
+    private ExpressionService expressionService;
+
+    public void setExpressionService( ExpressionService expressionService )
+    {
+        this.expressionService = expressionService;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -71,12 +81,19 @@
         return periodValid;
     }
     
-    private Collection<DataElement> significantZeros = new HashSet<DataElement>();
+    private Set<DataElement> significantZeros = new HashSet<DataElement>();
 
-    public Collection<DataElement> getSignificantZeros()
+    public Set<DataElement> getSignificantZeros()
     {
         return significantZeros;
     }
+    
+    private Collection<Indicator> indicators = new HashSet<Indicator>();
+
+    public Collection<Indicator> getIndicators()
+    {
+        return indicators;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -127,6 +144,18 @@
                     significantZeros.add( dataElement );
                 }
             }
+
+            // -----------------------------------------------------------------
+            // Explode and add indicators from data set
+            // -----------------------------------------------------------------
+
+            for ( Indicator indicator : selectedDataSet.getIndicators() )
+            {
+                indicator.setExplodedNumerator( expressionService.explodeExpression( indicator.getNumerator() ) );
+                indicator.setExplodedDenominator( expressionService.explodeExpression( indicator.getDenominator() ) );
+                
+                indicators.add( indicator );
+            }
             
             // -----------------------------------------------------------------
             // Clear display mode when loading new data set

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-05-07 23:05:00 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-05-10 08:58:10 +0000
@@ -37,6 +37,7 @@
 	<bean id="org.hisp.dhis.de.action.LoadPeriodsAction" class="org.hisp.dhis.de.action.LoadPeriodsAction" scope="prototype">
 		<property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
 		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+		<property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
 	</bean>
 	
 	<bean id="org.hisp.dhis.de.action.LoadNextPreviousPeriodsAction" class="org.hisp.dhis.de.action.LoadNextPreviousPeriodsAction" scope="prototype">

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-05-08 22:03:05 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-05-10 08:58:10 +0000
@@ -7,8 +7,6 @@
 var COLOR_YELLOW = '#fffe8c';
 var COLOR_RED = '#ff8a8a';
 
-var indicatorFormulas = new Array();
-
 var FORMULA_PATTERN = /\[.+?\]/g;
 var SEPARATOR = '.';
 
@@ -21,10 +19,12 @@
 	var entryFieldValues = getEntryFieldValues();
 
 	$( 'input[name="indicator"]' ).each( function( index ) {
-		var indicatorId = $( this ).attr( 'indicatorId' );
+		var indicatorId = $( this ).attr( 'indicatorid' );
+		
 		var formula = indicatorFormulas[ indicatorId ];
 		
-		var expression = generateExpression( formula );		
+		var expression = generateExpression( formula );
+		
 		var value = eval( expression );
 		
 		if ( value )
@@ -70,7 +70,7 @@
 		
 		var value = entryField && entryField.value ? entryField.value : '0';
 		
-		expression = expression.replace( match, value );
+		expression = expression.replace( match, value ); // TODO signed numbers
 	}
 	
 	return expression;
@@ -83,7 +83,7 @@
 {
 	var dataElementName = document.getElementById( 'value[' + dataElementId + '].name' ).innerHTML;
 	
-	saveValue( dataElementId, optionComboId, dataElementName, null );
+	saveValueInternal( dataElementId, optionComboId, dataElementName, null );
 }
 
 /**
@@ -91,6 +91,12 @@
 */
 function saveValue( dataElementId, optionComboId, dataElementName )
 {
+	saveValueInternal( dataElementId, optionComboId, dataElementName );
+	updateIndicators();
+}
+
+function saveValueInternal( dataElementId, optionComboId, dataElementName )
+{
     var field = document.getElementById( 'value[' + dataElementId + '].value' + ':' +  'value[' + optionComboId + '].value');
     var type = document.getElementById( 'value[' + dataElementId + '].type' ).innerHTML;   
 	var organisationUnitId = getFieldValue( 'organisationUnitId' );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-04-12 19:30:34 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-05-10 08:58:10 +0000
@@ -1,5 +1,6 @@
 
 var significantZeros = []; // Identifiers for which zero values are insignificant, also used in entry.js
+var indicatorFormulas = []; // Associative array with [indicator id, expression] for indicators in form, also used in entry.js
 
 function addEventListeners()
 {
@@ -124,6 +125,7 @@
 	    
 	    $.getJSON( url, function( json ) {
 	    	significantZeros = json.significantZeros;
+	    	indicatorFormulas = json.indicatorFormulas;
 	    	
 	    	addOptionById( 'selectedPeriodIndex', '-1', '[ ' + i18n_select_period + ' ]' );
 		
@@ -180,6 +182,7 @@
 	addEventListeners();
 	hideLoader();
 	enable( 'validationButton' );
+	updateIndicators();
 }
 
 function setDisplayModes()

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm	2010-11-24 20:34:35 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm	2011-05-10 08:58:10 +0000
@@ -14,5 +14,10 @@
 #foreach( $dataElement in $significantZeros )
   ${dataElement.id}#if( $velocityCount < $size2 ),#end
 #end ],
+#set( $size3 = $indicators.size() )
+  "indicatorFormulas": {
+#foreach( $indicator in $indicators )
+  "${indicator.id}": "$!{indicator.explodedNumerator}/$!{indicator.explodedDenominator}"#if( $velocityCount < $size3 ),#end
+#end },
   "periodValid": ${periodValid}
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-09 15:20:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-10 08:58:10 +0000
@@ -35,7 +35,7 @@
 		if($(this).attr("selected")) {
 			var id = $(this).data("id");
 			var title = $(this).val();
-			var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" name="indicator" indicatorId="' + id + '" style="width:10em;text-align:center;" disabled="disabled" />';
+			var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" name="indicator" indicatorId="' + id + '" style="width:10em;text-align:center;" readonly="readonly" />';
 
 			if(!checkExisted("indicator" + id)) {
 				oEditor.insertHtml( template )