← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20086: Program indicator, casting zero_pos_value_count / value_count to double to allow for decimals

 

------------------------------------------------------------
revno: 20086
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-09-11 13:45:33 +0200
message:
  Program indicator, casting zero_pos_value_count / value_count to double to allow for decimals
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.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-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-09-10 19:45:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-09-11 11:45:33 +0000
@@ -733,6 +733,8 @@
      */
     private String getVariableAsSql( String var, String expression )
     {
+        final String dbl = statementBuilder.getDoubleColumnType();
+        
         if ( ProgramIndicator.VAR_EXECUTION_DATE.equals( var ) )
         {
             return "executiondate";
@@ -751,25 +753,25 @@
         }
         else if ( ProgramIndicator.VAR_VALUE_COUNT.equals( var ) )
         {
-            String sql = "nullif((";
+            String sql = "nullif(cast((";
 
             for ( String uid : ProgramIndicator.getDataElementAndAttributeIdentifiers( expression ) )
             {
                 sql += "case when " + statementBuilder.columnQuote( uid ) + " is not null then 1 else 0 end + ";
             }
 
-            return TextUtils.removeLast( sql, "+" ).trim() + "),0)";
+            return TextUtils.removeLast( sql, "+" ).trim() + ") as " + dbl + "),0)";
         }
         else if ( ProgramIndicator.VAR_ZERO_POS_VALUE_COUNT.equals( var ) )
         {
-            String sql = "nullif((";
+            String sql = "nullif(cast((";
 
             for ( String uid : ProgramIndicator.getDataElementAndAttributeIdentifiers( expression ) )
             {
                 sql += "case when " + statementBuilder.columnQuote( uid ) + " >= 0 then 1 else 0 end + ";
             }
 
-            return TextUtils.removeLast( sql, "+" ).trim() + "),0)";
+            return TextUtils.removeLast( sql, "+" ).trim() + ") as " + dbl + "),0)";
         }
 
         return null;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-09-10 19:45:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-09-11 11:45:33 +0000
@@ -498,7 +498,7 @@
         String expected = 
             "coalesce(case when \"EZq9VbPWgML\" < 0 then 0 else \"EZq9VbPWgML\" end, 0) + " +
             "coalesce(\"GCyeKSqlpdk\",0) + " +
-            "nullif((case when \"EZq9VbPWgML\" >= 0 then 1 else 0 end + case when \"GCyeKSqlpdk\" >= 0 then 1 else 0 end),0)";
+            "nullif(cast((case when \"EZq9VbPWgML\" >= 0 then 1 else 0 end + case when \"GCyeKSqlpdk\" >= 0 then 1 else 0 end) as double),0)";
         
         String expression = 
             "d2:zing(#{OXXcwl6aPCQ.EZq9VbPWgML}) + " +