dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30189
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15309: tei registration and enrollment - wip
------------------------------------------------------------
revno: 15309
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2014-05-20 10:20:18 +0200
message:
tei registration and enrollment - wip
modified:
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/views/registration.html
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/trackedEntityList.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/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-05-19 14:00:19 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-05-20 08:20:18 +0000
@@ -162,7 +162,7 @@
$scope.generateGridColumns = function(attributes){
var columns = angular.copy(attributes);
- //also add extra columns - orgunit for example
+ //also add extra columns which are not part of attributes (orgunit for example)
columns.push({id: 'orgUnitName', name: 'Organisation unit', type: 'string'});
//generate grid column for the selected program/attributes
@@ -328,14 +328,12 @@
$scope.trackedEntityList = [];
$scope.attributes = AttributesFactory.getByProgram($scope.selectedProgram);
}
- });
-
- $scope.showDashboard = function(){
- $scope.registerEntity();
- };
-
- $scope.registerEntity = function(){
+ });
+
+
+ $scope.registerEntity = function(showDashboard){
+ //get selected entity
var selectedTrackedEntity = '';
if($scope.selectedProgram){
selectedTrackedEntity = $scope.selectedProgram.trackedEntity.id;
@@ -344,6 +342,7 @@
selectedTrackedEntity = $scope.trackedEntities.selected.id;
}
+ //get tei attributes and their values
var registrationAttributes = [];
angular.forEach($scope.attributes, function(attribute){
if(!angular.isUndefined(attribute.value)){
@@ -352,38 +351,59 @@
}
});
- $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: registrationAttributes };
-
- //Register TEI
+ //prepare tei model and do registration
+ $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: registrationAttributes };
+ var teiId = '';
+
TEIService.register($scope.tei).then(function(tei){
- if(tei.status === 'SUCCESS'){
- //check for enrollment
- if($scope.selectedProgram){
+
+ if(tei.status === 'SUCCESS'){
+
+ teiId = tei.reference;
+
+ //registration is successful and check for enrollment
+ if($scope.selectedProgram){
//enroll TEI
- var enrollment = {trackedEntityInstance: tei.reference,
- program: $scope.selectedProgram.id,
- status: 'ACTIVE',
- dateOfEnrollment: $scope.enrollment.enrollmentDate,
- dateOfIncident: $scope.enrollment.incidentDate
- };
+ var enrollment = {trackedEntityInstance: teiId,
+ program: $scope.selectedProgram.id,
+ status: 'ACTIVE',
+ dateOfEnrollment: $scope.enrollment.enrollmentDate,
+ dateOfIncident: $scope.enrollment.incidentDate
+ };
EnrollmentService.enroll(enrollment).then(function(data){
- if(data.status === 'SUCCESS'){
- $location.path('/dashboard').search({selectedEntityId: tei.reference,
- selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id: null});
+ if(data.status != 'SUCCESS'){
+ //enrollment has failed
+ var dialogOptions = {
+ headerText: 'enrollment_error',
+ bodyText: data.description
+ };
+ DialogService.showDialog({}, dialogOptions);
+ return;
}
});
}
- else{
- $location.path('/dashboard').search({selectedEntityId: tei.reference,
- selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id: null});
- }
}
else{
+ //registration has failed
var dialogOptions = {
headerText: 'registration_error',
bodyText: tei.description
};
DialogService.showDialog({}, dialogOptions);
+ return;
+ }
+
+ if(showDashboard){
+ $location.path('/dashboard').search({selectedEntityId: teiId,
+ selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id : null});
+ }
+ else{
+
+ angular.forEach($scope.attributes, function(attribute){
+ attribute.value = '';
+ });
+ $scope.enrollment.enrollmentDate = '';
+ $scope.enrollment.incidentDate = '';
}
});
};
@@ -618,27 +638,24 @@
var programStages = [];
angular.forEach(program.programStages, function(ps){
-
- programStages.push(storage.get(ps.id));
+ ps = storage.get(ps.id);
+ programStages.push(ps);
var dhis2Event = {programStage: ps.id,
orgUnit: $scope.selectedOrgUnitId,
eventDate: moment(),
name: ps.name,
status: 'ACTIVE'};
- var date = moment();
-
- if( moment().add('days', ps.minDaysFromStart).isBefore(date)){
+ var today = moment();
+
+ dhis2Event.statusColor = 'stage-on-time';
+
+ if( moment().add('d', ps.minDaysFromStart).isBefore(today)){
dhis2Event.statusColor = 'stage-overdue';
- }
- else{
- dhis2Event.statusColor = 'stage-on-time';
- }
-
+ }
+
$scope.dhis2Events.push(dhis2Event);
});
-
- console.log('the stages are: ', $scope.dhis2Events);
}
}
=== 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-05-19 14:00:19 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-05-20 08:20:18 +0000
@@ -211,6 +211,15 @@
return EntityService.formatter(response.data);
});
return promise;
+ },
+ update: function(tei){
+
+ var url = '../api/trackedEntityInstances';
+
+ var promise = $http.put( url + '/' + tei.trackedEntityInstance , tei).then(function(response){
+ return response.data;
+ });
+ return promise;
},
register: function(tei){
@@ -220,15 +229,6 @@
return response.data;
});
return promise;
- },
- update: function(tei){
-
- var url = '../api/trackedEntityInstances';
-
- var promise = $http.put( url + '/' + tei.trackedEntityInstance , tei).then(function(response){
- return response.data;
- });
- return promise;
}
};
})
@@ -282,7 +282,6 @@
};
})
-
/* factory for handling events */
.factory('DHIS2EventFactory', function($http) {
@@ -293,76 +292,6 @@
return response.data.events;
});
return promise;
- },
-
- getByStage: function(orgUnit, programStage){
- var promise = $http.get( '../api/events.json?' + 'orgUnit=' + orgUnit + '&programStage=' + programStage + '&paging=false')
- .then(function(response){
-
- return response.data.events;
-
- }, function(){
-
- return dhis2.ec.storageManager.getEvents(orgUnit, programStage);
-
- });
-
- return promise;
- },
-
- get: function(eventUid){
-
- var promise = $http.get( '../api/events/' + eventUid + '.json').then(function(response){
- return response.data;
-
- }, function(){
- return dhis2.ec.storageManager.getEvent(eventUid);
- });
- return promise;
- },
-
- create: function(dhis2Event){
-
- var e = angular.copy(dhis2Event);
- dhis2.ec.storageManager.saveEvent(e);
-
- var promise = $http.post( '../api/events.json', dhis2Event).then(function(response){
- dhis2.ec.storageManager.clearEvent(e);
- return response.data;
- }, function(){
- return {importSummaries: [{status: 'SUCCESS', reference: e.event}]};
- });
- return promise;
- },
-
- delete: function(dhis2Event){
- dhis2.ec.storageManager.clearEvent(dhis2Event);
- var promise = $http.delete( '../api/events/' + dhis2Event.event).then(function(response){
- return response.data;
- }, function(){
- });
- return promise;
- },
-
- update: function(dhis2Event){
- dhis2.ec.storageManager.saveEvent(dhis2Event);
- var promise = $http.put( '../api/events/' + dhis2Event.event, dhis2Event).then(function(response){
- dhis2.ec.storageManager.clearEvent(dhis2Event);
- return response.data;
- });
- return promise;
- },
-
- updateForSingleValue: function(singleValue, fullValue){
-
- dhis2.ec.storageManager.saveEvent(fullValue);
-
- var promise = $http.put( '../api/events/' + singleValue.event + '/' + singleValue.dataValues[0].dataElement, singleValue ).then(function(response){
- dhis2.ec.storageManager.clearEvent(fullValue);
- return response.data;
- }, function(){
- });
- return promise;
}
};
})
@@ -681,59 +610,6 @@
});
});
return {headers: attributes, rows: entityList};
- }
+ }
};
-});
-
-
-/*
-* Helper functions
-*/
-//This is is to have consistent display of entities and attributes
-//as every entity might not have value for every attribute.
-function entityFormatter(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 = [];
- for(var i=5; i<grid.headers.length; i++){
- attributes.push({id: grid.headers[i].name, name: grid.headers[i].column});
- }
-
- var entityList = [];
-
- OrgUnitService.open().then(function(){
-
- angular.forEach(grid.rows, function(row){
- var entity = {};
- var isEmpty = true;
-
- entity.id = row[0];
- entity.orgUnit = row[3];
- entity[row[3]] = row[3]; //this is orgunit.
- entity.type = row[4];
-
- OrgUnitService.get(row[3]).then(function(ou){
- if(ou){
- entity[row[3]] = 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.push(entity);
- }
- });
- return {headers: attributes, rows: entityList};
- });
-}
\ No newline at end of file
+});
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html 2014-05-19 11:33:07 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html 2014-05-20 08:20:18 +0000
@@ -82,11 +82,10 @@
</div>
<div class="btn-group vertical-spacing">
- <button type="button" class="btn btn-default" ng-click="showDashboard()">{{'save_and_continue'| translate}}</button>
- <button type="button" class="btn btn-default" ng-click="registerEntity()">{{'save_and_add_new'| translate}}</button>
+ <button type="button" class="btn btn-default" ng-click="registerEntity(true)">{{'save_and_continue'| translate}}</button>
+ <button type="button" class="btn btn-default" ng-click="registerEntity(false)">{{'save_and_add_new'| translate}}</button>
<button type="button" class="btn btn-default" ng-click="showRegistration()">{{'cancel'| translate}}</button>
</div>
-
</form>
</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/views/trackedEntityList.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/trackedEntityList.html 2014-05-16 13:58:07 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/trackedEntityList.html 2014-05-20 08:20:18 +0000
@@ -26,8 +26,7 @@
<table class="listTable dhis2-table-striped-border dhis2-table-hover">
<thead>
<tr>
- <th ng-show="gridColumn.show"
- class="max-column-width"
+ <th ng-show="gridColumn.show"
ng-repeat="gridColumn in gridColumns">
<!-- sort icon begins -->
@@ -72,7 +71,7 @@
<tbody id="list">
<tr ng-repeat="trackedEntity in trackedEntityList.rows| paginate:rowsPerPage | orderBy:sortHeader:reverse | gridFilter:filterText:currentFilter"
ng-click="showDashboard(trackedEntity)">
- <td class="max-column-width" ng-show="gridColumn.show"
+ <td ng-show="gridColumn.show"
ng-repeat="gridColumn in gridColumns">
{{trackedEntity[gridColumn.id]}}
</td>