← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16747: tracker capture - upcoming and overdue reports

 

------------------------------------------------------------
revno: 16747
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-18 15:36:12 +0200
message:
  tracker capture - upcoming and overdue reports
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.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-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js


--
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/report/AbstractEventRowService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java	2014-09-17 16:00:06 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java	2014-09-18 13:36:12 +0000
@@ -59,36 +59,39 @@
 
     @Autowired
     private EventService eventService;
-    
+
     @Autowired
     private IdentifiableObjectManager manager;
-    
+
     @Autowired
     private TrackedEntityInstanceService trackedEntityInstanceService;
 
     @Override
-    public EventRows getOverDueEventRows( Program program, List<OrganisationUnit> organisationUnits, EventStatus status )
+    public EventRows getEventRows( Program program, List<OrganisationUnit> organisationUnits,
+        ProgramStatus programStatus, EventStatus eventStatus, Date startDate, Date endDate )
     {
         List<EventRow> eventRowList = new ArrayList<EventRow>();
         EventRows eventRows = new EventRows();
 
-        Events events = eventService.getEvents( program, null, ProgramStatus.ACTIVE, null, organisationUnits, null, null, null, status );
+        Events events = eventService.getEvents( program, null, programStatus, null, organisationUnits, null, startDate,
+            endDate, eventStatus );
 
         for ( Event event : events.getEvents() )
         {
             if ( event.getTrackedEntityInstance() != null )
             {
-                TrackedEntityInstance tei =  trackedEntityInstanceService.getTrackedEntityInstance( event.getTrackedEntityInstance() );
-                EventRow eventRow = new EventRow();   
+                TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance( event
+                    .getTrackedEntityInstance() );
+                EventRow eventRow = new EventRow();
                 eventRow.setTrackedEntityInstance( event.getTrackedEntityInstance() );
-                eventRow.setAttributes( tei.getAttributes() );                
-                eventRow.setEvent( event.getEvent() );                
+                eventRow.setAttributes( tei.getAttributes() );
+                eventRow.setEvent( event.getEvent() );
                 eventRow.setProgram( program.getUid() );
                 eventRow.setProgramStage( event.getProgramStage() );
                 eventRow.setEventName( manager.get( ProgramStage.class, event.getProgramStage() ).getName() );
                 eventRow.setRegistrationOrgUnit( manager.get( OrganisationUnit.class, tei.getOrgUnit() ).getName() );
                 eventRow.setRegistrationDate( tei.getCreated() );
-                //eventRow.setOrgUnit( event.getOrgUnit() );
+                // eventRow.setOrgUnit( event.getOrgUnit() );
                 eventRow.setDueDate( event.getDueDate() );
                 eventRow.setFollowup( event.getFollowup() );
                 eventRowList.add( eventRow );
@@ -99,13 +102,4 @@
 
         return eventRows;
     }
-
-    @Override
-    public EventRows getUpcomingEventRows( Program program, List<OrganisationUnit> organisationUnits, Date startDate,
-        Date endDate, EventStatus eventStatus )
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java	2014-09-17 14:53:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java	2014-09-18 13:36:12 +0000
@@ -46,7 +46,7 @@
  *
  */
 
-@JacksonXmlRootElement( localName = "event", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement( localName = "eventRow", namespace = DxfNamespaces.DXF_2_0 )
 public class EventRow
     extends BaseLinkableObject
 {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java	2014-09-17 14:53:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java	2014-09-18 13:36:12 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.event.EventStatus;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStatus;
 
 /**
  * @author Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
@@ -41,12 +42,12 @@
  */
 public interface EventRowService
 {
-    
+
     // -------------------------------------------------------------------------
     // READ
     // -------------------------------------------------------------------------
 
-    EventRows getOverDueEventRows( Program program, List<OrganisationUnit> organisationUnits, EventStatus status );
+    EventRows getEventRows( Program program, List<OrganisationUnit> organisationUnits, ProgramStatus programStatus,
+        EventStatus eventStatus, Date startDate, Date endDate );
 
-    EventRows getUpcomingEventRows( Program program, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate, EventStatus status );
 }

=== 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-09-17 14:51:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-09-18 13:36:12 +0000
@@ -211,7 +211,10 @@
         @RequestParam( required = false ) String program,        
         @RequestParam( required = false ) String orgUnit,
         @RequestParam( required = false ) OrganisationUnitSelectionMode ouMode,
-        @RequestParam( required = false ) EventStatus status,
+        @RequestParam( required = false ) ProgramStatus programStatus,
+        @RequestParam( required = false ) EventStatus eventStatus,
+        @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
+        @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
         @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
     {
         WebOptions options = new WebOptions( parameters );
@@ -241,8 +244,8 @@
                 organisationUnits.add( rootOrganisationUnit );
             }
         }
-        
-        EventRows eventRows = eventRowService.getOverDueEventRows( pr, organisationUnits, status);
+
+        EventRows eventRows = eventRowService.getEventRows( pr, organisationUnits, programStatus, eventStatus, startDate, endDate);
         
         if ( options.hasPaging() )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2014-09-17 14:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2014-09-18 13:36:12 +0000
@@ -92,7 +92,7 @@
             $scope.reportFinished = false;
             $scope.reportStarted = true;            
             $scope.overdueEvents = [];
-            EventReportService.getOverdueEvents($scope.selectedOrgUnit.id, $scope.selectedOuMode, $scope.selectedProgram.id, 'OVERDUE', $scope.pager).then(function(data){                     
+            EventReportService.getEventReport($scope.selectedOrgUnit.id, $scope.selectedOuMode, $scope.selectedProgram.id, null, null, 'ACTIVE','OVERDUE', $scope.pager).then(function(data){                     
                 
                 if( data.pager ){
                     $scope.pager = data.pager;
@@ -129,8 +129,6 @@
 
                 $scope.reportFinished = true;
                 $scope.reportStarted = false;
-                    
-                console.log('The data is:  ',  $scope.overdueEvents);
             });
         }
     };    

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-09-11 12:35:41 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-09-18 13:36:12 +0000
@@ -6,6 +6,8 @@
                 orderByFilter,
                 DateUtils,                
                 TEIService,
+                Paginator,
+                EventReportService,
                 TEIGridService,
                 TranslationService,
                 AttributesFactory,
@@ -22,6 +24,9 @@
     $scope.displayMode = {};
     $scope.printMode = false;
     
+    //Paging
+    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5};
+    
     //watch for selection of org unit from tree
     $scope.$watch('selectedOrgUnit', function() {        
         if( angular.isObject($scope.selectedOrgUnit)){            
@@ -31,14 +36,31 @@
     });
     
     //load programs associated with the selected org unit.
-    $scope.loadPrograms = function(orgUnit) {
+    $scope.loadPrograms = function(orgUnit) {        
         $scope.selectedOrgUnit = orgUnit;        
         if (angular.isObject($scope.selectedOrgUnit)){
             ProgramFactory.getAll().then(function(programs){
                 $scope.programs = programs;                
                 if($scope.programs.length === 1){
                     $scope.selectedProgram = $scope.programs[0];
-                } 
+                }
+                else{
+                    if(angular.isObject($scope.selectedProgram)){
+                        var continueLoop = true;
+                        for(var i=0; i<programs.length && continueLoop; i++){
+                            if(programs[i].id === $scope.selectedProgram.id){
+                                $scope.selectedProgram = programs[i];
+                                continueLoop = false;
+                            }
+                        }
+                        if(continueLoop){
+                            $scope.selectedProgram = null;
+                        }
+                    }
+                    else{
+                        $scope.selectedProgram = null;
+                    }
+                }
             });
         }        
     };
@@ -47,13 +69,13 @@
     $scope.$watch('selectedProgram', function() {   
         $scope.reportFinished = false;
         $scope.reportStarted = false;
+        
+        if (angular.isObject($scope.selectedProgram)){
+            $scope.generateGridHeader();
+        }
     });
     
-    $scope.generateReport = function(program, report, ouMode){
-
-        $scope.selectedProgram = program;
-        $scope.report = report;
-        $scope.selectedOuMode = ouMode;
+    $scope.generateReport = function(){
         
         //check for form validity
         $scope.outerForm.submitted = true;        
@@ -63,65 +85,73 @@
         
         $scope.reportFinished = false;
         $scope.reportStarted = true;        
-        $scope.programStages = [];
-        $scope.filterTypes = {};
-        $scope.filterText = {};
-        
-        angular.forEach($scope.selectedProgram.programStages, function(stage){
-            $scope.programStages[stage.id] = stage;
-        });
-            
-        AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){            
-            $scope.gridColumns = TEIGridService.generateGridColumns(atts, $scope.selectedOuMode);
-
-            $scope.gridColumns.push({name: $translate('event_name'), id: 'eventName', type: 'string', displayInListNoProgram: false, showFilter: false, show: true});
-            $scope.filterTypes['eventName'] = 'string';
-            $scope.gridColumns.push({name: $translate('due_date'), id: 'dueDate', type: 'date', displayInListNoProgram: false, showFilter: false, show: true});
-            $scope.filterTypes['dueDate'] = 'date';
-            $scope.filterText['dueDate']= {};                
-        });  
-        
-        //fetch TEIs for the selected program and orgunit/mode
-        TEIService.search($scope.selectedOrgUnit.id, 
-                            $scope.selectedOuMode,
-                            null,
-                            'program=' + $scope.selectedProgram.id,
-                            null,
-                            $scope.pager,
-                            false).then(function(data){                     
-            
-            //process tei grid
-            var teis = TEIGridService.format(data,true);     
-            $scope.upcomingEvents = [];          
-            DHIS2EventFactory.getByOrgUnitAndProgram($scope.selectedOrgUnit.id, $scope.selectedOuMode, $scope.selectedProgram.id, null, null).then(function(eventList){
-                angular.forEach(eventList, function(ev){
-                    if(ev.dueDate){
-                        ev.dueDate = DateUtils.format(ev.dueDate);
-                        
-                        if( ev.trackedEntityInstance && 
-                            !ev.eventDate && 
-                            ev.dueDate >= report.startDate && 
-                            ev.dueDate <= report.endDate){
-                        
-                            var upcomingEvent = {};
-                            angular.copy(teis.rows[ev.trackedEntityInstance],upcomingEvent);
-                            angular.extend(upcomingEvent,{eventName: $scope.programStages[ev.programStage].name, dueDate: ev.dueDate, followup: ev.followup});
-
-                            $scope.upcomingEvents.push(upcomingEvent);
-                        }                        
-                    }
+        
+        $scope.upcomingEvents = [];
+        EventReportService.getEventReport($scope.selectedOrgUnit.id, $scope.selectedOuMode, $scope.selectedProgram.id, $scope.report.startDate, $scope.report.endDate, 'ACTIVE','SCHEDULE', $scope.pager).then(function(data){                     
+                
+            if( data.pager ){
+                $scope.pager = data.pager;
+                $scope.pager.toolBarDisplay = 5;
+
+                Paginator.setPage($scope.pager.page);
+                Paginator.setPageCount($scope.pager.pageCount);
+                Paginator.setPageSize($scope.pager.pageSize);
+                Paginator.setItemCount($scope.pager.total);                    
+            }
+
+            angular.forEach(data.eventRows, function(row){
+                var upcomingEvent = {};
+                angular.forEach(row.attributes, function(att){
+                    upcomingEvent[att.attribute] = att.value;
                 });
 
-                //sort upcoming events by their due dates - this is default
-                $scope.upcomingEvents = orderByFilter($scope.upcomingEvents, '-dueDate');
-                $scope.upcomingEvents.reverse();
+                upcomingEvent.dueDate = DateUtils.format(row.dueDate);
+                upcomingEvent.event = row.event;
+                upcomingEvent.eventName = row.eventName;
+                upcomingEvent.followup = row.followup;
+                upcomingEvent.program = row.program;
+                upcomingEvent.programStage = row.programStage;
+                upcomingEvent.trackedEntityInstance = row.trackedEntityInstance;
+                upcomingEvent.orgUnitName = row.registrationOrgUnit;
+                upcomingEvent.created = DateUtils.format(row.registrationDate);;
+                $scope.upcomingEvents.push(upcomingEvent);
 
-                $scope.reportFinished = true;
-                $scope.reportStarted = false;
             });
+
+            //sort overdue events by their due dates - this is default
+            $scope.upcomingEvents = orderByFilter($scope.upcomingEvents, '-dueDate');
+            $scope.upcomingEvents.reverse();
+
+            $scope.reportFinished = true;
+            $scope.reportStarted = false;
         });
     };
     
+    $scope.generateGridHeader = function(){
+        
+        if (angular.isObject($scope.selectedProgram)){
+            
+            $scope.programStages = [];
+            $scope.filterTypes = {};
+            $scope.filterText = {};
+
+            angular.forEach($scope.selectedProgram.programStages, function(stage){
+                $scope.programStages[stage.id] = stage;
+            });
+
+            AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){            
+                $scope.gridColumns = TEIGridService.generateGridColumns(atts, $scope.selectedOuMode);
+
+                $scope.gridColumns.push({name: $translate('event_name'), id: 'eventName', type: 'string', displayInListNoProgram: false, showFilter: false, show: true});
+                $scope.filterTypes['eventName'] = 'string';
+                $scope.gridColumns.push({name: $translate('due_date'), id: 'dueDate', type: 'date', displayInListNoProgram: false, showFilter: false, show: true});
+                $scope.filterTypes['dueDate'] = 'date';
+                $scope.filterText['dueDate']= {};                
+            });
+            
+        }      
+    };
+    
     $scope.showHideColumns = function(){
         
         $scope.hiddenGridColumns = 0;
@@ -191,7 +221,7 @@
     };
     
     $scope.showDashboard = function(tei){
-        $location.path('/dashboard').search({tei: tei.id,                                            
+        $location.path('/dashboard').search({tei: tei,                                            
                                             program: $scope.selectedProgram ? $scope.selectedProgram.id: null});
     };
     
@@ -202,4 +232,18 @@
     $scope.generateReportHeader = function(){
         return TEIGridService.getHeader($scope.gridColumns);
     };
+    
+    $scope.jumpToPage = function(){
+        $scope.generateReport();
+    };
+    
+    $scope.resetPageSize = function(){
+        $scope.pager.page = 1;        
+        $scope.generateReport();
+    };
+    
+    $scope.getPage = function(page){    
+        $scope.pager.page = page;
+        $scope.generateReport();
+    };
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events.html	2014-09-11 12:35:41 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events.html	2014-09-18 13:36:12 +0000
@@ -104,7 +104,7 @@
                 </table>                
             </div>
             <div class="col-md-6 trim">
-                <button type="button" class="btn btn-primary" ng-click="generateReport(selectedProgram, report, selectedOuMode)" ng-disabled="!selectedProgram">{{'go'| translate}}</button>
+                <button type="button" class="btn btn-primary" ng-click="generateReport()" ng-disabled="!selectedProgram">{{'go'| translate}}</button>
                 <button type="button"
                         class="btn btn-success small-horizonal-spacing"
                         ng-if="upcomingEvents.length > 0"
@@ -207,7 +207,7 @@
                         </thead>
                         <tbody id="list">
                             <tr ng-repeat="upcomingEvent in upcomingEvents| orderBy:sortHeader:reverse | gridFilter:filterText:filterTypes"
-                                ng-click="showDashboard(upcomingEvent)"
+                                ng-click="showDashboard(upcomingEvent.trackedEntityInstance)"
                                 title="{{'go_to_dashboard'| translate}}">
                                 <td ng-show="gridColumn.show"                                            
                                     ng-repeat="gridColumn in gridColumns" ng-if='displayMode.onlyMarkedFollowup ? upcomingEvent.followup:true'>                                                
@@ -215,7 +215,8 @@
                                 </td>                                
                             </tr>
                         </tbody>        
-                    </table>                    
+                    </table>
+                    <serverside-paginator></serverside-paginator>
                 </div>
                 <!-- report ends -->
             </div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-09-17 14:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-09-18 13:36:12 +0000
@@ -594,20 +594,15 @@
 /* factory for handling event reports */
 .factory('EventReportService', function($http, $q) {   
     
-    return {     
-        
-        getOverdueEvents: function(orgUnit, ouMode, program, status, pager){ 
-            var pgSize = pager ? pager.pageSize : 50;
-        	var pg = pager ? pager.page : 1;
-            var promise = $http.get( '../api/events/overdue.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + '&status=' + status + '&pageSize=' + pgSize + '&page=' + pg ).then(function(response){
-                return response.data;
-            });            
-            return promise;
-        },
-        getUpcomingEvents: function(orgUnit, ouMode, program, startDate, endDate, status, pager){
-            var pgSize = pager ? pager.pageSize : 50;
-        	var pg = pager ? pager.page : 1;
-            var promise = $http.get( '../api/events/overdue.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + '&startDate=' + startDate + '&endDate=' + endDate + '&status=' + status + '&pageSize=' + pgSize + '&page=' + pg ).then(function(response){
+    return {        
+        getEventReport: function(orgUnit, ouMode, program, startDate, endDate, programStatus, eventStatus, pager){ 
+            var pgSize = pager ? pager.pageSize : 50;
+        	var pg = pager ? pager.page : 1;
+            var url = '../api/events/overdue.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + '&programStatus=' + programStatus + '&eventStatus='+ eventStatus + '&pageSize=' + pgSize + '&page=' + pg;
+            if(startDate && endDate){
+                url = url + '&startDate=' + startDate + '&endDate=' + endDate ;
+            }
+            var promise = $http.get( url ).then(function(response){
                 return response.data;
             });            
             return promise;