← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15790: event creation in tei dashboard

 

------------------------------------------------------------
revno: 15790
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Fri 2014-06-20 16:23:28 +0200
message:
  event creation in tei dashboard
modified:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js
  dhis-2/dhis-web/dhis-web-tracker-capture/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-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-06-19 15:27:17 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-06-20 14:23:28 +0000
@@ -69,7 +69,7 @@
     $scope.broadCastProgram = function(){
         CurrentSelection.set({tei: $scope.selectedEntity, pr: $scope.selectedProgram});
         $timeout(function() { 
-            $rootScope.$broadcast('selectedEntity', {});
+            $rootScope.$broadcast('selectedEntity', {programExists: $scope.programs.length > 0});
         }, 100); 
     };
      

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-06-20 14:23:28 +0000
@@ -2,11 +2,13 @@
         function($scope, 
                 $filter,
                 DateUtils,
+                EventUtils,
                 orderByFilter,
                 storage,
                 ProgramStageFactory,
                 DHIS2EventFactory,
                 OrgUnitService,
+                DialogService,
                 CurrentSelection,
                 TranslationService) {
 
@@ -17,98 +19,152 @@
     today = $filter('date')(today, 'yyyy-MM-dd');
      
     //listen for the selected items
-    $scope.$on('dashboard', function(event, args) { 
+    $scope.$on('dashboard', function(event, args) {  
+        $scope.showDataEntryDiv = false;
+        $scope.showEventCreationDiv = false;
+        $scope.currentDummyEvent = null;
         $scope.currentEvent = null;
+            
         $scope.allowEventCreation = false;
         $scope.repeatableStages = [];        
-        $scope.dhis2Events = [];       
+        $scope.dhis2Events = [];
         
         var selections = CurrentSelection.get();          
         $scope.selectedOrgUnit = storage.get('SELECTED_OU');
         $scope.selectedEntity = selections.tei;      
         $scope.selectedProgram = selections.pr;        
-        $scope.selectedEnrollment = selections.enrollment;        
+        $scope.selectedEnrollment = selections.enrollment;   
+        $scope.selectedProgramWithStage = [];
         
         if($scope.selectedOrgUnit && 
                 $scope.selectedProgram && 
                 $scope.selectedEntity && 
                 $scope.selectedEnrollment){
             
-            DHIS2EventFactory.getByEntity($scope.selectedEntity.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id).then(function(data){
-                $scope.dhis2Events = data;
-               
-                if(angular.isUndefined($scope.dhis2Events)){
-                    
-                    //create dummy events
-                    $scope.dummyEvents = [];
-                    
-                    if($scope.selectedEnrollment.status === 'ACTIVE'){
-                        //create dummy events for the selected enrollment                        
-                        angular.forEach($scope.selectedProgram.programStages, function(programStage){                                                        
-                            var dummyEvent = $scope.createDummyEvent(programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
-                            $scope.dummyEvents.push(dummyEvent);                            
-                        });
-                        
-                        $scope.dummyEvents = orderByFilter($scope.dummyEvents, '-eventDate');
-                        $scope.dummyEvents.reverse();                        
-                    }
+            angular.forEach($scope.selectedProgram.programStages, function(stage){
+                $scope.selectedProgramWithStage[stage.id] = stage;
+            });
+            $scope.getEvents();
+        }
+    });
+    
+    $scope.getEvents = function(){
+        
+        DHIS2EventFactory.getByEntity($scope.selectedEntity.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id).then(function(data){
+            $scope.dhis2Events = data;
+
+            if(angular.isUndefined($scope.dhis2Events)){
+
+                //create dummy events
+                $scope.dummyEvents = [];
+
+                if($scope.selectedEnrollment.status === 'ACTIVE'){
+                    //create dummy events for the selected enrollment                        
+                    angular.forEach($scope.selectedProgram.programStages, function(programStage){                                                        
+                        var dummyEvent = EventUtils.createDummyEvent(programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+                        $scope.dummyEvents.push(dummyEvent);                            
+                    });
+
+                    $scope.dummyEvents = orderByFilter($scope.dummyEvents, '-eventDate');
+                    $scope.dummyEvents.reverse();                        
                 }
-                else{
-                    angular.forEach($scope.dhis2Events, function(dhis2Event){
+            }
+            else{
+                angular.forEach($scope.dhis2Events, function(dhis2Event){
                     
-                        ProgramStageFactory.get(dhis2Event.programStage).then(function(stage){
-                            //check if a stage is repeatable
-                            if(stage.repeatable){
-                                $scope.allowEventCreation = true;
-                                if($scope.repeatableStages.indexOf(stage) === -1){
-                                    $scope.repeatableStages.push(stage);
-                                }
-                            }
-
-                            dhis2Event.name = stage.name;
-                        });
+                    var eventStage = $scope.selectedProgramWithStage[dhis2Event.programStage];
+                    if(angular.isObject(eventStage)){
                         
-                        dhis2Event.eventDate = DateUtils.format(dhis2Event.eventDate);
-
+                        dhis2Event.name = eventStage.name;
                         if(dhis2Event.status === 'COMPLETED'){
                             dhis2Event.statusColor = 'stage-completed';
                         }
                         else{
                             dhis2Event.statusColor = 'stage-on-time';
 
-                            if(moment(today).isAfter(dhis2Event.eventDate)){
+                            if(dhis2Event.dueDate){
+                                dhis2Event.dueDate = DateUtils.format(dhis2Event.dueDate);
+                            }
+                            else{
+                                dhis2Event.dueDate = DateUtils.getDueDate(eventStage, $scope.selectedEnrollment);
+                            }
+
+                            if(moment(today).isAfter(dhis2Event.dueDate) && !dhis2Event.dataValues){
                                 dhis2Event.statusColor = 'stage-overdue';
-                            }                        
-                        } 
-
-                        //get orgunit name for the event
-                        if(dhis2Event.orgUnit){
-                            OrgUnitService.open().then(function(){
-                                OrgUnitService.get(dhis2Event.orgUnit).then(function(ou){
-                                    if(ou){
-                                        dhis2Event.orgUnitName = ou.n;
-                                    }                                                       
-                                });                            
-                            }); 
-                        }                                                             
-                    });
-
-                    $scope.dhis2Events = orderByFilter($scope.dhis2Events, '-eventDate');
-                    $scope.dhis2Events.reverse();                    
-                }
-            });          
-        }
-    });
+                            }
+                        }
+                    }                     
+                    
+                    dhis2Event.eventDate = DateUtils.format(dhis2Event.eventDate);
+                    
+                    //get orgunit name for the event
+                    if(dhis2Event.orgUnit){
+                        OrgUnitService.open().then(function(){
+                            OrgUnitService.get(dhis2Event.orgUnit).then(function(ou){
+                                if(ou){
+                                    dhis2Event.orgUnitName = ou.n;
+                                }                                                       
+                            });                            
+                        }); 
+                    }                                                             
+                });
+
+                $scope.dhis2Events = orderByFilter($scope.dhis2Events, '-eventDate');
+                $scope.dhis2Events.reverse();                    
+            }
+        });          
+    };
     
-    $scope.createNewEvent = function(){
-        console.log('need to create new event:  ', $scope.repeatableStages);        
+    $scope.createEvent = function(){
+        //check for form validity
+        $scope.eventCreationForm.submitted = true;        
+        if( $scope.eventCreationForm.$invalid ){
+            return false;
+        } 
+        
+        //form is valid, proceed to event creation
+        var newEvent = 
+                {
+                    trackedEntityInstance: $scope.selectedEntity.trackedEntityInstance,
+                    program: $scope.selectedProgram.id,
+                    programStage: $scope.currentDummyEvent.programStage,
+                    orgUnit: $scope.currentDummyEvent.orgUnit,
+                    eventDate: $scope.currentDummyEvent.eventDate,
+                    dueDate: $scope.currentDummyEvent.dueDate,
+                    status: 'ACTIVE',
+                    notes: [],
+                    dataValues: []
+                };
+                
+        DHIS2EventFactory.create(newEvent).then(function(data) {
+            if (data.importSummaries[0].status === 'ERROR') {
+                var dialogOptions = {
+                    headerText: 'event_creation_error',
+                    bodyText: data.importSummaries[0].description
+                };
+
+                DialogService.showDialog({}, dialogOptions);
+            }
+            else {
+                $scope.getEvents();
+                
+            }
+        });
     };
     
     $scope.showEventCreation = function(dummyEvent){
         
-        if(dummyEvent){            
-            $scope.currentDummyEvent = dummyEvent;
-            console.log('need to provide event creation interface');            
+        if(dummyEvent){    
+            
+            if($scope.currentDummyEvent == dummyEvent){ 
+                //clicked on the same stage, do toggling
+                $scope.currentDummyEvent = null;
+                $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
+            }
+            else{
+                $scope.currentDummyEvent = dummyEvent;
+                $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
+            }   
         }
     };   
     
@@ -116,35 +172,47 @@
         
         if(event){
             
-            $scope.currentEvent = event;
-            $scope.currentEvent.providedElsewhere = [];
-            
-            ProgramStageFactory.get($scope.currentEvent.programStage).then(function(stage){
-                $scope.currentStage = stage;
-           
-                angular.forEach($scope.currentStage.programStageDataElements, function(prStDe){
-                    $scope.currentStage.programStageDataElements[prStDe.dataElement.id] = prStDe.dataElement;
-                    if(prStDe.allowProvidedElsewhere){
-                        $scope.currentEvent.providedElsewhere[prStDe.dataElement.id] = '';   
-                    }                
-                });
-
-                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){
-                            val = parseInt(val);
-                            dataValue.value = val;
-                        }
-                        $scope.currentEvent[dataValue.dataElement] = val;
-                    }                    
-                });
-                
-                $scope.currentEvent.dataValues = [];
-            });                 
+            if($scope.currentEvent && $scope.currentEvent.event === event.event){
+                //clicked on the same stage, do toggling
+                $scope.currentEvent = null;
+                $scope.showDataEntryDiv = !$scope.showDataEntryDiv;                
+            }
+            else{
+                $scope.currentEvent = event;
+                $scope.showDataEntryDiv = !$scope.showDataEntryDiv;
+                $scope.getDataEntryForm();
+            }               
         }
