← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19430: event-capture: skip logic. Skipped input fields are hidden in default forms but disabled in custo...

 

------------------------------------------------------------
revno: 19430
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-06-17 13:50:16 +0200
message:
  event-capture: skip logic. Skipped input fields are hidden in default forms but disabled in custom forms.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html
  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-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-06-15 11:04:20 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-06-17 11:50:16 +0000
@@ -7,7 +7,8 @@
 
 //Controller for settings page
 .controller('MainController',
-        function($scope,
+        function($rootScope,
+                $scope,
                 $modal,
                 $timeout,
                 $anchorScroll,
@@ -29,11 +30,14 @@
                 CurrentSelection,
                 ModalService,
                 DialogService,
-                AuthorityService) {
+                AuthorityService,
+                TrackerRulesExecutionService) {
     //selected org unit
     $scope.selectedOrgUnit = '';
     $scope.treeLoaded = false;    
-    $scope.selectedSection = {id: 'ALL'};
+    $scope.selectedSection = {id: 'ALL'};    
+    $rootScope.ruleeffects = {};
+    $scope.hiddenFields = {};
     
     $scope.calendarSetting = CalendarService.getSetting();
     
@@ -300,7 +304,7 @@
                 }                
                 $scope.eventFetched = true;
             });
-        }        
+        }
     };    
     
     $scope.jumpToPage = function(){
@@ -886,6 +890,73 @@
         $scope.infiniteScroll.currentOptions += $scope.infiniteScroll.optionsToAdd;
     };
     
