← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18104: event-capture - filter those programs without program stage. Such metadata could exist if the db ...

 

------------------------------------------------------------
revno: 18104
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-01-22 14:34:11 +0100
message:
  event-capture - filter those programs without program stage. Such metadata could exist if the db is manipulated directly.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.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/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-12-17 14:21:45 +0000
+++ 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
@@ -303,19 +303,22 @@
     var build = builder.promise();
 
     _.each( _.values( programs ), function ( program ) {
-        build = build.then(function() {
-            var d = $.Deferred();
-            var p = d.promise();
-            dhis2.ec.store.get('programs', program.id).done(function(obj) {
-                if(!obj || obj.version !== program.version) {
-                    promise = promise.then( getProgram( program.id ) );
-                }
-
-                d.resolve();
+        
+        if(program.programStages && program.programStages[0].programStageDataElements){
+            build = build.then(function() {
+                var d = $.Deferred();
+                var p = d.promise();
+                dhis2.ec.store.get('programs', program.id).done(function(obj) {
+                    if(!obj || obj.version !== program.version) {
+                        promise = promise.then( getProgram( program.id ) );
+                    }
+
+                    d.resolve();
+                });
+
+                return p;
             });
-
-            return p;
-        });
+        }        
     });
 
     build.done(function() {
@@ -380,21 +383,22 @@
     var build = builder.promise();
 
     _.each( _.values( programs ), function ( program ) {
-
-        build = build.then(function() {
-            var d = $.Deferred();
-            var p = d.promise();
-            dhis2.ec.store.get('programStages', program.programStages[0].id).done(function(obj) {
-                if(!obj || obj.version !== program.programStages[0].version) {
-                    promise = promise.then( getProgramStage( program.programStages[0].id ) );
-                }
-
-                d.resolve();
+        
+        if(program.programStages){
+            build = build.then(function() {
+                var d = $.Deferred();
+                var p = d.promise();
+                dhis2.ec.store.get('programStages', program.programStages[0].id).done(function(obj) {
+                    if(!obj || obj.version !== program.programStages[0].version) {
+                        promise = promise.then( getProgramStage( program.programStages[0].id ) );
+                    }
+
+                    d.resolve();
+                });
+
+                return p;
             });
-
-            return p;
-        });
-              
+        }              
     });
 
     build.done(function() {
@@ -442,22 +446,25 @@
     var build = builder.promise();    
 
     _.each( _.values( programs ), function ( program ) {
-        _.each(_.values( program.programStages[0].programStageDataElements), function(prStDe){
-            if( prStDe.dataElement.optionSet && prStDe.dataElement.optionSet.id ){
-                build = build.then(function() {
-                    var d = $.Deferred();
-                    var p = d.promise();
-                    dhis2.ec.store.get('optionSets', prStDe.dataElement.optionSet.id).done(function(obj) {                    
-                        if(!obj || obj.version !== prStDe.dataElement.optionSet.version) {
-                            promise = promise.then( getOptionSet( prStDe.dataElement.optionSet.id ) );
-                        }
-                        d.resolve();
+        
+        if(program.programStages && program.programStages[0].programStageDataElements){
+            _.each(_.values( program.programStages[0].programStageDataElements), function(prStDe){
+                if( prStDe.dataElement && prStDe.dataElement.optionSet && prStDe.dataElement.optionSet.id ){
+                    build = build.then(function() {
+                        var d = $.Deferred();
+                        var p = d.promise();
+                        dhis2.ec.store.get('optionSets', prStDe.dataElement.optionSet.id).done(function(obj) {                    
+                            if(!obj || obj.version !== prStDe.dataElement.optionSet.version) {
+                                promise = promise.then( getOptionSet( prStDe.dataElement.optionSet.id ) );
+                            }
+                            d.resolve();
+                        });
+
+                        return p;
                     });
-
-                    return p;
-                });
-            }            
-        });                      
+                }            
+            }); 
+        }                             
     });
 
     build.done(function() {