-    };    
+    }; 
+    
+    $scope.getDataEntryForm = function(){
+        $scope.currentEvent.providedElsewhere = [];
+            
+        ProgramStageFactory.get($scope.currentEvent.programStage).then(function(stage){
+            $scope.currentStage = stage;
+
+            angular.forEach($scope.currentStage.programStageDataElements, function(prStDe){
+                $scope.currentStage.programStageDataElements[prStDe.dataElement.id] = prStDe.dataElement;
+                if(prStDe.allowProvidedElsewhere){
+                    $scope.currentEvent.providedElsewhere[prStDe.dataElement.id] = '';   
+                }                
+            });
+
+            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){
+                        val = parseInt(val);
+                        dataValue.value = val;
+                    }
+                    $scope.currentEvent[dataValue.dataElement] = val;
+                }                    
+            });
+
+            $scope.currentEvent.dataValues = [];
+        }); 
+    };
     
     $scope.saveDatavalue = function(prStDe){
         
@@ -207,19 +275,17 @@
     
     $scope.createDummyEvent = function(programStage, orgUnit, enrollment){
         
-        var eventDate = moment(moment(enrollment.dateOfIncident).add('d', programStage.minDaysFromStart), 'YYYY-MM-DD')._d;
-        eventDate = Date.parse(eventDate);
-        eventDate = $filter('date')(eventDate, 'yyyy-MM-dd');
+        var dueDate = DateUtils.getDueDate(programStage, enrollment);
         var dummyEvent = {programStage: programStage.id, 
                           orgUnit: orgUnit.id,
                           orgUnitName: orgUnit.name,
-                          eventDate: eventDate,
+                          dueDate: dueDate,
                           name: programStage.name,
                           status: 'ACTIVE'};
         dummyEvent.statusColor = 'stage-on-time';
-        if(moment(today).isAfter(dummyEvent.eventDate)){
+        if(moment(today).isAfter(dummyEvent.dueDate)){
             dummyEvent.statusColor = 'stage-overdue';
-        }        
-        return dummyEvent;        
+        }
+        return dummyEvent;
     };
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-06-20 14:23:28 +0000
@@ -27,105 +27,124 @@
                     </tr>
                 </tbody>                
             </table>
-            <hr>
-            <div ng-show="currentEvent">
-                <table class="table-borderless table-striped">
-                    <thead class="align-center">
+        </div>
+        <div ng-show="!dhis2Events && selectedEnrollment">            
+            <div ng-show="dummyEvents">
+                <div class="alert alert-warning">{{'no_event_is_yet_created'| translate}}</div>
+                <table class="table-borderless">
+                    <tbody>
                         <tr>
-                            <th class="align-center">
-                                {{'data_element'| translate}}
-                            </th>
-                            <th class="align-center">
-                                {{'value'| translate}}
-                            </th>
-                            <th class="align-center">
-                                {{'provided_elsewhere'| translate}}
-                            </th>
-                        </tr>
-                    </thead>
-
-                    <tr ng-repeat="prStDe in currentStage.programStageDataElements">
-                        <td>
-                            {{prStDe.dataElement.name}}
-                        </td>
-                        <td>
-                            <div ng-switch="prStDe.dataElement.type">
-                                <div ng-switch-when="int">
-                                    <input type="number"
-                                           class="form-control"
-                                           ng-model="currentEvent[prStDe.dataElement.id]" 
-                                           ng-required={{prStDe.compulsory}}
-                                           ng-blur="saveDatavalue(prStDe)" 
-                                           name="foo"/>
-                                </div>
-                                <div ng-switch-when="string">                                        
-                                    <input type="text"
-                                           class="form-control"
-                                           ng-model="currentEvent[prStDe.dataElement.id]" 
-                                           ng-required={{prStDe.compulsory}} 
-                                           typeahead="option for option in prStDe.dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
-                                           typeahead-open-on-focus    
-                                           ng-blur="saveDatavalue(prStDe)" 
-                                           name="foo"/>
-                                </div>
-                                <div ng-switch-when="bool">
-                                    <select class="form-control"
-                                            ng-model="currentEvent[prStDe.dataElement.id]" 
-                                            ng-required={{prStDe.compulsory}} 
-                                            ng-change="saveDatavalue(prStDe)" 
-                                            name="foo">
-                                        <option value="">{{'please_select'| translate}}</option>                        
-                                        <option value="0">{{'no'| translate}}</option>
-                                        <option value="1">{{'yes'| translate}}</option>
-                                    </select>
-
-                                </div>
-                                <div ng-switch-when="date">
-                                    <input type="text" 
-                                           placeholder="yyyy-mm-dd" 
-                                           ng-date 
-                                           class="form-control"
-                                           ng-model="saveDatavalue(prStDe)" 
-                                           ng-required={{prStDe.compulsory}}  
-                                           blur-or-change="saveDatavalue(dhis2Event, eventGridColumn.id)"
-                                           name="foo"/>
-                                </div>
-                            </div>
-                        </td>
-                        <td>                        
-                            <div class="align-center" ng-if="prStDe.allowProvidedElsewhere">
-                                <input type="checkbox" 
-                                       ng-model="currentEvent.providedElsewhere[prStDe.dataElement.id]"
-                                       ng-change="saveDatavalueLocation(prStDe)"/>
-                            </div>
-                        </td>
-                    </tr>
-                </table>    
-
+                            <td class="inline-block" ng-repeat="dummyEvent in dummyEvents">
+                                <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
+                                <span class="stage-container"                                                     
+                                      ng-class="{'current-stage': currentDummyEvent && currentDummyEvent.programStage == dummyEvent.programStage, '{{dummyEvent.statusColor}}': true}"                                                      
+                                      ng-click="showEventCreation(dummyEvent)">
+                                    {{dummyEvent.name}}<br/>
+                                    {{dummyEvent.dueDate}}         
+                                </span>
+                                <i class="fa fa-arrow-right" ng-show="$index < dummyEvents.length - 1"></i>
+                            </td>                        
+                        </tr>                        
+                    </tbody>                
+                </table>
+                <form name="eventCreationForm" novalidate ng-show="currentDummyEvent">
+                    <div class="row">
+                        <div class="col-md-6">
+                            {{currentDummyEvent.reportDateDescription}}
+                            <input type="text" name="eventDate" class="form-control" ng-date ng-model="currentDummyEvent.eventDate" ng-required="true"/>
+                            <span ng-show="eventCreationForm.submitted && eventCreationForm.eventDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                        </div>
+                        <div class="col-md-6">
+                            {{'due_date'| translate}}
+                            <input type="text" name="dueDate" class="form-control" ng-date ng-model="currentDummyEvent.dueDate" />
+                            <span ng-show="eventCreationForm.submitted && eventCreationForm.dueDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                        </div>                        
+                    </div>
+                    <div class="row vertical-spacing">   
+                        <div class="col-md-6">
+                            <button type="button" class="btn btn-default" ng-click="createEvent()">{{'create'| translate}}</button>
+                        </div>                        
+                    </div>
+                </form>
                 <hr>
-
             </div>
-        </div>
-        <div ng-if="!dhis2Events && selectedEnrollment">
-            <div class="alert alert-warning">{{'no_event_is_yet_created'| translate}}</div>
-            <table class="table-borderless">
-                <tbody>
+        </div>        
+        <div ng-show="currentEvent">
+            <hr>
+            <table class="table-borderless table-striped">
+                <thead class="align-center">
                     <tr>
-                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents">
-                            <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
-                            <span class="stage-container"                                                     
-                                  ng-class="{'current-stage': currentDummyEvent && currentDummyEvent.programStage == dummyEvent.programStage, '{{dummyEvent.statusColor}}': true}"                                                      
-                                  ng-click="showEventCreation(dummyEvent)">
-                                {{dummyEvent.name}}<br/>
-                                {{dummyEvent.eventDate}}         
-                            </span>
-                            <i class="fa fa-arrow-right" ng-show="$index < dummyEvents.length - 1"></i>
-                        </td>                        
+                        <th class="align-center">
+                            {{'data_element'| translate}}
+                        </th>
+                        <th class="align-center">
+                            {{'value'| translate}}
+                        </th>
+                        <th class="align-center">
+                            {{'provided_elsewhere'| translate}}
+                        </th>
                     </tr>
-                </tbody>                
+                </thead>
+                <tr ng-repeat="prStDe in currentStage.programStageDataElements">
+                    <td>
+                        {{prStDe.dataElement.name}}
+                    </td>
+                    <td>
+                        <div ng-switch="prStDe.dataElement.type">
+                            <div ng-switch-when="int">
+                                <input type="number"
+                                       class="form-control"
+                                       ng-model="currentEvent[prStDe.dataElement.id]" 
+                                       ng-required={{prStDe.compulsory}}
+                                       ng-blur="saveDatavalue(prStDe)" 
+                                       name="foo"/>
+                            </div>
+                            <div ng-switch-when="string">                                        
+                                <input type="text"
+                                       class="form-control"
+                                       ng-model="currentEvent[prStDe.dataElement.id]" 
+                                       ng-required={{prStDe.compulsory}} 
+                                       typeahead="option for option in prStDe.dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
+                                       typeahead-open-on-focus    
+                                       ng-blur="saveDatavalue(prStDe)" 
+                                       name="foo"/>
+                            </div>
+                            <div ng-switch-when="bool">
+                                <select class="form-control"
+                                        ng-model="currentEvent[prStDe.dataElement.id]" 
+                                        ng-required={{prStDe.compulsory}} 
+                                        ng-change="saveDatavalue(prStDe)" 
+                                        name="foo">
+                                    <option value="">{{'please_select'| translate}}</option>                        
+                                    <option value="0">{{'no'| translate}}</option>
+                                    <option value="1">{{'yes'| translate}}</option>
+                                </select>
+
+                            </div>
+                            <div ng-switch-when="date">
+                                <input type="text" 
+                                       placeholder="yyyy-mm-dd" 
+                                       ng-date 
+                                       class="form-control"
+                                       ng-model="saveDatavalue(prStDe)" 
+                                       ng-required={{prStDe.compulsory}}  
+                                       blur-or-change="saveDatavalue(dhis2Event, eventGridColumn.id)"
+                                       name="foo"/>
+                            </div>
+                        </div>
+                    </td>
+                    <td>                        
+                        <div class="align-center" ng-show="prStDe.allowProvidedElsewhere">
+                            <input type="checkbox" 
+                                   ng-model="currentEvent.providedElsewhere[prStDe.dataElement.id]"
+                                   ng-change="saveDatavalueLocation(prStDe)"/>
+                        </div>
+                    </td>
+                </tr>
             </table>
+            <hr>
         </div>
-        <div ng-if="!selectedEnrollment">
+        <div ng-show="!selectedEnrollment">
             <div class="alert alert-warning">{{'not_yet_enrolled'| translate}}</div> 
         </div>
     </div>

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-06-20 14:23:28 +0000
@@ -26,6 +26,8 @@
         var selections = CurrentSelection.get();
         $scope.selectedEntity = selections.tei; 
         $scope.selectedProgram = selections.pr;
+        $scope.programExists = args.programExists;
+        
         $scope.selectedOrgUnit = storage.get('SELECTED_OU');
         
         if($scope.selectedProgram){ 

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-06-20 14:23:28 +0000
@@ -8,11 +8,11 @@
     <div class="panel-body dashboard-widget-container">
         <div ng-if="selectedEnrollment">
             <table class="table-borderless">
-                <tr>
-                    <td>
+                <tr class="col-md-12">
+                    <td class="col-md-6">
                         {{selectedProgram.dateOfIncidentDescription}}
                     </td>
-                    <td>
+                    <td class="col-md-6">
                         <input type="text" class="form-control" ng-date ng-model="selectedEnrollment.dateOfIncident" ng-disabled="true"/>
                     </td>
                 </tr>
@@ -21,20 +21,20 @@
             <hr>
             <table class="table-borderless table-striped">
                 <thead>
-                    <tr>
-                        <th>
+                    <tr class="col-md-12">
+                        <th class="col-md-6">
                             {{'program_stage'| translate}}
                         </th>
-                        <th>
+                        <th class="col-md-6">
                             {{'scheduled_date'| translate}}
                         </th>
                     </tr>                
                 </thead>           
-                <tr ng-repeat="programStage in programStages">
-                    <td>
+                <tr class="col-md-12" ng-repeat="programStage in programStages">
+                    <td class="col-md-6">
                         {{programStage.name}}
                     </td>
-                    <td>
+                    <td class="col-md-6">
                         <input type="text" class="form-control" ng-date ng-model="programStage.dueDate" ng-disabled="!showSchedulingDiv"/>
                     </td>
                 </tr>
@@ -65,30 +65,30 @@
 
         <div ng-if="selectedProgram && !selectedEnrollment">
             <table class="table-borderless">
-                <tr>
-                    <td>
+                <tr class="col-md-12">
+                    <td class="col-md-6">
                         {{selectedProgram.dateOfEnrollmentDescription}}
                     </td>
-                    <td>
+                    <td class="col-md-6">
                         <input type="text" class="form-control" ng-date ng-model="newEnrollment.dateOfEnrollment" />
                     </td>
                 </tr>     
-                <tr ng-if="selectedProgram.displayIncidentDate">
-                    <td>
+                <tr class="col-md-12" ng-if="selectedProgram.displayIncidentDate">
+                    <td class="col-md-6">
                         {{selectedProgram.dateOfIncidentDescription}}
                     </td>
-                    <td>
+                    <td class="col-md-6">
                         <input type="text" class="form-control" ng-date ng-model="newEnrollment.dateOfIncident" />                    
                     </td>
                 </tr>
             </table>
             <hr>
             <table class="table-borderless table-striped">
-                <tr ng-repeat="attribute in attributesForEnrollment">
-                    <td>
+                <tr class="col-md-12" ng-repeat="attribute in attributesForEnrollment">
+                    <td class="col-md-6">
                         {{attribute.name}}
                     </td>
-                    <td>
+                    <td class="col-md-6">
                         <div ng-switch="attribute.valueType">
                             <div ng-switch-when="date">
                                 <input type="text" class="form-control" ng-date ng-model="attribute.value" />
@@ -136,8 +136,11 @@
             </div>
         </div>
 
-        <div ng-if="!selectedProgram">
-            <div class="alert alert-warning">{{'please_select_a_program'| translate}}</div> 
+        <div ng-if="!selectedProgram && programExists">
+            <div class="alert alert-warning">{{'please_select_a_program_for_enrollment'| translate}}</div> 
+        </div>
+        <div ng-if="!programExists">
+            <div class="alert alert-warning">{{'no_program_exists'| translate}}</div> 
         </div>
 
     </div>

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-06-19 10:31:04 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-06-20 14:23:28 +0000
@@ -4,11 +4,16 @@
     "program": "Program",
     "please_select": "[Please select]",
     "please_select_a_program": "[Please select a program]",
+    "please_select_a_program_for_enrollment": "Please select a program for enrollment.",
+    "no_program_exists": "No program exists for the selected org unit. Enrollment not possible.",
+    "not_yet_enrolled": "Not yet enrolled. Data entry not possible.",
+    "no_event_is_yet_created": "No event is available for data entry. Please create one from below.",
     "not_selected": "Not selected",
     "view_all": "[View all]",
     "list_all_entities": "List all entities",
     "list_all": "List all",
     "list": "List",
+    "required": "Required",
     "search": "Search",
     "advanced_search": "Advanced search",
     "search_for": "Search for",
@@ -65,6 +70,7 @@
     "close": "Close",
     "list_programs": "List programs",
     "program_stage": "Program stage",
+    "due_date": "Due date",
     "scheduled_date": "Scheduled date",
     "scheduling": "Scheduling",
     "reschedule": "Reschedule",
@@ -85,6 +91,7 @@
     "register": "Register",
     "registration_error": "Error in registration",
     "update_error": "Error in update",
+    "event_creation_error": "Error in event creation",
     "category": "Category",
     "entity_type": "Entity type",
     "save": "Save",
@@ -93,7 +100,7 @@
     "save_and_continue": "Save and continue",
     "go_back": "Go back",
     "cancel": "Cancel",
-    "more": "More",
+    "more": "More",    
     "advanced_search": "Advanced search",
     "profile": "Profile",
     "applications": "Apps",

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-06-20 14:23:28 +0000
@@ -771,6 +771,37 @@
             dateValue = Date.parse(dateValue);
             dateValue = $filter('date')(dateValue, 'yyyy-MM-dd');
             return dateValue;
+        },
+        getDueDate: function(programStage, enrollment){
+            var dueDate = moment(moment(enrollment.dateOfIncident).add('d', programStage.minDaysFromStart), 'YYYY-MM-DD')._d;
+            dueDate = Date.parse(dueDate);
+            dueDate = $filter('date')(dueDate, 'yyyy-MM-dd');
+            return dueDate;
         }
     };            
