← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21498: tracker-capture: new layout for events in data entry widget

 

------------------------------------------------------------
revno: 21498
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-21 14:28:07 +0100
message:
  tracker-capture: new layout for events in data entry widget
added:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/referral-controller.js
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-buttons.html
  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/dataentry/event-layout.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event.html
  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/index.html


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-buttons.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-buttons.html	2015-12-17 16:15:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-buttons.html	2015-12-21 13:28:07 +0000
@@ -8,11 +8,7 @@
     <a href ng-click="completeIncompleteEvent()" 
        class="btn btn-warning"
        ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE' || currentEvent.editingNotAllowed && currentEvent.status !== 'COMPLETED' || currentEvent.orgUnit !== selectedOrgUnit.id"
-       ng-if="currentEvent.eventDate && currentEvent.status === 'COMPLETED'">{{'incomplete'| translate}}</a>                       
-    <!--<a href ng-click="validateEvent()" 
-       class="btn btn-info" 
-       ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE' || currentEvent.editingNotAllowed || currentEvent.orgUnit !== selectedOrgUnit.id" 
-       ng-if="currentEvent.eventDate">{{'validate'| translate}}</a>     -->
+       ng-if="currentEvent.eventDate && currentEvent.status === 'COMPLETED'">{{'incomplete'| translate}}</a>    
     <a href ng-click="skipUnskipEvent()" 
        class="btn btn-warning" 
        ng-disabled="selectedEnrollment.status !== 'ACTIVE' || currentEvent.editingNotAllowed || currentEvent.orgUnit !== selectedOrgUnit.id"

=== 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	2015-12-17 16:15:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2015-12-21 13:28:07 +0000
@@ -261,13 +261,13 @@
     $scope.executeRules = function () {        
         
         //$scope.allEventsSorted cannot be used, as it is not reflecting updates that happened within the current session
-        var allSorted = [];
+        /*var allSorted = [];
         for(var ps = 0; ps < $scope.programStages.length; ps++ ) {
             for(var e = 0; e < $scope.eventsByStageAsc[$scope.programStages[ps].id].length; e++) {
                 allSorted.push($scope.eventsByStageAsc[$scope.programStages[ps].id][e]);
             }
         }
-        allSorted = orderByFilter(allSorted, '-sortingDate').reverse();
+        allSorted = orderByFilter(allSorted, '-sortingDate').reverse();*/
         
         var evs = {all: $scope.allEventsSorted, byStage: $scope.eventsByStageAsc};
         var flag = {debug: true, verbose: true};
@@ -413,7 +413,6 @@
             });
             
             $scope.allEventsSorted = orderByFilter($scope.allEventsSorted, '-sortingDate').reverse();
-            console.log('the event:  ', $scope.allEventsSorted);
             sortEventsByStage(null);
             $scope.showDataEntry($scope.currentEvent, true);
         }
@@ -453,27 +452,26 @@
         angular.forEach($scope.programStages, function (stage) {
             $scope.setDisplayTypeForStage(stage);
         });
-    }    
+    };
     
     $scope.setDisplayTypeForStage = function(stage){
         if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) {
-                    stage.displayEventsInTable = $scope.showEventsAsTables;
+            stage.displayEventsInTable = $scope.showEventsAsTables;
         }
-    }
+    };
 
