← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19698: Added support for add days function in program rules

 

------------------------------------------------------------
revno: 19698
committer: Markus Bekken <markus.bekken@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-08-02 20:16:38 +0300
message:
  Added support for add days function in program rules
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.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-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-07-28 08:09:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-08-02 17:16:38 +0000
@@ -901,7 +901,7 @@
 })
 
 /* service for executing tracker rules and broadcasting results */
-.service('TrackerRulesExecutionService', function(VariableService, $rootScope, $log, $filter, orderByFilter){
+.service('TrackerRulesExecutionService', function(VariableService,DateUtils,CalendarService, $rootScope, $log, $filter, orderByFilter){
     
     var replaceVariables = function(expression, variablesHash){
         //replaces the variables in an expression with actual variable values.                
@@ -1004,7 +1004,8 @@
                                 {name:"dhis.yearsbetween",parameters:2},
                                 {name:"dhis.floor",parameters:1},
                                 {name:"dhis.modulus",parameters:2},
-                                {name:"dhis.concatenate"}];
+                                {name:"dhis.concatenate"},
+                                {name:"dhis.adddays",parameters:2}];
 
             angular.forEach(dhisFunctions, function(dhisFunction){
                 //Replace each * with a regex that matches each parameter, allowing commas only inside single quotation marks.
@@ -1075,6 +1076,15 @@
                         returnString += "'";
                         expression = expression.replace(callToThisFunction, returnString);
                     }
+                    else if(dhisFunction.name === "dhis.adddays")
+                    {
+                        var date = $filter('trimquotes')(parameters[0]);
+                        var daystoadd = $filter('trimquotes')(parameters[1]);
+                        var newdate = DateUtils.format( moment(date, CalendarService.getSetting().momentFormat).add(daystoadd, 'days') );
+                        var newdatestring = "'" + newdate + "'";
+                        //Replace the end evaluation of the dhis function:
+                        expression = expression.replace(callToThisFunction, newdatestring);
+                    }
                 });
             });
         }