← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17080: tracker capture now respects user defined calendar settings

 

------------------------------------------------------------
revno: 17080
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-10-13 16:47:39 +0200
message:
  tracker capture now respects user defined calendar settings
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/reportForm.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js
  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-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css


--
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/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-10-08 14:18:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-10-13 14:47:39 +0000
@@ -1,6 +1,5 @@
 trackerCapture.controller('DataEntryController',
         function($scope, 
-                $filter,
                 DateUtils,
                 EventUtils,
                 orderByFilter,
@@ -25,9 +24,7 @@
     if(loginDetails){
         storedBy = loginDetails.userCredentials.username;
     }
-    var today = moment();
-    today = Date.parse(today);
-    today = $filter('date')(today, 'yyyy-MM-dd');
+    var today = DateUtils.getToday();
     $scope.invalidDate = false;
     
     //note
@@ -83,30 +80,35 @@
     $scope.getEvents = function(){        
         $scope.dhis2Events = '';
         DHIS2EventFactory.getEventsByStatus($scope.selectedEntity.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id, 'ACTIVE').then(function(data){
-            $scope.dhis2Events = data;            
+            $scope.dhis2Events = data;
             if(angular.isObject($scope.dhis2Events)){
-                angular.forEach($scope.dhis2Events, function(dhis2Event){
+                angular.forEach($scope.dhis2Events, function(dhis2Event){                    
+                    if(dhis2Event.enrollment === $scope.selectedEnrollment.enrollment){
+                        
+                        if(dhis2Event.notes){
+                            dhis2Event.notes = orderByFilter(dhis2Event.notes, '-storedDate');            
+                            angular.forEach(dhis2Event.notes, function(note){
+                                note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
+                            });
+                        }
                     
-                    if(dhis2Event.enrollment === $scope.selectedEnrollment.enrollment){
                         var eventStage = $scope.selectedProgramWithStage[dhis2Event.programStage];
                         if(angular.isObject(eventStage)){
 
                             dhis2Event.name = eventStage.name; 
                             dhis2Event.reportDateDescription = eventStage.reportDateDescription;
-                            dhis2Event.dueDate = DateUtils.format(dhis2Event.dueDate);
+                            dhis2Event.dueDate = DateUtils.formatFromApiToUser(dhis2Event.dueDate);
+                            dhis2Event.sortingDate = dhis2Event.dueDate;
 
                             if(dhis2Event.eventDate){
-                                dhis2Event.eventDate = DateUtils.format(dhis2Event.eventDate);
-                                dhis2Event.sortingDate = DateUtils.format(dhis2Event.eventDate);
-                            }
-                            else{
-                                dhis2Event.sortingDate = dhis2Event.dueDate;
+                                dhis2Event.eventDate = DateUtils.formatFromApiToUser(dhis2Event.eventDate);
+                                dhis2Event.sortingDate = dhis2Event.eventDate;
                             }                       
 
                             dhis2Event.statusColor = EventUtils.getEventStatusColor(dhis2Event);  
                             dhis2Event = EventUtils.setEventOrgUnitName(dhis2Event);
                         } 
-                    }
+                    }                    
                 });
             }
             
@@ -120,7 +122,7 @@
         if($scope.selectedEnrollment.status === 'ACTIVE'){
             if(!angular.isObject(availableEvents)){
                 angular.forEach($scope.selectedProgram.programStages, function(programStage){                                                        
-                    var dummyEvent = EventUtils.createDummyEvent(programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+                    var dummyEvent = EventUtils.createDummyEvent(availableEvents, programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
                     dummyEvents.push(dummyEvent);                         
                 });
 
@@ -133,20 +135,40 @@
                 return dummyEvents;
             }      
             else{
-                for(var i=0; i<program.programStages.length; i++){
-                    var stageHasEvent = false;
-                    for(var j=0; j<availableEvents.length && !program.programStages[i].repeatable && !stageHasEvent; j++){
-                        if(program.programStages[i].id === availableEvents[j].programStage){
-                            stageHasEvent = true;
-                        }
+                var eventsPerStage = [];
+                angular.forEach(availableEvents, function(event){
+                    if(eventsPerStage[event.programStage]){
+                        eventsPerStage[event.programStage].push(event);
                     }
+                    else{
+                        eventsPerStage[event.programStage] = [];
+                        eventsPerStage[event.programStage].push(event);
+                    }                    
+                });
 
-                    if(!stageHasEvent){
+                angular.forEach(program.programStages, function(stage){
+                    if(!eventsPerStage[stage.id]){
                         $scope.allowEventCreation = true;
-                        var dummyEvent = EventUtils.createDummyEvent(program.programStages[i], $scope.selectedOrgUnit, $scope.selectedEnrollment);
+                        var dummyEvent = EventUtils.createDummyEvent(availableEvents, stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
                         dummyEvents.push(dummyEvent);
                     }
-                }
+                    else{
+                        if(stage.repeatable){
+                            var stageNeedsEvent = true;
+                            for(var j=0; j<eventsPerStage[stage.id].length && stageNeedsEvent; j++){
+                                if(!eventsPerStage[stage.id][j].eventDate){
+                                    stageNeedsEvent = false;
+                                }
+                            }
+                            
+                            if(stageNeedsEvent){
+                                $scope.allowEventCreation = true;
+                                var dummyEvent = EventUtils.createDummyEvent(availableEvents, stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);                                
+                                dummyEvents.push(dummyEvent);
+                            }
+                        }
+                    }                    
+                });
             }
         }        
         return dummyEvents;
@@ -161,7 +183,7 @@
     };
     
     $scope.showDummyEventCreation = function(dummyEvent){
-
+        
         if(dummyEvent){    
             
             if($scope.currentDummyEvent == dummyEvent){ 
@@ -190,8 +212,8 @@
                     program: $scope.selectedProgram.id,
                     programStage: $scope.currentDummyEvent.programStage,
                     orgUnit: $scope.currentDummyEvent.orgUnit,
-                    eventDate: $scope.currentDummyEvent.eventDate,
-                    dueDate: $scope.currentDummyEvent.dueDate,
+                    eventDate: DateUtils.formatFromUserToApi( $scope.currentDummyEvent.eventDate),
+                    dueDate: DateUtils.formatFromUserToApi( $scope.currentDummyEvent.dueDate),
                     status: 'SCHEDULE',
                     notes: [],
                     dataValues: []
@@ -228,7 +250,7 @@
         });
     };   
     
-    $scope.showDataEntry = function(event){
+    $scope.showDataEntry = function(event){        
         
         //$scope.dueDateSaved = false;
         //$scope.eventDateSaved = false;
@@ -269,19 +291,6 @@
     $scope.getDataEntryForm = function(){ 
         
         $scope.currentEvent.providedElsewhere = [];
-
-        $scope.currentEvent.dueDate = DateUtils.format($scope.currentEvent.dueDate);
-        if($scope.currentEvent.eventDate){
-            $scope.currentEvent.eventDate = DateUtils.format($scope.currentEvent.eventDate);
-        }        
-
-        if(!angular.isUndefined( $scope.currentEvent.notes)){
-            $scope.currentEvent.notes = orderByFilter($scope.currentEvent.notes, '-storedDate');            
-            angular.forEach($scope.currentEvent.notes, function(note){
-                note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
-            });
-        }
-
         
         $scope.currentStage = $scope.selectedProgramWithStage[$scope.currentEvent.programStage];
 
@@ -303,11 +312,10 @@
         
         angular.forEach($scope.currentEvent.dataValues, function(dataValue){
             var val = dataValue.value;
-            if(val){
-                var de = $scope.currentStage.programStageDataElements[dataValue.dataElement];
-                if( de && de.type === 'int' && val){
+            var de = $scope.currentStage.programStageDataElements[dataValue.dataElement];
+            if(val){                
+                if( de && de.type === 'int'){
                     val = parseInt(val);
-                    //dataValue.value = val;
                 }                    
             }    
             $scope.currentEvent[dataValue.dataElement] = val;
@@ -392,49 +400,47 @@
     };
     
     $scope.saveEventDate = function(){
-
+        
         $scope.eventDateSaved = false;
-        if($scope.currentEvent.eventDate == ''){
-            $scope.invalidDate = true;
-            return false;
-        }
-        else{
-            var rawDate = angular.copy($scope.currentEvent.eventDate);
-            var convertedDate = DateUtils.format($scope.currentEvent.eventDate);
-
-            if(rawDate !== convertedDate){
-                $scope.invalidDate = true;
-                return false;
-            } 
-
-            var e = {event: $scope.currentEvent.event,
-                 enrollment: $scope.currentEvent.enrollment,
-                 dueDate: $scope.currentEvent.dueDate,
-                 status: $scope.currentEvent.status == 'SCHEDULE' ? 'ACTIVE' : $scope.currentEvent.status,
-                 program: $scope.currentEvent.program,
-                 programStage: $scope.currentEvent.programStage,
-                 orgUnit: $scope.currentEvent.orgUnit,
-                 eventDate: $scope.currentEvent.eventDate,
-                 trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
-                };
-
-            DHIS2EventFactory.updateForEventDate(e).then(function(data){
-                $scope.currentEvent.sortingDate = $scope.currentEvent.eventDate;
-                $scope.invalidDate = false;
-                $scope.eventDateSaved = true;
-                
-                var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
-                var continueLoop = true;
-                for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
-                    if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
-                        $scope.dhis2Events[i].statusColor = statusColor;
-                        $scope.dhis2Events[i].status = e.status;
-                        continueLoop = false;
-                    }
+        if($scope.currentEvent.eventDate == ''){            
+            $scope.invalidDate = true;
+            return false;
+        }
+        
+        var rawDate = angular.copy($scope.currentEvent.eventDate);
+        var convertedDate = DateUtils.format($scope.currentEvent.eventDate);
+        
+        if(rawDate !== convertedDate){
+            $scope.invalidDate = true;
+            return false;
+        }
+        
+        var e = {event: $scope.currentEvent.event,
+             enrollment: $scope.currentEvent.enrollment,
+             dueDate: DateUtils.formatFromUserToApi($scope.currentEvent.dueDate),
+             status: $scope.currentEvent.status == 'SCHEDULE' ? 'ACTIVE' : $scope.currentEvent.status,
+             program: $scope.currentEvent.program,
+             programStage: $scope.currentEvent.programStage,
+             orgUnit: $scope.currentEvent.orgUnit,
+             eventDate: DateUtils.formatFromUserToApi($scope.currentEvent.eventDate),
+             trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
+            };
+
+        DHIS2EventFactory.updateForEventDate(e).then(function(data){
+            $scope.currentEvent.sortingDate = $scope.currentEvent.eventDate;
+            $scope.invalidDate = false;
+            $scope.eventDateSaved = true;
+
+            var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
+            var continueLoop = true;
+            for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+                if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
+                    $scope.dhis2Events[i].statusColor = statusColor;
+                    $scope.dhis2Events[i].status = e.status;
+                    continueLoop = false;
                 }
-            });
-        }
-        
+            }
+        });
     };
     
     $scope.saveDueDate = function(){
@@ -444,40 +450,40 @@
             $scope.invalidDate = true;
             return false;
         }
-        else{
-            var rawDate = angular.copy($scope.currentEvent.dueDate);
-            var convertedDate = DateUtils.format($scope.currentEvent.dueDate);           
-
-            if(rawDate !== convertedDate){
-                $scope.invalidDate = true;
-                return false;
-            } 
-
-            var e = {event: $scope.currentEvent.event,
-                 enrollment: $scope.currentEvent.enrollment,
-                 dueDate: $scope.currentEvent.dueDate,
-                 status: $scope.currentEvent.status,
-                 program: $scope.currentEvent.program,
-                 programStage: $scope.currentEvent.programStage,
-                 orgUnit: $scope.currentEvent.orgUnit,
-                 trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
-                };
-
-            DHIS2EventFactory.update(e).then(function(data){            
-                $scope.invalidDate = false;
-                $scope.dueDateSaved = true;
-                $scope.currentEvent.sortingDate = $scope.currentEvent.dueDate;                
-                var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
-                var continueLoop = true;
-                for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
-                    if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
-                        $scope.dhis2Events[i].statusColor = statusColor;
-                        continueLoop = false;
-                    }
+        
+        var rawDate = angular.copy($scope.currentEvent.dueDate);
+        var convertedDate = DateUtils.format($scope.currentEvent.dueDate);           
+
+        if(rawDate !== convertedDate){
+            $scope.invalidDate = true;
+            return false;
+        } 
+        
+        var e = {event: $scope.currentEvent.event,
+             enrollment: $scope.currentEvent.enrollment,
+             dueDate: DateUtils.formatFromUserToApi($scope.currentEvent.dueDate),
+             status: $scope.currentEvent.status,
+             program: $scope.currentEvent.program,
+             programStage: $scope.currentEvent.programStage,
+             orgUnit: $scope.currentEvent.orgUnit,
+             trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
+            };
+        
+        DHIS2EventFactory.update(e).then(function(data){            
+            $scope.invalidDate = false;
+            $scope.dueDateSaved = true;
+            $scope.currentEvent.sortingDate = $scope.currentEvent.dueDate;                
+            var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
+            var continueLoop = true;
+            for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+                if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
+                    $scope.dhis2Events[i].statusColor = statusColor;
+                    continueLoop = false;
                 }
-                $scope.schedulingEnabled = !$scope.schedulingEnabled;
-            });
-        }              
+            }
+            $scope.schedulingEnabled = !$scope.schedulingEnabled;
+        });
+                      
     };
     
     $scope.addNote = function(){
@@ -485,10 +491,10 @@
             var newNote = {value: $scope.note};
 
             if(angular.isUndefined( $scope.currentEvent.notes) ){
-                $scope.currentEvent.notes = [{value: $scope.note, storedDate: today, storedBy: storedBy}];
+                $scope.currentEvent.notes = [{value: $scope.note, storedDate: DateUtils.formatFromUserToApi(today), storedBy: storedBy}];
             }
             else{
-                $scope.currentEvent.notes.splice(0,0,{value: $scope.note, storedDate: today, storedBy: storedBy});
+                $scope.currentEvent.notes.splice(0,0,{value: $scope.note, storedDate: DateUtils.formatFromUserToApi(today), storedBy: storedBy});
             }
 
             var e = {event: $scope.currentEvent.event,

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-10-13 14:47:39 +0000
@@ -31,7 +31,7 @@
             <table class="table-borderless">
                 <tbody>
                     <tr>
-                        <td class="inline-block" ng-repeat="dhis2Event in dhis2Events| orderBy:'sortingDate':reverse">
+                        <td class="inline-block" ng-repeat="dhis2Event in dhis2Events | orderBy:'sortingDate':reverse">
                             <span class="block align-center">{{dhis2Event.eventOrgUnitName}}</span>                                              
                             <span class="stage-container"                                                     
                                   ng-class="{'current-stage': currentEvent && currentEvent.event == dhis2Event.event, '{{dhis2Event.statusColor}}': true}"                                                      
@@ -84,7 +84,7 @@
                         <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="closeEventCreation()">{{'cancel'| translate}}</button>
                     </div>                        
                 </div>
-            </form>            
+            </form>
         </div>        
 
         <div ng-if="currentEvent && !showEventCreationDiv">
@@ -92,14 +92,13 @@
                 <div class="col-md-6">
                     {{currentEvent.reportDateDescription}}
                     <input type="text"
-                           name="eventDate" 
                            placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
                            class="form-control" 
                            ng-class="{'input-success': eventDateSaved}"
                            ng-date 
                            ng-model="currentEvent.eventDate"
                            ng-disabled="currentEvent.status === 'SKIPPED'"    
-                           ng-required="true" 
+                           ng-required="true"
                            blur-or-change="saveEventDate()"/>
                     <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>
                 </div>
@@ -111,12 +110,11 @@
                         <a href ng-click="enableRescheduling()" title="{{ schedulingEnabled ? 'disable_rescheduling' : 'enable_rescheduling' | translate}}"><span class="text-primary bold">{{'due_date'| translate}}</span></a>                        
                     </span>                    
                     <input type="text" 
-                           name="dueDate" 
                            placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
                            class="form-control"
                            ng-class="{'input-success': dueDateSaved}"
                            ng-date 
-                           ng-model="currentEvent.dueDate" 
+                           ng-model="currentEvent.dueDate"
                            blur-or-change="saveDueDate()" 
                            ng-disabled="currentEvent.eventDate || !schedulingEnabled"/>
                     <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-10-13 14:47:39 +0000
@@ -17,7 +17,7 @@
                 DialogService) {
     TranslationService.translate();
     
-    $scope.today = DateUtils.format(moment());
+    $scope.today = DateUtils.getToday();
     
     //listen for the selected items
     $scope.$on('selectedItems', function(event, args) {   
@@ -77,19 +77,12 @@
             }); 
             
             if($scope.selectedEnrollment){//enrollment exists
-                $scope.selectedEnrollment.dateOfIncident = DateUtils.format($scope.selectedEnrollment.dateOfIncident);
-                $scope.selectedEnrollment.dateOfEnrollment = DateUtils.format($scope.selectedEnrollment.dateOfEnrollment);
-                
-                $scope.programStages = [];   
-                
-                var incidentDate = $scope.selectedEnrollment ? $scope.selectedEnrollment.dateOfIncident : new Date();
-
-                angular.forEach($scope.selectedProgram.programStages, function(stage){                    
-                    
-                    stage.dueDate = DateUtils.format(incidentDate);
-                    stage.dueDate = moment(moment(incidentDate).add('d', stage.minDaysFromStart))._d;
-                    stage.dueDate = DateUtils.format(stage.dueDate);
-                });
+                $scope.selectedEnrollment.dateOfIncident = DateUtils.formatFromApiToUser($scope.selectedEnrollment.dateOfIncident);
+                $scope.selectedEnrollment.dateOfEnrollment = DateUtils.formatFromApiToUser($scope.selectedEnrollment.dateOfEnrollment);
+                
+                /*angular.forEach($scope.selectedProgram.programStages, function(stage){                    
+                    stage.dueDate = EventUtils.getEventDueDate(stage, $scope.selectedEnrollment);
+                });*/
             }
             else{//prepare for possible enrollment
                 AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
@@ -171,8 +164,8 @@
         var enrollment = {trackedEntityInstance: tei.trackedEntityInstance,
                             program: $scope.selectedProgram.id,
                             status: 'ACTIVE',
-                            dateOfEnrollment: $scope.newEnrollment.dateOfEnrollment,
-                            dateOfIncident: $scope.newEnrollment.dateOfIncident ? $scope.newEnrollment.dateOfIncident : $scope.newEnrollment.dateOfEnrollment
+                            dateOfEnrollment: DateUtils.formatFromUserToApi($scope.newEnrollment.dateOfEnrollment),
+                            dateOfIncident: $scope.newEnrollment.dateOfIncident ? DateUtils.formatFromUserToApi($scope.newEnrollment.dateOfIncident) : DateUtils.formatFromUserToApi($scope.newEnrollment.dateOfEnrollment)
                         };
                         
         TEIService.update(tei).then(function(updateResponse){
@@ -284,7 +277,7 @@
         
     $scope.autoGenerateEvents = function(){
         if($scope.selectedTei && $scope.selectedProgram && $scope.selectedOrgUnit && $scope.selectedEnrollment){            
-            $scope.dhis2Events = {events: []};
+            var dhis2Events = {events: []};
             angular.forEach($scope.selectedProgram.programStages, function(stage){
                 if(stage.autoGenerateEvent){
                     var newEvent = {
@@ -292,15 +285,15 @@
                             program: $scope.selectedProgram.id,
                             programStage: stage.id,
                             orgUnit: $scope.selectedOrgUnit.id,                        
-                            dueDate: EventUtils.getEventDueDate(stage, $scope.selectedEnrollment),
+                            dueDate: DateUtils.formatFromUserToApi( EventUtils.getEventDueDate(dhis2Events.events, stage, $scope.selectedEnrollment) ),
                             status: 'SCHEDULE'
                         };
-                    $scope.dhis2Events.events.push(newEvent);    
+                    dhis2Events.events.push(newEvent);    
                 }
             });
             
-            if($scope.dhis2Events.events.length > 0){
-                DHIS2EventFactory.create($scope.dhis2Events).then(function(data) {
+            if(dhis2Events.events.length > 0){
+                DHIS2EventFactory.create(dhis2Events).then(function(data) {
                 });
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-10-13 14:47:39 +0000
@@ -85,7 +85,7 @@
                                    name="dateOfEnrollment" 
                                    class="form-control" 
                                    ng-date 
-                                   max-date="selectedProgram.selectEnrollmentDatesInFuture ? '' : today"
+                                   max-date="selectedProgram.selectEnrollmentDatesInFuture ? '' : 0"
                                    ng-model="newEnrollment.dateOfEnrollment" 
                                    ng-required="true"/>
                             <span ng-show="outerForm.submitted && outerForm.dateOfEnrollment.$invalid" class="red">{{'required'| translate}}</span>
@@ -100,7 +100,7 @@
                                    placeholder="{{dhis2CalendarFormat.keyDateFormat}}" 
                                    class="form-control" 
                                    ng-date
-                                   max-date="selectedProgram.selectIncidentDatesInFuture ? '' : today"
+                                   max-date="selectedProgram.selectIncidentDatesInFuture ? '' : 0"
                                    ng-model="newEnrollment.dateOfIncident" 
                                    max-date="today"/>
                         </td>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js	2014-09-18 14:53:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js	2014-10-13 14:47:39 +0000
@@ -16,7 +16,7 @@
         storedBy = loginDetails.userCredentials.username;
     }
     
-    var today = DateUtils.format(moment());
+    var today = DateUtils.getToday();
     
     $scope.showMessagingDiv = false;
     $scope.showNotesDiv = true;
@@ -66,11 +66,11 @@
             var newNote = {value: $scope.note};
 
             if(angular.isUndefined( $scope.selectedEnrollment.notes) ){
-                $scope.selectedEnrollment.notes = [{value: $scope.note, storedDate: today, storedBy: storedBy}];
+                $scope.selectedEnrollment.notes = [{value: $scope.note, storedDate: DateUtils.formatFromUserToApi(today), storedBy: storedBy}];
                 
             }
             else{
-                $scope.selectedEnrollment.notes.splice(0,0,{value: $scope.note, storedDate: today, storedBy: storedBy});
+                $scope.selectedEnrollment.notes.splice(0,0,{value: $scope.note, storedDate: DateUtils.formatFromUserToApi(today), storedBy: storedBy});
             }
 
             var e = angular.copy($scope.selectedEnrollment);

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-10-09 15:37:26 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-10-13 14:47:39 +0000
@@ -18,10 +18,10 @@
     //do translation of the registration page
     TranslationService.translate();    
     
-    $scope.today = DateUtils.format(moment());
+    $scope.today = DateUtils.getToday();
     
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
-    $scope.enrollment = {enrollmentDate: '', incidentDate: ''};   
+    $scope.enrollment = {dateOfEnrollment: '', dateOfIncident: ''};   
     
     /*AttributesFactory.getWithoutProgram().then(function(atts){
         $scope.attributes = atts;
@@ -35,13 +35,6 @@
     
     //watch for selection of program
     $scope.$watch('selectedProgram', function() {        
-        /*if( angular.isObject($scope.selectedProgram)){
-            $scope.trackedEntityList = [];
-            AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
-                $scope.attributes = atts;
-            });
-        }*/
-        
         $scope.getAttributes();
     });    
         
@@ -118,9 +111,10 @@
                     var enrollment = {trackedEntityInstance: teiId,
                                 program: $scope.selectedProgram.id,
                                 status: 'ACTIVE',
-                                dateOfEnrollment: $scope.enrollment.enrollmentDate,
-                                dateOfIncident: $scope.enrollment.incidentDate
-                            };
+                                dateOfEnrollment: DateUtils.formatFromUserToApi($scope.enrollment.dateOfEnrollment),
+                                dateOfIncident: $scope.enrollment.dateOfIncident == '' ? DateUtils.formatFromUserToApi($scope.enrollment.dateOfEnrollment) : DateUtils.formatFromUserToApi($scope.enrollment.dateOfIncident)
+                            };                           
+                    console.log('enrollment details:  ', enrollment);
                     EnrollmentService.enroll(enrollment).then(function(data){
                         if(data.status !== 'SUCCESS'){
                             //enrollment has failed
@@ -133,7 +127,7 @@
                         }
                         else{
                             enrollment.enrollment = data.reference;
-                            $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, enrollment);                          
+                            $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, $scope.enrollment);                          
                         }
                     });
                 }
@@ -154,8 +148,8 @@
                     delete attribute.value;                
                 });            
 
-                $scope.enrollment.enrollmentDate = '';
-                $scope.enrollment.incidentDate =  '';
+                $scope.enrollment.dateOfEnrollment = '';
+                $scope.enrollment.dateOfIncident =  '';
                 $scope.outerForm.submitted = false; 
 
 
@@ -167,7 +161,7 @@
                     $scope.tei.trackedEntityInstance = teiId;
                     $scope.broadCastSelections();
                 }
-            }, 100);        
+            }, 100);
             
         });
     };
@@ -182,7 +176,7 @@
         });
         
         $scope.tei.orgUnitName = $scope.selectedOrgUnit.name;
-        $scope.tei.created = DateUtils.format(new Date());
+        $scope.tei.created = DateUtils.formatFromApiToUser(new Date());
         CurrentSelection.setRelationshipInfo({tei: $scope.tei, src: $scope.selectedRelationshipSource});
         $timeout(function() { 
             $rootScope.$broadcast('relationship', {});
@@ -200,13 +194,16 @@
                             program: program.id,
                             programStage: stage.id,
                             orgUnit: orgUnit.id,                        
-                            dueDate: EventUtils.getEventDueDate(stage, enrollment),
+                            dueDate: DateUtils.formatFromUserToApi(EventUtils.getEventDueDate(null,stage, enrollment)),
                             status: 'SCHEDULE'
                         };
+                    console.log('enrollment details:  ', enrollment);     
+                    console.log('the event due date is:  ', EventUtils.getEventDueDate(null,stage, enrollment));    
                     dhis2Events.events.push(newEvent);    
                 }
             });
 
