← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20157: tracker-capture: pick right enrollment for the selected TEI

 

------------------------------------------------------------
revno: 20157
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-15 10:10:51 +0200
message:
  tracker-capture: pick right enrollment for the selected TEI
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.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-tracker-capture/components/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2015-09-11 15:16:03 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2015-09-15 08:10:51 +0000
@@ -161,14 +161,28 @@
                         //get enrollments for the selected tei
                         EnrollmentService.getByEntity($scope.selectedTeiId).then(function(response){                    
                             var enrollments = angular.isObject(response) && response.enrollments ? response.enrollments : [];
-                            var selectedEnrollment = null;
-                            if(enrollments.length === 1 && enrollments[0].status === 'ACTIVE'){
-                                selectedEnrollment = enrollments[0];
+                            var selectedEnrollment = null, backupSelectedEnrollment = null;                            
+                            if(enrollments.length === 1 ){
+                                selectedEnrollment = enrollments[0];                               
                             }
-
+                            else{
+                                if( $scope.selectedProgramId ){
+                                    angular.forEach(enrollments, function(en){
+                                        if( en.program === $scope.selectedProgramId ){
+                                            if( en.status === 'ACTIVE'){
+                                                selectedEnrollment = en;
+                                            }
+                                            else{
+                                                backupSelectedEnrollment = en;
+                                            }
+                                        }
+                                    });
+                                }                                
+                            }                            
+                            selectedEnrollment = selectedEnrollment ? selectedEnrollment : backupSelectedEnrollment;
+                            
                             ProgramFactory.getAll().then(function(programs){
                                 $scope.programs = [];
-
                                 $scope.programNames = [];  
                                 $scope.programStageNames = [];