← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17156: event capture - alwyas display option name but save option code

 

------------------------------------------------------------
revno: 17156
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-17 15:22:28 +0200
message:
  event capture - alwyas display option name but save option code
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/directives.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-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html


--
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	2014-09-23 10:48:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-10-17 13:22:28 +0000
@@ -11,7 +11,8 @@
                 $timeout,
                 storage,
                 Paginator,
-                TranslationService,                
+                TranslationService,
+                OptionSetFactory,
                 ProgramFactory,
                 ProgramStageFactory,
                 DHIS2EventFactory,       
@@ -101,6 +102,7 @@
                 
             });       
         }        
+    
     };    
         
     //get events for the selected program (and org unit)
@@ -120,142 +122,163 @@
                
         if( $scope.selectedProgram && $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){
-                
-                $scope.selectedProgramStage = programStage;   
-                
-                angular.forEach($scope.selectedProgramStage.programStageSections, function(section){
-                    section.open = true;
-                });
-
-                //$scope.customForm = CustomFormService.processCustomForm($scope.selectedProgramStage);
-                $scope.customForm = $scope.selectedProgramStage.dataEntryForm ? $scope.selectedProgramStage.dataEntryForm.htmlCode : null; 
-
-                $scope.programStageDataElements = [];  
-                $scope.eventGridColumns = [];
-                $scope.filterTypes = {};
-
-                $scope.newDhis2Event = {dataValues: []};
-                $scope.currentEvent = {dataValues: []};
-                
-                $scope.eventGridColumns.push({name: 'form_id', id: 'uid', type: 'string', compulsory: false, showFilter: false, show: true});
-                $scope.filterTypes['uid'] = 'string';                
-                
-                $scope.eventGridColumns.push({name: $scope.selectedProgramStage.reportDateDescription ? $scope.selectedProgramStage.reportDateDescription : 'incident_date', id: 'event_date', type: 'date', compulsory: false, showFilter: false, show: true});
-                $scope.filterTypes['event_date'] = 'date';
-                $scope.filterText['event_date']= {};
-
-                angular.forEach($scope.selectedProgramStage.programStageDataElements, function(prStDe){
-                    $scope.programStageDataElements[prStDe.dataElement.id] = prStDe; 
-
-                    //generate grid headers using program stage data elements
-                    //create a template for new event
-                    //for date type dataelements, filtering is based on start and end dates
-                    var dataElement = prStDe.dataElement;
-                    var name = dataElement.formName ? dataElement.formName : dataElement.name;
-                    
-                    $scope.newDhis2Event.dataValues.push({id: dataElement.id, value: ''});   
-                    if($scope.selectedProgramStage.captureCoordinates){
-                        $scope.newDhis2Event.coordinate = {};
-                    }
-                    
-                    $scope.eventGridColumns.push({name: name, id: dataElement.id, type: dataElement.type, compulsory: prStDe.compulsory, showFilter: false, show: prStDe.displayInReports});
-
-                    $scope.filterTypes[dataElement.id] = dataElement.type;
-
-                    if(dataElement.type === 'date' || dataElement.type === 'int' ){
-                        $scope.filterText[dataElement.id]= {};
-                    }
-
-                });           
-
-                //Load events for the selected program stage and orgunit
-                DHIS2EventFactory.getByStage($scope.selectedOrgUnit.id, $scope.selectedProgramStage.id, $scope.pager ).then(function(data){
-
-                    if(data.events){
-                        $scope.eventLength = data.events.length;
-                    }                
-
-                    $scope.dhis2Events = data.events; 
-
-                    if( data.pager ){
-                        $scope.pager = data.pager;
-                        $scope.pager.toolBarDisplay = 5;
-
-                        Paginator.setPage($scope.pager.page);
-                        Paginator.setPageCount($scope.pager.pageCount);
-                        Paginator.setPageSize($scope.pager.pageSize);
-                        Paginator.setItemCount($scope.pager.total);                    
-                    }
-
-                    //process event list for easier tabular sorting
-                    if( angular.isObject( $scope.dhis2Events ) ) {
-
-                        for(var i=0; i < $scope.dhis2Events.length; i++){  
-                            
-                            if($scope.dhis2Events[i].notes && !$scope.noteExists){
-                                $scope.noteExists = true;
-                            }
-
-                            //check if event is empty
-                            if(!angular.isUndefined($scope.dhis2Events[i].dataValues)){                            
-
-                                angular.forEach($scope.dhis2Events[i].dataValues, function(dataValue){
-
-                                    //converting event.datavalues[i].datavalue.dataelement = value to
-                                    //event[dataElement] = value for easier grid display.                                
-                                    if($scope.programStageDataElements[dataValue.dataElement]){                                    
-
-                                        var dataElement = $scope.programStageDataElements[dataValue.dataElement].dataElement;
-
-                                        if(angular.isObject(dataElement)){                               
-
-                                            //converting int string value to integer for proper sorting.
-                                            if(dataElement.type == 'int'){
-                                                if( !isNaN(parseInt(dataValue.value)) ){
-                                                    dataValue.value = parseInt(dataValue.value);
-                                                }
-                                                else{
-                                                    dataValue.value = '';
-                                                }                                        
-                                            }
-                                            else if( dataElement.type == 'trueOnly'){
-                                                if(dataValue.value == 'true'){
-                                                    dataValue.value = true;
-                                                }
-                                                else{
-                                                    dataValue.value = false;
-                                                }
+            $scope.optionSets = [];
+            $scope.optionNamesByCode = new Object();
+            $scope.optionCodesByName = new Object();
+            OptionSetFactory.getAll().then(function(optionSets){
+                
+                angular.forEach(optionSets, function(optionSet){
+                    //$scope.optionSets[optionSet.id] = optionSet;
+                    angular.forEach(optionSet.options, function(option){
+                        if(option.name && option.code){
+                            $scope.optionNamesByCode[ '"' + option.code + '"'] = option.name;
+                            $scope.optionCodesByName[ '"' + option.name + '"'] = option.code;
+                        }                       
+                    });
+                    $scope.optionSets[optionSet.id] = optionSet;
+                });                
+                
+                //because this is single event, take the first program stage
+                ProgramStageFactory.get($scope.selectedProgram.programStages[0].id).then(function (programStage){
+
+                    $scope.selectedProgramStage = programStage;   
+
+                    angular.forEach($scope.selectedProgramStage.programStageSections, function(section){
+                        section.open = true;
+                    });
+
+                    //$scope.customForm = CustomFormService.processCustomForm($scope.selectedProgramStage);
+                    $scope.customForm = $scope.selectedProgramStage.dataEntryForm ? $scope.selectedProgramStage.dataEntryForm.htmlCode : null; 
+
+                    $scope.prStDes = [];  
+                    $scope.eventGridColumns = [];
+                    $scope.filterTypes = {};
+
+                    $scope.newDhis2Event = {dataValues: []};
+                    $scope.currentEvent = {dataValues: []};
+
+                    $scope.eventGridColumns.push({name: 'form_id', id: 'uid', type: 'string', compulsory: false, showFilter: false, show: true});
+                    $scope.filterTypes['uid'] = 'string';                
+
+                    $scope.eventGridColumns.push({name: $scope.selectedProgramStage.reportDateDescription ? $scope.selectedProgramStage.reportDateDescription : 'incident_date', id: 'event_date', type: 'date', compulsory: false, showFilter: false, show: true});
+                    $scope.filterTypes['event_date'] = 'date';
+                    $scope.filterText['event_date']= {};
+
+                    angular.forEach($scope.selectedProgramStage.programStageDataElements, function(prStDe){
+                        $scope.prStDes[prStDe.dataElement.id] = prStDe;                    
+
+                        $scope.newDhis2Event.dataValues.push({id: prStDe.dataElement.id, value: ''});   
+                        if($scope.selectedProgramStage.captureCoordinates){
+                            $scope.newDhis2Event.coordinate = {};
+                        }
+
+                        //generate grid headers using program stage data elements
+                        //create a template for new event
+                        //for date type dataelements, filtering is based on start and end dates                    
+                        $scope.eventGridColumns.push({name: prStDe.dataElement.formName ? prStDe.dataElement.formName : prStDe.dataElement.name, 
+                                                      id: prStDe.dataElement.id, 
+                                                      type: prStDe.dataElement.type, 
+                                                      compulsory: prStDe.compulsory, 
+                                                      showFilter: false, 
+                                                      show: prStDe.displayInReports});
+
+                        $scope.filterTypes[prStDe.dataElement.id] = prStDe.dataElement.type;
+
+                        if(prStDe.dataElement.type === 'date' || prStDe.dataElement.type === 'int' ){
+                            $scope.filterText[prStDe.dataElement.id]= {};
+                        }
+                    });           
+
+                    //Load events for the selected program stage and orgunit
+                    DHIS2EventFactory.getByStage($scope.selectedOrgUnit.id, $scope.selectedProgramStage.id, $scope.pager ).then(function(data){
+
+                        if(data.events){
+                            $scope.eventLength = data.events.length;
+                        }                
+
+                        $scope.dhis2Events = data.events; 
+
+                        if( data.pager ){
+                            $scope.pager = data.pager;
+                            $scope.pager.toolBarDisplay = 5;
+
+                            Paginator.setPage($scope.pager.page);
+                            Paginator.setPageCount($scope.pager.pageCount);
+                            Paginator.setPageSize($scope.pager.pageSize);
+                            Paginator.setItemCount($scope.pager.total);                    
+                        }
+
+                        //process event list for easier tabular sorting
+                        if( angular.isObject( $scope.dhis2Events ) ) {
+
+                            for(var i=0; i < $scope.dhis2Events.length; i++){  
+
+                                if($scope.dhis2Events[i].notes && !$scope.noteExists){
+                                    $scope.noteExists = true;
+                                }
+
+                                //check if event is empty
+                                if(!angular.isUndefined($scope.dhis2Events[i].dataValues)){                            
+
+                                    angular.forEach($scope.dhis2Events[i].dataValues, function(dataValue){
+
+                                        //converting event.datavalues[i].datavalue.dataelement = value to
+                                        //event[dataElement] = value for easier grid display.                                
+                                        if($scope.prStDes[dataValue.dataElement]){                                    
+
+                                            var val = dataValue.value;
+                                            if(angular.isObject($scope.prStDes[dataValue.dataElement].dataElement)){                               
+
+                                                //converting int string value to integer for proper sorting.
+                                                if($scope.prStDes[dataValue.dataElement].dataElement.type == 'int'){
+                                                    if( !isNaN(parseInt(val)) ){
+                                                        val = parseInt(val);
+                                                    }
+                                                    else{
+                                                        val = '';
+                                                    }                                        
+                                                }
+                                                if($scope.prStDes[dataValue.dataElement].dataElement.type == 'string'){
+                                                    if($scope.prStDes[dataValue.dataElement].dataElement.optionSet && $scope.optionNamesByCode[  '"' + val + '"']){                                                        
+                                                        val = $scope.optionNamesByCode[  '"' + val + '"'];                                                      
+                                                    }                                                
+                                                }
+                                                if( $scope.prStDes[dataValue.dataElement].dataElement.type == 'trueOnly'){
+                                                    if(val == 'true'){
+                                                        val = true;
+                                                    }
+                                                    else{
+                                                        val = false;
+                                                    }
+                                                }                                    
                                             }                                    
-                                        }                                    
-                                    }
-
-                                    $scope.dhis2Events[i][dataValue.dataElement] = dataValue.value; 
-                                });
-                                
-                                $scope.dhis2Events[i]['uid'] = $scope.dhis2Events[i].event;                                
-                                $scope.dhis2Events[i].eventDate = DateUtils.format($scope.dhis2Events[i].eventDate);                                
-                                $scope.dhis2Events[i]['event_date'] = $scope.dhis2Events[i].eventDate;
-
-                                delete $scope.dhis2Events[i].dataValues;
-                            }
-                            /*else{//event is empty, remove from grid
-                                var index = $scope.dhis2Events.indexOf($scope.dhis2Events[i]);                           
-                                $scope.dhis2Events.splice(index,1);
-                                i--;                           
-                            }*/
-                        }  
-                        
-                        if($scope.noteExists){
-                            $scope.eventGridColumns.push({name: 'comment', id: 'comment', type: 'string', compulsory: false, showFilter: false, show: true});
-                        }
-                    }                
-                    $scope.eventFetched = true;
-                });            
-                
+                                            $scope.dhis2Events[i][dataValue.dataElement] = val; 
+                                        }
+
+                                    });
+
+                                    $scope.dhis2Events[i]['uid'] = $scope.dhis2Events[i].event;                                
+                                    $scope.dhis2Events[i].eventDate = DateUtils.format($scope.dhis2Events[i].eventDate);                                
+                                    $scope.dhis2Events[i]['event_date'] = $scope.dhis2Events[i].eventDate;
+
+                                    delete $scope.dhis2Events[i].dataValues;
+                                }
+                                /*else{//event is empty, remove from grid
+                                    var index = $scope.dhis2Events.indexOf($scope.dhis2Events[i]);                           
+                                    $scope.dhis2Events.splice(index,1);
+                                    i--;                           
+                                }*/
+                            }
+
+                            if($scope.noteExists){
+                                $scope.eventGridColumns.push({name: 'comment', id: 'comment', type: 'string', compulsory: false, showFilter: false, show: true});
+                            }
+                        }                
+                        $scope.eventFetched = true;
+                    });            
+
+                });
             });
-            
         }        
     };
     
