← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17697: Added support for defining number of decimas per indicator in analysis output

 

------------------------------------------------------------
revno: 17697
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-12-13 11:38:39 +0100
message:
  Added support for defining number of decimas per indicator in analysis output
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/AddIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/UpdateIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateIndicatorForm.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/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2014-09-15 20:06:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2014-12-13 10:38:39 +0000
@@ -63,6 +63,11 @@
 
     private boolean annualized;
 
+    /**
+     * Number of decimals to use for indicator value, null implies default.
+     */
+    private Integer decimals;
+
     private IndicatorType indicatorType;
 
     private String numerator;
@@ -156,6 +161,11 @@
     {
         return explodedDenominator != null ? explodedDenominator : denominator;
     }
+    
+    public boolean hasDecimals()
+    {
+        return decimals != null && decimals >= 0;
+    }
 
     // -------------------------------------------------------------------------
     // Getters and setters
@@ -182,6 +192,19 @@
     }
 
     @JsonProperty
+    @JsonView( {DetailedView.class, ExportView.class} )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    public Integer getDecimals()
+    {
+        return decimals;
+    }
+
+    public void setDecimals( Integer decimals )
+    {
+        this.decimals = decimals;
+    }
+
+    @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-11-30 15:45:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-12-13 10:38:39 +0000
@@ -320,9 +320,11 @@
 
                         row.add( indicatorIndex, new DimensionItem( INDICATOR_DIM_ID, indicator ) );
 
+                        Double roundedValue = indicator.hasDecimals() ? MathUtils.getRounded( value, indicator.getDecimals() ) : MathUtils.getRounded( value );
+                        
                         grid.addRow();
                         grid.addValues( DimensionItem.getItemIdentifiers( row ) );
-                        grid.addValue( params.isSkipRounding() ? value : MathUtils.getRounded( value ) );
+                        grid.addValue( params.isSkipRounding() ? value : roundedValue );
                     }
                 }
             }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml	2014-09-15 20:06:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml	2014-12-13 10:38:39 +0000
@@ -22,6 +22,8 @@
     <property name="description" type="text" />
 
     <property name="annualized" column="annualized" not-null="true" />
+    
+    <property name="decimals" />
 
     <many-to-one name="indicatorType" class="org.hisp.dhis.indicator.IndicatorType" column="indicatortypeid"
       foreign-key="fk_indicator_indicatortypeid" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/AddIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/AddIndicatorAction.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/AddIndicatorAction.java	2014-12-13 10:38:39 +0000
@@ -32,6 +32,7 @@
 import java.util.HashSet;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.attribute.AttributeService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
@@ -112,6 +113,13 @@
     {
         this.annualized = annualized;
     }
+    
+    private Integer decimals;
+
+    public void setDecimals( Integer decimals )
+    {
+        this.decimals = decimals;
+    }
 
     private Integer indicatorTypeId;
 
@@ -185,15 +193,8 @@
     {
         IndicatorType indicatorType = indicatorService.getIndicatorType( indicatorTypeId );
 
-        if ( code != null && code.trim().length() == 0 )
-        {
-            code = null;
-        }
-
-        if ( description != null && description.trim().length() == 0 )
-        {
-            description = null;
-        }
+        code = StringUtils.trimToNull( code );
+        description = StringUtils.trimToNull( description );
 
         MapLegendSet legendSet = mappingService.getMapLegendSet( selectedLegendSetId );
         
@@ -204,6 +205,7 @@
         indicator.setCode( code );
         indicator.setDescription( description );
         indicator.setAnnualized( annualized );
+        indicator.setDecimals( decimals );
         indicator.setIndicatorType( indicatorType );
         indicator.setLegendSet( legendSet );
         indicator.setUrl( url );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/UpdateIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/UpdateIndicatorAction.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/UpdateIndicatorAction.java	2014-12-13 10:38:39 +0000
@@ -31,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.attribute.AttributeService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
@@ -120,6 +121,13 @@
         this.annualized = annualized;
     }
 
+    private Integer decimals;
+
+    public void setDecimals( Integer decimals )
+    {
+        this.decimals = decimals;
+    }
+
     private Integer indicatorTypeId;
 
     public void setIndicatorTypeId( Integer indicatorTypeId )
@@ -203,21 +211,15 @@
 
         MapLegendSet legendSet = mappingService.getMapLegendSet( selectedLegendSetId );
         
-        if ( code != null && code.trim().length() == 0 )
-        {
-            code = null;
-        }
-
-        if ( description != null && description.trim().length() == 0 )
-        {
-            description = null;
-        }
+        code = StringUtils.trimToNull( code );
+        description = StringUtils.trimToNull( description );
 
         indicator.setName( name );
         indicator.setShortName( shortName );
         indicator.setCode( code );
         indicator.setDescription( description );
         indicator.setAnnualized( annualized );
+        indicator.setDecimals( decimals );
         indicator.setIndicatorType( indicatorType );
         indicator.setLegendSet( legendSet );
         indicator.setUrl( url );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2014-11-18 12:00:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2014-12-13 10:38:39 +0000
