← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18144: program validation - WIP

 

------------------------------------------------------------
revno: 18144
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-01-29 18:13:36 +0100
message:
  program validation - WIP
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html
  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/home.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.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/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html	2015-01-28 19:03:29 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html	2015-01-29 17:13:36 +0000
@@ -1,5 +1,6 @@
 <!DOCTYPE html>
-<html manifest="cacheManifest.action" ng-app="eventCapture">
+<html ng-app="eventCapture">
+<!--<html manifest="cacheManifest.action" ng-app="eventCapture">-->
     <head>
         <title>Event Capture</title>
 
@@ -59,7 +60,7 @@
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js"></script>
-        <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.appcache.js"></script>
+        <!--<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.appcache.js"></script>-->
         <script type="text/javascript" src="../dhis-web-commons/ouwt/ouwt.js"></script>
         <script type="text/javascript" src="scripts/event-capture.js"></script>
         

=== 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-01-26 17:47:09 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-01-29 17:13:36 +0000
@@ -13,6 +13,7 @@
                 storage,
                 Paginator,
                 OptionSetService,
+                ProgramValidationService,
                 ProgramFactory,
                 ProgramStageFactory,                
                 DHIS2EventFactory,
@@ -85,6 +86,7 @@
         $scope.resetOu = false;
         $scope.selectedProgram = null;
         $scope.selectedProgramStage = null;
+        $scope.programValidations = [];
         $scope.dhis2Events = [];
         $scope.currentEvent = {};
         $scope.currentEventOriginialValue = {};
@@ -109,14 +111,13 @@
                 
                 if(angular.isObject($scope.programs) && $scope.programs.length === 1){
                     $scope.selectedProgram = $scope.programs[0];
-                    //$scope.loadEvents();
-                    $scope.getPrograms();
+                    $scope.getProgramDetails();
                 }                
             });
         }    
     };
     
-    $scope.getPrograms = function(){        
+    $scope.getProgramDetails = function(){        
         
         $scope.selectedProgramStage = null;
         
@@ -128,7 +129,7 @@
         if( $scope.selectedProgram && 
                 $scope.selectedProgram.programStages && 
                 $scope.selectedProgram.programStages[0] && 
-                $scope.selectedProgram.programStages[0].id){                               
+                $scope.selectedProgram.programStages[0].id){ 
                 
             //because this is single event, take the first program stage
             ProgramStageFactory.get($scope.selectedProgram.programStages[0].id).then(function (programStage){
@@ -138,7 +139,7 @@
                 angular.forEach($scope.selectedProgramStage.programStageSections, function(section){
                     section.open = true;
                 });
-                
+
                 $scope.customForm = CustomFormService.getForProgramStage($scope.selectedProgramStage);
 
                 $scope.prStDes = [];  
@@ -185,18 +186,24 @@
                         $scope.filterText[prStDe.dataElement.id]= {};
                     }
                 });
-                
+
                 if($scope.selectedProgramStage.captureCoordinates){
                     $scope.newDhis2Event.coordinate = {};
                 }
                 $scope.newDhis2Event.eventDate = '';
-                
+
 
                 ErrorMessageService.setErrorMessages(errorMessages);
-                
-                $scope.loadEvents();
-                
-            });            
+
+                ProgramValidationService.getByProgram($scope.selectedProgram.id).then(function(pvs){
+
+                    $scope.programValidations = pvs;
+
+                    console.log('the validations:  ', $scope.programValidations);
+
+                    $scope.loadEvents();
+                });
+            });
         }
     };
         

