dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30455
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15452: tei enrollment and profile edit from dashboard
------------------------------------------------------------
revno: 15452
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-05-28 15:36:26 +0200
message:
tei enrollment and profile edit from dashboard
modified:
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/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/profile/profile-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/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-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-05-27 14:50:29 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2014-05-28 13:36:26 +0000
@@ -38,8 +38,6 @@
$scope.dhis2Events = [];
- console.log('need to create new ones: ', $scope.selectedEnrollment);
-
if($scope.selectedEnrollment.status === 'ACTIVE'){
//create events for the selected enrollment
var program = storage.get($scope.selectedProgramId);
@@ -67,6 +65,7 @@
angular.forEach($scope.dhis2Events, function(dhis2Event){
var ps = storage.get(dhis2Event.programStage);
+
//check if a stage is repeatable
if(ps.repeatable){
$scope.allowEventCreation = true;
=== 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-05-27 14:50:29 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2014-05-28 13:36:26 +0000
@@ -4,22 +4,25 @@
$filter,
storage,
ProgramFactory,
+ AttributesFactory,
CurrentSelection,
+ TEIService,
EnrollmentService,
- TranslationService) {
+ TranslationService,
+ DialogService) {
- TranslationService.translate();
-
//programs for enrollment
$scope.enrollments = [];
$scope.programs = [];
$scope.showEnrollmentDiv = false;
+ $scope.showSchedulingDiv = false;
+ TranslationService.translate();
$scope.selectedOrgUnit = storage.get('SELECTED_OU');
//listen for the selected items
- $scope.$on('selectedEntity', function(event, args) {
-
+ $scope.$on('selectedEntity', function(event, args) {
+ $scope.newEnrollment = {};
var selections = CurrentSelection.get();
$scope.selectedEntity = selections.tei;
@@ -32,6 +35,10 @@
}
});
+ EnrollmentService.get($scope.selectedEntity.trackedEntityInstance).then(function(data){
+ $scope.enrollments = data.enrollmentList;
+ });
+
if(selections.pr){
angular.forEach($scope.programs, function(program){
if(selections.pr.id === program.id){
@@ -46,49 +53,130 @@
if($scope.selectedProgram){
- $scope.selectedEnrollment = '';
-
- EnrollmentService.get($scope.selectedEntity.trackedEntityInstance).then(function(data){
- $scope.enrollments = data.enrollmentList;
+ //check for possible enrollment
+ $scope.selectedEnrollment = '';
+ angular.forEach($scope.enrollments, function(enrollment){
+ if(enrollment.program === $scope.selectedProgram.id ){
+ $scope.selectedEnrollment = enrollment;
+ }
+ });
+
+ if($scope.selectedEnrollment){//enrollment exists
+ $scope.selectedEnrollment.dateOfIncident = $filter('date')($scope.selectedEnrollment.dateOfIncident, 'yyyy-MM-dd');
+ }
+ else{//prepare for possible enrollment
+ $scope.attributesForEnrollment = AttributesFactory.getMissingAttributesForEnrollment($scope.selectedEntity, $scope.selectedProgram);
+ }
+
+ $scope.programStages = [];
+ var incidentDate = $scope.selectedEnrollment ? $scope.selectedEnrollment.dateOfIncident : new Date();
+
+ angular.forEach($scope.selectedProgram.programStages, function(stage){
+ var ps = storage.get(stage.id);
+ ps.dueDate = moment(moment(incidentDate).add('d', ps.minDaysFromStart), 'YYYY-MM-DD')._d;
+ ps.dueDate = Date.parse(ps.dueDate);
+ ps.dueDate= $filter('date')(ps.dueDate, 'yyyy-MM-dd');
+ $scope.programStages.push(ps);
+ });
+
+ $rootScope.$broadcast('dashboard', {selectedEntity: $scope.selectedEntity,
+ selectedOrgUnit: $scope.selectedOrgUnit,
+ selectedProgramId: $scope.selectedProgram.id,
+ selectedEnrollment: $scope.selectedEnrollment});
+ }
+ else{
+ $scope.selectedProgram = '';
+ $scope.selectedEnrollment = '';
+ $rootScope.$broadcast('dashboard', {selectedEntity: $scope.selectedEntity,
+ selectedOrgUnit: $scope.selectedOrgUnit,
+ selectedProgramId: $scope.selectedProgram.id,
+ selectedEnrollment: $scope.selectedEnrollment});
+ }
+ };
+
+ $scope.showEnrollment = function(){
+ $scope.showEnrollmentDiv = !$scope.showEnrollmentDiv;
+
+ console.log('Enrollment', $scope.selectedEntity, ' ', $scope.selectedProgram);
+ };
+
+ $scope.showScheduling = function(){
+ $scope.showSchedulingDiv = !$scope.showSchedulingDiv;
+
+ console.log('Scheduling', $scope.selectedEntity, ' ', $scope.selectedProgram);
+ };
+
+ $scope.enroll = function(){
+
+ var tei = angular.copy($scope.selectedEntity);
+ tei.attributes = [];
+
+ //get enrollment attributes and their values - new attributes because of enrollment
+ angular.forEach($scope.attributesForEnrollment, function(attribute){
+ if(!angular.isUndefined(attribute.value)){
+ //$scope.selectedEntity.attributes.push({attribute: attribute.id, value: attribute.value, type: attribute.valueType, displayName: attribute.name});
+ tei.attributes.push({attribute: attribute.id, value: attribute.value});
+ }
+ });
+
+ //existing attributes
+ angular.forEach($scope.selectedEntity.attributes, function(attribute){
+ if(!angular.isUndefined(attribute.value)){
+ tei.attributes.push({attribute: attribute.attribute, value: attribute.value});
+ }
+ });
+
+ var enrollment = {trackedEntityInstance: tei.trackedEntityInstance,
+ program: $scope.selectedProgram.id,
+ status: 'ACTIVE',
+ dateOfEnrollment: $scope.newEnrollment.dateOfEnrollment,
+ dateOfIncident: $scope.newEnrollment.dateOfIncident ? $scope.newEnrollment.dateOfIncident : $scope.newEnrollment.dateOfEnrollment
+ };
+
+ TEIService.update(tei).then(function(updateResponse){
+
+ if(updateResponse.status === 'SUCCESS'){
- angular.forEach($scope.enrollments, function(enrollment){
- if(enrollment.program === $scope.selectedProgram.id ){
- $scope.selectedEnrollment = enrollment;
+ //registration is successful and continue for enrollment
+ EnrollmentService.enroll(enrollment).then(function(enrollmentResponse){
+ if(enrollmentResponse.status !== 'SUCCESS'){
+ //enrollment has failed
+ var dialogOptions = {
+ headerText: 'enrollment_error',
+ bodyText: data.description
+ };
+ DialogService.showDialog({}, dialogOptions);
+ return;
}
- });
-
- $scope.programStages = [];
- angular.forEach($scope.selectedProgram.programStages, function(stage){
- $scope.programStages.push(storage.get(stage.id));
+
+ //update tei attributes without refetching from the server
+ angular.forEach($scope.attributesForEnrollment, function(attribute){
+ if(!angular.isUndefined(attribute.value)){
+ if(attribute.type === 'number' && !isNaN(parseInt(attribute.value))){
+ attribute.value = parseInt(attribute.value);
+ }
+ $scope.selectedEntity.attributes.push({attribute: attribute.id, value: attribute.value, type: attribute.valueType, displayName: attribute.name});
+ }
+ });
});
-
- if($scope.selectedEnrollment){
- $scope.selectedEnrollment.dateOfIncident = $filter('date')($scope.selectedEnrollment.dateOfIncident, 'yyyy-MM-dd');
- }
-
- $rootScope.$broadcast('dashboard', {selectedEntity: $scope.selectedEntity,
- selectedOrgUnit: $scope.selectedOrgUnit,
- selectedProgramId: $scope.selectedProgram.id,
- selectedEnrollment: $scope.selectedEnrollment});
- });
- }
-
- /*$rootScope.$broadcast('dashboard', {selectedEntity: $scope.selectedEntity,
- selectedOrgUnit: $scope.selectedOrgUnit,
- selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id : null,
- selectedEnrollment: $scope.selectedEnrollment ? $scope.selectedEnrollment : null});*/
-
- };
-
-
-
- $scope.showEnrollment = function(){
- $scope.showEnrollmentDiv = !$scope.showEnrollmentDiv;
-
- console.log('Enrollment', $scope.selectedEntity, ' ', $scope.selectedProgram);
- };
-
- $scope.enroll = function(){
- console.log('Enrollment', $scope.selectedEntity, ' ', $scope.selectedProgram);
+
+ }
+ else{
+ //update has failed
+ var dialogOptions = {
+ headerText: 'registration_error',
+ bodyText: updateResponse.description
+ };
+ DialogService.showDialog({}, dialogOptions);
+ return;
+ }
+ });
+
+ console.log('tei', tei, ' ');
+ console.log('scope', $scope.selectedEntity, ' ');
+ };
+
+ $scope.cancelEnrollment = function(){
+ $scope.selectedProgram = '';
};
});
\ 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-05-27 14:50:29 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html 2014-05-28 13:36:26 +0000
@@ -7,9 +7,6 @@
</div>
<table class="table-borderless table-striped">
<tr>
- <!--<td>
- {{'program'| translate}}
- </td>-->
<td>
<select ng-model="selectedProgram"
class="form-control"
@@ -17,51 +14,137 @@
ng-change="loadEvents()">
<option value="">{{'please_select_a_program'| translate}}</option>
</select>
- </td>
- <td ng-if="selectedProgram && !selectedEnrollment" >
- <button type="button"
- class="btn btn-default"
- ng-click="showEnrollment()">
- {{'enroll'| translate}}
- </button>
- </td>
- <td ng-if="selectedProgram && selectedEnrollment" >
- <button type="button"
- class="btn btn-default"
- ng-click="scheduling()">
- {{'scheduling'| translate}}
- </button>
- </td>
+ </td>
</tr>
</table>
- <div ng-if="selectedProgram">
- <div ng-if="programStages">
- <hr>
- <table class="table-borderless table-striped">
- <thead>
- <tr>
- <th>
- {{'program_stage'| translate}}
- </th>
- <th>
- {{'scheduled_date'| translate}}
- </th>
- </tr>
- </thead>
- <tr ng-repeat="programStage in programStages">
- <td>
- {{programStage.name}}
- </td>
- <td>
- {{programStage.minDaysFromStart}}
- {{selectedEnrollment.dateOfIncident}}
- </td>
- </tr>
- </table>
- </div>
- <div ng-if="showEnrollmentDiv">
-
+ <div class="horizonal-spacing" ng-if="selectedEnrollment">
+ <hr>
+ <table class="table-borderless">
+ <tr>
+ <td>
+ {{selectedProgram.dateOfIncidentDescription}}
+ </td>
+ <td>
+ <input type="text" class="form-control" ng-date ng-model="selectedEnrollment.dateOfIncident" ng-disabled="true"/>
+ </td>
+ </tr>
+
+ </table>
+ <hr>
+ <table class="table-borderless table-striped">
+ <thead>
+ <tr>
+ <th>
+ {{'program_stage'| translate}}
+ </th>
+ <th>
+ {{'scheduled_date'| translate}}
+ </th>
+ </tr>
+ </thead>
+ <tr ng-repeat="programStage in programStages">
+ <td>
+ {{programStage.name}}
+ </td>
+ <td>
+ <input type="text" class="form-control" ng-date ng-model="programStage.dueDate" ng-disabled="!showSchedulingDiv"/>
+ </td>
+ </tr>
+ </table>
+
+ <div class="vertical-spacing small-horizonal-spacing">
+ <button type="button"
+ class="btn btn-default"
+ ng-disabled="showSchedulingDiv"
+ ng-click="showScheduling()">
+ {{'reschedule'| translate}}
+ </button>
+ <button type="button"
+ class="btn btn-default"
+ ng-show="showSchedulingDiv"
+ ng-click="showScheduling()">
+ {{'save'| translate}}
+ </button>
+ <button type="button"
+ class="btn btn-default"
+ ng-show="showSchedulingDiv"
+ ng-click="showScheduling()">
+ {{'cancel'| translate}}
+ </button>
</div>
</div>
+ <div class="vertical-spacing horizonal-spacing" ng-if="selectedProgram && !selectedEnrollment">
+ <hr>
+ <table class="table-borderless">
+ <tr>
+ <td>
+ {{selectedProgram.dateOfEnrollmentDescription}}
+ </td>
+ <td>
+ <input type="text" class="form-control" ng-date ng-model="newEnrollment.dateOfEnrollment" />
+ </td>
+ </tr>
+ <tr ng-if="selectedProgram.displayIncidentDate">
+ <td>
+ {{selectedProgram.dateOfIncidentDescription}}
+ </td>
+ <td>
+ <input type="text" class="form-control" ng-date ng-model="newEnrollment.dateOfIncident" />
+ </td>
+ </tr>
+ </table>
+ <hr>
+ <table class="table-borderless table-striped">
+ <tr ng-repeat="attribute in attributesForEnrollment">
+ <td>
+ {{attribute.name}}
+ </td>
+ <td>
+ <div ng-switch="attribute.valueType">
+ <div ng-switch-when="date">
+ <input type="text" class="form-control" ng-date ng-model="attribute.value" />
+ </div>
+ <div ng-switch-when="trueOnly">
+ <input type="checkbox" class="form-control" ng-model="attribute.value" />
+ </div>
+ <div ng-switch-when="bool">
+ <select ng-model="attribute.value" class="form-control">
+ <option value="">{{'please_select'| translate}}</option>
+ <option value="0">{{'no'| translate}}</option>
+ <option value="1">{{'yes'| translate}}</option>
+ </select>
+ </div>
+ <div ng-switch-when="combo">
+ <input type="text"
+ class="form-control"
+ ng-model="attribute.value"
+ typeahead="option for option in attribute.optionSet.options | filter:$viewValue | limitTo:20"
+ typeahead-open-on-focus
+ />
+ </div>
+ <div ng-switch-when="number">
+ <input type="number" class="form-control" ng-model="attribute.value"/>
+ </div>
+ <div ng-switch-default>
+ <input type="text" class="form-control" ng-model="attribute.value" />
+ </div>
+ </div>
+ </td>
+ </tr>
+ </table>
+
+ <div class="vertical-spacing small-horizonal-spacing">
+ <button type="button"
+ class="btn btn-default"
+ ng-click="enroll()">
+ {{'enroll'| translate}}
+ </button>
+ <button type="button"
+ class="btn btn-default"
+ ng-click="cancelEnrollment()">
+ {{'cancel'| translate}}
+ </button>
+ </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/profile/profile-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2014-05-27 12:38:36 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2014-05-28 13:36:26 +0000
@@ -2,6 +2,7 @@
function($scope,
storage,
CurrentSelection,
+ TEIService,
TranslationService) {
TranslationService.translate();
@@ -23,8 +24,13 @@
if($scope.selectedEntity.trackedEntity === te.id){
$scope.trackedEntity = te;
}
- });
+ });
+ angular.forEach($scope.selectedEntity.attributes, function(att){
+ if(att.type === 'number' && !isNaN(parseInt(att.value))){
+ att.value = parseInt(att.value);
+ }
+ });
$scope.entityAttributes = angular.copy($scope.selectedEntity.attributes);
});
@@ -34,6 +40,28 @@
$scope.save = function(){
+ var tei = angular.copy($scope.selectedEntity);
+ tei.attributes = [];
+ //prepare to update the tei on the server side
+ angular.forEach($scope.selectedEntity.attributes, function(attribute){
+ if(!angular.isUndefined(attribute.value)){
+ tei.attributes.push({attribute: attribute.attribute, value: attribute.value});
+ }
+ });
+
+ TEIService.update(tei).then(function(updateResponse){
+
+ if(updateResponse.status !== 'SUCCESS'){//update has failed
+ var dialogOptions = {
+ headerText: 'registration_error',
+ bodyText: updateResponse.description
+ };
+ DialogService.showDialog({}, dialogOptions);
+ return;
+ }
+ });
+
+ console.log('the tei is: ', tei);
$scope.editProfile = !$scope.editProfile;
};
=== 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-05-27 12:38:36 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json 2014-05-28 13:36:26 +0000
@@ -67,6 +67,7 @@
"program_stage": "Program stage",
"scheduled_date": "Scheduled date",
"scheduling": "Scheduling",
+ "reschedule": "Reschedule",
"enroll": "Enroll",
"like": "LIKE",
"not_like": "NOT LIKE",
=== 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-27 12:38:36 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-05-28 13:36:26 +0000
@@ -279,6 +279,23 @@
});
return param;
+ },
+ getMissingAttributesForEnrollment: function(tei, program){
+ var programAttributes = this.getByProgram(program);
+ var existingAttributes = tei.attributes;
+ var missingAttributes = [];
+ for(var i=0; i<programAttributes.length; i++){
+ var exists = false;
+ for(var j=0; j<existingAttributes.length && !exists; j++){
+ if(programAttributes[i].id === existingAttributes[j].attribute){
+ exists = true;
+ }
+ }
+ if(!exists){
+ missingAttributes.push(programAttributes[i]);
+ }
+ }
+ return missingAttributes;
}
};
})
=== 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-05-27 14:50:29 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css 2014-05-28 13:36:26 +0000
@@ -574,7 +574,8 @@
}
.vertical-spacing{
- margin-top: 10px;
+ margin-top: 10px;
+ margin-bottom: 10px;
}
.small-horizonal-spacing{