+    //listen for rule effect changes
+    $scope.$on('ruleeffectsupdated', function(event, args) {
+        if($rootScope.ruleeffects[args.event]) {
+            //Establish which event was affected:
+            var affectedEvent = $scope.currentEvent;
+            //In most cases the updated effects apply to the current event. In case the affected event is not the current event, fetch the correct event to affect:
+            if(args.event !== affectedEvent.event) {
+                angular.forEach($scope.currentStageEvents, function(searchedEvent) {
+                    if(searchedEvent.event === args.event) {
+                        affectedEvent = searchedEvent;
+                    }
+                });
+            }
+            
+            angular.forEach($rootScope.ruleeffects[args.event], function(effect) {
+                if( effect.dataElement ) {
+                    //in the data entry controller we only care about the "hidefield" actions
+                    if(effect.action === "HIDEFIELD") {
+                        if(effect.dataElement) {
+                            if(effect.ineffect && affectedEvent[effect.dataElement.id]) {
+                                //If a field is going to be hidden, but contains a value, we need to take action;
+                                if(effect.content) {
+                                    //TODO: Alerts is going to be replaced with a proper display mecanism.
+                                    alert(effect.content);
+                                }
+                                else {
+                                    //TODO: Alerts is going to be replaced with a proper display mecanism.
+                                    alert($scope.prStDes[effect.dataElement.id].dataElement.formName + "Was blanked out and hidden by your last action");
+                                }
+
+                                //Blank out the value:
+                                affectedEvent[effect.dataElement.id] = "";
+                                $scope.saveDatavalueForEvent($scope.prStDes[effect.dataElement.id],null,affectedEvent);
+                            }
+
+                            $scope.hiddenFields[effect.dataElement.id] = effect.ineffect;
+                        }
+                        else {
+                            $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have a dataelement defined");
+                        }
+                    }
+                }
+            });
+        }
+    });
+    
+    $scope.executeRules = function() {
+        $scope.eventsByStage = [];
+        $scope.eventsByStage[$scope.selectedProgramStage.id] = [$scope.currentEvent];
+        TrackerRulesExecutionService.executeRules($scope.selectedProgram.id,$scope.currentEvent,$scope.eventsByStage,$scope.prStDes,null);
+    };
+    
+    //check if field is hidden
+    $scope.isHidden = function(id) {
+        //In case the field contains a value, we cant hide it. 
+        //If we hid a field with a value, it would falsely seem the user was aware that the value was entered in the UI.
+        if($scope.currentEvent[id]) {
+           return false; 
+        }
+        else {
+            return $scope.hiddenFields[id];
+        }
+    }; 
+    
+    $scope.saveDatavalue = function(){
+        $scope.executeRules();
+    };
     /*$scope.getInputNotifcationClass = function(id, custom, event){
         var style = "";
         if($scope.currentElement.id && $scope.currentElement.id === id){            

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2015-06-16 12:17:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2015-06-17 11:50:16 +0000
@@ -497,7 +497,7 @@
 
 function getProgramRuleVariables( programRuleVariables )
 {
-    return getD2Objects( programRuleVariables, 'programRuleVariables', '../api/programRuleVariables', 'fields=id,name,displayName,programRuleVariableSourceType,program[id],dataElement[id]');
+    return getD2Objects( programRuleVariables, 'programRuleVariables', '../api/programRuleVariables', 'fields=id,name,displayName,programRuleVariableSourceType,program[id],programStage[id],dataElement[id]');
 }
 
 function getD2MetaObject( programs, objNames, url, filter )

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2015-06-16 09:57:57 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2015-06-17 11:50:16 +0000
@@ -399,6 +399,80 @@
     };    
 })
 
+    /* Returns a function for getting rules for a specific program */
+.factory('TrackerRulesFactory', function($q,$rootScope,ECStorageService){
+    return{
+        getOldProgramStageRules :function(programUid, programstageUid) {
+            var rules = this.getProgramRules(programUid);
+            
+            //Only keep the rules actually matching the program stage we are in, or rules with no program stage defined.
+            var programStageRules = [];
+            angular.forEach(rules, function(rule) {
+                if(rule.programstage_uid == null || rule.programstage_uid == "" || rule.programstage_uid == programstageUid) {
+                   programStageRules.push(rule);
+                }
+            });
+            
+            return programStageRules;
+        },
+        
+        getProgramStageRules : function(programUid, programStageUid){
+            var def = $q.defer();
+            
+            ECStorageService.currentStore.open().done(function(){
+                ECStorageService.currentStore.getAll('programRules').done(function(rules){                    
+                    //The array will ultimately be returned to the caller.
+                    var programRulesArray = [];
+                    //Loop through and add the rules belonging to this program and program stage
+                    angular.forEach(rules, function(rule){
+                       if(rule.program.id == programUid) {
+                           if(!rule.programStage || !rule.programStage.id || rule.programStage.id == programStageUid) {
+                                programRulesArray.push(rule);
+                            }
+                       }
+                    });
+
+                    $rootScope.$apply(function(){
+                        def.resolve(programRulesArray);
+                    });
+                });     
+            });
+                        
+            return def.promise;
+        }
+    };  
+})
+
+/* Returns user defined variable names and their corresponding UIDs and types for a specific program */
+.factory('TrackerRuleVariableFactory', function($rootScope, $q, ECStorageService){
+    return{
+        getProgramRuleVariables : function(programUid){
+            var def = $q.defer();
+
+            ECStorageService.currentStore.open().done(function(){
+                
+                ECStorageService.currentStore.getAll('programRuleVariables').done(function(variables){
+                    
+                    //The array will ultimately be returned to the caller.
+                    var programRuleVariablesArray = [];
+                    //Loop through and add the variables belonging to this program
+                    angular.forEach(variables, function(variable){
+                       if(variable.program.id == programUid) {
+                            programRuleVariablesArray.push(variable);
+                       }
+                    });
+
+                    $rootScope.$apply(function(){
+                        def.resolve(programRuleVariablesArray);
+                    });
+                });
+            });
+                        
+            return def.promise;
+        }
+    };
+})
+
 /* service for dealing with events */
 .service('DHIS2EventService', function(){
     return {     

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-06-15 11:04:20 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-06-17 11:50:16 +0000
@@ -68,7 +68,7 @@
                     </div>
                 </td>                                                            
             </tr>            
-            <tr ng-repeat="eventGridColumn in eventGridColumns" ng-if="eventGridColumn.id !== 'comment' && eventGridColumn.id !== 'uid' && eventGridColumn.id !== 'event_date'">
+            <tr ng-repeat="eventGridColumn in eventGridColumns" ng-if="eventGridColumn.id !== 'comment' && eventGridColumn.id !== 'uid' && eventGridColumn.id !== 'event_date' && !isHidden(eventGridColumn.id)">
                 <td >
                     {{eventGridColumn.name}}<span ng-if="eventGridColumn.compulsory" class="required">*</span>
                 </td>
@@ -81,6 +81,7 @@
                                            ng-required={{eventGridColumn.compulsory}}
                                            name="foo" 
                                            input-field-id={{eventGridColumn.id}}
+                                           on-select="saveDatavalue()" 
                                            class='form-control'>
                                     <ui-select-match allow-clear="true" class="form-control" placeholder="{{'select_or_search' | translate}}">{{$select.selected.name  || $select.selected}}</ui-select-match>
                                     <ui-select-choices  infinite-scroll="addMoreOptions()"
@@ -95,6 +96,7 @@
                                     <input type="radio" 
                                            name="foo"  
                                            input-field-id={{eventGridColumn.id}}   
+                                           ng-change="saveDatavalue()" 
                                            ng-required={{eventGridColumn.compulsory}}
                                            ng-model="currentEvent[eventGridColumn.id]"
                                            value=""> {{'no_value' | translate}}<br>
@@ -103,6 +105,7 @@
                                     <input type="radio" 
                                            name={{eventGridColumn.id}}   
                                            input-field-id={{eventGridColumn.id}}    
+                                           ng-change="saveDatavalue()" 
                                            ng-required={{eventGridColumn.compulsory}}
                                            ng-model="currentEvent[eventGridColumn.id]"
                                            value={{option.name}}> {{option.name}}<br>                                        
@@ -118,6 +121,7 @@
                                        ng-required={{eventGridColumn.compulsory}}
                                        name="foo" 
                                        input-field-id={{eventGridColumn.id}} 
+                                       ng-blur="saveDatavalue()" 
                                        class="form-control"/>
                             </div>
                             <div ng-switch-when="string">     
@@ -127,6 +131,7 @@
                                         ng-required={{eventGridColumn.compulsory}}
                                         name="foo" 
                                         input-field-id={{eventGridColumn.id}} 
+                                        ng-blur="saveDatavalue()" 
                                         class="form-control">
                                     </textarea>
                                 </span>
@@ -136,6 +141,7 @@
                                         ng-required={{eventGridColumn.compulsory}}
                                         name="foo" 
                                         input-field-id={{eventGridColumn.id}} 
+                                        ng-blur="saveDatavalue()" 
                                         class="form-control"/>                  
                                 </span>                                              
                             </div>
@@ -144,6 +150,7 @@
                                         ng-required={{eventGridColumn.compulsory}}
                                         name="foo" 
                                         input-field-id={{eventGridColumn.id}} 
+                                        ng-change="saveDatavalue()" 
                                         class="form-control">
                                 <option value="">{{'please_select'| translate}}</option>                        
                                 <option value="false">{{'no'| translate}}</option>
@@ -160,6 +167,7 @@
                                        ng-required={{eventGridColumn.compulsory}}
                                        name="foo" 
                                        input-field-id={{eventGridColumn.id}} 
+                                       blur-or-change="saveDatavalue()" 
                                        class="form-control">
                             </div>
                             <div ng-switch-when="trueOnly">
@@ -167,7 +175,8 @@
                                        ng-model="currentEvent[eventGridColumn.id]"                                                               
                                        ng-required={{eventGridColumn.compulsory}}
                                        name="foo" 
-                                       input-field-id={{eventGridColumn.id}} />
+                                       input-field-id={{eventGridColumn.id}} 
+                                       ng-change="saveDatavalue()" />
                             </div>
                             <div ng-switch-default>
                                 <input type="text"                                             
@@ -175,6 +184,7 @@
                                     ng-required={{eventGridColumn.compulsory}}
                                     name="foo" 
                                     input-field-id={{eventGridColumn.id}} 
+                                    ng-blur="saveDatavalue()" 
                                     class="form-control"> 
                             </div>
                         </div>                        
@@ -269,7 +279,7 @@
                 </tr>                        
             </thead>
             <tbody>       
-                <tr ng-repeat="de in section.programStageDataElements">
+                <tr ng-repeat="de in section.programStageDataElements" ng-if="!isHidden(de.dataElement.id)">
                     <td >
                         {{prStDes[de.dataElement.id].dataElement.formName ? prStDes[de.dataElement.id].dataElement.formName : prStDes[de.dataElement.id].dataElement.name}}<span ng-if="prStDes[de.dataElement.id].compulsory" class="required">*</span>                        </td>
                     <td >
@@ -280,7 +290,8 @@
                                                theme="select2" 
                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                ng-app=""name="foo" 
-                                               ng-app=""input-field-id={{de.dataElement.id}}
+                                               ng-app=""input-field-id={{de.dataElement.id}} 
+                                               on-select="saveDataValue()"
                                                class='form-control'>
                                         <ui-select-match allow-clear="true" class="form-control" placeholder="{{'select_or_search' | translate}}">{{$select.selected.name || $select.selected}}</ui-select-match>
                                         <ui-select-choices  infinite-scroll="addMoreOptions()"
@@ -295,6 +306,7 @@
                                         <input type="radio" 
                                                name="foo"  
                                                input-field-id={{de.dataElement.id}} 
+                                               ng-change="saveDatavalue()" 
                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                ng-model="currentEvent[de.dataElement.id]"
                                                value="">{{'no_value' | translate}}<br>
@@ -303,6 +315,7 @@
                                         <input type="radio" 
                                                name={{de.dataElement.id}}   
                                                input-field-id={{de.dataElement.id}} 
+                                               ng-change="saveDatavalue()" 
                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                ng-model="currentEvent[de.dataElement.id]"
                                                value={{option.name}}> {{option.name}}<br>                                        
@@ -318,6 +331,7 @@
                                            ng-required={{prStDes[de.dataElement.id].compulsory}}
                                            name="foo" 
                                            input-field-id={{de.dataElement.id}} 
+                                           ng-blur="saveDatavalue()" 
                                            class="form-control"/>
                                 </div>
                                 <div ng-switch-when="string">
@@ -327,6 +341,7 @@
                                             ng-required={{prStDes[de.dataElement.id].compulsory}}
                                             name="foo" 
                                             input-field-id={{de.dataElement.id}} 
+                                            ng-blur="saveDatavalue()" 
                                             class="form-control">
                                         </textarea>
                                     </span>
@@ -336,6 +351,7 @@
                                             ng-required={{prStDes[de.dataElement.id].compulsory}}
                                             name="foo" 
                                             input-field-id={{de.dataElement.id}} 
+                                            ng-blur="saveDatavalue()" 
                                             class="form-control">                  
                                     </span>
                                 </div>
@@ -344,6 +360,7 @@
                                             ng-required={{prStDes[de.dataElement.id].compulsory}}
                                             name="foo" 
                                             input-field-id={{de.dataElement.id}} 
+                                            ng-change="saveDatavalue()" 
                                             class="form-control">
                                     <option value="">{{'please_select'| translate}}</option>                        
                                     <option value="false">{{'no'| translate}}</option>
@@ -360,6 +377,7 @@
                                            ng-required={{prStDes[de.dataElement.id].compulsory}}
                                            name="foo" 
                                            input-field-id={{de.dataElement.id}} 
+                                           blur-or-change="saveDatavalue()" 
                                            class="form-control"/>
                                 </div>
                                 <div ng-switch-when="trueOnly">
@@ -367,7 +385,8 @@
                                            ng-model="currentEvent[de.dataElement.id]"                                                               
                                            ng-required={{prStDes[de.dataElement.id].compulsory}}
                                            name="foo" 
-                                           input-field-id={{de.dataElement.id}}/>
+                                           input-field-id={{de.dataElement.id}}
+                                           ng-change="saveDatavalue()" />
                                 </div>
                                 <div ng-switch-default>
                                     <input type="text"                                                  
@@ -375,6 +394,7 @@
                                         ng-required={{prStDes[de.dataElement.id].compulsory}}
                                         name="foo" 
                                         input-field-id={{de.dataElement.id}} 
+                                        ng-blur="saveDatavalue()" 
                                         class="form-control"/>
                                 </div>
                             </div>

=== 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-06-17 08:54:51 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-06-17 11:50:16 +0000
@@ -280,7 +280,7 @@
                                     ' style="width:100%;" ' +
                                     ' input-field-id="' + fieldId + '"' +
                                     ' ng-class="{{getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id, true)}}" ' +
-                                    ' ng-disabled="selectedEnrollment.status===\'CANCELLED\' || selectedEnrollment.status===\'COMPLETED\' || currentEvent[uid]==\'uid\' || currentEvent.editingNotAllowed"' +
+                                    ' ng-disabled="isHidden(prStDes.' + fieldId + '.dataElement.id) || selectedEnrollment.status===\'CANCELLED\' || selectedEnrollment.status===\'COMPLETED\' || currentEvent[uid]==\'uid\' || currentEvent.editingNotAllowed"' +
                                     ' ng-required="{{prStDes.' + fieldId + '.compulsory}}" ';
 
                             if (prStDe && prStDe.dataElement && prStDe.dataElement.type) {