+            console.log('the events are:  ', dhis2Events);
             if(dhis2Events.events.length > 0){
                 DHIS2EventFactory.create(dhis2Events).then(function(data){
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2014-10-09 15:37:26 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2014-10-13 14:47:39 +0000
@@ -115,8 +115,9 @@
                                name="dateOfEnrollment" 
                                class="form-control" 
                                ng-date 
-                               ng-model="enrollment.enrollmentDate" 
-                               max-date="selectedProgram.selectEnrollmentDatesInFuture ? '' : today" 
+                               ng-model="enrollment.dateOfEnrollment" 
+                               max-date="selectedProgram.selectEnrollmentDatesInFuture ? '' : 0"
+                               min-date=""
                                ng-required="true"/>
                         <span ng-show="outerForm.submitted && outerForm.dateOfEnrollment.$invalid" class="error">{{'required'| translate}}</span>
                     </td>
@@ -127,11 +128,13 @@
                     </td>
                     <td>
                         <input type="text" 
-                               placeholder="{{dhis2CalendarFormat.keyDateFormat}}" 
+                               placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
+                               name="dateOfIncident"
                                class="form-control" 
                                ng-date 
-                               max-date="selectedProgram.selectIncidentDatesInFuture ? '' : today"
-                               ng-model="enrollment.incidentDate"/>
+                               max-date="selectedProgram.selectIncidentDatesInFuture ? '' : 0"
+                               min-date=""
+                               ng-model="enrollment.dateOfIncident"/>
                     </td>
                 </tr>
             </table>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-10-01 09:56:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-10-13 14:47:39 +0000
@@ -458,8 +458,8 @@
                     var enrollment = {trackedEntityInstance: teiId,
                                 program: $scope.selectedProgramForRelative.id,
                                 status: 'ACTIVE',
-                                dateOfEnrollment: $scope.enrollment.enrollmentDate,
-                                dateOfIncident: $scope.enrollment.incidentDate
+                                dateOfEnrollment: DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate),
+                                dateOfIncident: $scope.enrollment.incidentDate == '' ? DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate) : DateUtils.formatFromUserToApi($scope.enrollment.incidentDate)
                             };
                     EnrollmentService.enroll(enrollment).then(function(data){
                         if(data.status !== 'SUCCESS'){
@@ -513,7 +513,7 @@
             });
 
             $scope.tei.orgUnitName = $scope.selectedOrgUnit.name;
-            $scope.tei.created = DateUtils.format(new Date());
+            $scope.tei.created = DateUtils.formatFromApiToUser(new Date());
             
             CurrentSelection.setRelationshipInfo({tei: $scope.tei, src: $scope.selectedRelationshipSource});
             

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2014-09-18 13:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2014-10-13 14:47:39 +0000
@@ -15,7 +15,7 @@
 
     TranslationService.translate();
     
-    $scope.today = DateUtils.format(moment());
+    $scope.today = DateUtils.getToday();
     
     $scope.selectedOuMode = 'SELECTED';
     $scope.report = {};
@@ -110,7 +110,7 @@
                         overdueEvent[att.attribute] = att.value;
                     });
                     