@@ -391,7 +414,7 @@
     };
     
     $scope.addEvent = function(addingAnotherEvent){                
-        
+
         //check for form validity
         $scope.outerForm.submitted = true;        
         if( $scope.outerForm.$invalid ){            
@@ -410,11 +433,19 @@
         //the event form comes empty, in this case enforce at least one value
         var valueExists = false;
         var dataValues = [];        
-        for(var dataElement in $scope.programStageDataElements){
-            if($scope.currentEvent[dataElement]){
-                valueExists = true;
+        for(var dataElement in $scope.prStDes){            
+            var val = $scope.currentEvent[dataElement];
+            if(val){
+                valueExists = true;            
+                if($scope.prStDes[dataElement].dataElement.type == 'string'){
+                    if($scope.prStDes[dataElement].dataElement.optionSet){
+                        if($scope.optionCodesByName[  '"' + val + '"']){
+                            val = $scope.optionCodesByName[  '"' + val + '"'];
+                        }
+                    }
+                }            
             }
-            dataValues.push({dataElement: dataElement, value: $scope.currentEvent[dataElement]});
+            dataValues.push({dataElement: dataElement, value: val});
         }
         
         if(!valueExists){
@@ -455,6 +486,7 @@
             dhis2Event.coordinate = {latitude: $scope.currentEvent.coordinate.latitude ? $scope.currentEvent.coordinate.latitude : '',
                                      longitude: $scope.currentEvent.coordinate.longitude ? $scope.currentEvent.coordinate.longitude : ''};             
         }
+
         //send the new event to server
         DHIS2EventFactory.create(dhis2Event).then(function(data) {
             if (data.importSummaries[0].status === 'ERROR') {
@@ -513,8 +545,17 @@
         
         //the form is valid, get the values
         var dataValues = [];        
-        for(var dataElement in $scope.programStageDataElements){
-            dataValues.push({dataElement: dataElement, value: $scope.currentEvent[dataElement]});
+        for(var dataElement in $scope.prStDes){
+            var val = $scope.currentEvent[dataElement];
+            
+            if(val && $scope.prStDes[dataElement].dataElement.type == 'string'){
+                if($scope.prStDes[dataElement].dataElement.optionSet){                        
+                    if($scope.optionCodesByName[  '"' + val + '"']){
+                        val = $scope.optionCodesByName[  '"' + val + '"'];
+                    }                                            
+                }    
+            }
+            dataValues.push({dataElement: dataElement, value: val});
         }
         
         var updatedEvent = {
@@ -574,7 +615,7 @@
         $scope.currentElement = {id: dataElement};
         
         //get new and old values
-        var newValue = currentEvent[dataElement];
+        var newValue = currentEvent[dataElement];        
         var oldValue = $scope.currentEventOrginialValue[dataElement];
         
         //check for form validity
@@ -585,18 +626,25 @@
             return;
         }   
         
-        if( $scope.programStageDataElements[dataElement].compulsory && !newValue ) {            
+        if( $scope.prStDes[dataElement].compulsory && !newValue ) {            
             currentEvent[dataElement] = oldValue;
             $scope.currentElement.updated = false;
             return;
         }        
                 
-        if( newValue != oldValue ){                     
+        if( newValue != oldValue ){
+            
+            if($scope.prStDes[dataElement].dataElement.type === 'string'){
+                if($scope.prStDes[dataElement].dataElement.optionSet){
+                    if($scope.optionCodesByName[  '"' + newValue + '"']){
+                        newValue = $scope.optionCodesByName[  '"' + newValue + '"'];
+                    }
+                }
+            }
             
             var updatedSingleValueEvent = {event: currentEvent.event, dataValues: [{value: newValue, dataElement: dataElement}]};
             var updatedFullValueEvent = DHIS2EventService.reconstructEvent(currentEvent, $scope.selectedProgramStage.programStageDataElements);
-            console.log('single:  ', updatedSingleValueEvent);
-            console.log('full:  ', updatedFullValueEvent);
+
             DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){
                 
                 var continueLoop = true;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-08-12 10:04:27 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-10-17 13:22:28 +0000
@@ -73,7 +73,7 @@
             });
             
             //listen to user selection, and inform angular         
-            selection.setListenerFunction( organisationUnitSelected );            
+            selection.setListenerFunction( organisationUnitSelected, true );            
             selection.responseReceived();
             
             function organisationUnitSelected( orgUnits, orgUnitNames ) {

=== 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	2014-09-23 10:48:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-10-17 13:22:28 +0000
@@ -5,6 +5,17 @@
 var eventCaptureServices = angular.module('eventCaptureServices', ['ngResource'])
 
 
+.factory('StorageService', function(){
+    var store = new dhis2.storage.Store({
+        name: EC_STORE_NAME,
+        adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
+        objectStores: ['eventCapturePrograms', 'programStages', 'optionSets']
+    });
+    return{
+        currentStore: store
+    };
+})
+
 .service('DateUtils', function($filter){
     
     return {
@@ -34,14 +45,48 @@
     };  
 })
 
+
+/* Factory to fetch optioSets */
+.factory('OptionSetFactory', function($q, $rootScope, StorageService) { 
+    return {
+        getAll: function(){
+            
+            var def = $q.defer();
+            
+            StorageService.currentStore.open().done(function(){
+                StorageService.currentStore.getAll('optionSets').done(function(optionSets){
+                    $rootScope.$apply(function(){
+                        def.resolve(optionSets);
+                    });                    
+                });
+            });            
+            
+            return def.promise;            
+        },
+        get: function(uid){
+            
+            var def = $q.defer();
+            
+            StorageService.currentStore.open().done(function(){
+                StorageService.currentStore.get('optionSets', uid).done(function(optionSet){                    
+                    $rootScope.$apply(function(){
+                        def.resolve(optionSet);
+                    });
+                });
+            });                        
+            return def.promise;            
+        }
+    };
+})
+
 /* Factory to fetch programs */
-.factory('ProgramFactory', function($q, $rootScope) {  
+.factory('ProgramFactory', function($q, $rootScope, StorageService) {  
     
-    dhis2.ec.store = new dhis2.storage.Store({
+    /*dhis2.ec.store = new dhis2.storage.Store({
         name: EC_STORE_NAME,
         adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
         objectStores: ['eventCapturePrograms', 'programStages', 'optionSets']
-    });
+    });*/
         
     return {
         
@@ -49,38 +94,35 @@
             
             var def = $q.defer();
             
-            dhis2.ec.store.open().done(function(){
-                dhis2.ec.store.getAll('eventCapturePrograms').done(function(programs){
-                    
+            StorageService.currentStore.open().done(function(){
+                StorageService.currentStore.getAll('eventCapturePrograms').done(function(programs){                    
                     $rootScope.$apply(function(){
                         def.resolve(programs);
                     });                    
                 });
-            });            
-            
-            return def.promise;            
+            });
+            return def.promise;
         }        
-        
     };
 })
 
 /* Factory to fetch programStages */
-.factory('ProgramStageFactory', function($q, $rootScope) {  
+.factory('ProgramStageFactory', function($q, $rootScope, StorageService) {  
 
-    dhis2.ec.store = new dhis2.storage.Store({
+    /*dhis2.ec.store = new dhis2.storage.Store({
         name: EC_STORE_NAME,
         adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
         objectStores: ['eventCapturePrograms', 'programStages', 'optionSets']
-    });
+    });*/
     
     return {        
         get: function(uid){
             
             var def = $q.defer();
             
-            dhis2.ec.store.open().done(function(){
-                dhis2.ec.store.get('programStages', uid).done(function(pst){                    
-                    angular.forEach(pst.programStageDataElements, function(pstDe){   
+            StorageService.currentStore.open().done(function(){
+                StorageService.currentStore.get('programStages', uid).done(function(pst){                    
+                    /*angular.forEach(pst.programStageDataElements, function(pstDe){   
                         if(pstDe.dataElement.optionSet){
                             dhis2.ec.store.get('optionSets', pstDe.dataElement.optionSet.id).done(function(optionSet){
                                 pstDe.dataElement.optionSet = optionSet;                                
@@ -89,7 +131,10 @@
                         $rootScope.$apply(function(){
                             def.resolve(pst);
                         });
-                    });                                        
+                    });*/
+                    $rootScope.$apply(function(){
+                        def.resolve(pst);
+                    });
                 });
             });                        
             return def.promise;            
@@ -246,31 +291,33 @@
                             newInputField = '<input type="number" ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '"' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">';
+                                            ' ng-required="prStDes.' + deId + '.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "string"){
                             if(programStageDataElements[deId].dataElement.optionSet){
+                                var optionSetId = programStageDataElements[deId].dataElement.optionSet.id;
                         		newInputField = '<input type="text" ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory"' +
-                                            ' typeahead="option.code as option.name for option in programStageDataElements.'+deId+'.dataElement.optionSet.options | filter:$viewValue | limitTo:20"' +
-                                            ' typeahead-open-on-focus ng-required="programStageDataElements.'+deId+'.compulsory">';
+                                            ' ng-required="prStDes.' + deId + '.compulsory"' +
+                                            ' typeahead="option.name as option.name for option in optionSets.'+optionSetId+'.options | filter:$viewValue | limitTo:20"' +
+                                            ' typeahead-editable="false" ' +
+                                            ' typeahead-open-on-focus ng-required="prStDes.'+deId+'.compulsory">';
                         	}
                         	else{
                         		newInputField = '<input type="text" ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">';
+                                            ' ng-required="prStDes.' + deId + '.compulsory">';
                         	}
                         }
                         if(programStageDataElements[deId].dataElement.type == "bool"){
                             newInputField = '<select ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '" ' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">' + 
+                                            ' ng-required="prStDes.' + deId + '.compulsory">' + 
                                             '<option value="">{{\'please_select\'| translate}}</option>' +
                                             '<option value="false">{{\'no\'| translate}}</option>' + 
                                             '<option value="true">{{\'yes\'| translate}}</option>' +
@@ -281,13 +328,13 @@
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '"' +
                                             ' ng-date' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">';
+                                            ' ng-required="prStDes.' + deId + '.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "trueOnly"){
                             newInputField = '<input type="checkbox" ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '"' +
-                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">';
+                                            ' ng-required="prStDes.' + deId + '.compulsory">';
                         }
 
                         newInputField = //'<ng-form name="innerForm">' + 

=== 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	2014-10-02 10:25:39 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2014-10-17 13:22:28 +0000
@@ -81,18 +81,19 @@
                                 <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                             </div>
                             <div ng-switch-when="string">                                
-                                <div class="container-fluid" ng-if="programStageDataElements[eventGridColumn.id].dataElement.optionSet">
-                                    <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length >= 7">
+                                <div class="container-fluid" ng-if="prStDes[eventGridColumn.id].dataElement.optionSet">
+                                    <span ng-if="!selectedProgram.dataEntryMethod || optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options.length >= 7">
                                         <input type="text"
                                                ng-model="currentEvent[eventGridColumn.id]"                                                                    
-                                               typeahead="option.code as option.name for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
-                                               typeahead-open-on-focus
+                                               typeahead="option.name as option.name for option in optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                               typeahead-open-on-focus   
+                                               typeahead-editable=false
                                                ng-required={{eventGridColumn.compulsory}}
                                                name="foo" 
                                                style="width:99%;"/>
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                     </span>
-                                    <span ng-if="selectedProgram.dataEntryMethod && programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length < 7">                                    
+                                    <span ng-if="selectedProgram.dataEntryMethod && optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options.length < 7">                                    
                                         <label>
                                             <input type="radio" 
                                                    name="foo" 
@@ -100,17 +101,17 @@
                                                    ng-model="currentEvent[eventGridColumn.id]"
                                                    value=""> {{'no_value' | translate}}<br>
                                         </label>                                    
-                                        <label ng-repeat="option in  programStageDataElements[eventGridColumn.id].dataElement.optionSet.options">
+                                        <label ng-repeat="option in  optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options">
                                             <input type="radio" 
                                                    name={{eventGridColumn.id}}   
                                                    ng-required={{eventGridColumn.compulsory}}
                                                    ng-model="currentEvent[eventGridColumn.id]"
-                                                   value={{option.code}}> {{option.name}}<br>                                        
+                                                   value={{option.name}}> {{option.name}}<br>                                        
                                         </label>                                    
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
                                     </span>
                                 </div>
-                                <div ng-if="!programStageDataElements[eventGridColumn.id].dataElement.optionSet">
+                                <div ng-if="!prStDes[eventGridColumn.id].dataElement.optionSet">
                                     <input type="text"
                                         ng-model="currentEvent[eventGridColumn.id]"                                        
                                         ng-required={{eventGridColumn.compulsory}}
@@ -240,53 +241,54 @@
                 <tbody id="list">       
                     <tr ng-repeat="de in section.programStageDataElements">
                         <td >
-                            {{programStageDataElements[de.dataElement.id].dataElement.formName ? programStageDataElements[de.dataElement.id].dataElement.formName : programStageDataElements[de.dataElement.id].dataElement.name}}
+                            {{prStDes[de.dataElement.id].dataElement.formName ? prStDes[de.dataElement.id].dataElement.formName : prStDes[de.dataElement.id].dataElement.name}}
                         </td>
                         <td >
                             <ng-form name="innerForm">
-                                <div ng-switch="programStageDataElements[de.dataElement.id].dataElement.type">
+                                <div ng-switch="prStDes[de.dataElement.id].dataElement.type">
                                     <div ng-switch-when="int">
                                         <input type="number"
                                                ng-model="currentEvent[de.dataElement.id]"                                                                
-                                               ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                               ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                name="foo" 
                                                style="width:99%;"/>
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                     </div>
                                     <div ng-switch-when="string">
-                                        <div class="container-fluid" ng-if="programStageDataElements[de.dataElement.id].dataElement.optionSet">                                
-                                            <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[de.dataElement.id].dataElement.optionSet.options.length > 8">
+                                        <div class="container-fluid" ng-if="prStDes[de.dataElement.id].dataElement.optionSet">                                
+                                            <span ng-if="!selectedProgram.dataEntryMethod || prStDes[de.dataElement.id].dataElement.optionSet.options.length > 8">
                                                 <input type="text"
                                                        ng-model="currentEvent[de.dataElement.id]"                                                                    
-                                                       typeahead="option.code as option.name for option in programStageDataElements[de.dataElement.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
-                                                       typeahead-open-on-focus
-                                                       ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                       typeahead="option.name as option.name for option in prStDes[de.dataElement.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
+                                                       typeahead-open-on-focus   
+                                                       typeahead-editable="false"
+                                                       ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                        name="foo" 
                                                        style="width:99%;"/>
                                                 <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                             </span>
-                                            <span ng-if="selectedProgram.dataEntryMethod && programStageDataElements[de.dataElement.id].dataElement.optionSet.options.length < 7">                                    
+                                            <span ng-if="selectedProgram.dataEntryMethod && prStDes[de.dataElement.id].dataElement.optionSet.options.length < 7">                                    
                                                 <label>
                                                     <input type="radio" 
                                                            name="foo" 
-                                                           ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                           ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                            ng-model="currentEvent[de.dataElement.id]"
                                                            value=""> {{'no_value' | translate}}<br>
                                                 </label>                                    
-                                                <label ng-repeat="option in  programStageDataElements[de.dataElement.id].dataElement.optionSet.options">
+                                                <label ng-repeat="option in  prStDes[de.dataElement.id].dataElement.optionSet.options">
                                                     <input type="radio" 
                                                            name={{de.dataElement.id}}   
-                                                           ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                           ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                            ng-model="currentEvent[de.dataElement.id]"
-                                                           value={{option.code}}> {{option.name}}<br>                                        
+                                                           value={{option.name}}> {{option.name}}<br>                                        
                                                 </label>                                    
                                                 <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
                                             </span>
                                         </div>
-                                        <div ng-if="!programStageDataElements[de.dataElement.id].dataElement.optionSet">
+                                        <div ng-if="!prStDes[de.dataElement.id].dataElement.optionSet">
                                             <input type="text"
                                                 ng-model="currentEvent[de.dataElement.id]"
-                                                ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                 name="foo" 
                                                 style="width:99%;"/>
                                             <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
@@ -294,7 +296,7 @@
                                     </div>
                                     <div ng-switch-when="bool">
                                         <select ng-model="currentEvent[de.dataElement.id]"                                                                
-                                                ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                 name="foo" 
                                                 style="width:99%;">
                                         <option value="">{{'please_select'| translate}}</option>                        
@@ -308,7 +310,7 @@
                                                placeholder="yyyy-mm-dd" 
                                                ng-date 
                                                ng-model="currentEvent[de.dataElement.id]"                                                               
-                                               ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                               ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                name="foo" 
                                                style="width:99%;"/>
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
@@ -316,7 +318,7 @@
                                     <div ng-switch-when="trueOnly">
                                         <input type="checkbox"                                                                      
                                                ng-model="currentEvent[de.dataElement.id]"                                                               
-                                               ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                               ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                name="foo"/>
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                     </div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html	2014-09-23 10:48:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html	2014-10-17 13:22:28 +0000
@@ -123,7 +123,7 @@
                                     <div ng-switch="eventGridColumn.type">
                                         <div ng-switch-when="int">
                                             <input type="number" 
-                                                   program-stage-data-element={{programStageDataElements[eventGridColumn.id]}}
+                                                   program-stage-data-element={{prStDes[eventGridColumn.id]}}
                                                    ng-model="dhis2Event[eventGridColumn.id]" 
                                                    ng-blur="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
                                                    ng-required={{eventGridColumn.compulsory}}
@@ -143,13 +143,14 @@
                                                        style="width:99%;"/>                                                    
                                             </div>
                                             <div ng-if="eventGridColumn.id !== 'uid'">
-                                                <div class="container-fluid" ng-if="programStageDataElements[eventGridColumn.id].dataElement.optionSet">                                                
-                                                    <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length > 7">
+                                                <div class="container-fluid" ng-if="optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id]">                                                
+                                                    <span ng-if="!selectedProgram.dataEntryMethod || optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options.length > 7">
                                                         <input type="text" 
                                                            ng-model="dhis2Event[eventGridColumn.id]" 
-                                                           ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
-                                                           typeahead="option.code as option.name for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
+                                                           ng-blur="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
+                                                           typeahead="option.name as option.name for option in optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                                            typeahead-open-on-focus
+                                                           typeahead-editable="false"
                                                            ng-required={{eventGridColumn.compulsory}}
                                                            ng-disabled="eventGridColumn.id == 'uid'"
                                                            name="foo" 
@@ -159,7 +160,7 @@
                                                            />
                                                         <span ng-show="outerForm.submitted && innerFormGrid.foo.$invalid" class="red"><em title="{{'required'| translate}}" class="required">*</em></span>
                                                     </span>
-                                                    <span ng-if="selectedProgram.dataEntryMethod && programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length < 7">                                    
+                                                    <span ng-if="selectedProgram.dataEntryMethod && optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options.length < 7">                                    
                                                         <label>
                                                             <input type="radio" 
                                                                    name="foo" 
@@ -168,7 +169,7 @@
                                                                    ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
                                                                    value=""> {{'no_value' | translate}}<br>                                     
                                                         </label>                                    
-                                                        <label ng-repeat="option in  programStageDataElements[eventGridColumn.id].dataElement.optionSet.options">
+                                                        <label ng-repeat="option in  optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options">
                                                             <input type="radio" 
                                                                    name={{eventGridColumn.id}}   
                                                                    ng-required={{eventGridColumn.compulsory}}
@@ -176,12 +177,12 @@
                                                                    ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)"
                                                                    ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
                                                                    ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
-                                                                   value={{option.code}}> {{option.name}}<br>                                    
+                                                                   value={{option.name}}> {{option.name}}<br>                                    
                                                         </label>                                    
                                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
                                                     </span>                                                
                                                 </div>
-                                                <div ng-if="!programStageDataElements[eventGridColumn.id].dataElement.optionSet">
+                                                <div ng-if="!optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id]">
                                                     <input type="text" 
                                                         ng-model="dhis2Event[eventGridColumn.id]" 
                                                         ng-blur="updateEventDataValue(dhis2Event, eventGridColumn.id)"