-    $scope.stageNeedsEvent = function (stage) {        
+    $scope.stageNeedsEvent = function (stage) {
         if($scope.selectedEnrollment && $scope.selectedEnrollment.status === 'ACTIVE'){
-            if(!stage){            
+            if(!stage){
                 if(!$scope.allEventsSorted || $scope.allEventsSorted.length === 0){
                     return true;
                 }
-                
                 for(var key in $scope.eventsByStage){
                     stage = $scope.stagesById[key];
                     if(stage && stage.repeatable){
                         for (var j = 0; j < $scope.eventsByStage[stage.id].length; j++) {
                             if (!$scope.eventsByStage[stage.id][j].eventDate && $scope.eventsByStage[stage.id][j].status !== 'SKIPPED') {
-                                return false;
+                                return true;
                             }
                         }
                         return true;
@@ -513,23 +511,58 @@
         sortEventsByStage('ADD', newEvent);
     };
 
-    $scope.showCreateEvent = function (stage,eventCreationAction) {
-
-        var dummyEvent = EventUtils.createDummyEvent($scope.eventsByStage[stage.id], $scope.selectedEntity, $scope.selectedProgram, stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+    $scope.showCreateEvent = function (stage, eventCreationAction) {
+                
+        var stages = [];
+        if(!stage){
+            if(!$scope.allEventsSorted || $scope.allEventsSorted.length === 0){                
+                stages = $scope.programStages;
+            }
+            for(var key in $scope.eventsByStage){
+                var st = $scope.stagesById[key];
+                var needEvent = true;
+                if(st && st.repeatable){
+                    for (var j = 0; j < $scope.eventsByStage[st.id].length; j++) {
+                        if (!$scope.eventsByStage[st.id][j].eventDate && $scope.eventsByStage[st.id][j].status !== 'SKIPPED') {
+                            needEvent = false;
+                        }
+                    }
+                    if(needEvent){
+                        stages.push(st);
+                    }
+                }
+            }
+        }
+        
         
         var modalInstance = $modal.open({
             templateUrl: 'components/dataentry/new-event.html',
             controller: 'EventCreationController',
             resolve: {
+                eventsByStage: function () {
+                    return $scope.eventsByStage;
+                },
                 stage: function () {
-                    return $scope.stagesById[stage.id];
-                },
-                dummyEvent: function () {
-                    return dummyEvent;
+                    return stage;
+                },                
+                stages: function(){
+                    return stages;
+                },
+                tei: function(){
+                    return $scope.selectedEntity;
+                },
+                program: function(){
+                    return $scope.selectedProgram;
+                },
+                orgUnit: function(){
+                    return $scope.selectedOrgUnit;
+                },
+                enrollment: function(){
+                    return $scope.selectedEnrollment;
                 },
                 autoCreate: function () {
                     //In case the programstage is a table, autocreate
-                    return stage.displayEventsInTable;
+                    return stage && stage.displayEventsInTable ? stage.displayEventsInTable : false;
                 },
                 eventCreationAction: function(){
                     return eventCreationAction;
@@ -537,8 +570,8 @@
             }
         });
 
-        modalInstance.result.then(function (ev) {
-            if (angular.isObject(ev)) {
+        modalInstance.result.then(function (dummyEvent, ev) {
+            if (angular.isObject(ev) && angular.isObject(dummyEvent)) {
                 
                 var newEvent = ev;
                 newEvent.orgUnitName = dummyEvent.orgUnitName;
@@ -568,6 +601,7 @@
         if (event) {
             if ($scope.currentEvent && !rightAfterEnrollment && $scope.currentEvent.event === event.event) {
                 //clicked on the same stage, do toggling
+                $scope.currentStage = null;
                 $scope.currentEvent = null;
                 $scope.currentElement = {id: '', saved: false};
                 $scope.showDataEntryDiv = !$scope.showDataEntryDiv;
@@ -1388,7 +1422,6 @@
             }
         });
     };
-    
 
     $scope.skipUnskipEvent = function () {
         var modalOptions;
@@ -1658,18 +1691,20 @@
     $scope.getEventPage = function(direction){
         if(direction === 'FORWARD'){
             $scope.eventPagingStart += $scope.eventPageSize;
-            $scope.eventPagingEnd += $scope.eventPageSize;
+            $scope.eventPagingEnd += $scope.eventPageSize;            
         }
         
         if(direction === 'BACKWARD'){
             $scope.eventPagingStart -= $scope.eventPageSize;
             $scope.eventPagingEnd -= $scope.eventPageSize;
-        }        
+        }
+        
+        $scope.showDataEntry($scope.allEventsSorted[$scope.eventPagingStart], false);
     };    
 
     $scope.deselectCurrent = function(id){        
         
-        if($scope.currentEvent.event === id){
+        if($scope.currentEvent && $scope.currentEvent.event === id){
             $scope.currentEvent = {};
         }        
     };
@@ -1688,248 +1723,6 @@
     };
 })
 
-.controller('EventCreationController',
-        function ($scope,
-                $modalInstance,
-                $timeout,
-                DateUtils,
-                DHIS2EventFactory,
-                OrgUnitFactory,
-                DialogService,
-                EventCreationService,
-                stage,
-                dummyEvent,
-                eventCreationAction,
-                autoCreate) {
-    $scope.eventCreationAction = eventCreationAction;
-    $scope.eventCreationActions = EventCreationService.eventCreationActions;
-    
-    $scope.selectedStage = stage;
-    $scope.isNewEvent = (eventCreationAction === $scope.eventCreationActions.add);
-    $scope.isScheduleEvent = (eventCreationAction === $scope.eventCreationActions.schedule || eventCreationAction === $scope.eventCreationActions.referral);
-    $scope.isReferralEvent = (eventCreationAction === $scope.eventCreationActions.referral);
-    
-    $scope.dhis2Event = {eventDate: $scope.isScheduleEvent ? '' : DateUtils.getToday(), dueDate: dummyEvent.dueDate, excecutionDateLabel : dummyEvent.excecutionDateLabel, name: dummyEvent.name, invalid: true};
-    
-    ////custom code for folkehelsa. Set empty eventDate if selectedStage is previous pregnancies
-    if($scope.selectedStage.id === 'PUZaKR0Jh2k'){
-        $scope.dhis2Event.eventDate = '';
-    }
-    
-    if ($scope.selectedStage.periodType) {
-        $scope.dhis2Event.eventDate = dummyEvent.dueDate;
-        $scope.dhis2Event.periodName = dummyEvent.periodName;
-        $scope.dhis2Event.periods = dummyEvent.periods;
-        $scope.dhis2Event.selectedPeriod = dummyEvent.periods[0];
-    }
-
-    $scope.dueDateInvalid = false;
-    $scope.eventDateInvalid = false;
-
-
-    //watch for changes in due/event-date
-    $scope.$watchCollection('[dhis2Event.dueDate, dhis2Event.eventDate]', function () {
-        if (angular.isObject($scope.dhis2Event)) {
-            if (!$scope.dhis2Event.dueDate) {
-                $scope.dueDateInvalid = true;
-                return;
-            }
-
-            if ($scope.dhis2Event.dueDate) {
-                var rDueDate = $scope.dhis2Event.dueDate;
-                var cDueDate = DateUtils.format($scope.dhis2Event.dueDate);
-                $scope.dueDateInvalid = rDueDate !== cDueDate;
-            }
-
-            if ($scope.dhis2Event.eventDate) {
-                var rEventDate = $scope.dhis2Event.eventDate;
-                var cEventDate = DateUtils.format($scope.dhis2Event.eventDate);
-                $scope.eventDateInvalid = rEventDate !== cEventDate;
-            }
-        }
-    });
-
-    $scope.save = function () {
-        //check for form validity
-        if ($scope.dueDateInvalid || $scope.eventDateInvalid) {
-            return false;
-        }
-        if($scope.isReferralEvent && !$scope.selectedSearchingOrgUnit){
-            $scope.orgUnitError = true;
-            return false;
-        }
-        $scope.orgUnitError =  false;
-        
-        if ($scope.selectedStage.periodType) {
-            $scope.dhis2Event.eventDate = $scope.dhis2Event.selectedPeriod.endDate;
-            $scope.dhis2Event.dueDate = $scope.dhis2Event.selectedPeriod.endDate;
-        }
-        
-        var eventDate = DateUtils.formatFromUserToApi($scope.dhis2Event.eventDate);
-        var dueDate = DateUtils.formatFromUserToApi($scope.dhis2Event.dueDate);
-        var newEvents = {events: []};
-        var newEvent = {
-            trackedEntityInstance: dummyEvent.trackedEntityInstance,
-            program: dummyEvent.program,
-            programStage: dummyEvent.programStage,
-            enrollment: dummyEvent.enrollment,
-            orgUnit: dummyEvent.orgUnit,
-            dueDate: dueDate,
-            eventDate: eventDate,
-            notes: [],
-            dataValues: [],
-            status: 'ACTIVE'
-        };
-
-        newEvent.status = newEvent.eventDate ? 'ACTIVE' : 'SCHEDULE';
-
-        newEvents.events.push(newEvent);
-        DHIS2EventFactory.create(newEvents).then(function (response) {
-            if (response.response && response.response.importSummaries[0].status === 'SUCCESS') {
-                newEvent.event = response.response.importSummaries[0].reference;
-                $modalInstance.close(newEvent);
-            }
-            else {
-                var dialogOptions = {
-                    headerText: 'event_creation_error',
-                    bodyText: response.message
-                };
-
-                DialogService.showDialog({}, dialogOptions);
-            }
-        });
-    };
-
-    //Start referral logic
-    $scope.setSelectedSearchingOrgUnit = function(orgUnit){
-        $scope.selectedSearchingOrgUnit = orgUnit;
-        dummyEvent.orgUnit = orgUnit.id;
-        dummyEvent.orgUnitName = orgUnit.name;
-    };
-    
-    var orgPath = [dummyEvent.orgUnit];
-    function initOrgUnits(uid){
-        $scope.orgUnitsLoading =true;
-        $timeout(function(){
-            OrgUnitFactory.getWithParents(uid).then(function(ou){
-                if(ou.organisationUnits && ou.organisationUnits[0] && ou.organisationUnits[0].parent){
-                    orgPath.push(ou.organisationUnits[0].parent.id);
-                    var parent = ou.organisationUnits[0].parent;
-                    var lastId = ou.organisationUnits[0].id;
-                    while(parent){
-                        orgPath.push(parent.id);
-                        lastId = parent.id;
-                        parent = parent.parent;
-                    }
-                    initOrgUnits(lastId);
-                }else{
-                    OrgUnitFactory.getSearchTreeRoot().then(function(response) {
-                        $scope.orgUnits = response.organisationUnits;
-                        angular.forEach($scope.orgUnits, function(ou){
-                            ou.show = true;
-                            angular.forEach(ou.children, function(o){
-                                o.hasChildren = o.children && o.children.length > 0 ? true : false;
-                                initExpand(o);
-                            });
-                        });
-                    });
-                }
-            });
-        },150);
-        
-    };
-    
-    function initExpand(orgUnit){
-        if(orgPath.indexOf(orgUnit.id)>-1){
-            if(orgUnit.hasChildren){
-                //Get children for the selected orgUnit
-                OrgUnitFactory.get(orgUnit.id).then(function(ou) {     
-                    orgUnit.show = true;
-                    orgUnit.hasChildren = false;
-                    orgUnit.children = ou.organisationUnits[0].children;
-                    angular.forEach(orgUnit.children, function(ou){            
-                        ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
-                        initExpand(ou);
-                    });    
-                });
-            }else{
-                setDefaultOrgUnit();
-            }
-        }
-    };
-    
-    var defaultOrgUnitGroup = 'hrc';
-    function setDefaultOrgUnit(){
-        if(orgPath && orgPath.length>1){
-            OrgUnitFactory.getWithGroups(orgPath[1]).then(function(ou){
-                if(ou.organisationUnits && ou.organisationUnits[0]){
-                    var o = ou.organisationUnits[0];
-                    angular.forEach(o.children, function(oo){
-                        angular.forEach(oo.organisationUnitGroups, function(oug){
-                            var shortNameLC = oug.shortName.toLowerCase();
-                            if(shortNameLC === defaultOrgUnitGroup){
-                                $scope.setSelectedSearchingOrgUnit(oo);
-                            }
-                        });
-                    });
-
-                }
-                $scope.orgUnitsLoading = false;
-            });   
-        }else{
-            $scope.orgUnitsLoading = false;
-        }
-    };
-    
-    if($scope.isReferralEvent){
-        initOrgUnits(orgPath[0]);
-    }
-           
-    $scope.expandCollapse = function(orgUnit) {
-        if( orgUnit.hasChildren ){            
-            //Get children for the selected orgUnit
-            OrgUnitFactory.get(orgUnit.id).then(function(ou) {                
-                orgUnit.show = !orgUnit.show;
-                orgUnit.hasChildren = false;
-                orgUnit.children = ou.organisationUnits[0].children;                
-                angular.forEach(orgUnit.children, function(ou){                    
-                    ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
-                });                
-            });           
-        }
-        else{
-            orgUnit.show = !orgUnit.show;   
-        }
-    };
-    
-
-    /*if($scope.isReferralEvent){
-        OrgUnitFactory.getSearchTreeRoot().then(function(response) {
-            $scope.orgUnits = response.organisationUnits;
-            angular.forEach($scope.orgUnits, function(ou){
-                ou.show = true;
-                angular.forEach(ou.children, function(o){
-                    o.hasChildren = o.children && o.children.length > 0 ? true : false;
-                });
-            });
-        });
-    }*/
-    //end referral logic
-    
-    
-    //If the caller wants to create right away, go ahead and save.
-    if (autoCreate) {
-        $scope.save();
-    }
-    ;
-
-    $scope.cancel = function () {
-        $modalInstance.close();
-    };
-    
-
-})
-
 .controller('EventOptionsInTableController', function($scope){
     
     var COMPLETE = "Complete";
@@ -2042,134 +1835,4 @@
             $scope.eventTableOptionsArr[$scope.eventTableOptions[key].sort] = $scope.eventTableOptions[key];
         }
     }        
-})
-.controller('MakeReferralController', function($scope, $modalInstance, stage, OrgUnitFactory){
-    $scope.stage = stage;
-    $scope.cancel = function(){
-        $modalInstance.close();
-    };
-    
-    $scope.makeReferral = function(){
-        if(!$scope.referralDate){
-            $scope.dateError = true;
-        }else{
-            $scope.dateError = false;
-        }
-        
-        if(!$scope.selectedSearchingOrgUnit){
-            $scope.orgError = true;     
-        }else{
-            $scope.orgError = false;
-        }
-        if(!$scope.dateError && !$scope.orgError){
-            $modalInstance.close();
-        }
-    };
-    
-    $scope.setSelectedSearchingOrgUnit = function(orgUnit){
-        $scope.selectedSearchingOrgUnit = orgUnit;     
-    };
-    
-    OrgUnitFactory.getSearchTreeRoot().then(function(response) {
-        $scope.orgUnits = response.organisationUnits;
-        angular.forEach($scope.orgUnits, function(ou){
-            ou.show = true;
-            angular.forEach(ou.children, function(o){                    
-                o.hasChildren = o.children && o.children.length > 0 ? true : false;
-            });            
-        });
-    });
-    
-    $scope.expandCollapse = function(orgUnit) {
-        if( orgUnit.hasChildren ){            
-            //Get children for the selected orgUnit
-            OrgUnitFactory.get(orgUnit.id).then(function(ou) {                
-                orgUnit.show = !orgUnit.show;
-                orgUnit.hasChildren = false;
-                orgUnit.children = ou.organisationUnits[0].children;                
-                angular.forEach(orgUnit.children, function(ou){                    
-                    ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
-                });                
-            });           
-        }
-        else{
-            orgUnit.show = !orgUnit.show;   
-        }        
-    };
-})
-.controller('ModalDefaultFormController', function($scope){
-    
-    var defaultRequestError = "Server error. Please try again later.";
-    
-    $scope.completeIncompleteEventModal = function(){  
-           
-        $scope.requestError = "";
-        debugger;
-        if ($scope.currentEvent.status === 'COMPLETED'){
-            var dhis2Event = $scope.makeDhis2EventToUpdate();
-            dhis2Event.status = 'ACTIVE';
-        }
-        else{
-            $scope.modalForm.$setSubmitted();
-            $scope.modalForm.outerForm.$setSubmitted();     
-            
-            if($scope.modalForm.$invalid){
-                return;
-            }     
-            
-            //check for errors!
-            if(angular.isDefined($scope.errorMessages[$scope.currentEvent.event]) && $scope.errorMessages[$scope.currentEvent.event].length > 0) {
-                //There is unresolved program rule errors - show error message.
-                return;
-            }
-            
-            var dhis2Event = $scope.makeDhis2EventToUpdate();
-            dhis2Event.status = 'COMPLETED';
-        }        
-        
-        $scope.executeCompleteIncompleteEvent(dhis2Event).then(function(){                                    
-            if(dhis2Event.status === 'COMPLETED'){
-                $scope.eventEditFormModalInstance.close();            
-            }
-        }, function(error){
-            $scope.requestError = defaultRequestError;                                   
-        });
-    };
-    
-    $scope.deleteEventModal = function(){
-        
-        $scope.executeDeleteEvent().then(function(){
-            
-            $scope.eventEditFormModalInstance.close();
-        }, function(){
-            
-            $scope.requestError = defaultRequestError; 
-        });        
-    };
-    
-    $scope.skipUnskipEventModal = function(){
-                
-        var dhis2Event = $scope.makeDhis2EventToUpdate();
-        
-        if ($scope.currentEvent.status === 'SKIPPED') {//unskip event
-            dhis2Event.status = 'ACTIVE';
-        }
-        else {//skip event
-            dhis2Event.status = 'SKIPPED';
-        }
-        
-        
-        $scope.executeSkipUnskipEvent(dhis2Event).then(function(){
-            if(dhis2Event.status === 'SKIPPED'){
-                $scope.eventEditFormModalInstance.close();
-            }
-        }, function(){
-            $scope.requestError = defaultRequestError;
-        });        
-    };
-    
-    $scope.closeEventModal = function(){
-        $scope.eventEditFormModalInstance.dismiss();
-    };
-})
-;
\ No newline at end of file
+});
\ No newline at end of file

=== 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	2015-12-17 16:15:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2015-12-21 13:28:07 +0000
@@ -2,27 +2,11 @@
     <div ng-include="'components/dataentry/dataentry-print.html'">
     </div>
     <div class="panel-heading handle bold">
-        {{dataentryWidget.title| translate}}  
-        <span ng-if="currentStage && stageNeedsEvent(currentStage) && selectedEnrollment.status === 'ACTIVE'">
-            <a href title="{{'create_new_event'| translate}}" ng-click="showCreateEvent(stage,eventCreationActions.add)" style="vertical-align:middle">
-                {{'add'|translate}}
-            </a>
-            |
-            <a href title="{{'schedule_new_event'| translate}}" ng-click="showCreateEvent(stage,eventCreationActions.schedule)" style="vertical-align:middle">
-                {{'schedule'|translate}}
-            </a>
-            |
-            <a href title="Make referral" ng-click="showCreateEvent(stage, eventCreationActions.referral)" style="vertical-align: middle" ng-if="showReferral">
-                Referral
-            </a>
+        {{dataentryWidget.title| translate}}
+        <span class="nav-pills" ng-if="stageNeedsEvent(currentStage)">
+            | <a href ng-click="showCreateEvent(currentStage, eventCreationActions.add)" title="{{'add_new_event'| translate}}"><span ng-class="{true: 'widget - link - active', false: 'widget - link'} [!editingDisabled]">{{'add_new_event'| translate}}</span></a>
         </span>
-        <!--<span class="nav-pills" ng-if="stageNeedsEvent(null)">
-            | <a href ng-click="showCreateEvent(currentStage)" title="{{'add_new_event'| translate}}"><span ng-class="{true: 'widget - link - active', false: 'widget - link'} [!editingDisabled]">{{'add_new_event'| translate}}</span></a>
-        </span>-->
-        <span class="pull-right widget-link">
-            <a href ng-click="toggleTableEditMode()" title="{{tableEditMode === tableEditModes.form ? 'use combined table edit mode' : 'use form only table edit mode'}}"><span ng-if="tableEditMode === tableEditModes.form"><i class="fa fa-clipboard vertical-center"></i></span><span ng-if="tableEditMode !== tableEditModes.form"><i class="fa fa-external-link vertical-center"></i></span></a>
-            <a href ng-click="toggleEventsTableDisplay()" title="{{showEventsAsTables ? 'toggle_table_view_off' : 'toggle_table_view_on'| translate}}" ng-show="stagesCanBeShownAsTable"><span ng-if="!showEventsAsTables"><i class="fa fa-bars vertical-center"></i></span><span ng-if="showEventsAsTables"><i class="fa fa-square vertical-center"></i></span></a>
-            <a href ng-click="filterEvents = !filterEvents" title="{{filterEvents ? 'list_events' : 'filter_events'| translate}}" ng-show="eventFilteringRequired"><span ng-if="!filterEvents"><i class="fa fa-filter vertical-center"></i></span><span ng-if="filterEvents"><i class="fa fa-list vertical-center"></i></span></a>
+        <span class="pull-right widget-link">            
             <a href ng-click="toggleLegend()" title="{{'event_color_legend'| translate}}" class="small-horizonal-spacing"><i class="fa fa-info-circle vertical-center"></i></a>
             <a class="small-horizonal-spacing" href ng-click="expandCollapse(dataentryWidget)">
                 <span ng-show="dataentryWidget.expand"><i class="fa fa-chevron-up vertical-center" title="{{collapseLabel}}"></i></span>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/event-layout.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/event-layout.html	2015-12-18 09:15:32 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/event-layout.html	2015-12-21 13:28:07 +0000
@@ -1,77 +1,27 @@
-<div class="row col-sm-12">
-    <div ng-repeat="dhis2Event in allEventsSorted.slice(eventPagingStart, eventPagingEnd)" ng-init="$index = $index + 1">        
-        <div class="event-container" ng-click="getEventPage('BACKWARD')" ng-if="$index === 1 && eventPagingStart > 0">
-            &nbsp;<br/>
-            {{'previous'| translate}}
-        </div>
-        <div class="event-container" title="[{{'org_unit' | translate}}: {{dhis2Event.orgUnitName}}, {{'program_stage' | translate}}: {{dhis2Event.name}}]" ng-class="getEventStyle(dhis2Event)" ng-click="showDataEntry(dhis2Event, false)">
-            {{dhis2Event.sortingDate}}<br/>
-            {{dhis2Event.orgUnitName}}<br/>
-            {{dhis2Event.name}}
-        </div>
-        <div class="arrow-container" ng-if="$index < eventPageSize && $index + eventPagingStart < allEventsSorted.length">
-            <i class="fa fa-arrow-right"></i>
-        </div>
-        <div class="event-container" ng-click="getEventPage('FORWARD')" ng-if="$index === eventPageSize && $index < allEventsSorted.length">
-            &nbsp;<br/>
-            {{'next'| translate}}
-        </div>
+<div class="row equal-height-columns">
+    <div class="col-sm-12">
+        <div ng-repeat="dhis2Event in allEventsSorted.slice(eventPagingStart, eventPagingEnd)" ng-init="$index = $index + 1">        
+            <div class="event-container" ng-click="getEventPage('BACKWARD')" ng-if="$index === 1 && eventPagingStart > 0">
+                &nbsp;<br/>
+                {{'previous'| translate}}
+            </div>
+            <div class="event-container" title="[{{'org_unit' | translate}}: {{dhis2Event.orgUnitName}}, {{'program_stage' | translate}}: {{dhis2Event.name}}]" ng-class="getEventStyle(dhis2Event)" ng-click="showDataEntry(dhis2Event, false)">
+                {{dhis2Event.sortingDate}}<br/>
+                {{dhis2Event.orgUnitName}}<br/>
+                {{dhis2Event.name}}
+            </div>
+            <div class="arrow-container" ng-if="$index < eventPageSize && $index + eventPagingStart < allEventsSorted.length">
+                <i class="fa fa-arrow-right"></i>
+            </div>
+            <div class="event-container" ng-click="getEventPage('FORWARD')" ng-if="$index === eventPageSize && $index < allEventsSorted.length">
+                &nbsp;<br/>
+                {{'next'| translate}}
+            </div>
+        </div>    
     </div>
-
     <div ng-if="allEventsSorted.length < 1">
         <div class="alert alert-warning">{{'no_events_exist'| translate}}</div> 
     </div>
 </div>
 
-<hr>
-<!--<table class="table table-bordered">
-    <thead>
-        <tr>
-            <th class="active" style="vertical-align:middle" ng-repeat="stage in programStages">                            
-                {{stage.name}}
-                <span class='pull-right'>
-                    <span ng-if="stageNeedsEvent(stage) && selectedEnrollment.status === 'ACTIVE'">
-                        <a href title="{{'create_new_event'| translate}}" ng-click="showCreateEvent(stage,eventCreationActions.add)" style="vertical-align:middle">
-                            {{'add'|translate}}
-                        </a>
-                        |
-                        <a href title="{{'schedule_new_event'| translate}}" ng-click="showCreateEvent(stage,eventCreationActions.schedule)" style="vertical-align:middle">
-                            {{'schedule'|translate}}
-                        </a>
-                        |
-                        <a href title="Make referral" ng-click="showCreateEvent(stage, eventCreationActions.referral)" style="vertical-align: middle" ng-if="showReferral">
-                            Referral
-                        </a>
-                    </span>
-                </span>
-            </th>
-        </tr>
-    </thead>
-    <tbody>
-        <tr>
-            <td ng-repeat="stage in programStages">
-                <div class="inline-block" ng-repeat="dhis2Event in eventsByStage[stage.id]">
-                    <div class="event-container" 
-                         ng-class="getEventStyle(dhis2Event)" 
-                         ng-show="!currentPeriod[stage.id] || !filterEvents || currentPeriod[stage.id] && currentPeriod[stage.id].event === dhis2Event.event"
-                         ng-click="showDataEntry(dhis2Event, false)">
-                        {{dhis2Event.orgUnitName}}<br/>
-                        {{dhis2Event.sortingDate}}<br>
-                        <span ng-if="eventsByStage[stage.id].length > 1 && !filterEvents">[{{$index + 1}}]</span>
-                    </div>
-                </div>
-                <span ng-if="eventsByStage[stage.id].length > 1 && filterEvents">
-                    <span ng-if="currentEvent.programStage !== stage.id">
-                        <div class="event-paging">
-                            <a href class="event-paging" ng-click="showDataEntryForEvent(eventsByStage[stage.id][0])">{{'show_more'| translate}}</a>
-                        </div>
-                    </span>
-                    <event-paginator ng-if="stage.id === currentEvent.programStage"></event-paginator>                             
-                </span>
-                <div ng-if="!eventsByStage[stage.id] || eventsByStage[stage.id].length < 1">
-                    <div class="alert alert-warning">{{'no_events_exist'| translate}}</div> 
-                </div>
-            </td>
-        </tr>
-    </tbody>
-</table>-->
\ No newline at end of file
+<hr>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js	2015-12-21 13:28:07 +0000
@@ -0,0 +1,75 @@
+trackerCapture.controller('ModalDefaultFormController', function($scope){
+    
+    var defaultRequestError = "Server error. Please try again later.";
+    
+    $scope.completeIncompleteEventModal = function(){  
+           
+        $scope.requestError = "";
+        debugger;
+        if ($scope.currentEvent.status === 'COMPLETED'){
+            var dhis2Event = $scope.makeDhis2EventToUpdate();
+            dhis2Event.status = 'ACTIVE';
+        }
+        else{
+            $scope.modalForm.$setSubmitted();
+            $scope.modalForm.outerForm.$setSubmitted();     
+            
+            if($scope.modalForm.$invalid){
+                return;
+            }     
+            
+            //check for errors!
+            if(angular.isDefined($scope.errorMessages[$scope.currentEvent.event]) && $scope.errorMessages[$scope.currentEvent.event].length > 0) {
+                //There is unresolved program rule errors - show error message.
+                return;
+            }
+            
+            var dhis2Event = $scope.makeDhis2EventToUpdate();
+            dhis2Event.status = 'COMPLETED';
+        }        
+        
+        $scope.executeCompleteIncompleteEvent(dhis2Event).then(function(){                                    
+            if(dhis2Event.status === 'COMPLETED'){
+                $scope.eventEditFormModalInstance.close();            
+            }
+        }, function(error){
+            $scope.requestError = defaultRequestError;                                   
+        });
+    };
+    
+    $scope.deleteEventModal = function(){
+        
+        $scope.executeDeleteEvent().then(function(){
+            
+            $scope.eventEditFormModalInstance.close();
+        }, function(){
+            
+            $scope.requestError = defaultRequestError; 
+        });        
+    };
+    
+    $scope.skipUnskipEventModal = function(){
+                
+        var dhis2Event = $scope.makeDhis2EventToUpdate();
+        
+        if ($scope.currentEvent.status === 'SKIPPED') {//unskip event
+            dhis2Event.status = 'ACTIVE';
+        }
+        else {//skip event
+            dhis2Event.status = 'SKIPPED';
+        }
+        
+        
+        $scope.executeSkipUnskipEvent(dhis2Event).then(function(){
+            if(dhis2Event.status === 'SKIPPED'){
+                $scope.eventEditFormModalInstance.close();
+            }
+        }, function(){
+            $scope.requestError = defaultRequestError;
+        });        
+    };
+    
+    $scope.closeEventModal = function(){
+        $scope.eventEditFormModalInstance.dismiss();
+    };
+});
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event-controller.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event-controller.js	2015-12-21 13:28:07 +0000
@@ -0,0 +1,264 @@
+
+/* global trackerCapture, angular */
+
+trackerCapture.controller('EventCreationController',
+        function ($scope,
+                $modalInstance,
+                $timeout,
+                DateUtils,
+                DHIS2EventFactory,
+                OrgUnitFactory,
+                DialogService,
+                EventCreationService,
+                eventsByStage,
+                stage,
+                stages,
+                tei,
+                program,
+                orgUnit,
+                enrollment,                
+                eventCreationAction,
+                autoCreate,
+                EventUtils) {
+    $scope.stages = stages;
+    $scope.eventCreationAction = eventCreationAction;
+    $scope.eventCreationActions = EventCreationService.eventCreationActions;
+    $scope.isNewEvent = (eventCreationAction === $scope.eventCreationActions.add);
+    $scope.isScheduleEvent = (eventCreationAction === $scope.eventCreationActions.schedule || eventCreationAction === $scope.eventCreationActions.referral);
+    $scope.isReferralEvent = (eventCreationAction === $scope.eventCreationActions.referral);
+    $scope.model = {selectedStage: stage, dueDateInvalid: false, eventDateInvalid: false};
+    var orgPath = [];    
+    var dummyEvent = {};
+    
+    function prepareEvent(){
+        
+        dummyEvent = EventUtils.createDummyEvent(eventsByStage[stage.id], tei, program, stage, orgUnit, enrollment);
+        
+        $scope.newEvent = {programStage: stage};
+        $scope.dhis2Event = {eventDate: $scope.isScheduleEvent ? '' : DateUtils.getToday(), dueDate: dummyEvent.dueDate, excecutionDateLabel : dummyEvent.excecutionDateLabel, name: dummyEvent.name, invalid: true};
+
+        //custom code for folkehelsa. Set empty eventDate if selectedStage is previous pregnancies
+        if($scope.model.selectedStage.id === 'PUZaKR0Jh2k'){
+            $scope.dhis2Event.eventDate = '';
+        }
+
+        if ($scope.model.selectedStage.periodType) {
+            $scope.dhis2Event.eventDate = dummyEvent.dueDate;
+            $scope.dhis2Event.periodName = dummyEvent.periodName;
+            $scope.dhis2Event.periods = dummyEvent.periods;
+            $scope.dhis2Event.selectedPeriod = dummyEvent.periods[0];
+        }
+        
+        orgPath.push(dummyEvent.orgUnit);
+    };
+    
+    if($scope.model.selectedStage){
+        prepareEvent();
+    }
+    
+    $scope.$watch('model.selectedStage', function(){       
+        if(angular.isObject($scope.model.selectedStage)){
+            stage = $scope.model.selectedStage;
+            prepareEvent();
+        }
+    });
+
+    //watch for changes in due/event-date
+    $scope.$watchCollection('[dhis2Event.dueDate, dhis2Event.eventDate]', function () {
+        if (angular.isObject($scope.dhis2Event)) {
+            if (!$scope.dhis2Event.dueDate) {
+                $scope.model.dueDateInvalid = true;
+                return;
+            }
+
+            if ($scope.dhis2Event.dueDate) {
+                var rDueDate = $scope.dhis2Event.dueDate;
+                var cDueDate = DateUtils.format($scope.dhis2Event.dueDate);
+                $scope.model.dueDateInvalid = rDueDate !== cDueDate;
+            }
+
+            if ($scope.dhis2Event.eventDate) {
+                var rEventDate = $scope.dhis2Event.eventDate;
+                var cEventDate = DateUtils.format($scope.dhis2Event.eventDate);
+                $scope.model.eventDateInvalid = rEventDate !== cEventDate;
+            }
+        }
+    });
+
+    $scope.save = function () {
+        //check for form validity
+        if ($scope.model.dueDateInvalid || $scope.model.eventDateInvalid) {
+            return false;
+        }
+        if($scope.isReferralEvent && !$scope.selectedSearchingOrgUnit){
+            $scope.orgUnitError = true;
+            return false;
+        }
+        $scope.orgUnitError =  false;
+        
+        if ($scope.model.selectedStage.periodType) {
+            $scope.dhis2Event.eventDate = $scope.dhis2Event.selectedPeriod.endDate;
+            $scope.dhis2Event.dueDate = $scope.dhis2Event.selectedPeriod.endDate;
+        }
+        
+        var eventDate = DateUtils.formatFromUserToApi($scope.dhis2Event.eventDate);
+        var dueDate = DateUtils.formatFromUserToApi($scope.dhis2Event.dueDate);
+        var newEvents = {events: []};
+        var newEvent = {
+            trackedEntityInstance: dummyEvent.trackedEntityInstance,
+            program: dummyEvent.program,
+            programStage: dummyEvent.programStage,
+            enrollment: dummyEvent.enrollment,
+            orgUnit: dummyEvent.orgUnit,
+            dueDate: dueDate,
+            eventDate: eventDate,
+            notes: [],
+            dataValues: [],
+            status: 'ACTIVE'
+        };
+
+        newEvent.status = newEvent.eventDate ? 'ACTIVE' : 'SCHEDULE';
+
+        newEvents.events.push(newEvent);
+        DHIS2EventFactory.create(newEvents).then(function (response) {
+            if (response.response && response.response.importSummaries[0].status === 'SUCCESS') {
+                newEvent.event = response.response.importSummaries[0].reference;
+                $modalInstance.close(newEvent);
+            }
+            else {
+                var dialogOptions = {
+                    headerText: 'event_creation_error',
+                    bodyText: response.message
+                };
+
+                DialogService.showDialog({}, dialogOptions);
+            }
+        });
+    };
+
+    //Start referral logic
+    $scope.setSelectedSearchingOrgUnit = function(orgUnit){
+        $scope.selectedSearchingOrgUnit = orgUnit;
+        dummyEvent.orgUnit = orgUnit.id;
+        dummyEvent.orgUnitName = orgUnit.name;
+    };
+    
+    
+    function initOrgUnits(uid){
+        $scope.orgUnitsLoading =true;
+        $timeout(function(){
+            OrgUnitFactory.getWithParents(uid).then(function(ou){
+                if(ou.organisationUnits && ou.organisationUnits[0] && ou.organisationUnits[0].parent){
+                    orgPath.push(ou.organisationUnits[0].parent.id);
+                    var parent = ou.organisationUnits[0].parent;
+                    var lastId = ou.organisationUnits[0].id;
+                    while(parent){
+                        orgPath.push(parent.id);
+                        lastId = parent.id;
+                        parent = parent.parent;
+                    }
+                    initOrgUnits(lastId);
+                }else{
+                    OrgUnitFactory.getSearchTreeRoot().then(function(response) {
+                        $scope.orgUnits = response.organisationUnits;
+                        angular.forEach($scope.orgUnits, function(ou){
+                            ou.show = true;
+                            angular.forEach(ou.children, function(o){
+                                o.hasChildren = o.children && o.children.length > 0 ? true : false;
+                                initExpand(o);
+                            });
+                        });
+                    });
+                }
+            });
+        },150);
+        
+    };
+    
+    function initExpand(orgUnit){
+        if(orgPath.indexOf(orgUnit.id)>-1){
+            if(orgUnit.hasChildren){
+                //Get children for the selected orgUnit
+                OrgUnitFactory.get(orgUnit.id).then(function(ou) {     
+                    orgUnit.show = true;
+                    orgUnit.hasChildren = false;
+                    orgUnit.children = ou.organisationUnits[0].children;
+                    angular.forEach(orgUnit.children, function(ou){            
+                        ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
+                        initExpand(ou);
+                    });    
+                });
+            }else{
+                setDefaultOrgUnit();
+            }
+        }
+    };
+    
+    var defaultOrgUnitGroup = 'hrc';
+    function setDefaultOrgUnit(){
+        if(orgPath && orgPath.length>1){
+            OrgUnitFactory.getWithGroups(orgPath[1]).then(function(ou){
+                if(ou.organisationUnits && ou.organisationUnits[0]){
+                    var o = ou.organisationUnits[0];
+                    angular.forEach(o.children, function(oo){
+                        angular.forEach(oo.organisationUnitGroups, function(oug){
+                            var shortNameLC = oug.shortName.toLowerCase();
+                            if(shortNameLC === defaultOrgUnitGroup){
+                                $scope.setSelectedSearchingOrgUnit(oo);
+                            }
+                        });
+                    });
+
+                }
+                $scope.orgUnitsLoading = false;
+            });   
+        }else{
+            $scope.orgUnitsLoading = false;
+        }
+    };
+    
+    if($scope.isReferralEvent){
+        initOrgUnits(orgPath[0]);
+    }
+           
+    $scope.expandCollapse = function(orgUnit) {
+        if( orgUnit.hasChildren ){            
+            //Get children for the selected orgUnit
+            OrgUnitFactory.get(orgUnit.id).then(function(ou) {                
+                orgUnit.show = !orgUnit.show;
+                orgUnit.hasChildren = false;
+                orgUnit.children = ou.organisationUnits[0].children;                
+                angular.forEach(orgUnit.children, function(ou){                    
+                    ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
+                });                
+            });           
+        }
+        else{
+            orgUnit.show = !orgUnit.show;   
+        }
+    };
+    
+
+    /*if($scope.isReferralEvent){
+        OrgUnitFactory.getSearchTreeRoot().then(function(response) {
+            $scope.orgUnits = response.organisationUnits;
+            angular.forEach($scope.orgUnits, function(ou){
+                ou.show = true;
+                angular.forEach(ou.children, function(o){
+                    o.hasChildren = o.children && o.children.length > 0 ? true : false;
+                });
+            });
+        });
+    }*/
+    //end referral logic
+    
+    
+    //If the caller wants to create right away, go ahead and save.
+    if (autoCreate) {
+        $scope.save();
+    };
+
+    $scope.cancel = function () {
+        $modalInstance.close();
+    };
+});

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event.html	2015-12-17 15:00:48 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/new-event.html	2015-12-21 13:28:07 +0000
@@ -1,12 +1,26 @@
 <div class="modal-header page">
-    <h3 ng-if="isNewEvent">{{'add'| translate}} - {{dhis2Event.name}}</h3>
-    <h3 ng-if="isScheduleEvent && !isReferralEvent">{{'schedule'| translate}} - {{dhis2Event.name}}</h3>
-    <h3 ng-if="isReferralEvent">{{'referral' | translate}} - {{dhis2Event.name}}</h3>
+    <h3 ng-if="isNewEvent">{{'add'| translate}}<span ng-if="model.selectedStage"> - {{model.selectedStage.name}}</span></h3>
+    <h3 ng-if="isScheduleEvent && !isReferralEvent">{{'schedule'| translate}}<span ng-if="model.selectedStage"> - {{model.selectedStage.name}}</span></h3>
+    <h3 ng-if="isReferralEvent">{{'referral' | translate}}<span ng-if="model.selectedStage"> - {{model.selectedStage.name}}</span></h3>
 </div>
 <div class="modal-body page">
     <form name="eventCreationForm" class="form-horizontal" role="form" novalidate>
-        <div ng-if="!selectedStage.periodType">
-            <div ng-if="isScheduleEvent && !isReferralEvent" class="form-group">
+        <div ng-if="!model.selectedStage">
+            <div class="form-group">
+                <label class="col-sm-2 control-label">
+                    {{'program_stage' | translate}}
+                </label>
+                <div class="col-sm-10">
+                    <select class="form-control-program" 
+                            ng-model="model.selectedStage"
+                            ng-options="stage.name for stage in stages">                    
+                    </select>
+                </div>                
+            </div>            
+        </div>
+        
+        <div ng-if="model.selectedStage && !model.selectedStage.periodType">
+            <div ng-if="isScheduleEvent && !isReferralEvent && !model.selectedStage.hideDueDate" class="form-group">
                 <label class="col-sm-2 control-label">{{'scheduled_date'| translate}}</label>
                 <div class="col-sm-10">
                     <input type="text" 
@@ -16,11 +30,11 @@
                            ng-rquired="true" 
                            d2-date
                            ng-model="dhis2Event.dueDate">
-                    <span ng-if="dueDateInvalid" class="error">{{'required'| translate}}</span>
+                    <span ng-if="model.dueDateInvalid" class="error">{{'required'| translate}}</span>
                 </div>                
             </div>
             <div ng-if="isNewEvent" class="form-group">
-                <label class="col-sm-2 control-label">{{dhis2Event.excecutionDateLabel}}</label>
+                <label class="col-sm-2 control-label">{{model.selectedStage.excecutionDateLabel}}</label>
                 <div class="col-sm-10">
                     <input type="text" 
                            class="form-control" 
@@ -31,7 +45,7 @@
                            max-date="0"
                            min-date=""
                            ng-model="dhis2Event.eventDate">
-                    <span ng-if="eventDateInvalid" class="error">{{'required'| translate}}</span>
+                    <span ng-if="model.eventDateInvalid" class="error">{{'required'| translate}}</span>
                 </div>
             </div>
             <div ng-if="isReferralEvent">
@@ -73,10 +87,11 @@
                         <input type="checkbox" ng-model="referralMovePermanent" id="referralMovePermanent" /> <strong>Move permanent</strong>
                     </label>
                 </div>
-                <span ng-if="dueDateInvalid" class="error">{{'required'| translate}}</span>
+                <span ng-if="model.dueDateInvalid" class="error">{{'required'| translate}}</span>
             </div>
         </div>
-        <div ng-if="selectedStage.periodType">
+        <div ng-if="model.selectedStage && model.selectedStage.periodType">
+            2
             <div class="form-group"> 
                 <label class="control-label">
                     {{'period'| translate}}

=== added file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/referral-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/referral-controller.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/referral-controller.js	2015-12-21 13:28:07 +0000
@@ -0,0 +1,54 @@
+trackerCapture.controller('MakeReferralController', function($scope, $modalInstance, stage, OrgUnitFactory){
+    $scope.stage = stage;
+    $scope.cancel = function(){
+        $modalInstance.close();
+    };
+    
+    $scope.makeReferral = function(){
+        if(!$scope.referralDate){
+            $scope.dateError = true;
+        }else{
+            $scope.dateError = false;
+        }
+        
+        if(!$scope.selectedSearchingOrgUnit){
+            $scope.orgError = true;     
+        }else{
+            $scope.orgError = false;
+        }
+        if(!$scope.dateError && !$scope.orgError){
+            $modalInstance.close();
+        }
+    };
+    
+    $scope.setSelectedSearchingOrgUnit = function(orgUnit){
+        $scope.selectedSearchingOrgUnit = orgUnit;     
+    };
+    
+    OrgUnitFactory.getSearchTreeRoot().then(function(response) {
+        $scope.orgUnits = response.organisationUnits;
+        angular.forEach($scope.orgUnits, function(ou){
+            ou.show = true;
+            angular.forEach(ou.children, function(o){                    
+                o.hasChildren = o.children && o.children.length > 0 ? true : false;
+            });            
+        });
+    });
+    
+    $scope.expandCollapse = function(orgUnit) {
+        if( orgUnit.hasChildren ){            
+            //Get children for the selected orgUnit
+            OrgUnitFactory.get(orgUnit.id).then(function(ou) {                
+                orgUnit.show = !orgUnit.show;
+                orgUnit.hasChildren = false;
+                orgUnit.children = ou.organisationUnits[0].children;                
+                angular.forEach(orgUnit.children, function(ou){                    
+                    ou.hasChildren = ou.children && ou.children.length > 0 ? true : false;
+                });                
+            });           
+        }
+        else{
+            orgUnit.show = !orgUnit.show;   
+        }        
+    };
+})
\ No newline at end of file

=== 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	2015-12-16 10:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2015-12-21 13:28:07 +0000
@@ -21,7 +21,7 @@
             
             <!-- operations on selected enrollment begins -->
             <div class="row equal-height-columns">
-                <div class="col-sm-6">                
+                <div class="col-sm-8">                
                     <div class="title small-vertical-spacing">
                         {{'for_selected_program'| translate}}
 
@@ -133,7 +133,7 @@
                     </div>
                     
                 </div>
-                <div class="col-sm-6 border-left" ng-if="!showEnrollmentDiv">
+                <div class="col-sm-4 border-left" ng-if="!showEnrollmentDiv">
                     <div class="title small-vertical-spacing">{{'for_other_programs'| translate}}</div>
                     <div class="vertical-spacing">
                         <div ng-if="activeEnrollments.length > 0">

=== 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	2015-12-11 15:18:54 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html	2015-12-21 13:28:07 +0000
@@ -93,6 +93,10 @@
         <script type="text/javascript" src="components/registration/registration-controller.js"></script>
         <script type="text/javascript" src="components/enrollment/enrollment-controller.js"></script>
         <script type="text/javascript" src="components/dataentry/dataentry-controller.js"></script>
+        <script type="text/javascript" src="components/dataentry/referral-controller.js"></script>
+        <script type="text/javascript" src="components/dataentry/modal-default-form-controller.js"></script>
+        <script type="text/javascript" src="components/dataentry/new-event-controller.js"></script>
+        
         <script type="text/javascript" src="components/report/tei-report-controller.js"></script>
         <script type="text/javascript" src="components/report/program-summary-controller.js"></script>
         <script type="text/javascript" src="components/report/program-statistics-controller.js"></script>