-                    overdueEvent.dueDate = DateUtils.format(row.dueDate);
+                    overdueEvent.dueDate = DateUtils.formatFromApiToUser(row.dueDate);
                     overdueEvent.event = row.event;
                     overdueEvent.eventName = row.eventName;
                     overdueEvent.followup = row.followup;
@@ -118,7 +118,7 @@
                     overdueEvent.programStage = row.programStage;
                     overdueEvent.trackedEntityInstance = row.trackedEntityInstance;
                     overdueEvent.orgUnitName = row.registrationOrgUnit;
-                    overdueEvent.created = DateUtils.format(row.registrationDate);;
+                    overdueEvent.created = DateUtils.formatFromApiToUser(row.registrationDate);;
                     $scope.overdueEvents.push(overdueEvent);
                     
                 });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js	2014-10-01 15:19:59 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js	2014-10-13 14:47:39 +0000
@@ -13,7 +13,7 @@
 
     TranslationService.translate();
     
-    $scope.today = DateUtils.format(moment());
+    $scope.today = DateUtils.getToday();
     
     $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
     $scope.selectedOuMode = $scope.ouModes[0];
@@ -85,14 +85,18 @@
             var teis = TEIGridService.format(data,true);     
             $scope.teiList = [];
 
-            DHIS2EventFactory.getByOrgUnitAndProgram($scope.selectedOrgUnit.id, $scope.selectedOuMode.name, $scope.selectedProgram.id, report.startDate, report.endDate).then(function(eventList){
+            DHIS2EventFactory.getByOrgUnitAndProgram($scope.selectedOrgUnit.id, 
+                                                    $scope.selectedOuMode.name, 
+                                                    $scope.selectedProgram.id, 
+                                                    DateUtils.formatFromUserToApi(report.startDate), 
+                                                    DateUtils.formatFromUserToApi(report.endDate)).then(function(eventList){
                 $scope.dhis2Events = [];                
                 angular.forEach(eventList, function(ev){
                     if(ev.trackedEntityInstance){
                         ev.name = $scope.programStages[ev.programStage].name;
                         ev.programName = $scope.selectedProgram.name;
                         ev.statusColor = EventUtils.getEventStatusColor(ev); 
-                        ev.eventDate = DateUtils.format(ev.eventDate);
+                        ev.eventDate = DateUtils.formatFromApiToUser(ev.eventDate);
                         
                         if($scope.dhis2Events[ev.trackedEntityInstance]){
                             if(teis.rows[ev.trackedEntityInstance]){

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/reportForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/reportForm.html	2014-10-09 15:37:26 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/reportForm.html	2014-10-13 14:47:39 +0000
@@ -38,12 +38,19 @@
                            class="form-control" 
                            ng-date 
                            ng-model="report.startDate" 
-                           max="today" 
+                           max="today"
                            ng-required="true"/> 
                     <span ng-show="outerForm.submitted && outerForm.reportStartDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}} ({{dhis2CalendarFormat.keyDateFormat}})</span>
                 </td>
                 <td>
-                    <input type="text" name="reportEndDate" placeholder="{{'end_date'| translate}} ({{dhis2CalendarFormat.keyDateFormat}})" class="form-control" ng-date ng-model="report.endDate" max="today" ng-required="true"/>
+                    <input type="text" 
+                           name="reportEndDate" 
+                           placeholder="{{'end_date'| translate}} ({{dhis2CalendarFormat.keyDateFormat}})" 
+                           class="form-control" 
+                           ng-date 
+                           ng-model="report.endDate" 
+                           max="today" 
+                           ng-required="true"/>
                     <span ng-show="outerForm.submitted && outerForm.reportEndDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}} ({{dhis2CalendarFormat.keyDateFormat}})</span>
                 </td>
             </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js	2014-10-08 08:48:34 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js	2014-10-13 14:47:39 +0000
@@ -61,7 +61,7 @@
             angular.forEach(eventList, function(ev){
                 if(ev.program){       
                     ev.visited = true;
-                    ev.dueDate = DateUtils.format(ev.dueDate);  
+                    ev.dueDate = DateUtils.formatFromApiToUser(ev.dueDate);  
                     ev.sortingDate = ev.dueDate;
                     ev.name = $scope.programStageNames[ev.programStage].name;
                     ev.programName = $scope.programNames[ev.program].name;
@@ -104,7 +104,7 @@
         $scope.selectedReport = $scope.report[pr.id];
         
         //today as report date
-        $scope.today = DateUtils.format(moment());
+        $scope.today = DateUtils.getToday();
 
         //process tei attributes, this is to have consistent display so that the tei 
         //contains program attributes whether it has value or not
@@ -150,8 +150,8 @@
 
             //get enrollment details
             EnrollmentService.get(enr).then(function(enrollment){
-                enrollment.dateOfEnrollment = DateUtils.format(enrollment.dateOfEnrollment);
-                enrollment.dateOfIncident = DateUtils.format(enrollment.dateOfIncident);            
+                enrollment.dateOfEnrollment = DateUtils.formatFromApiToUser(enrollment.dateOfEnrollment);
+                enrollment.dateOfIncident = DateUtils.formatFromApiToUser(enrollment.dateOfIncident);            
                 angular.forEach(enrollment.notes, function(note){
                     note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
                 });            

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-09-18 14:53:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-10-13 14:47:39 +0000
@@ -15,7 +15,7 @@
 
     TranslationService.translate();
     
-    $scope.today = DateUtils.format(moment());
+    $scope.today = DateUtils.getToday();
     
     $scope.selectedOuMode = 'SELECTED';
     $scope.report = {};
@@ -85,7 +85,14 @@
         $scope.reportStarted = true;        
         
         $scope.upcomingEvents = [];
-        EventReportService.getEventReport($scope.selectedOrgUnit.id, $scope.selectedOuMode, $scope.selectedProgram.id, $scope.report.startDate, $scope.report.endDate, 'ACTIVE','SCHEDULE', $scope.pager).then(function(data){                     
+        EventReportService.getEventReport($scope.selectedOrgUnit.id, 
+                                        $scope.selectedOuMode, 
+                                        $scope.selectedProgram.id, 
+                                        DateUtils.formatFromUserToApi($scope.report.startDate), 
+                                        DateUtils.formatFromUserToApi($scope.report.endDate), 
+                                        'ACTIVE',
+                                        'SCHEDULE', 
+                                        $scope.pager).then(function(data){                     
                 
             if( data.pager ){
                 $scope.pager = data.pager;
@@ -103,7 +110,7 @@
                     upcomingEvent[att.attribute] = att.value;
                 });
 
-                upcomingEvent.dueDate = DateUtils.format(row.dueDate);
+                upcomingEvent.dueDate = DateUtils.formatFromApiToUser(row.dueDate);
                 upcomingEvent.event = row.event;
                 upcomingEvent.eventName = row.eventName;
                 upcomingEvent.followup = row.followup;
@@ -111,7 +118,7 @@
                 upcomingEvent.programStage = row.programStage;
                 upcomingEvent.trackedEntityInstance = row.trackedEntityInstance;
                 upcomingEvent.orgUnitName = row.registrationOrgUnit;
-                upcomingEvent.created = DateUtils.format(row.registrationDate);;
+                upcomingEvent.created = DateUtils.formatFromApiToUser(row.registrationDate);;
                 $scope.upcomingEvents.push(upcomingEvent);
 
             });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html	2014-10-13 14:47:39 +0000
@@ -7,17 +7,31 @@
         <meta name="keywords" content="DHIS 2">        
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">              
-        
-        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>        
+
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/ui/jquery-ui.min.js"></script>
-        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.tmpl.js"></script> 
-        <link rel="stylesheet" type="text/css" href="../dhis-web-commons/javascripts/jQuery/ui/css/redmond/jquery-ui.css">
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.plugin.min.js"></script>
+        
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.picker.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.plus.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.picker.ext.js"></script>
+        
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.coptic.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.ethiopian.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.islamic.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.julian.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.nepali.min.js"></script>
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.thai.min.js"></script>      
 
+        <link type="text/css" rel="stylesheet" href="../dhis-web-commons/javascripts/jQuery/ui/css/redmond/jquery-ui.css">
+        <link type="text/css" rel="stylesheet" href="../dhis-web-commons/javascripts/jQuery/calendars/css/ui-redmond.calendars.picker.css">
+        
         <script type="text/javascript" src="../dhis-web-commons/select2/select2.min.js"></script>
         <link type="text/css" rel="stylesheet" media="screen" href="../dhis-web-commons/select2/select2.css"> 
 
         <script type="text/javascript" src="../dhis-web-commons/bootstrap/js/bootstrap.min.js"></script>     
-        <link rel="stylesheet" type="text/css" href="../dhis-web-commons/bootstrap/css/bootstrap.min.css">
+        <link type="text/css" rel="stylesheet"  href="../dhis-web-commons/bootstrap/css/bootstrap.min.css">        
 
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-resource.js"></script>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/app.js	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/app.js	2014-10-13 14:47:39 +0000
@@ -54,10 +54,8 @@
     $translateProvider.preferredLanguage('en');
 })
 
-.run(function($rootScope, storage){
-    $rootScope.dhis2CalendarFormat = {keyDateFormat: 'yyyy-MM-dd', keyCalendar: 'iso8601'};
-    var storedFormat = storage.get('CALENDAR_SETTING');
-    if(angular.isObject(storedFormat) && storedFormat.keyDateFormat && storedFormat.keyCalendar){
-        $rootScope.dhis2CalendarFormat = storedFormat;
-    }    
+.run(function($rootScope){    
+    setTimeout(function () {
+        $rootScope.$apply(function () {});
+    }, 1000);
 });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-10-09 15:37:26 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-10-13 14:47:39 +0000
@@ -60,7 +60,7 @@
             
             $scope.loadPrograms($scope.selectedOrgUnit);                                
         }
-    });    
+    });
     
     //watch for changes in ou mode - mode could be selected without notifcation to grid column generator
     $scope.$watch('selectedOuMode.name', function() {           
@@ -85,8 +85,8 @@
     }
     
     //load programs associated with the selected org unit.
-    $scope.loadPrograms = function(orgUnit) {        
-  
+    $scope.loadPrograms = function(orgUnit) {
+        
         $scope.selectedOrgUnit = orgUnit;
         
         if (angular.isObject($scope.selectedOrgUnit)) {   

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-10-13 14:47:39 +0000
@@ -17,7 +17,7 @@
     };   
 })
 
-.directive('selectedOrgUnit', function() {
+.directive('selectedOrgUnit', function(storage) {
     return {        
         restrict: 'A',        
         link: function(scope, element, attrs){  
@@ -69,8 +69,8 @@
             selection.setListenerFunction( organisationUnitSelected );
             selection.responseReceived();
             
-            function organisationUnitSelected( orgUnits, orgUnitNames ) {
-                scope.selectedOrgUnit = {id: orgUnits[0], name: orgUnitNames[0]};                    
+            function organisationUnitSelected( orgUnits, orgUnitNames ) {                
+                scope.selectedOrgUnit = {id: orgUnits[0], name: orgUnitNames[0]};
                 scope.$apply();
             }            
         }  
@@ -185,14 +185,14 @@
     };
 })
 
-.directive('ngDate', function(DateUtils, $rootScope) {
+/*.directive('ngDate', function(DateUtils, $rootScope) {
     return {
         restrict: 'A',
         require: 'ngModel',        
         link: function(scope, element, attrs, ctrl) {
 
             var dateFormat = 'yy-mm-dd';
-            if($rootScope.keyDateFormat === 'dd-MM-yyyy'){
+            if($rootScope.dhis2CalendarFormat.keyDateFormat === 'dd-MM-yyyy'){
                 dateFormat = 'dd-mm-yy';
             }
             element.datepicker({
@@ -228,12 +228,64 @@
             });    
         }      
     };   
+})*/
+
+.directive('ngDate', function(DateUtils, CalendarService, storage, $parse) {
+    return {
+        restrict: 'A',
+        require: 'ngModel',        
+        link: function(scope, element, attrs, ctrl) {    
+            
+            var calendarSetting = CalendarService.getSetting();            
+            var dateFormat = 'yyyy-mm-dd';
+            if(calendarSetting.keyDateFormat === 'dd-MM-yyyy'){
+                dateFormat = 'dd-mm-yyyy';
+            }            
+            
+            var minDate = $parse(attrs.minDate)(scope), 
+                maxDate = $parse(attrs.maxDate)(scope),
+                calendar = $.calendars.instance(calendarSetting.keyCalendar);
+            
+            element.calendarsPicker({
+                changeMonth: true,
+                dateFormat: dateFormat,
+                yearRange: '-120:+30',
+                minDate: minDate,
+                maxDate: maxDate,
+                calendar: calendar, 
+                renderer: $.calendars.picker.themeRollerRenderer,
+                onSelect: function(date) {
+                    //scope.date = date;
+                    ctrl.$setViewValue(date);
+                    $(this).change();                    
+                    scope.$apply();
+                }
+            })
+            .change(function() {                
+                var rawDate = this.value;
+                var convertedDate = DateUtils.format(this.value);
+
+                if(rawDate != convertedDate){
+                    scope.invalidDate = true;
+                    ctrl.$setViewValue(this.value);                                   
+                    ctrl.$setValidity('foo', false);                    
+                    scope.$apply();     
+                }
+                else{
+                    scope.invalidDate = false;
+                    ctrl.$setViewValue(this.value);                                   
+                    ctrl.$setValidity('foo', true);                    
+                    scope.$apply();     
+                }
+            });    
+        }      
+    };   
 })
 
 .directive('blurOrChange', function() {
     
     return function( scope, elem, attrs) {
-        elem.datepicker({
+        elem.calendarsPicker({
             onSelect: function() {
                 scope.$apply(attrs.blurOrChange);
                 $(this).change();                                        

=== 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	2014-10-09 15:37:26 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-10-13 14:47:39 +0000
@@ -66,7 +66,6 @@
     };
 })
 
-
 /* Factory to fetch programs */
 .factory('ProgramFactory', function($q, $rootScope, StorageService) { 
     return {
@@ -429,7 +428,7 @@
                 StorageService.currentStore.getAll('attributes').done(function(attributes){
                     angular.forEach(attributes, function(att){
                         if(att.optionSet){
-                           StorageService.currentStore.get('optionSets', att.optionSet.id).done(function(optionSet){
+                            StorageService.currentStore.get('optionSets', att.optionSet.id).done(function(optionSet){
                                 att.optionSet = optionSet;
                             });
                         }
@@ -1209,31 +1208,61 @@
     };
 })
 
-.service('DateUtils', function($filter, storage, $rootScope){
+.service('DateUtils', function($filter, CalendarService){
     
     return {
         format: function(dateValue) {            
-            dateValue = Date.parse(dateValue);
-            dateValue = $filter('date')(dateValue, $rootScope.dhis2CalendarFormat.keyDateFormat);            
+            if(!dateValue){
+                return;
+            }            
+            var calendarSetting = CalendarService.getSetting();
+            dateValue = $filter('date')(dateValue, calendarSetting.keyDateFormat);            
             return dateValue;
         },
-        formatToHrsMins: function(dateValue) {          
+        formatToHrsMins: function(dateValue) {
+            var calendarSetting = CalendarService.getSetting();
             var dateFormat = 'YYYY-MM-DD @ hh:mm A';
-            if($rootScope.dhis2CalendarFormat.keyDateFormat === 'dd-MM-yyyy'){
+            if(calendarSetting.keyDateFormat === 'dd-MM-yyyy'){
                 dateFormat = 'DD-MM-YYYY @ hh:mm A';
             }            
             return moment(dateValue).format(dateFormat);
+        },
+        getToday: function(){  
+            var calendarSetting = CalendarService.getSetting();
+            var tdy = $.calendars.instance(calendarSetting.keyCalendar).newDate();            
+            var today = moment(tdy._year + '-' + tdy._month + '-' + tdy._day, 'YYYY-MM-DD')._d;            
+            today = Date.parse(today);     
+            today = $filter('date')(today,  calendarSetting.keyDateFormat);
+            return today;
+        },
+        formatFromUserToApi: function(dateValue){            
+            if(!dateValue){
+                return;
+            }
+            var calendarSetting = CalendarService.getSetting();            
+            dateValue = moment(dateValue, calendarSetting.momentFormat)._d;
+            dateValue = Date.parse(dateValue);     
+            dateValue = $filter('date')(dateValue, 'yyyy-MM-dd'); 
+            return dateValue;            
+        },
+        formatFromApiToUser: function(dateValue){            
+            if(!dateValue){
+                return;
+            }            
+            var calendarSetting = CalendarService.getSetting();
+            dateValue = moment(dateValue, 'YYYY-MM-DD')._d;
+            dateValue = Date.parse(dateValue);     
+            dateValue = $filter('date')(dateValue, calendarSetting.keyDateFormat); 
+            return dateValue;
         }
     };
 })
 
-.service('EventUtils', function(DateUtils, OrgUnitService){
+.service('EventUtils', function(DateUtils, CalendarService, OrgUnitService, $filter, orderByFilter){
     return {
-        createDummyEvent: function(programStage, orgUnit, enrollment){
-            
-            var today = DateUtils.format(moment());
-    
-            var dueDate = this.getEventDueDate(programStage, enrollment);
+        createDummyEvent: function(events, programStage, orgUnit, enrollment){            
+            var today = DateUtils.getToday();    
+            var dueDate = this.getEventDueDate(events, programStage, enrollment);
             var dummyEvent = {programStage: programStage.id, 
                               orgUnit: orgUnit.id,
                               orgUnitName: orgUnit.name,
@@ -1249,8 +1278,8 @@
             return dummyEvent;        
         },
         getEventStatusColor: function(dhis2Event){    
-            var today = DateUtils.format(moment());
-            var eventDate = today;
+            var eventDate = DateUtils.getToday();
+            var calendarSetting = CalendarService.getSetting();
             
             if(dhis2Event.eventDate){
                 eventDate = dhis2Event.eventDate;
@@ -1267,17 +1296,34 @@
                     return 'alert alert-info'; //'stage-executed';
                 }
                 else{
-                    if(moment(eventDate).isAfter(dhis2Event.dueDate)){
+                    if(moment(eventDate, calendarSetting.momentFormat).isAfter(dhis2Event.dueDate)){
                         return 'alert alert-danger';//'stage-overdue';
                     }                
                     return 'alert alert-warning';//'stage-on-time';
                 }               
             }            
         },
-        getEventDueDate: function(programStage, enrollment){
-            //var dueDate = DateUtils.format(enrollment.dateOfIncident);
-            var dueDate = moment(enrollment.dateOfIncident).add('d', programStage.minDaysFromStart);
-            dueDate = DateUtils.format(dueDate);            
+        getEventDueDate: function(events, programStage, enrollment){
+            var referenceDate = enrollment.dateOfIncident ? enrollment.dateOfIncident : enrollment.dateOfEnrollment;
+            var offset = programStage.minDaysFromStart;
+            
+            if(programStage.repeatable){
+                var eventsPerStage = [];
+                angular.forEach(events, function(event){
+                    if(event.programStage === programStage.id){
+                        eventsPerStage.push(event);
+                    }
+                });
+
+                if(eventsPerStage.length > 0){
+                    eventsPerStage = orderByFilter(eventsPerStage, '-eventDate');
+                    referenceDate = eventsPerStage[0].eventDate;
+                    offset = programStage.standardInterval;
+                }                
+            }
+            var calendarSetting = CalendarService.getSetting();
+            var dueDate = moment(referenceDate, calendarSetting.momentFormat).add('d', offset)._d;
+            dueDate = $filter('date')(dueDate, calendarSetting.keyDateFormat); 
             return dueDate;
         },
         getEventOrgUnitName: function(orgUnitId){            
@@ -1328,4 +1374,30 @@
             return e;
         }
     }; 
+})
+
+/* service for getting calendar setting */
+.service('CalendarService', function(storage, $rootScope){    
+
+    return {
+        getSetting: function() {
+            
+            var dhis2CalendarFormat = {keyDateFormat: 'yyyy-MM-dd', keyCalendar: 'gregorian', momentFormat: 'YYYY-MM-DD'};                
+            var storedFormat = storage.get('CALENDAR_SETTING');
+            if(angular.isObject(storedFormat) && storedFormat.keyDateFormat && storedFormat.keyCalendar){
+                if(storedFormat.keyCalendar === 'iso8601'){
+                    storedFormat.keyCalendar = 'gregorian';
+                }
+
+                if(storedFormat.keyDateFormat === 'dd-MM-yyyy'){
+                    dhis2CalendarFormat.momentFormat = 'DD-MM-YYYY';
+                }
+                
+                dhis2CalendarFormat.keyCalendar = storedFormat.keyCalendar;
+                dhis2CalendarFormat.keyDateFormat = storedFormat.keyDateFormat;
+            }
+            $rootScope.dhis2CalendarFormat = dhis2CalendarFormat;
+            return dhis2CalendarFormat;
+        }
+    };            
 });
\ 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	2014-10-09 13:41:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-10-13 14:47:39 +0000
@@ -20,6 +20,8 @@
 
 var TRACKER_VALUES = 'TRACKER_VALUES';
 
+var optionSetsInPromise = [];
+
 dhis2.tc.store = new dhis2.storage.Store({
     name: TC_STORE_NAME,
     adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
@@ -277,7 +279,8 @@
                 var d = $.Deferred();
                 var p = d.promise();
                 dhis2.tc.store.get('optionSets', attribute.optionSet.id).done(function(obj) {                    
-                    if(!obj || obj.version !== attribute.optionSet.version) {
+                    if((!obj || obj.version !== attribute.optionSet.version) && !optionSetsInPromise[attribute.optionSet.id]) {
+                        optionSetsInPromise[attribute.optionSet.id] = attribute.optionSet.id;
                         promise = promise.then( getOptionSet( attribute.optionSet.id ) );
                     }
                     d.resolve();
@@ -394,7 +397,7 @@
         return $.ajax( {
             url: '../api/programs.json',
             type: 'GET',
-            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,dataEntryMethod,relationshipText,relationshipFromA,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,realionshipText,relationshipFromA,selectEnrollmentDatesInFuture,selectIncidentDatesInFuture,onlyEnrollOnce,externalAccess,displayOnAllOrgunit,registration,trackedEntity[id,name,description],userRoles[id,name],organisationUnits[id,name],programStages[id,name,version,minDaysFromStart,reportDateDescription,repeatable,autoGenerateEvent],programTrackedEntityAttributes[displayInList,mandatory,trackedEntityAttribute[id]]'
+            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,dataEntryMethod,relationshipText,relationshipFromA,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,realionshipText,relationshipFromA,selectEnrollmentDatesInFuture,selectIncidentDatesInFuture,onlyEnrollOnce,externalAccess,displayOnAllOrgunit,registration,trackedEntity[id,name,description],userRoles[id,name],organisationUnits[id,name],programStages[id,name,version,minDaysFromStart,standardInterval,reportDateDescription,repeatable,autoGenerateEvent],programTrackedEntityAttributes[displayInList,mandatory,trackedEntityAttribute[id]]'
         }).done( function( response ){
             
             _.each( _.values( response.programs ), function ( program ) { 
@@ -471,7 +474,7 @@
         return $.ajax( {
             url: '../api/programStages.json',
             type: 'GET',
-            data: 'filter=id:eq:' + id +'&fields=id,name,version,dataEntryForm,captureCoordinates,blockEntryForm,autoGenerateEvent,reportDateDescription,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,formName,type,optionSet[id]]]'
+            data: 'filter=id:eq:' + id +'&fields=id,name,version,dataEntryForm,captureCoordinates,blockEntryForm,autoGenerateEvent,reportDateDescription,minDaysFromStart,standardInterval,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,formName,type,optionSet[id]]]'
         }).done( function( response ){            
             _.each( _.values( response.programStages ), function( programStage ) {
                 dhis2.tc.store.set( 'programStages', programStage );
@@ -496,22 +499,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.tc.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();
+        _.each(_.values( program.programStages), function( programStage) {
+            _.each(_.values( programStage.programStageDataElements), function(prStDe){            
+                if( prStDe.dataElement.optionSet && prStDe.dataElement.optionSet.id ){
+                    build = build.then(function() {
+                        var d = $.Deferred();
+                        var p = d.promise();
+                        dhis2.tc.store.get('optionSets', prStDe.dataElement.optionSet.id).done(function(obj) {                            
+                            if((!obj || obj.version !== prStDe.dataElement.optionSet.version) && !optionSetsInPromise[prStDe.dataElement.optionSet.id]) {                                
+                                optionSetsInPromise[prStDe.dataElement.optionSet.id] = prStDe.dataElement.optionSet.id;                                
+                                promise = promise.then( getOptionSet( prStDe.dataElement.optionSet.id ) );
+                            }
+                            d.resolve();
+                        });
+
+                        return p;
                     });
-
-                    return p;
-                });
-            }            
-        });                      
+                }            
+            });
+        });                              
     });
 
     build.done(function() {

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-10-03 08:25:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-10-13 14:47:39 +0000
@@ -796,6 +796,11 @@
     cursor: pointer;
 }
 
+.ui-datepicker-group .ui-datepicker-header {
+	//height: 1.5em; 
+    height: inherit;  //this is to make it play nice with bootstrap
+}
+
 @media print {
     #header, #leftBar, .not-printable {
         display: none;