dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31453
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16025: tracker capture - reports, WIP
------------------------------------------------------------
revno: 16025
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2014-07-08 18:14:36 +0200
message:
tracker capture - reports, WIP
modified:
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report-controller.js
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report.html
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
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/styles/style.css
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report-controller.js 2014-07-08 08:30:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report-controller.js 2014-07-08 16:14:36 +0000
@@ -4,33 +4,78 @@
storage,
DateUtils,
EventUtils,
+ TEIService,
+ TEIGridService,
TranslationService,
+ AttributesFactory,
DHIS2EventFactory) {
TranslationService.translate();
$scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];
$scope.selectedOuMode = $scope.ouModes[0];
-
-
-
-
-
- $scope.getEvents = function(){
-
- $scope.dhis2Events = '';
- $scope.dataExists = false;
- DHIS2EventFactory.getEventsByProgram($scope.selectedEntity.trackedEntityInstance, $scope.selectedOrgUnit.id, $scope.selectedProgram.id).then(function(data){
- $scope.dhis2Events = data;
- if(!angular.isUndefined($scope.dhis2Events) ){
- for(var i=0; i<$scope.dhis2Events.length && !$scope.dataExists; i++){
- if(!angular.isUndefined($scope.dhis2Events[i].dataValues)){
- $scope.dataExists = true;
- }
- }
+ $scope.report = {};
+
+ $scope.generateReport = function(){
+
+ $scope.dataReady = false;
+
+ //check for form validity
+ $scope.outerForm.submitted = true;
+ if( $scope.outerForm.$invalid || !$scope.selectedProgram){
+ return false;
+ }
+
+ $scope.programStages = [];
+ 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.name);
+ });
+
+ //fetch TEIs for the selected program and orgunit/mode
+ TEIService.search($scope.selectedOrgUnit.id,
+ $scope.selectedOuMode.name,
+ null,
+ 'program=' + $scope.selectedProgram.id,
+ null,
+ $scope.pager,
+ false).then(function(data){
+ if(data.rows){
+ $scope.teiCount = data.rows.length;
+ $scope.dataReady = true;
}
- });
+
+
+ //process tei grid
+ $scope.teiList = TEIGridService.format(data);
+
+ DHIS2EventFactory.getByOrgUnitAndProgram($scope.selectedOrgUnit.id, $scope.selectedOuMode.name, $scope.selectedProgram.id).then(function(eventList){
+ $scope.dhis2Events = [];
+ angular.forEach(eventList, function(ev){
+ if(ev.trackedEntityInstance){
+ ev.name = $scope.programStages[ev.programStage].name;
+ ev.statusColor = EventUtils.getEventStatusColor(ev);
+ ev.eventDate = DateUtils.format(ev.eventDate);
+
+ if($scope.dhis2Events[ev.trackedEntityInstance]){
+ $scope.dhis2Events[ev.trackedEntityInstance].push(ev);
+ }
+ else{
+ $scope.dhis2Events[ev.trackedEntityInstance] = [ev];
+ }
+ ev = EventUtils.setEventOrgUnitName(ev);
+ }
+ });
+ });
+ });
};
+
+ $scope.showEventDetails = function(dhis2Event){
+ console.log('I will show details of...: ', dhis2Event);
+ };
})
//conroller for tei report
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report.html 2014-07-08 08:30:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/report/report.html 2014-07-08 16:14:36 +0000
@@ -17,19 +17,21 @@
</div>
<div class="row">
<div class="col-md-6">
- <table class="table-borderless">
+ <table class="table-borderless table-with-fixed-layout">
<tr>
<td>
- <input type="text" name="startDate" placeholder="{{'start_date'| translate}}" class="form-control" ng-date ng-model="startDate" ng-required="true"/>
+ <input type="text" name="reportStartDate" placeholder="{{'start_date'| translate}}" class="form-control" ng-date ng-model="report.startDate" ng-required="true"/>
+ <span ng-show="outerForm.submitted && outerForm.reportStartDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
</td>
<td>
- <input type="text" name="endDate" placeholder="{{'end_date'| translate}}" class="form-control" ng-date ng-model="endDate" ng-required="true"/>
+ <input type="text" name="reportEndDate" placeholder="{{'end_date'| translate}}" class="form-control" ng-date ng-model="report.endDate" ng-required="true"/>
+ <span ng-show="outerForm.submitted && outerForm.reportEndDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
</td>
</tr>
</table>
</div>
<div class="col-md-6 trim">
- <button type="button" class="btn btn-primary" ng-click="generateReport()">{{'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-default small-horizonal-spacing" ng-click="showReport()">{{'cancel'| translate}}</button>
</div>
</div>
@@ -39,4 +41,54 @@
<div class="alert alert-warning">{{'please_select_program_report'| translate}}</div>
</div>
</div>
+ <div ng-if="dataReady">
+ <div ng-switch="teiCount">
+ <div ng-switch-when="undefined">
+ <div class="alert alert-warning vertical-spacing">
+ {{'no'| translate}} {{selectedProgram.trackedEntity.name|| 'records' | translate}} {{'found'| translate}}
+ </div>
+ </div>
+ <div ng-switch-when="0">
+ <div class="alert alert-warning vertical-spacing">
+ {{'no'| translate}} {{selectedProgram.trackedEntity.name|| 'records' | translate}} {{'found'| translate}}
+ </div>
+ </div>
+ <div ng-switch-default>
+
+ <!-- report begins -->
+ <div class="vertical-spacing">
+ <table class="table table-compact table-striped">
+ <thead>
+ <tr>
+ <th>{{selectedProgram.trackedEntity.name}}</th>
+ <th>{{'registered_data' | translate}}</th>
+ </tr>
+ </thead>
+ <tr ng-repeat="tei in teiList.rows">
+ <td>
+ <span ng-repeat="gridColumn in gridColumns">
+ <span class="bold">{{gridColumn.name}}:</span> {{tei[gridColumn.id]}}<br>
+ </span>
+ </td>
+ <td>
+ <div class='bold vertical-center' ng-if='!dhis2Events[tei.id]'>{{'no_visit_made' | translate}}</div>
+ <div class="inline-block vertical-center" ng-repeat="ev in dhis2Events[tei.id] | orderBy: 'eventDate'">
+ <div class="block align-center">{{ev.orgUnitName}}</div>
+ <div class="stage-container"
+ title="{{ev.dataValues ? 'details' : 'no_data_registerd' | translate}}"
+ ng-class="{'{{ev.statusColor}}': true}"
+ ng-click="showEventDetails(ev)">
+ {{ev.name}}<br/>
+ {{ev.eventDate}}
+ </div>
+ <i class="fa fa-arrow-right" ng-show="$index < dhis2Events[tei.id].length - 1"></i>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <!-- report ends -->
+ </div>
+ </div>
+ </div>
</div>
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json 2014-07-08 08:30:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json 2014-07-08 16:14:36 +0000
@@ -91,6 +91,9 @@
"search_from_existing": "Search from existing",
"dataentry": "Data Entry",
"report": "Report",
+ "registered_data": "Registered data",
+ "no_data_registerd": "No data registered",
+ "no_visit_made": "No visit made",
"current_selections": "Current selections",
"org_unit": "Organisation unit",
"SELECTED": "Selected",
@@ -98,7 +101,7 @@
"DESCENDANTS": "All children",
"ACCESSIBLE": "All accessible",
"data_element": "Data element",
- "value": "Value",
+ "value": "Value",
"provided_elsewhere": "Provided elsewhere",
"expand": "Expand",
"collapse": "Collapse",
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-07-08 08:30:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-07-08 16:14:36 +0000
@@ -208,7 +208,8 @@
$scope.queryUrl,
$scope.programUrl,
$scope.attributeUrl.url,
- $scope.pager).then(function(data){
+ $scope.pager,
+ true).then(function(data){
//$scope.trackedEntityList = data;
if(data.rows){
$scope.teiCount = data.rows.length;
=== 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-07 15:04:56 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-07-08 16:14:36 +0000
@@ -313,10 +313,7 @@
});
return promise;
},
- search: function(ouId, ouMode, queryUrl, programUrl, attributeUrl, pager) {
-
- var pgSize = pager ? pager.pageSize : 50;
- var pg = pager ? pager.page : 1;
+ search: function(ouId, ouMode, queryUrl, programUrl, attributeUrl, pager, paging) {
var url = '../api/trackedEntityInstances.json?ou=' + ouId + '&ouMode='+ ouMode;
@@ -330,7 +327,16 @@
url = url + '&' + attributeUrl;
}
- promise = $http.get( url + '&pageSize=' + pgSize + '&page=' + pg ).then(function(response){
+ if(paging){
+ var pgSize = pager ? pager.pageSize : 50;
+ var pg = pager ? pager.page : 1;
+ url = url + '&pageSize=' + pgSize + '&page=' + pg;
+ }
+ else{
+ url = url + '&paging=false';
+ }
+
+ promise = $http.get( url ).then(function(response){
return response.data;
});
return promise;
@@ -459,6 +465,12 @@
});
return promise;
},
+ getByOrgUnitAndProgram: function(orgUnit, ouMode, program){
+ var promise = $http.get( '../api/events.json?' + '&orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + '&paging=false').then(function(response){
+ return response.data.events;
+ });
+ return promise;
+ },
get: function(eventUid){
var promise = $http.get('../api/events/' + eventUid + '.json').then(function(response){
return response.data;
@@ -835,7 +847,7 @@
})
-.service('TEIGridService', function(OrgUnitService, DateUtils, $filter){
+.service('TEIGridService', function(OrgUnitService, DateUtils){
return {
format: function(grid){
@@ -884,7 +896,76 @@
});
});
return {headers: attributes, rows: entityList, pager: grid.metaData.pager};
- }
+ },
+ formatForReport: function(grid){
+ if(!grid || !grid.rows){
+ return;
+ }
+
+ //grid.headers[0-4] = Instance, Created, Last updated, Org unit, Tracked entity
+ //grid.headers[5..] = Attribute, Attribute,....
+ var attributes = [];
+ var entityList = [];
+ for(var i=5; i<grid.headers.length; i++){
+ attributes.push({id: grid.headers[i].name, name: grid.headers[i].column, type: grid.headers[i].type});
+ }
+
+ OrgUnitService.open().then(function(){
+
+ angular.forEach(grid.rows, function(row){
+ var entity = {};
+ var isEmpty = true;
+
+ entity.id = row[0];
+ var rDate = row[1];
+ rDate = DateUtils.format(rDate);
+ entity.created = rDate;
+ entity.orgUnit = row[3];
+ entity.type = row[4];
+
+ OrgUnitService.get(row[3]).then(function(ou){
+ if(ou){
+ entity.orgUnitName = ou.n;
+ }
+ });
+
+ for(var i=5; i<row.length; i++){
+ if(row[i] && row[i] !== ''){
+ isEmpty = false;
+ entity[grid.headers[i].name] = row[i];
+ }
+ }
+
+ if(!isEmpty){
+ entityList[entity.id] = entity;
+ }
+ });
+ var returnVal = {headers: attributes, rows: entityList};
+ console.log('the return is: ', returnVal);
+ return returnVal;
+ });
+ },
+ generateGridColumns: function(attributes, ouMode){
+
+ var columns = attributes ? angular.copy(attributes) : [];
+
+ //also add extra columns which are not part of attributes (orgunit for example)
+ columns.push({id: 'orgUnitName', name: 'Organisation unit', type: 'string', displayInListNoProgram: false});
+ columns.push({id: 'created', name: 'Registration date', type: 'string', displayInListNoProgram: false});
+
+ //generate grid column for the selected program/attributes
+ angular.forEach(columns, function(column){
+ if(column.id === 'orgUnitName' && ouMode !== 'SELECTED'){
+ column.show = true;
+ }
+
+ if(column.displayInListNoProgram){
+ column.show = true;
+ }
+ });
+
+ return columns;
+ }
};
})
@@ -948,6 +1029,17 @@
dueDate = $filter('date')(dueDate, 'yyyy-MM-dd');
return dueDate;
},
+ getEventOrgUnitName: function(orgUnitId){
+ if(orgUnitId){
+ OrgUnitService.open().then(function(){
+ OrgUnitService.get(orgUnitId).then(function(ou){
+ if(ou){
+ return ou.n;
+ }
+ });
+ });
+ }
+ },
setEventOrgUnitName: function(dhis2Event){
if(dhis2Event.orgUnit){
OrgUnitService.open().then(function(){
=== 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-08 13:28:19 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css 2014-07-08 16:14:36 +0000
@@ -99,6 +99,10 @@
display: inline-block;
}
+.vertical-center {
+ vertical-align: middle;
+}
+
.stage-container {
display: inline-block;
width: 135px;
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html 2014-07-04 10:10:13 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html 2014-07-08 16:14:36 +0000
@@ -1,12 +1,12 @@
<div ng-switch="teiCount">
<div ng-switch-when="undefined">
<div class="alert alert-warning vertical-spacing">
- {{'no'| translate}} {{selectedProgram.trackedEntity.name|| 'records' | translate}} {{'found'| translate}}
+ {{'no'| translate}} {{selectedProgram.trackedEntity.name || 'records' | translate}} {{'found'| translate}}
</div>
</div>
<div ng-switch-when="0">
<div class="alert alert-warning vertical-spacing">
- {{'no'| translate}} {{selectedProgram.trackedEntity.name|| 'records' | translate}} {{'found'| translate}}
+ {{'no'| translate}} {{selectedProgram.trackedEntity.name || 'records' | translate}} {{'found'| translate}}
</div>
</div>
<div ng-switch-default>