← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16154: tracker capture - basic work in scheduling, autogeneration of events, and some filtering on event...

 

------------------------------------------------------------
revno: 16154
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-07-17 12:35:43 +0200
message:
  tracker capture - basic work in scheduling, autogeneration of events, and some filtering on events to return proper datavalues and notes
removed:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/widgets.html
added:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-widgets.html
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java
  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/components/notes/notes.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-07-14 05:03:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-07-17 10:35:43 +0000
@@ -364,6 +364,7 @@
         if ( event.getEventDate() != null )
         {
             executionDate = DateUtils.getMediumDate( event.getEventDate() );
+            programStageInstance.setExecutionDate( executionDate );
         }
 
         Date dueDate = new Date();
@@ -395,7 +396,6 @@
         }
 
         programStageInstance.setDueDate( dueDate );
-        programStageInstance.setExecutionDate( executionDate );
         programStageInstance.setOrganisationUnit( organisationUnit );
 
         if ( programStageInstance.getProgramStage().getCaptureCoordinates() && event.getCoordinate().isValid() )
@@ -447,7 +447,7 @@
         }
 
     }
-    
+
     public void updateEventForNote( Event event )
     {
         ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event
@@ -457,11 +457,10 @@
         {
             return;
         }
-        
         saveTrackedEntityComment( programStageInstance, event, getStoredBy( event, null ) );
-        
+
     }
-    
+
     public void updateEventForEventDate( Event event )
     {
         ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event
@@ -471,17 +470,34 @@
         {
             return;
         }
-        
+
         Date executionDate = new Date();
 
         if ( event.getEventDate() != null )
         {
             executionDate = DateUtils.getMediumDate( event.getEventDate() );
         }
-        
+
+        if ( event.getStatus() == EventStatus.ACTIVE )
+        {
+            programStageInstance.setStatus( EventStatus.ACTIVE );
+        }
+        else if ( event.getStatus() == EventStatus.COMPLETED )
+        {
+            programStageInstance.setStatus( EventStatus.COMPLETED );
+        }
+        else if ( event.getStatus() == EventStatus.SCHEDULE )
+        {
+            programStageInstance.setStatus( EventStatus.ACTIVE );
+        }
+        else if ( event.getStatus() == EventStatus.SKIPPED )
+        {
+            programStageInstance.setStatus( EventStatus.ACTIVE );
+        }
+
         programStageInstance.setExecutionDate( executionDate );
         programStageInstanceService.updateProgramStageInstance( programStageInstance );
-        
+
     }
 
     // -------------------------------------------------------------------------
@@ -750,10 +766,10 @@
 
         Date eventDate = DateUtils.getMediumDate( event.getEventDate() );
 
-        if ( eventDate == null )
-        {
-            return new ImportSummary( ImportStatus.ERROR, "Event.eventDate is not in a valid format." );
-        }
+        /*
+         * if ( eventDate == null ) { return new ImportSummary(
+         * ImportStatus.ERROR, "Event.eventDate is not in a valid format." ); }
+         */
 
         Date dueDate = DateUtils.getMediumDate( event.getDueDate() );
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-07-10 05:12:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-07-17 10:35:43 +0000
@@ -160,28 +160,21 @@
                 }
 
                 events.add( event );