@@ -237,4 +237,5 @@
 intro_category_option_combo = View and edit data element category option combos. Category Option Combo are fine-grained break-downs of catagory.
 edit_data_element_category_option_combo = Edit data element category option combo
 average_sum_in_org_unit_hierarchy=Average (sum in org unit hierarchy)
-approve_data=Approve data
\ No newline at end of file
+approve_data=Approve data
+decimals_in_data_output=Decimals in data output
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm	2014-04-22 16:33:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addIndicatorForm.vm	2014-12-13 10:38:39 +0000
@@ -31,7 +31,7 @@
 		<th colspan="2">$i18n.getString( "details" )</th>
 	</tr>
 	<tr>
-		<td style="width:120px"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+		<td style="width:140px"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td><input type="text" id="name" name="name" onchange="nameChanged()" /></td>
 	</tr>
 	<tr>
@@ -56,10 +56,24 @@
 		</td>
 	</tr>
 	<tr>
+		<td><label for="decimals">$i18n.getString( "decimals_in_data_output" )</label></td>
+		<td>
+			<select id="decimals" name="decimals">
+				<option>[$i18n.getString( "default" )]</option>
+				<option value="0">0</option>
+				<option value="1">1</option>
+				<option value="2">2</option>
+				<option value="3">3</option>
+				<option value="4">4</option>
+				<option value="5">5</option>
+			</select>
+		</td>
+	</tr>
+	<tr>
 		<td><label for="indicatorTypeId">$i18n.getString( "indicator_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
 			<select id="indicatorTypeId" name="indicatorTypeId" onchange='indicatorTypeChanged();'>
-				<option value="">[ $i18n.getString('select') ]</option>
+				<option value="">[$i18n.getString('select')]</option>
 			#foreach( $indicatorType in $indicatorTypes )
 				<option value="$indicatorType.id" number="$indicatorType.number">$encoder.htmlEncode( $indicatorType.name )</option>
 			#end
@@ -87,7 +101,7 @@
 
 <table>
 	<tr>
-		<td style="width:120px"></td>
+		<td style="width:140px"></td>
 		<td>
 			<input type="button" value="$i18n.getString( 'edit_numerator' )" onclick="indicatorNumeratorForm()" style="width:200px"/>
 			<input type="hidden" id="numerator" name="numerator"/>
@@ -118,7 +132,7 @@
 		<td><label>$encoder.htmlEncode( $groupSet.name )</label></td>			
 		<td>
 			<select id="selectedGroups" name="selectedGroups">
-				<option value="-1">[ $i18n.getString( "select_group" ) ]</option>
+				<option value="-1">[$i18n.getString( "select_group" )]</option>
 				#foreach ( $group in $groupSet.getSortedGroups() )
 				<option value="$group.id">$group.name</option>
 				#end

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateIndicatorForm.vm	2014-04-22 16:33:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateIndicatorForm.vm	2014-12-13 10:38:39 +0000
@@ -30,7 +30,7 @@
 		<th colspan="2">$i18n.getString( "details" )</th>
 	</tr>
 	<tr>
-		<td style="width:120px"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+		<td style="width:140px"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td><input type="text" id="name" name="name" value="$encoder.htmlEncode( $indicator.name )"></td>
 	</tr>
 	<tr>
@@ -55,6 +55,20 @@
 		</td>
 	</tr>
 	<tr>
+		<td><label for="decimals">$i18n.getString( "decimals_in_data_output" )</label></td>
+		<td>
+			<select id="decimals" name="decimals">
+				<option>[$i18n.getString( "default" )]</option>
+				<option value="0"#if( $indicator.decimals == 0 ) selected="selected"#end>0</option>
+				<option value="1"#if( $indicator.decimals == 1 ) selected="selected"#end>1</option>
+				<option value="2"#if( $indicator.decimals == 2 ) selected="selected"#end>2</option>
+				<option value="3"#if( $indicator.decimals == 3 ) selected="selected"#end>3</option>
+				<option value="4"#if( $indicator.decimals == 4 ) selected="selected"#end>4</option>
+				<option value="5"#if( $indicator.decimals == 5 ) selected="selected"#end>5</option>
+			</select>
+		</td>
+	</tr>
+	<tr>
 		<td><label for="indicatorTypeId">$i18n.getString( "indicator_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
 			<select id="indicatorTypeId" name="indicatorTypeId" onchange='indicatorTypeChanged();'>
@@ -85,7 +99,7 @@
 
 <table>
 	<tr>
-		<td style="width:120px"></td>
+		<td style="width:140px"></td>
 		<td>
 			<input type="button" value="$i18n.getString( 'edit_numerator' )" onclick="indicatorNumeratorForm()" style="width:200px"/>
 			<input type="hidden" id="numerator" name="numerator" value="$!indicator.numerator"/>
@@ -115,7 +129,7 @@
 		<td><label>$encoder.htmlEncode( $groupSet.name )</label></td>
 		<td>
 			<select id="indicatorGroups" name="indicatorGroups">
-				<option value="-1">[ $i18n.getString( "select_group" ) ]</option>
+				<option value="-1">[$i18n.getString( "select_group" )]</option>
 				#foreach ( $group in $groupSet.getSortedGroups() )
 				<option value="$group.id" #if( $group.members.contains( $indicator ) ) selected="selected" #end>$group.name</option>
 				#end