=== 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 @@ - - - +
- - - - -
-
-
-
- - - - - - - - - - - -
- {{'program_stage'| translate}} - - {{'scheduled_date'| translate}} -
- {{programStage.name}} - - {{programStage.minDaysFromStart}} - {{selectedEnrollment.dateOfIncident}} -
-
-
- +
+
+ + + + + + +
+ {{selectedProgram.dateOfIncidentDescription}} + + +
+
+ + + + + + + + + + + +
+ {{'program_stage'| translate}} + + {{'scheduled_date'| translate}} +
+ {{programStage.name}} + + +
+ +
+ + +
+
+
+ + + + + + + + + +
+ {{selectedProgram.dateOfEnrollmentDescription}} + + +
+ {{selectedProgram.dateOfIncidentDescription}} + + +
+
+ + + + + +
+ {{attribute.name}} + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + +
+
\ 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