-            }
-
-            if ( rowSet.getString( "pdv_value" ) == null || rowSet.getString( "de_uid" ) == null )
-            {
-                continue;
-            }
-
-            DataValue dataValue = new DataValue();
-            dataValue.setValue( rowSet.getString( "pdv_value" ) );
-            dataValue.setProvidedElsewhere( rowSet.getBoolean( "pdv_providedelsewhere" ) );
-            dataValue.setDataElement( rowSet.getString( "de_uid" ) );
-            dataValue.setStoredBy( rowSet.getString( "pdv_storedby" ) );
-
-            event.getDataValues().add( dataValue );
-            
-            if ( rowSet.getString( "psinote_value" ) == null )
-            {
-                continue;
-            }
-
-            if( !notes.contains( rowSet.getString( "psinote_id" ) ) )
-            {
+            }            
+            
+            if ( rowSet.getString( "pdv_value" ) != null && rowSet.getString( "de_uid" ) != null )
+            {
+                DataValue dataValue = new DataValue();
+                dataValue.setValue( rowSet.getString( "pdv_value" ) );
+                dataValue.setProvidedElsewhere( rowSet.getBoolean( "pdv_providedelsewhere" ) );
+                dataValue.setDataElement( rowSet.getString( "de_uid" ) );
+                dataValue.setStoredBy( rowSet.getString( "pdv_storedby" ) );
+
+                event.getDataValues().add( dataValue );
+            }            
+            
+            if ( rowSet.getString( "psinote_value" ) != null && !notes.contains( rowSet.getString( "psinote_id" ) ) )
+            {                
                 Note note = new Note();
                 note.setValue( rowSet.getString( "psinote_value" ) );
                 note.setStoredDate( StringUtils.defaultIfEmpty( 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-07-02 16:24:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-07-17 10:35:43 +0000
@@ -442,7 +442,7 @@
         Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEventForNote( updatedEvent );
+        eventService.updateEventForEventDate( updatedEvent );
         ContextUtils.okResponse( response, "Event updated: " + uid );
     }
 

=== 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-07-15 10:04:47 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-07-17 10:35:43 +0000
@@ -117,7 +117,7 @@
     
     $scope.showHideWidgets = function(){
         var modalInstance = $modal.open({
-            templateUrl: "views/widgets.html",
+            templateUrl: "components/dashboard/dashboard-widgets.html",
             controller: "DashboardWidgetsController"
         });
 

=== added file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-widgets.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-widgets.html	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-widgets.html	2014-07-17 10:35:43 +0000
@@ -0,0 +1,28 @@
+<div class="modal-header">
+    <h1>{{'select_widgets_to_show'| translate}}</h1>
+</div>
+
+<div class="modal-body">   
+    <table class="listTable dhis2-table-striped-border">
+        <tr ng-repeat="biggerWidget in biggerDashboardWidgets">
+            <td>
+                {{biggerWidget.title | translate}}
+            </td>
+            <td>
+                <input type="checkbox" ng-model="biggerWidget.show">
+            </td>
+        </tr>
+        <tr ng-repeat="smallerWidget in smallerDashboardWidgets">
+            <td>
+                {{smallerWidget.title | translate}}
+            </td>
+            <td>
+                <input type="checkbox" ng-model="smallerWidget.show">
+            </td>
+        </tr>
+    </table>    
+</div>
+
+<div class="modal-footer">     
+    <button type="button" class="btn btn-default" data-ng-click="close()">{{'close'| translate}}</button>
+</div> 

=== 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-07-15 09:20:54 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-07-17 10:35:43 +0000
@@ -28,6 +28,9 @@
     today = Date.parse(today);
     today = $filter('date')(today, 'yyyy-MM-dd');
     $scope.invalidDate = false;
+    
+    //note
+    $scope.note = '';
      
     //listen for the selected items
     $scope.$on('dashboardWidgets', function(event, args) {  
@@ -64,28 +67,32 @@
         
         $scope.dhis2Events = '';
         DHIS2EventFactory.getEventsByStatus($scope.selectedEntity.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id, 'ACTIVE').then(function(data){
-            $scope.dhis2Events = data;
-            
+            $scope.dhis2Events = data;            
             if(angular.isObject($scope.dhis2Events)){
                 angular.forEach($scope.dhis2Events, function(dhis2Event){
                     
-                    var eventStage = $scope.selectedProgramWithStage[dhis2Event.programStage];
-                    
-                    if(angular.isObject(eventStage)){
-                        
-                        dhis2Event.name = eventStage.name;                        
-                        dhis2Event.eventDate = DateUtils.format(dhis2Event.eventDate);
-                        if(dhis2Event.dueDate){
+                    if(dhis2Event.enrollment === $scope.selectedEnrollment.enrollment){
+                        var eventStage = $scope.selectedProgramWithStage[dhis2Event.programStage];
+
+                        if(angular.isObject(eventStage)){
+
+                            dhis2Event.name = eventStage.name; 
+                            dhis2Event.reportDateDescription = eventStage.reportDateDescription;
                             dhis2Event.dueDate = DateUtils.format(dhis2Event.dueDate);
-                        }
-                        else{
-                            dhis2Event.dueDate = EventUtils.getEventDueDate(eventStage, $scope.selectedEnrollment);
-                        }                        
-                        
-                        dhis2Event.statusColor = EventUtils.getEventStatusColor(dhis2Event);  
-                        dhis2Event = EventUtils.setEventOrgUnitName(dhis2Event);
-                    } 
-                                                                                 
+
+                            if(dhis2Event.eventDate){
+                                dhis2Event.eventDate = DateUtils.format(dhis2Event.eventDate);
+                                dhis2Event.sortingDate = DateUtils.format(dhis2Event.eventDate);
+                            }
+                            else{
+                                dhis2Event.sortingDate = dhis2Event.dueDate;
+                            }                       
+
+                            dhis2Event.statusColor = EventUtils.getEventStatusColor(dhis2Event);  
+                            dhis2Event = EventUtils.setEventOrgUnitName(dhis2Event);
+                        } 
+                    }
+
                 });
             }
             
@@ -106,7 +113,7 @@
                 dummyEvents = orderByFilter(dummyEvents, '-eventDate');
 
                 if(dummyEvents){
-                    $scope.showEventCreationDiv = true;
+                    $scope.allowEventCreation = true;
                 }
 
                 return dummyEvents;
@@ -167,7 +174,7 @@
                     orgUnit: $scope.currentDummyEvent.orgUnit,
                     eventDate: $scope.currentDummyEvent.eventDate,
                     dueDate: $scope.currentDummyEvent.dueDate,
-                    status: 'ACTIVE',
+                    status: 'SCHEDULE',
                     notes: [],
                     dataValues: []
                 };
@@ -185,6 +192,8 @@
                 newEvent.event = data.importSummaries[0].reference;
                 newEvent.orgUnitName = $scope.currentDummyEvent.orgUnitName;
                 newEvent.name = $scope.currentDummyEvent.name;
+                newEvent.reportDateDescription = $scope.currentDummyEvent.reportDateDescription;
+                newEvent.sortingDate = $scope.currentDummyEvent.dueDate,
                 newEvent.statusColor = $scope.currentDummyEvent.statusColor;
                 
                 if(!angular.isObject($scope.dhis2Events)){
@@ -192,33 +201,17 @@
                 }
                 else{
                     $scope.dhis2Events.splice(0,0,newEvent);
-                    $scope.dhis2Events = orderByFilter($scope.dhis2Events, '-eventDate');
-                    $scope.dhis2Events.reverse();
+                    /*$scope.dhis2Events = orderByFilter($scope.dhis2Events, '-sortingDate');
+                    $scope.dhis2Events.reverse();*/
                 }                
                 $scope.showDataEntry(newEvent);
             }
         });
     };   
     
-    $scope.createDummyEvent = function(programStage, orgUnit, enrollment){
-        
-        var dueDate = EventUtils.getEventDueDate(programStage, enrollment);
-        var dummyEvent = {programStage: programStage.id, 
-                          orgUnit: orgUnit.id,
-                          orgUnitName: orgUnit.name,
-                          dueDate: dueDate,
-                          name: programStage.name,
-                          status: 'ACTIVE',
-                          statusColor: 'alert alert-info'//'stage-on-time'
-                        };        
-        
-        dummyEvent.statusColor = EventUtils.getEventStatusColor(dummyEvent);
-        
-        return dummyEvent;
-    };
-    
-    $scope.showDataEntry = function(event){
-
+    $scope.showDataEntry = function(event){        
+        $scope.dueDateSaved = false;
+        $scope.eventDateSaved = false;
         if(event){
 
             if($scope.currentEvent && $scope.currentEvent.event === event.event){
@@ -233,8 +226,18 @@
                 $scope.showDataEntryDiv = true;   
                 $scope.showDummyEventDiv = false;
                 $scope.showEventCreationDiv = false;
-                $scope.getDataEntryForm();  
-                $scope.newEventDate = $scope.currentEvent.eventDate;
+                
+                angular.forEach($scope.currentEvent.notes, function(note){
+                    note.storedDate = moment(note.storedDate).format('YYYY-MM-DD @ hh:mm A');
+                });
+                
+                if($scope.currentEvent.notes.length > 0 ){
+                    $scope.currentEvent.notes = orderByFilter($scope.currentEvent.notes, '-storedDate');
+                }
+                
+                if($scope.currentEvent.eventDate){
+                    $scope.getDataEntryForm();
+                }
             }               
         }
     }; 
@@ -366,44 +369,98 @@
     };
     
     $scope.saveEventDate = function(){
+
+        $scope.eventDateSaved = false;
+        if($scope.currentEvent.eventDate == ''){
+            $scope.invalidDate = true;
+            return false;
+        }
+        else{
+            var rawDate = $filter('date')($scope.currentEvent.eventDate, 'yyyy-MM-dd'); 
+            var convertedDate = moment($scope.currentEvent.eventDate, 'YYYY-MM-DD')._d;
+            convertedDate = $filter('date')(convertedDate, 'yyyy-MM-dd'); 
+
+            if(rawDate !== convertedDate){
+                $scope.invalidDate = true;
+                return false;
+            } 
+
+            var e = {event: $scope.currentEvent.event,
+                 enrollment: $scope.currentEvent.enrollment,
+                 dueDate: $scope.currentEvent.dueDate,
+                 status: $scope.currentEvent.status === 'SCHEDULE' ? 'ACTIVE' : $scope.currentEvent.status,
+                 program: $scope.currentEvent.program,
+                 programStage: $scope.currentEvent.programStage,
+                 orgUnit: $scope.currentEvent.orgUnit,
+                 eventDate: $scope.currentEvent.eventDate,
+                 trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
+                };
+
+            DHIS2EventFactory.updateForEventDate(e).then(function(data){
+                $scope.currentEvent.sortingDate = $scope.currentEvent.eventDate;
+                $scope.invalidDate = false;
+                $scope.eventDateSaved = true;
+                
+                var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
+                var continueLoop = true;
+                for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+                    if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
+                        $scope.dhis2Events[i].statusColor = statusColor;
+                        continueLoop = false;
+                    }
+                }
+            });
+        }
         
-        if($scope.newEventDate != $scope.currentEvent.eventDate){
-            if($scope.newEventDate == ''){
+    };
+    
+    $scope.saveDueDate = function(){
+        $scope.dueDateSaved = false;
+
+        if($scope.currentEvent.dueDate == ''){
+            $scope.invalidDate = true;
+            return false;
+        }
+        else{
+            var rawDate = $filter('date')($scope.currentEvent.dueDate, 'yyyy-MM-dd'); 
+            var convertedDate = moment($scope.currentEvent.dueDate, 'YYYY-MM-DD')._d;
+            convertedDate = $filter('date')(convertedDate, 'yyyy-MM-dd'); 
+
+            if(rawDate !== convertedDate){
                 $scope.invalidDate = true;
                 return false;
-            }
-            else{
-                var rawDate = $filter('date')($scope.newEventDate, 'yyyy-MM-dd'); 
-                var convertedDate = moment($scope.newEventDate, 'YYYY-MM-DD')._d;
-                convertedDate = $filter('date')(convertedDate, 'yyyy-MM-dd'); 
-
-                if(rawDate !== convertedDate){
-                    $scope.invalidDate = true;
-                    return false;
+            } 
+
+            var e = {event: $scope.currentEvent.event,
+                 enrollment: $scope.currentEvent.enrollment,
+                 dueDate: $scope.currentEvent.dueDate,
+                 status: $scope.currentEvent.status,
+                 program: $scope.currentEvent.program,
+                 programStage: $scope.currentEvent.programStage,
+                 orgUnit: $scope.currentEvent.orgUnit,
+                 trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
+                };
+
+            DHIS2EventFactory.update(e).then(function(data){            
+                $scope.invalidDate = false;
+                $scope.dueDateSaved = true;
+                $scope.currentEvent.sortingDate = $scope.currentEvent.dueDate;                
+                var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
+                var continueLoop = true;
+                for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+                    if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
+                        $scope.dhis2Events[i].statusColor = statusColor;
+                        continueLoop = false;
+                    }
                 } 
-                
-                var e = {event: $scope.currentEvent.event,
-                     program: $scope.currentEvent.program,
-                     programStage: $scope.currentEvent.programStage,
-                     orgUnit: $scope.currentEvent.orgUnit,
-                     eventDate: $scope.newEventDate,
-                     trackedEntityInstance: $scope.currentEvent.trackedEntityInstance
-                    };
-                    
-                DHIS2EventFactory.updateForEventDate(e).then(function(data){
-                    $scope.currentEvent.eventDate = $scope.newEventDate;
-                    $scope.newEventDate = '';
-                    $scope.invalidDate = false;
-                });
-            }
-        }
-        
+            });
+        }              
     };
     
     $scope.addNote = function(){
         
         if(!angular.isUndefined($scope.note) && $scope.note != ""){
-            
+
             var newNote = {value: $scope.note};
 
             if(angular.isUndefined( $scope.currentEvent.notes) ){
@@ -422,7 +479,7 @@
                     };
 
             DHIS2EventFactory.updateForNote(e).then(function(data){
-                $scope.note = '';                
+                $scope.note = ''; 
             });
         }        
     };    