=== 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-01-22 13:34:11 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2015-01-29 17:13:36 +0000
@@ -29,7 +29,7 @@
 dhis2.ec.store = new dhis2.storage.Store({
     name: 'dhis2ec',
     adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
-    objectStores: ['programs', 'programStages', 'geoJsons', 'optionSets', 'events']       
+    objectStores: ['programs', 'programStages', 'geoJsons', 'optionSets', 'events', 'programValidations']
 });
 
 (function($) {
@@ -149,6 +149,8 @@
     promise = promise.then( getPrograms );     
     promise = promise.then( getProgramStages );
     promise = promise.then( getOptionSets );
+    promise = promise.then( getMetaProgramValidations );
+    promise = promise.then( getProgramValidations );
     promise.done( function() {    
         //Enable ou selection after meta-data has downloaded
         $( "#orgUnitTree" ).removeClass( "disable-clicks" );
@@ -496,6 +498,117 @@
     };
 }
 
+
+function getMetaProgramValidations( programs )
+{
+    if( !programs ){
+        return;
+    }
+    
+    var def = $.Deferred();
+    
+    var programIds = [];
+    _.each( _.values( programs ), function ( program ) { 
+        if( program.id ) {
+            programIds.push( program.id );
+        }
+    });
+    
+    $.ajax({
+        url: '../api/programValidations.json',
+        type: 'GET',
+        data:'paging=false&fields=id,program[id]'
+    }).done( function(response) {          
+        var programValidations = [];
+        _.each( _.values( response.programValidations ), function ( programValidation ) { 
+            if( programValidation &&
+                programValidation.id &&
+                programValidation.program &&
+                programValidation.program.id &&
+                programIds.indexOf( programValidation.program.id ) !== -1) {
+            
+                programValidations.push( programValidation );
+            }  
+            
+        });
+        
+        def.resolve( programValidations );
+        
+    }).fail(function(){
+        def.resolve( null );
+    });
+    
+    return def.promise();    
+}
+
+function getProgramValidations( programValidations )
+{
+    if( !programValidations ){
+        return;
+    }
+    
+    var mainDef = $.Deferred();
+    var mainPromise = mainDef.promise();
+
+    var def = $.Deferred();
+    var promise = def.promise();
+
+    var builder = $.Deferred();
+    var build = builder.promise();
+
+    _.each( _.values( programValidations ), function ( programValidation ) {
+        build = build.then(function() {
+            var d = $.Deferred();
+            var p = d.promise();
+            dhis2.ec.store.get('programValidations', programValidation.id).done(function(obj) {
+                if(!obj) {
+                    promise = promise.then( getProgramValidation( programValidation.id ) );
+                }
+                d.resolve();
+            });
+
+            return p;
+        });
+    });
+
+    build.done(function() {
+        def.resolve();
+
+        promise = promise.done( function () {
+            mainDef.resolve();
+        } );
+    }).fail(function(){
+        mainDef.resolve();
+    });
+
+    builder.resolve();
+
+    return mainPromise;
+}
+
+function getProgramValidation( id )
+{
+    return function() {
+        return $.ajax( {
+            url: '../api/programValidations.json',
+            type: 'GET',
+            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,operator,displayName,rightSide,leftSide,program[id]'
+        }).done( function( response ){
+            
+            _.each( _.values( response.programValidations ), function ( programValidation ) { 
+                
+                if( programValidation &&
+                    programValidation.id &&
+                    programValidation.program &&
+                    programValidation.program.id ) {
+                
+                    dhis2.ec.store.set( 'programValidations', programValidation );
+                }
+            });
+        });
+    };
+}
+
 function uploadLocalData()
 {
     var OfflineECStorageService = angular.element('body').injector().get('OfflineECStorageService');

=== 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-01-13 22:47:45 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2015-01-29 17:13:36 +0000
@@ -8,7 +8,7 @@
     var store = new dhis2.storage.Store({
         name: 'dhis2ec',
         adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
-        objectStores: ['programs', 'programStages', 'geoJsons', 'optionSets', 'events']
+        objectStores: ['programs', 'programStages', 'geoJsons', 'optionSets', 'events', 'programValidations']
     });
     return{
         currentStore: store
@@ -191,6 +191,55 @@
     };        
 })
 
+/* Service to fetch and process programValidations */
+.service('ProgramValidationService', function($q, $rootScope, ECStorageService) {  
+    
+    return {        
+        get: function(uid){
+            
+            var def = $q.defer();
+            
+            ECStorageService.currentStore.open().done(function(){
+                ECStorageService.currentStore.get('programValidations', uid).done(function(pv){                    
+                    $rootScope.$apply(function(){
+                        def.resolve(pv);
+                    });
+                });
+            });                        
+            return def.promise;
+        },
+        getByProgram: function(program){
+            var def = $q.defer();
+            var programValidations = [];
+            
+            ECStorageService.currentStore.open().done(function(){
+                ECStorageService.currentStore.getAll('programValidations').done(function(pvs){   
+                    angular.forEach(pvs, function(pv){
+                        if(pv.program.id === program){                            
+                            programValidations.push(pv);                               
+                        }                        
+                    });
+                    $rootScope.$apply(function(){
+                        def.resolve(programValidations);
+                    });
+                });                
+            });            
+            return def.promise;
+        },
+        getExpression: function(str){
+            if( !str ){
+                return null;
+            }
+            
+            var expression = str.substring(1, str.length-1);
+            
+            if(expression){
+                
+            }
+        }
+    };        
+})
+
 /* factory for handling events */
 .factory('DHIS2EventFactory', function($http, $q, ECStorageService, $rootScope) {   
     

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html	2015-01-27 14:40:27 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html	2015-01-29 17:13:36 +0000
@@ -38,7 +38,7 @@
                             name="programId" 
                             ng-model="selectedProgram" 
                             ng-options="program as program.name for program in programs | orderBy: 'name'" 
-                            ng-change="getPrograms()"
+                            ng-change="getProgramDetails()"
                             ng-disabled="eventRegistration || editingEventInFull || editingEventInGrid">
                         <option value="">{{'please_select'| translate}}</option>
                     </select>      

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-01-26 09:43:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-01-29 17:13:36 +0000
@@ -8,7 +8,7 @@
     var store = new dhis2.storage.Store({
         name: "dhis2tc",
         adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
-        objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets']
+        objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations']
     });
     return{
         currentStore: store
@@ -213,6 +213,44 @@
     };    
 })
 
+/* Factory to fetch programValidations */
+.factory('ProgramValidationFactory', function($q, $rootScope, ECStorageService) {  
+    
+    return {        
+        get: function(uid){
+            
+            var def = $q.defer();
+            
+            ECStorageService.currentStore.open().done(function(){
+                ECStorageService.currentStore.get('programValidations', uid).done(function(pv){                    
+                    $rootScope.$apply(function(){
+                        def.resolve(pv);
+                    });
+                });
+            });                        
+            return def.promise;
+        },
+        getByProgram: function(program){
+            var def = $q.defer();
+            var programValidations = [];
+            
+            TCStorageService.currentStore.open().done(function(){
+                TCStorageService.currentStore.getAll('programValidations').done(function(pvs){   
+                    angular.forEach(pvs, function(pv){
+                        if(pv.program.id === program){                            
+                            programValidations.push(pv);                               
+                        }                        
+                    });
+                    $rootScope.$apply(function(){
+                        def.resolve(programValidations);
+                    });
+                });                
+            });            
+            return def.promise;
+        }
+    };        
+})
+
 /*Orgunit service for local db */
 .service('OrgUnitService', function($window, $q){
     
@@ -1264,4 +1302,4 @@
             return e;
         }
     }; 
-});
\ No newline at end of file
+});

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2015-01-05 16:25:01 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2015-01-29 17:13:36 +0000
@@ -26,7 +26,7 @@
 dhis2.tc.store = new dhis2.storage.Store({
     name: 'dhis2tc',
     adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
-    objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets']      
+    objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations']      
 });
 
 (function($) {
@@ -165,6 +165,8 @@
     promise = promise.then( getOptionSetsForDataElements );
     promise = promise.then( getTrackedEntityAttributes );
     promise = promise.then( getOptionSetsForAttributes );
+    promise = promise.then( getMetaProgramValidations );
+    promise = promise.then( getProgramValidations );
     promise = promise.then( getMetaTrackedEntityForms );
     promise = promise.then( getTrackedEntityForms );        
     promise.done(function() {
@@ -608,10 +610,131 @@
     };
 }
 
-
-function getMetaTrackedEntityForms()
-{
-    var def = $.Deferred();
+function getMetaProgramValidations( programs )
+{
+    if( !programs ){
+        return;
+    }
+    
+    var def = $.Deferred();
+    
+    var programIds = [];
+    _.each( _.values( programs ), function ( program ) { 
+        if( program.id ) {
+            programIds.push( program.id );
+        }
+    });
+    
+    $.ajax({
+        url: '../api/programValidations.json',
+        type: 'GET',
+        data:'paging=false&fields=id,program[id]'
+    }).done( function(response) {          
+        var programValidations = [];
+        _.each( _.values( response.programValidations ), function ( programValidation ) { 
+            if( programValidation &&
+                programValidation.id &&
+                programValidation.program &&
+                programValidation.program.id &&
+                programIds.indexOf( programValidation.program.id ) !== -1) {
+            
+                programValidations.push( programValidation );
+            }  
+            
+        });
+        
+        def.resolve( {programValidations: programValidations, programs: programs} );
+        
+    }).fail(function(){
+        def.resolve( null );
+    });
+    
+    return def.promise();    
+}
+
+function getProgramValidations( data )
+{
+    if( !data || !data.programValidations ){
+        return;
+    }
+    
+    var mainDef = $.Deferred();
+    var mainPromise = mainDef.promise();
+
+    var def = $.Deferred();
+    var promise = def.promise();
+
+    var builder = $.Deferred();
+    var build = builder.promise();
+
+    _.each( _.values( data.programValidations ), function ( programValidation ) {
+        build = build.then(function() {
+            var d = $.Deferred();
+            var p = d.promise();
+            dhis2.tc.store.get('programValidations', programValidation.id).done(function(obj) {
+                if(!obj) {
+                    promise = promise.then( getProgramValidation( programValidation.id ) );
+                }
+                d.resolve();
+            });
+
+            return p;
+        });
+    });
+
+    build.done(function() {
+        def.resolve();
+
+        promise = promise.done( function () {
+            mainDef.resolve( data.programs );
+        } );
+    }).fail(function(){
+        mainDef.resolve( null );
+    });
+
+    builder.resolve();
+
+    return mainPromise;
+}
+
+function getProgramValidation( id )
+{
+    return function() {
+        return $.ajax( {
+            url: '../api/programValidations.json',
+            type: 'GET',
+            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,operator,displayName,rightSide,leftSide,program[id]'
+        }).done( function( response ){
+            
+            _.each( _.values( response.programValidations ), function ( programValidation ) { 
+                
+                if( programValidation &&
+                    programValidation.id &&
+                    programValidation.program &&
+                    programValidation.program.id ) {
+                
+                    dhis2.tc.store.set( 'programValidations', programValidation );
+                }
+            });
+        });
+    };
+}
+
+function getMetaTrackedEntityForms( programs )
+{
+	
+    if( !programs ){
+        return;
+    }
+    
+    var def = $.Deferred();
+    
+    var programIds = [];
+    _.each( _.values( programs ), function ( program ) { 
+        if( program.id ) {
+            programIds.push( program.id );
+        }
+    });
 
     $.ajax({
         url: '../api/trackedEntityForms.json',
@@ -623,7 +746,8 @@
             if( trackedEntityForm &&
                 trackedEntityForm.id &&
                 trackedEntityForm.program &&
-                trackedEntityForm.program.id ) {
+                trackedEntityForm.program.id && 
+                programIds.indexOf( trackedEntityForm.program.id ) !== -1) {
             
                 trackedEntityForms.push( trackedEntityForm );
             }  
@@ -707,4 +831,4 @@
             });
         });
     };
-}
\ No newline at end of file
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js	2014-12-16 15:44:11 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js	2015-01-29 17:13:36 +0000
@@ -3,16 +3,6 @@
 /* Controllers */
 var d2Controllers = angular.module('d2Controllers', [])
 
-//Controller for header page
-.controller('HeaderController',
-        function($scope,                
-                DHIS2URL) {
-    
-    $scope.home = function(){        
-        window.location = DHIS2URL;
-    };    
-})
-
 //Controller for column show/hide
 .controller('ColumnDisplayController', 
     function($scope,