← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3114: Fix bug: Calculated-data-element-decimal-factors-are-truncated-in-display.

 

------------------------------------------------------------
revno: 3114
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-03-22 12:49:48 +0700
message:
  Fix bug: Calculated-data-element-decimal-factors-are-truncated-in-display.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DataEntryScreenManager.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DefaultDataEntryScreenManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm


--
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/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2011-02-01 08:11:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2011-03-22 05:49:48 +0000
@@ -340,7 +340,7 @@
      * @return a map of factors for the DataElements in the given
      *         CalculatedDataElement
      */
-    Map<DataElement, Integer> getDataElementFactors( CalculatedDataElement calculatedDataElement );
+    Map<DataElement, Double> getDataElementFactors( CalculatedDataElement calculatedDataElement );
 
     /**
      * Returns a Map of factors for the Operands in the given
@@ -350,7 +350,7 @@
      * @return a map of factors for the Operands in the given
      *         CalculatedDataElement
      */
-    Map<String, Integer> getOperandFactors( CalculatedDataElement calculatedDataElement );
+    Map<String, Double> getOperandFactors( CalculatedDataElement calculatedDataElement );
 
     /**
      * Returns a collection of OperandIds in the given CalculatedDataElement

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2011-02-01 08:11:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2011-03-22 05:49:48 +0000
@@ -399,11 +399,11 @@
         return i18n( i18nService, dataElementStore.getCalculatedDataElementsByDataElements( dataElements ) );
     }
 
-    public Map<DataElement, Integer> getDataElementFactors( CalculatedDataElement calculatedDataElement )
+    public Map<DataElement, Double> getDataElementFactors( CalculatedDataElement calculatedDataElement )
     {
-        Map<DataElement, Integer> factorMap = new HashMap<DataElement, Integer>();
+        Map<DataElement, Double> factorMap = new HashMap<DataElement, Double>();
 
-        Pattern pattern = Pattern.compile( "\\[(\\d+)\\]\\s*\\*\\s*(\\d+)" );
+        Pattern pattern = Pattern.compile( "\\[(\\d+)\\]\\s*\\*\\s*(\\d+(\\.\\d)*)" );
 
         // ---------------------------------------------------------------------
         // In readable form: \[(\d+)\]\s*\*\s*(\d+)
@@ -419,18 +419,18 @@
             // Value: Factor
             // -----------------------------------------------------------------
 
-            factorMap.put( getDataElement( Integer.parseInt( matcher.group( 1 ) ) ), Integer.parseInt( matcher
+            factorMap.put( getDataElement( Integer.parseInt( matcher.group( 1 ) ) ), Double.parseDouble( matcher
                 .group( 2 ) ) );
         }
 
         return factorMap;
     }
 
-    public Map<String, Integer> getOperandFactors( CalculatedDataElement calculatedDataElement )
+    public Map<String, Double> getOperandFactors( CalculatedDataElement calculatedDataElement )
     {
-        Map<String, Integer> factorMap = new HashMap<String, Integer>();
+        Map<String, Double> factorMap = new HashMap<String, Double>();
 
-        Pattern pattern = Pattern.compile( "\\[(\\d+\\.\\d+)\\]\\s*\\*\\s*(-?\\d+)" );
+        Pattern pattern = Pattern.compile( "\\[(\\d+\\.\\d+)\\]\\s*\\*\\s*(-?\\d+(\\.\\d)*)" );
 
         // ---------------------------------------------------------------------
         // In readable form: \[(\d+)\]\s*\*\s*(\d+)
@@ -446,7 +446,7 @@
             // Value: Factor
             // -----------------------------------------------------------------
 
-            factorMap.put( matcher.group( 1 ), Integer.parseInt( matcher.group( 2 ) ) );
+            factorMap.put( matcher.group( 1 ), Double.parseDouble( matcher.group( 2 ) ) );
         }
 
         return factorMap;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2011-02-15 20:14:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2011-03-22 05:49:48 +0000
@@ -508,7 +508,7 @@
         cdes = dataElementService.getCalculatedDataElementsByDataElements( dataElements );
         assertEquals( 2, cdes.size() );
         
-        Map<DataElement,Integer> factorMap = dataElementService.getDataElementFactors(cdeX);
+        Map<DataElement,Double> factorMap = dataElementService.getDataElementFactors(cdeX);
         assertEquals( 2, factorMap.size() );
         assertTrue(factorMap.keySet().contains(deA));
         assertEquals( new Integer(2), factorMap.get(deA));

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DataEntryScreenManager.java	2011-01-06 16:37:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DataEntryScreenManager.java	2011-03-22 05:49:48 +0000
@@ -53,7 +53,7 @@
 
     Collection<Integer> getAllCalculatedDataElements(ProgramStage programStage);
 
-    Map<CalculatedDataElement, Map<DataElement, Integer>> getNonSavedCalculatedDataElements(ProgramStage programStage);
+    Map<CalculatedDataElement, Map<DataElement, Double>> getNonSavedCalculatedDataElements(ProgramStage programStage);
 
     Map<CalculatedDataElement, Integer> populateValuesForCalculatedDataElements(OrganisationUnit organisationUnit,
         ProgramStage programStage, ProgramStageInstance programStageInstance);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DefaultDataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DefaultDataEntryScreenManager.java	2011-01-21 02:26:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/screen/DefaultDataEntryScreenManager.java	2011-03-22 05:49:48 +0000
@@ -179,10 +179,10 @@
         return calculatedDataElementIds;
     }
 
-    public Map<CalculatedDataElement, Map<DataElement, Integer>> getNonSavedCalculatedDataElements(
+    public Map<CalculatedDataElement, Map<DataElement, Double>> getNonSavedCalculatedDataElements(
         ProgramStage programStage )
     {
-        Map<CalculatedDataElement, Map<DataElement, Integer>> calculatedDataElementMap = new HashMap<CalculatedDataElement, Map<DataElement, Integer>>();
+        Map<CalculatedDataElement, Map<DataElement, Double>> calculatedDataElementMap = new HashMap<CalculatedDataElement, Map<DataElement, Double>>();
 
         Collection<DataElement> dataElements = programStageDataElementService.getListDataElement( programStage );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java	2011-02-14 04:01:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java	2011-03-22 05:49:48 +0000
@@ -175,9 +175,9 @@
         this.dataElementIds = dataElementIds;
     }
 
-    private List<String> factors;
+    private List<Double> factors;
 
-    public void setFactors( List<String> factors )
+    public void setFactors( List<Double> factors )
     {
         this.factors = factors;
     }
@@ -259,7 +259,7 @@
                     continue;
                 }
 
-                Double factor = Double.parseDouble( factors.get( i ) );
+                Double factor = factors.get( i );
 
                 expressionString += " + ([" + operandId + "] * " + factor + ")";
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java	2011-02-01 08:11:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java	2011-03-22 05:49:48 +0000
@@ -111,9 +111,9 @@
         return dataElementGroups;
     }
 
-    private Map<String, Integer> factorMap;
+    private Map<String, Double> factorMap;
 
-    public Map<String, Integer> getFactorMap()
+    public Map<String, Double> getFactorMap()
     {
         return factorMap;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java	2011-02-14 04:01:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java	2011-03-22 05:49:48 +0000
@@ -138,14 +138,7 @@
     {
         this.domainType = domainType;
     }
-
-    private String valueType;
-
-    public void setValueType( String valueType )
-    {
-        this.valueType = valueType;
-    }
-
+    
     private String numberType;
 
     public void setNumberType( String numberType )
@@ -188,9 +181,9 @@
         this.dataElementIds = dataElementIds;
     }
 
-    private List<String> factors;
+    private List<Double> factors;
 
-    public void setFactors( List<String> factors )
+    public void setFactors( List<Double> factors )
     {
         this.factors = factors;
     }
@@ -250,7 +243,6 @@
         dataElement.setDescription( description );
         dataElement.setActive( active );
         dataElement.setDomainType( domainType );
-        dataElement.setType( valueType );
         dataElement.setNumberType( numberType );
         dataElement.setAggregationOperator( aggregationOperator );
         dataElement.setUrl( url );
@@ -287,8 +279,8 @@
                 {
                     continue;
                 }
-
-                Double factor = Double.parseDouble( factors.get( i ) );
+                
+                Double factor = factors.get( i );
 
                 expressionString += " + ([" + operandId + "] * " + factor + ")";
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js	2011-02-14 04:01:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js	2011-03-22 05:49:48 +0000
@@ -207,7 +207,7 @@
     var factorTd = tr.appendChild(document.createElement('td'));
     var factorInput = factorTd.appendChild(document.createElement('input'));
     factorInput.type = 'text';
-    factorInput.name = 'factors-' + index;
+    factorInput.name = 'factors' + index;
     factorInput.value = 1;
 
     var opTd = tr.appendChild(document.createElement('td'));
@@ -254,7 +254,7 @@
 
 function updateValidatorRulesForFactors()
 {
-	var inputs = jQuery("#selectedDataElements input[name|=factors]");
+	var inputs = jQuery("#selectedDataElements input[name*=factors]");
 	
 	jQuery.each(inputs, function(i, item ){
 		removeValidatorRules( item );
@@ -264,7 +264,7 @@
 
 function removeValidatorRulesForFactors()
 {
-	var inputs = jQuery("#selectedDataElements input[name|=factors]");
+	var inputs = jQuery("#selectedDataElements input[name*=factors]");
 	
 	jQuery.each(inputs, function(i, item ){			
 		removeValidatorRules( item );		
@@ -304,9 +304,9 @@
 function getFactors()
 {
 	var factorsSubmit = jQuery("#factorsSubmit");
-	var inputs = jQuery("#selectedDataElements input[name|=factors]");
+	var inputs = jQuery("#selectedDataElements input[name*=factors]");
 
-	jQuery.each(inputs, function(i, item ){				
+	jQuery.each(inputs, function(i, item ){		
 		factorsSubmit.append('<option value="' + item.value + '" selected="selected">' + item.value + '</option>');	
 	});
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm	2011-03-18 14:14:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm	2011-03-22 05:49:48 +0000
@@ -74,7 +74,7 @@
 	<tr #if( $calculatedDataElement ) style="display:none" #end>
 		<td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
-			<select id="valueType" name="valueType" style="min-width:20em" onchange="changeValueType( this.value )">
+			<select id="valueType" name="valueType" style="min-width:20em">
 				<option value="int" #if( $dataElement.type == 'int' ) selected="selected" #end  onclick="enable('numberType');">$i18n.getString( "number" )</option>
 				<option value="string" #if( $dataElement.type == 'string' ) selected="selected" #end  onclick="disable('numberType');">$i18n.getString( "text" )</option>
 				<option value="bool" #if( $dataElement.type == 'bool' ) selected="selected" #end  onclick="disable('numberType');">$i18n.getString( "yes_no" )</option>
@@ -203,7 +203,7 @@
 					#foreach ( $operand in $operands )
 					<tr>
 						<td>$operand.operandName<input type="hidden" name="dataElementIds" value="$operand.operandId"></td>
-						<td><input type="text" name="factors-$i" value="$factorMap.get($operand.operandId)"/></td>
+						<td><input type="text" name="factors$i" value="$factorMap.get($operand.operandId)"/></td>
 						<td><button type="button" title="$i18n.getString('remove_all')" onclick="removeCDEDataElement( this )"><img src="../images/delete.png" alt="$i18n.getString('delete_icon')"/></button></td>
 					</tr>
 					#set($i = $i + 1)