@@ -453,54 +510,38 @@
         $scope.showDummyEventDiv = !$scope.showDummyEventDiv;
     };
     
-    $scope.completeEvent = function(){
-        
-        var modalOptions = {
-            closeButtonText: 'cancel',
-            actionButtonText: 'complete',
-            headerText: 'complete',
-            bodyText: 'are_you_sure_to_complete_event'
-        };
-
-        ModalService.showModal({}, modalOptions).then(function(result){
-            
-            var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage);
-            dhis2Event.status = 'COMPLETED';            
-        
-            DHIS2EventFactory.update(dhis2Event).then(function(data){
-                
-                $scope.currentEvent.status = 'COMPLETED';
-                var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
-                var continueLoop = true;
-                for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
-                    if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
-                        $scope.dhis2Events[i].statusColor = statusColor;
-                        continueLoop = false;
-                    }
-                }                
-            });
-        });
-    };
-    
-    $scope.incompleteEvent = function(){
-        
-        var modalOptions = {
-            closeButtonText: 'cancel',
-            actionButtonText: 'incomplete',
-            headerText: 'incomplete',
-            bodyText: 'are_you_sure_to_incomplete_event'
-        };
-
-        ModalService.showModal({}, modalOptions).then(function(result){
-            
-            var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage);
-            dhis2Event.status = 'ACTIVE';
-            $scope.currentEvent.status = 'ACTIVE';
-        
-            DHIS2EventFactory.update(dhis2Event).then(function(data){
-                
-                
-                $scope.currentEvent.status = 'ACTIVE';
+    $scope.completeIncompleteEvent = function(){
+        var modalOptions;
+        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage);        
+        if($scope.currentEvent.status === 'COMPLETED'){//activiate event
+            modalOptions = {
+                closeButtonText: 'cancel',
+                actionButtonText: 'incomplete',
+                headerText: 'incomplete',
+                bodyText: 'are_you_sure_to_incomplete_event'
+            };
+            dhis2Event.status = 'ACTIVE';        
+        }
+        else{//complete event
+            modalOptions = {
+                closeButtonText: 'cancel',
+                actionButtonText: 'complete',
+                headerText: 'complete',
+                bodyText: 'are_you_sure_to_complete_event'
+            };
+            dhis2Event.status = 'COMPLETED';
+        }        
+
+        ModalService.showModal({}, modalOptions).then(function(result){
+            
+            DHIS2EventFactory.update(dhis2Event).then(function(data){
+                
+                if($scope.currentEvent.status === 'COMPLETED'){//activiate event                    
+                    $scope.currentEvent.status = 'ACTIVE'; 
+                }
+                else{//complete event                    
+                    $scope.currentEvent.status = 'COMPLETED';
+                }
                 var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);  
                 var continueLoop = true;
                 for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
@@ -513,17 +554,15 @@
         });
     };
     
-    $scope.validateEvent = function(){
-        
-    };
+    $scope.validateEvent = function(){};    
     
-    $scope.removeEvent = function(){
+    $scope.deleteEvent = function(){
         
         var modalOptions = {
             closeButtonText: 'cancel',
-            actionButtonText: 'remove',
-            headerText: 'remove',
-            bodyText: 'are_you_sure_to_remove_event'
+            actionButtonText: 'delete',
+            headerText: 'delete',
+            bodyText: 'are_you_sure_to_delete_event'
         };
 
         ModalService.showModal({}, modalOptions).then(function(result){

=== 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-07-13 13:08:50 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-07-17 10:35:43 +0000
@@ -18,13 +18,13 @@
             <table class="table-borderless">
                 <tbody>
                     <tr>
-                        <td class="inline-block" ng-repeat="dhis2Event in dhis2Events">
+                        <td class="inline-block" ng-repeat="dhis2Event in dhis2Events | orderBy:'sortingDate':reverse">
                             <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
                             <span class="stage-container"                                                     
                                   ng-class="{'current-stage': currentEvent && currentEvent.event == dhis2Event.event, '{{dhis2Event.statusColor}}': true}"                                                      
                                   ng-click="showDataEntry(dhis2Event)">
                                 {{dhis2Event.name}}<br/>
-                                {{dhis2Event.eventDate}}         
+                                {{dhis2Event.sortingDate}}         
                             </span>
                             <i class="fa fa-arrow-right" ng-show="$index < dhis2Events.length - 1"></i>
                         </td>                        
@@ -39,7 +39,7 @@
             <table class="table-borderless">
                 <tbody>
                     <tr>
-                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents">
+                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents | orderBy:'sortingDate':reverse">
                             <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
                             <span class="stage-container"                                                     
                                   ng-class="{'current-stage': currentDummyEvent && currentDummyEvent.programStage == dummyEvent.programStage, '{{dummyEvent.statusColor}}': true}"                                                      
@@ -56,12 +56,12 @@
                 <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"/>
+                        <input type="text" name="eventDate" class="form-control" ng-date ng-model="currentDummyEvent.eventDate" ng-required="false"/>
                         <span ng-show="eventCreationForm.submitted && eventCreationForm.eventDate.$invalid" class="error">{{'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" />
+                        <input type="text" name="dueDate" class="form-control" ng-date ng-model="currentDummyEvent.dueDate" ng-required="true"/>
                         <span ng-show="eventCreationForm.submitted && eventCreationForm.dueDate.$invalid" class="error">{{'required'| translate}}</span>
                     </div>                        
                 </div>
@@ -77,27 +77,39 @@
         <div ng-show="currentEvent && !showEventCreationDiv">
             <div class="row">
                 <div class="col-md-6">
-                    {{currentStage.reportDateDescription}}
-                    <input class="form-control" ng-date ng-model="newEventDate" ng-required="true" blur-or-change="saveEventDate()"/>
+                    {{currentEvent.reportDateDescription}}
+                    <input type="text"
+                           name="eventDate" 
+                           class="form-control" 
+                           ng-class="{'input-success': eventDateSaved}"
+                           ng-date 
+                           ng-model="currentEvent.eventDate" 
+                           ng-required="true" 
+                           blur-or-change="saveEventDate()"/>
                     <span ng-show="invalidDate" class="error">{{'date_required'| translate}}</span>     
                 </div>
                 <div class="col-md-6">
                     {{'due_date'| translate}}
-                    <input type="text" name="dueDate" class="form-control" ng-date ng-model="currentEvent.dueDate" ng-disabled="true"/>
+                    <input type="text" 
+                           name="dueDate" 
+                           class="form-control"
+                           ng-class="{'input-success': dueDateSaved}"
+                           ng-date 
+                           ng-model="currentEvent.dueDate" 
+                           blur-or-change="saveDueDate()" 
+                           ng-disabled="currentEvent.eventDate"/>
                 </div>                        
             </div>
-            <div class='row'><hr></div>
-            <div class='col-md-12' ng-if="customForm">
-                <a href ng-click="switchDataEntryForm()" title="{{displayCustomForm ? 'default_form' : 'custom_form'| translate}}"><span class="primary pull-right"><i class="fa fa-file-text fa-2x"></i></span></a>                
-                <!--<button type="button" class="btn btn-default pull-right" ng-click="switchDataEntryForm()">
-                    {{displayCustomForm ? 'default_form' : 'custom_form'| translate}}
-                </button>--> 
+            <div ng-show="currentEvent.eventDate">
+            
+                <div class='row'><hr></div>
+                <div class='col-md-12' ng-if="customForm">
+                    <a href ng-click="switchDataEntryForm()" title="{{displayCustomForm ? 'default_form' : 'custom_form'| translate}}"><span class="primary pull-right"><i class="fa fa-file-text fa-2x"></i></span></a>                
+                </div>
+                <div class="vertical-spacing" ng-if="displayCustomForm" ng-include="'components/dataentry/custom-form.html'"></div>  
+                <div class="vertical-spacing" ng-if="!displayCustomForm" ng-include="'components/dataentry/default-form.html'"></div>
+                <div class='row'><hr></div>                                
             </div>
-
-            <div class="vertical-spacing" ng-if="displayCustomForm" ng-include="'components/dataentry/custom-form.html'"></div>  
-            <div class="vertical-spacing" ng-if="!displayCustomForm" ng-include="'components/dataentry/default-form.html'"></div>
-
-            <div class='row'><hr></div>
             <div class="row">
                 <div class="col-md-10">
                     <textarea class="form-control" rows="3" ng-model="note" placeholder="{{'add_your_note_here'| translate}}"></textarea>
@@ -112,7 +124,7 @@
 
                 <table class="table table-striped dhis2-table-hover">
                     <tr ng-repeat="note in currentEvent.notes">
-                        <td class="over-flow-hidden">
+                        <td class="overflow-ellipsis">
                             <d2-pop-over content="note" template="note.html" details="{{'details'| translate}}">
                                 <div>{{note.value}}</div>
                             </d2-pop-over>
@@ -129,12 +141,13 @@
             <div class='row'><hr></div>
             <div class="form-group">
                 <div class="btn-group btn-group-justified">
-                    <a href ng-click="completeEvent()" class="btn btn-info" ng-disabled="currentEvent.status !== 'ACTIVE'">{{'complete'| translate}}</a>
-                    <a href ng-click="incompleteEvent()" class="btn btn-warning" ng-disabled="currentEvent.status !== 'COMPLETED'">{{'incomplete'| translate}}</a>
-                    <a href ng-click="validateEvent()" class="btn btn-info" ng-disabled="true">{{'validate'| translate}}</a>
-                    <a href ng-click="removeEvent()" class="btn btn-info">{{'remove'| translate}}</a>
+                        <a href ng-click="completeIncompleteEvent()" class="btn btn-warning" ng-if="currentEvent.eventDate && currentEvent.status === 'ACTIVE'">{{'complete'| translate}}</a>
+                        <a href ng-click="completeIncompleteEvent()" class="btn btn-warning" ng-if="currentEvent.eventDate && currentEvent.status === 'COMPLETED'">{{'incomplete'| translate}}</a>                       
+                        <a href ng-click="validateEvent()" class="btn btn-info" ng-disabled="true" ng-if="currentEvent.eventDate">{{'validate'| translate}}</a>
+                        <a href ng-click="skipEvent()" class="btn btn-warning" ng-if="!currentEvent.eventDate">{{'skipped'| translate}}</a>               
+                    <a href ng-click="deleteEvent()" class="btn btn-danger">{{'delete'| translate}}</a>
                 </div>
             </div>
-        </div>        
+    </div>        
     </div>
 </div>
\ No newline at end of file

=== 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-07-15 10:04:47 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-07-17 10:35:43 +0000
@@ -1,15 +1,19 @@
 trackerCapture.controller('EnrollmentController',
         function($rootScope,
                 $scope,  
-                $filter,
                 $timeout,
                 $location,
+                orderByFilter,
+                DateUtils,
+                EventUtils,
                 storage,
+                DHIS2EventFactory,
                 AttributesFactory,
                 CurrentSelection,
                 TEIService,
                 EnrollmentService,
                 TranslationService,
+                ModalService,
                 DialogService) {
     TranslationService.translate();
 
@@ -19,10 +23,12 @@
         //programs for enrollment        
         $scope.enrollments = [];
         $scope.showEnrollmentDiv = false;
-        $scope.showSchedulingDiv = false;    
+        $scope.showReSchedulingDiv = false;
+        $scope.showEnrollmentHistoryDiv = false;
+        $scope.hasEnrollmentHistory = false;
         $scope.selectedEnrollment = null;
         $scope.newEnrollment = {};
-        
+        $scope.eventsForRescheduling = [];
         var selections = CurrentSelection.get();
         $scope.selectedTei = angular.copy(selections.tei); 
         $scope.selectedEntity = selections.te;
@@ -40,21 +46,39 @@
         else{
             $scope.broadCastSelections('dashboardWidgets');
         }
-    }); 
+    });
     
     $scope.loadEnrollmentDetails = function() {
         
-        if($scope.selectedProgram){
+        if($scope.selectedProgram){           
+            
+            $scope.selectedProgramWithStage = [];        
+            angular.forEach($scope.selectedProgram.programStages, function(stage){
+                $scope.selectedProgramWithStage[stage.id] = stage;
+            });
           
-            //check for possible enrollment
+            //check for possible enrollment, there is only one active enrollment
+            $scope.terminatedEnrollments = [];
+            $scope.completedEnrollments = [];
             angular.forEach($scope.enrollments, function(enrollment){
                 if(enrollment.program === $scope.selectedProgram.id ){
-                    $scope.selectedEnrollment = enrollment;
+                    if(enrollment.status === 'ACTIVE'){
+                        $scope.selectedEnrollment = enrollment;
+                    }
+                    if(enrollment.status === 'CANCELLED'){//check for cancelled ones
+                        $scope.terminatedEnrollments.push(enrollment);
+                        $scope.hasEnrollmentHistory = true;
+                    }
+                    if(enrollment.status === 'COMPLETED'){//check for completed ones
+                        $scope.completedEnrollments.push(enrollment);
+                        $scope.hasEnrollmentHistory = true;
+                    }
                 }
             }); 
             
             if($scope.selectedEnrollment){//enrollment exists
-                $scope.selectedEnrollment.dateOfIncident = $filter('date')($scope.selectedEnrollment.dateOfIncident, 'yyyy-MM-dd');
+                $scope.selectedEnrollment.dateOfIncident = DateUtils.format($scope.selectedEnrollment.dateOfIncident);
+                $scope.selectedEnrollment.dateOfEnrollment = DateUtils.format($scope.selectedEnrollment.dateOfEnrollment);
                 
                 $scope.programStages = [];   
                 
@@ -63,7 +87,7 @@
                 angular.forEach($scope.selectedProgram.programStages, function(stage){                
                     stage.dueDate = moment(moment(incidentDate).add('d', stage.minDaysFromStart), 'YYYY-MM-DD')._d;
                     stage.dueDate = Date.parse(stage.dueDate);
-                    stage.dueDate= $filter('date')(stage.dueDate, 'yyyy-MM-dd');
+                    stage.dueDate = DateUtils.format(stage.dueDate);//$filter('date')(stage.dueDate, 'yyyy-MM-dd');
                     $scope.programStages.push(stage);               
                 });
             }
@@ -88,12 +112,22 @@
         $scope.broadCastSelections('dashboardWidgets');
     };
         
-    $scope.showEnrollment = function(){        
+    $scope.showNewEnrollment = function(){       
+        if($scope.showEnrollmentDiv){//this is hiding enrollment div
+            /*currently the only way to cancel enrollment window is by going through
+            * the main dashboard controller. Here I am mixing program and programId, 
+            * as I didn't want to refetch program from server, the main dashboard
+            * has already fetched the programs. With the ID passed to it, it will
+            * pass back the actual program than ID. 
+            */
+           $scope.selectedProgram = ($location.search()).program;
+           $scope.broadCastSelections('mainDashboard');
+        }
         $scope.showEnrollmentDiv = !$scope.showEnrollmentDiv;
     };    
        
-    $scope.showScheduling = function(){        
-        $scope.showSchedulingDiv = !$scope.showSchedulingDiv;
+    $scope.showReScheduling = function(){        
+        $scope.showReSchedulingDiv = !$scope.showReSchedulingDiv;
     };
     
     $scope.enroll = function(){    
@@ -156,8 +190,8 @@
                     });
                     
                     enrollment.enrollment = enrollmentResponse.reference;
-                    $scope.selectedEnrollment = enrollment;
-                    
+                    $scope.selectedEnrollment = enrollment;                    
+                    $scope.autoGenerateEvents();                    
                     $scope.broadCastSelections('dashboardWidgets'); 
                     
                     $scope.outerForm.submitted = false;      
@@ -182,7 +216,7 @@
         }, 100);
     };
     
-    $scope.cancelEnrollment = function(){
+    $scope.hideEnrollmentDiv = function(){
         
         /*currently the only way to cancel enrollment window is by going through
          * the main dashboard controller. Here I am mixing program and programId, 
@@ -193,4 +227,92 @@
         $scope.selectedProgram = ($location.search()).program;
         $scope.broadCastSelections('mainDashboard'); 
     };
+    
+    $scope.terminateEnrollment = function(){        
+
+        var modalOptions = {
+            closeButtonText: 'cancel',
+            actionButtonText: 'terminate',
+            headerText: 'terminate_enrollment',
+            bodyText: 'are_you_sure_to_terminate_enrollment'
+        };
+
+        ModalService.showModal({}, modalOptions).then(function(result){
+            
+            EnrollmentService.cancelled($scope.selectedEnrollment).then(function(data){                
+                $scope.selectedEnrollment.status = 'CANCELLED';
+                $scope.loadEnrollmentDetails();                
+            });
+        });
+    };
+    
+    $scope.completeEnrollment = function(){        
+
+        var modalOptions = {
+            closeButtonText: 'cancel',
+            actionButtonText: 'complete',
+            headerText: 'complete_enrollment',
+            bodyText: 'are_you_sure_to_complete_enrollment'
+        };
+
+        ModalService.showModal({}, modalOptions).then(function(result){
+            
+            EnrollmentService.completed($scope.selectedEnrollment).then(function(data){                
+                $scope.selectedEnrollment.status = 'COMPLETED';
+                $scope.loadEnrollmentDetails();                
+            });
+        });
+    };
+    
+    $scope.showEnrollmentHistory = function(){
+        //$scope.showEnrollmentHistoryDiv = !$scope.showEnrollmentHistoryDiv;
+        console.log('need to figure out how to deal with previous enrollments'); 
+    };
+    
+    $scope.getEventsForRescheduling = function(){
+        
+        DHIS2EventFactory.getEventsByStatus($scope.selectedTei.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id, 'ACTIVE', 'SCHEDULE').then(function(data){
+            if(angular.isObject(data)){
+                angular.forEach(data, function(ev){                    
+                    if(ev.enrollment === $scope.selectedEnrollment.enrollment){                        
+                        ev.name = $scope.selectedProgramWithStage[ev.programStage].name;                        
+                        ev.dueDate = DateUtils.format(ev.dueDate);                        
+                        ev.statusColor = EventUtils.getEventStatusColor(ev);                          
+                        $scope.eventsForRescheduling.push(ev);
+                        ev = EventUtils.setEventOrgUnitName(ev);
+                    }                                                                                 
+                });
+            }  
+            
+            if($scope.eventsForRescheduling.length > 0 ){
+                $scope.eventsForRescheduling = orderByFilter($scope.eventsForRescheduling, '-eventDate');
+                $scope.eventsForRescheduling.reverse();
+            }
+        });        
+    };
+    
+    $scope.autoGenerateEvents = function(){
+        if($scope.selectedTei && $scope.selectedProgram && $scope.selectedOrgUnit && $scope.selectedEnrollment){            
+            $scope.dhis2Events = {events: []};
+            angular.forEach($scope.selectedProgram.programStages, function(stage){
+                if(stage.autoGenerateEvent){
+                    var newEvent = {
+                            trackedEntityInstance: $scope.selectedTei.trackedEntityInstance,
+                            program: $scope.selectedProgram.id,
+                            programStage: stage.id,
+                            orgUnit: $scope.selectedOrgUnit.id,                        
+                            dueDate: EventUtils.getEventDueDate(stage, $scope.selectedEnrollment),
+                            status: 'SCHEDULE'
+                        };
+                    $scope.dhis2Events.events.push(newEvent);    
+                }
+            });
+            
+            if($scope.dhis2Events.events.length > 0){
+                DHIS2EventFactory.create($scope.dhis2Events).then(function(data) {
+                    console.log('the response is:  ', data);
+                });
+            }
+        }
+    };
 });
\ No newline at end of file

=== 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-07-15 13:13:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-07-17 10:35:43 +0000
@@ -1,8 +1,15 @@
 <div class="panel panel-default" ng-controller="EnrollmentController">
-    <div class="panel-heading handle bold">
+    <div class="panel-heading handle bold">                                            
+        <!--<span ng-class="{'text-primary': !showEnrollmentHistoryDiv}">{{enrollmentWidget.title| translate}}</span>-->
         {{enrollmentWidget.title| translate}}
         <span class="nav-pills" ng-show="selectedProgram && !selectedEnrollment">
-            | <a href ng-click="showEnrollment()" title="{{'new_enrollment'| translate}}"><span class="bold">{{'new_enrollment'| translate}}</span></a>
+            | <a href ng-click="showNewEnrollment()" title="{{'new'| translate}}"><span class="bold">{{'new'| translate}}</span></a>
+        </span>
+        <span class="nav-pills" ng-show="terminatedEnrollments.length > 0 || completedEnrollments.length > 0">
+            | <a href ng-click="showEnrollmentHistory()" title="{{'history'| translate}}"><span class="bold">{{'history'| translate}}</span></a>
+        </span>        
+        <span class="nav-pills" ng-show="eventsForRescheduling.length > 0">
+            | <a href ng-click="showReScheduling()" title="{{'rescheduling'| translate}}"><span class="bold">{{'rescheduling'| translate}}</span></a>
         </span>
         <span class="pull-right">
             <a class="small-horizonal-spacing" href ng-click="expandCollapse(enrollmentWidget)">
@@ -13,60 +20,42 @@
         </span>
     </div>
     <div ng-show="enrollmentWidget.expand" class="panel-body dashboard-widget-container">
-        <div ng-if="selectedEnrollment">
-            <table class="table-borderless">
+        <!-- operations on selected enrollment begins -->
+        <div ng-if="selectedEnrollment && !showEnrollmentHistoryDiv && !showReSchedulingDiv">
+            <table class="table-borderless table-striped">
                 <tr class="col-md-12">
                     <td class="col-md-6">
+                        {{selectedProgram.dateOfEnrollmentDescription}}
+                    </td>
+                    <td class="col-md-6">
+                        <input type="text" class="form-control" ng-date ng-model="selectedEnrollment.dateOfEnrollment" ng-disabled="true"/>
+                    </td>
+                </tr>
+                <tr class="col-md-12">                    
+                    <td class="col-md-6">
                         {{selectedProgram.dateOfIncidentDescription}}
                     </td>
                     <td class="col-md-6">
                         <input type="text" class="form-control" ng-date ng-model="selectedEnrollment.dateOfIncident" ng-disabled="true"/>
                     </td>
-                </tr>
-            </table>
-            <div class='row'><hr></div>
-            <table class="table-borderless table-striped">
-                <thead>
-                    <tr class="col-md-12">
-                        <th class="col-md-6">
-                            {{'program_stage'| translate}}
-                        </th>
-                        <th class="col-md-6">
-                            {{'scheduled_date'| translate}}
-                        </th>
-                    </tr>                
-                </thead>           
-                <tr class="col-md-12" ng-repeat="programStage in programStages">
-                    <td class="col-md-6">
-                        {{programStage.name}}
-                    </td>
-                    <td class="col-md-6">
-                        <input type="text" class="form-control" ng-date ng-model="programStage.dueDate" ng-disabled="!showSchedulingDiv"/>
-                    </td>
-                </tr>
-            </table>
+                </tr>                
+            </table>            
             <div class="vertical-spacing small-horizonal-spacing">
                 <button type="button" 
-                        class="btn btn-primary"
-                        ng-disabled="showSchedulingDiv"
-                        ng-click="showScheduling()">
-                    {{'reschedule'| translate}}
-                </button>
-                <button type="button" 
-                        class="btn btn-primary"
-                        ng-show="showSchedulingDiv"
-                        ng-click="showScheduling()">
-                    {{'save'| translate}}
-                </button>
-                <button type="button" 
-                        class="btn btn-default"
-                        ng-show="showSchedulingDiv"
-                        ng-click="showScheduling()">
-                    {{'cancel'| translate}}
+                        class="btn btn-info"
+                        ng-click="completeEnrollment()">
+                    {{'complete'| translate}}
+                </button>
+                <button type="button" 
+                        class="btn btn-warning"
+                        ng-click="terminateEnrollment()">
+                    {{'terminate'| translate}}
                 </button>
             </div>
         </div>
-        
+        <!-- operations on selected enrollment ends -->
+
+        <!-- new enrollment registration form begins -->
         <form name="outerForm" novalidate>
             <div ng-if="showEnrollmentDiv">
                 <table class="table-borderless">
@@ -136,7 +125,6 @@
                         </td>
                     </tr>                        
                 </table>
-
                 <div class="vertical-spacing col-md-12">            
                     <button type="button" 
                             class="btn btn-primary"
@@ -145,16 +133,39 @@
                     </button>  
                     <button type="button" 
                             class="btn btn-default"
-                            ng-click="cancelEnrollment()">
+                            ng-click="showNewEnrollment()">
                         {{'cancel'| translate}}
                     </button>
                 </div>
             </div>
         </form>    
+        <!-- new enrollment registration form ends -->
 
-        <div ng-if="selectedProgram && !selectedEnrollment && !showEnrollmentDiv">
+        <!-- operations on historical enrollment begins -->
+        <div ng-if="showEnrollmentHistoryDiv">
+            enrollment history here...
+        </div>
+        <!-- operations on historical enrollment ends -->
+        
+        <div ng-if="showReSchedulingDiv && eventsForRescheduling.length > 0">
+            <table class="table-borderless table-striped">
+                <tr class="col-md-12" ng-repeat="ev in eventsForRescheduling">
+                    <td class="col-md-6">
+                        {{ev.name}}
+                    </td>
+                    <td class="col-md-6">
+                        <input type="text" class="form-control" ng-date ng-model="ev.dueDate" blur-or-change="saveScheduledDate(ev)"/>
+                    </td>
+                </tr>                                
+            </table>  
+        </div>
+        
+        <div ng-if="selectedProgram && !selectedEnrollment && !showEnrollmentDiv && !hasEnrollmentHistory">
             <div class="alert alert-warning">{{'not_yet_enrolled_enrollment'| translate}}</div> 
         </div>
+        <div ng-if="selectedProgram && !selectedEnrollment && !showEnrollmentDiv && hasEnrollmentHistory">
+            <div class="alert alert-warning">{{'not_active_enrollment_exists'| translate}}</div> 
+        </div>
         <div ng-if="!selectedProgram && programExists">
             <div class="alert alert-warning">{{'please_select_a_program_for_enrollment'| translate}}</div> 
         </div>

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/notes/notes.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/notes/notes.html	2014-07-10 13:17:04 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/notes/notes.html	2014-07-17 10:35:43 +0000
@@ -30,10 +30,10 @@
             </button>
         </div>
 
-        <div ng-show='selectedEnrollment' class='remove-default-padding'>
+        <div ng-show='selectedEnrollment' class='remove-default-padding overflow-ellipsis'>
             <table class="table table-striped dhis2-table-hover">
                 <tr ng-repeat="note in selectedEnrollment.notes| filter:noteSearchText">
-                    <td class="over-flow-hidden">
+                    <td>
                         <d2-pop-over content="note" template="note.html" details="{{'details'| translate}}">
                             <div>{{note.value}}</div>
                         </d2-pop-over>

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-07-04 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-07-17 10:35:43 +0000
@@ -4,11 +4,13 @@
                 $location,
                 $timeout,
                 AttributesFactory,
+                DHIS2EventFactory,
                 TEService,
                 TEIService,
                 EnrollmentService,
                 DialogService,
                 CurrentSelection,
+                EventUtils,
                 DateUtils,
                 storage,
                 TranslationService) {
@@ -101,6 +103,10 @@
                             DialogService.showDialog({}, dialogOptions);
                             return;
                         }
+                        else{
+                            enrollment.enrollment = data.reference;
+                            $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, enrollment);                          
+                        }
                     });
                 }
             }
@@ -154,4 +160,31 @@
             $rootScope.$broadcast('relationship', {});
         }, 100);
     };
+    
+    $scope.autoGenerateEvents = function(teiId, program, orgUnit, enrollment){            
+            
+        if(teiId && program && orgUnit && enrollment){            
+            var dhis2Events = {events: []};
+            angular.forEach(program.programStages, function(stage){
+                if(stage.autoGenerateEvent){
+                    var newEvent = {
+                            trackedEntityInstance: teiId,
+                            program: program.id,
+                            programStage: stage.id,
+                            orgUnit: orgUnit.id,                        
+                            dueDate: EventUtils.getEventDueDate(stage, enrollment),
+                            status: 'SCHEDULE'
+                        };
+                    dhis2Events.events.push(newEvent);    
+                }
+            });
+
+            if(dhis2Events.events.length > 0){
+                DHIS2EventFactory.create(dhis2Events).then(function(data){
+
+                });
+            }
+        }
+    };       
+    
 });
\ No newline at end of file

=== 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-07-15 13:13:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-07-17 10:35:43 +0000
@@ -14,6 +14,7 @@
     "no_program_exists_report": "No program exists for the selected org unit. Reporting not possible.",
     "not_yet_enrolled_data_entry": "Not yet enrolled. Data entry not possible.",
     "not_yet_enrolled_enrollment": "Not yet enrolled. Please enroll.",
+    "not_active_enrollment_exists": "No active enrollment exists for the selected program",
     "not_yet_enrolled_note": "Not yet enrolled. Note recording not possible.",
     "not_yet_enrolled_report": "Not yet enrolled. Reporting not possible",
     "no_data_report": "No record exists for reporting",
@@ -55,12 +56,19 @@
     "association": "Manage associations",
     "change_location": "Manage location",
     "details_history": "Details/history",
+    "history": "History",
+    "complete": "Complete",
+    "terminate": "Terminate",
+    "completed": "Completed",
+    "terminated": "Terminated",
+    "delete": "Delete",
     "remove": "Remove",
     "entity": "Entity",
     "add": "Add",
     "add_note": "Add note",
     "search_note": "Search notes",
     "add_your_note_here": "Add your note here",
+    "skipped": "Skipped",
     "complete": "Complete",
     "incomplete": "Incomplete",
     "validate": "Validate",
@@ -71,8 +79,6 @@
     "date": "Date",
     "_date": "date",
     "add_new": "Add new",
-    "add_filter": "Add filter",
-    "remove_filter": "Remove filter",
     "new_event": "New event",
     "create_new_event": "Create new event",
     "create_new_event_repeatable": "Create new event from a repeatable stage",
@@ -86,6 +92,9 @@
     "back": "Back",
     "profile": "Profile",
     "enrollment": "Enrollment",
+    "delete_enrollment": "Delete enrollment",
+    "terminate_enrollment": "Terminate enrollment",
+    "complete_enrollment": "Complete enrollment",
     "enrollment_date": "Enrollment date",
     "notes": "Notes",
     "relationship": "Relationship",
@@ -133,6 +142,7 @@
     "scheduled_date": "Scheduled date",
     "scheduling": "Scheduling",
     "reschedule": "Reschedule",
+    "rescheduling": "Rescheduling",
     "enroll": "Enroll",
     "new_enrollment": "New enrollment",
     "start_date": "Start date",
@@ -160,6 +170,7 @@
     "found": "Found",
     "move_to_selected": "Move to selected",
     "move_all_to_selected": "Move all to selected",
+    "new": "New",
     "add_new": "Add new",
     "register_new": "Register new",
     "registration": "Registration",
@@ -179,7 +190,10 @@
     "save_relationship": "Save relationship",
     "go_back": "Go back",
     "cancel": "Cancel",
-    "are_you_sure_to_remove_event": "Are you sure you want to remove the selected event?",
+    "are_you_sure_to_delete_enrollment": "Are you sure you want to delete the selected enrollment?",
+    "are_you_sure_to_complete_enrollment": "Are you sure you want to complete the selected enrollment?",
+    "are_you_sure_to_terminate_enrollment": "Are you sure you want to terminate the selected enrollment?",
+    "are_you_sure_to_delete_event": "Are you sure you want to delete the selected event?",
     "are_you_sure_to_complete_event": "Are you sure you want to complete the selected event?",
     "are_you_sure_to_incomplete_event": "Are you sure you want to incomplete the selected event?",
     "more": "More",    

=== 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-07-13 13:08:50 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-07-17 10:35:43 +0000
@@ -203,7 +203,7 @@
 })
 
 /* Service to deal with enrollment */
-.service('EnrollmentService', function($http) {
+.service('EnrollmentService', function($http, EventUtils, DHIS2EventFactory) {
     
     return {        
         get: function( enrollmentUid ){
@@ -235,7 +235,19 @@
                 return response.data;
             });
             return promise;
-        }
+        },
+        cancelled: function(enrollment){
+            var promise = $http.put('../api/enrollments/' + enrollment.enrollment + '/cancelled').then(function(response){
+                return response.data;               
+            });
+            return promise;           
+        },
+        completed: function(enrollment){
+            var promise = $http.put('../api/enrollments/' + enrollment.enrollment + '/completed').then(function(response){
+                return response.data;               
+            });
+            return promise;           
+        }        
     };   
 })
 
@@ -504,12 +516,12 @@
 })
 
 /* factory for handling events */
-.factory('DHIS2EventFactory', function($http) {   
+.factory('DHIS2EventFactory', function($http, $q) {   
     
-    return {
+    return {     
         
         getEventsByStatus: function(entity, orgUnit, program, programStatus){   
-            var promise = $http.get( '../api/events.json?' + 'trackedEntityInstance=' + entity + '&orgUnit=' + orgUnit + '&program=' + program + '&programStatus=' + programStatus + '&paging=false').then(function(response){
+            var promise = $http.get( '../api/events.json?' + 'trackedEntityInstance=' + entity + '&orgUnit=' + orgUnit + '&program=' + program + '&programStatus=' + programStatus  + '&paging=false').then(function(response){
                 return response.data.events;
             });            
             return promise;
@@ -1119,6 +1131,7 @@
                               orgUnit: orgUnit.id,
                               orgUnitName: orgUnit.name,
                               dueDate: dueDate,
+                              sortingDate: dueDate,
                               name: programStage.name,
                               reportDateDescription: programStage.reportDateDescription,
                               status: 'ACTIVE'};

=== 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-07-13 13:08:50 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-07-17 10:35:43 +0000
@@ -372,7 +372,7 @@
         return $.ajax( {
             url: '../api/programs.json',
             type: 'GET',
-            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,relationshipText,relationshipFromA,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]]'
+            data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,version,relationshipText,relationshipFromA,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,realionshipText,trackedEntity[id,name,description],userRoles[id,name],organisationUnits[id,name],programStages[id,name,version,minDaysFromStart,reportDateDescription,repeatable,autoGenerateEvent],programTrackedEntityAttributes[displayInList,mandatory,attribute[id]]'
         }).done( function( response ){
             
             _.each( _.values( response.programs ), function ( program ) { 
@@ -449,7 +449,7 @@
         return $.ajax( {
             url: '../api/programStages.json',
             type: 'GET',
-            data: 'filter=id:eq:' + id +'&fields=id,name,version,dataEntryForm,captureCoordinates,reportDateDescription,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,formName,type,optionSet[id]]]'
+            data: 'filter=id:eq:' + id +'&fields=id,name,version,dataEntryForm,captureCoordinates,blockEntryForm,autoGenerateEvent,reportDateDescription,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,formName,type,optionSet[id]]]'
         }).done( function( response ){            
             _.each( _.values( response.programStages ), function( programStage ) {                
                 dhis2.tc.store.set( 'programStages', programStage );

=== 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-07-15 13:13:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-07-17 10:35:43 +0000
@@ -122,6 +122,7 @@
     white-space: normal;
     padding-top: 5px;
     text-align: center;
+    border: 2px dotted;
 }
 
 .stage-container:hover {
@@ -442,6 +443,10 @@
     margin-top: 5px;    
 }
 
+.small-padding {
+    padding-left: 5px;
+    padding-right: 5px;
+}
 .search-container-main {
     width: 100%;
     float: left;
@@ -487,12 +492,10 @@
     margin-left: -5px;
 }
 
-.over-flow-hidden {
+.overflow-ellipsis {
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
-    -o-text-overflow: ellipsis;
-    -webkit-text-overflow: ellipsis;
 }
 
 .modal-full-window .modal-dialog {
@@ -724,6 +727,10 @@
     color: inherit;
 }
 
+a:active {
+    color: red;
+}
+
 .note-container {
     width: 100%;
     display: block;

=== removed file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/widgets.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/widgets.html	2014-07-07 15:04:56 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/widgets.html	1970-01-01 00:00:00 +0000
@@ -1,28 +0,0 @@
-<div class="modal-header">
-    <h1>{{'select_widgets_to_show'| translate}}</h1>
-</div>
-
-<div class="modal-body">   
-    <table class="listTable dhis2-table-striped-border">
-        <tr ng-repeat="biggerWidget in biggerDashboardWidgets">
-            <td>
-                {{biggerWidget.title | translate}}
-            </td>
-            <td>
-                <input type="checkbox" ng-model="biggerWidget.show">
-            </td>
-        </tr>
-        <tr ng-repeat="smallerWidget in smallerDashboardWidgets">
-            <td>
-                {{smallerWidget.title | translate}}
-            </td>
-            <td>
-                <input type="checkbox" ng-model="smallerWidget.show">
-            </td>
-        </tr>
-    </table>    
-</div>
-
-<div class="modal-footer">     
-    <button type="button" class="btn btn-default" data-ng-click="close()">{{'close'| translate}}</button>
-</div>