+})
+
+.service('EventUtils', function(DateUtils, $filter){
+    return {
+        createDummyEvent: function(programStage, orgUnit, enrollment){
+            
+            var today = moment();
+            today = Date.parse(today);
+            today = $filter('date')(today, 'yyyy-MM-dd');
+    
+            var dueDate = DateUtils.getDueDate(programStage, enrollment);
+            var dummyEvent = {programStage: programStage.id, 
+                              orgUnit: orgUnit.id,
+                              orgUnitName: orgUnit.name,
+                              dueDate: dueDate,
+                              name: programStage.name,
+                              reportDateDescription: programStage.reportDateDescription,
+                              status: 'ACTIVE'};
+            dummyEvent.statusColor = 'stage-on-time';
+            if(moment(today).isAfter(dummyEvent.dueDate)){
+                dummyEvent.statusColor = 'stage-overdue';
+            }
+            return dummyEvent;        
+        }
+    }; 
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-06-20 07:32:57 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-06-20 14:23:28 +0000
@@ -338,7 +338,7 @@
         return $.ajax( {
             url: '../api/programs.json',
             type: 'GET',
-            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,realionshipText,trackedEntity[id,name,description],userRoles[id,name],organisationUnits[id,name],programStages[id,name,version,minDaysFromStart,repeatable],programTrackedEntityAttributes[displayInList,mandatory,attribute[id]]'
+            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,realionshipText,trackedEntity[id,name,description],userRoles[id,name],organisationUnits[id,name],programStages[id,name,version,minDaysFromStart,reportDateDescription,repeatable],programTrackedEntityAttributes[displayInList,mandatory,attribute[id]]'
         }).done( function( response ){
             
             _.each( _.values( response.programs ), function ( program ) { 
@@ -415,7 +415,7 @@
         return $.ajax( {
             url: '../api/programStages.json',
             type: 'GET',
-            data: 'filter=id:eq:' + id +'&fields=id,name,dataEntryForm,description,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id]]]'
+            data: 'filter=id:eq:' + id +'&fields=id,name,dataEntryForm,reportDateDescription,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id]]]'
         }).done( function( response ){            
             _.each( _.values( response.programStages ), function( programStage ) {                
                 dhis2.tc.store.set( 'programStages', programStage );

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-06-19 15:27:17 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-06-20 14:23:28 +0000
@@ -120,11 +120,6 @@
     width: 10px;
 }
 
-.stage-container {
-    width:100%;
-    height:100px;
-}
-
 .stage-flow {
     height:100px;
     overflow: scroll;
@@ -163,7 +158,6 @@
     height: 60px;
     cursor: pointer;
     opacity: 1.0;
-    margin: 5px;
     white-space: normal;
     padding-top: 5px;
     text-align: center;
@@ -411,7 +405,6 @@
 .table-borderless>tbody>tr>td, 
 .table-borderless>tfoot>tr>td {
     border-top: none; 
-    padding: 5px;
 }
 
 .dhis2-table>thead>tr>th, 
@@ -806,9 +799,9 @@
     border-color:red;
 }
 
-.alert {
+/*.alert {
     padding: 5px;
-}
+}*/
 
 .input-field {
     border: 1px solid #aaa;