=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-03-19 10:18:00 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-03-25 16:43:47 +0000 @@ -251,7 +251,7 @@ var val = dataValue.value; var de = $scope.prStDes[dataValue.dataElement].dataElement; - if(de){ + if(de){ if(val && de.type === 'string' && de.optionSet && $scope.optionSets[de.optionSet.id].options ){ val = OptionSetService.getName($scope.optionSets[de.optionSet.id].options, val); } @@ -276,8 +276,7 @@ if(stage.captureCoordinates){ event.coordinate = {latitude: event.coordinate.latitude ? event.coordinate.latitude : '', longitude: event.coordinate.longitude ? event.coordinate.longitude : ''}; - } - + } event.allowProvidedElsewhereExists = false; angular.forEach(stage.programStageDataElements, function(prStDe){ === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-11 11:21:40 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-25 16:43:47 +0000 @@ -1,20 +1,18 @@ +/* global trackerCapture, angular */ + trackerCapture.controller('EnrollmentController', function($rootScope, $scope, $location, $timeout, DateUtils, - EventUtils, storage, - DHIS2EventFactory, AttributesFactory, CurrentSelection, - TEIService, TEFormService, CustomFormService, EnrollmentService, - ModalService, - DialogService) { + ModalService) { $scope.today = DateUtils.getToday(); $scope.selectedOrgUnit = storage.get('SELECTED_OU'); @@ -97,11 +95,15 @@ $scope.trackedEntityForm = teForm; $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'ENROLLMENT'); } + if($scope.selectedEnrollment.enrollment){ + $scope.broadCastSelections('dashboardWidgets'); + } + }); + } + else{ + if($scope.selectedEnrollment.enrollment){ $scope.broadCastSelections('dashboardWidgets'); - }); - } - else{ - $scope.broadCastSelections('dashboardWidgets'); + } } }); }; @@ -110,12 +112,21 @@ $scope.showEnrollmentDiv = !$scope.showEnrollmentDiv; - if($scope.showEnrollmentDiv){ + $timeout(function() { + $rootScope.$broadcast('enrollmentEditing', {enrollmentEditing: $scope.showEnrollmentDiv}); + }, 100); + + if($scope.showEnrollmentDiv){ + $scope.showEnrollmentHistoryDiv = false; //load new enrollment details $scope.selectedEnrollment = {}; $scope.loadEnrollmentDetails($scope.selectedEnrollment); + + $timeout(function() { + $rootScope.$broadcast('registrationWidget', {registrationMode: 'ENROLLMENT', selectedTei: $scope.selectedTei}); + }, 100); } else{ hideEnrollmentDiv(); @@ -134,77 +145,6 @@ } }; - $scope.enroll = function(){ - - //check for form validity - $scope.outerForm.submitted = true; - if( $scope.outerForm.$invalid ){ - return false; - } - - //form is valid, continue with enrollment - var result = getProcessedForm(); - $scope.formEmpty = result.formEmpty; - var tei = result.tei; - - if($scope.formEmpty){//form is empty - return false; - } - - var enrollment = {trackedEntityInstance: tei.trackedEntityInstance, - program: $scope.selectedProgram.id, - status: 'ACTIVE', - dateOfEnrollment: $scope.selectedEnrollment.dateOfEnrollment, - dateOfIncident: $scope.selectedEnrollment.dateOfIncident ? $scope.selectedEnrollment.dateOfIncident : $scope.selectedEnrollment.dateOfEnrollment - }; - - TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){ - - if(updateResponse.status === 'SUCCESS'){ - //registration is successful, continue for enrollment - EnrollmentService.enroll(enrollment).then(function(enrollmentResponse){ - if(enrollmentResponse.status !== 'SUCCESS'){ - //enrollment has failed - var dialogOptions = { - headerText: 'enrollment_error', - bodyText: enrollmentResponse - }; - DialogService.showDialog({}, dialogOptions); - return; - } - - enrollment.enrollment = enrollmentResponse.reference; - $scope.selectedEnrollment = enrollment; - $scope.enrollments.push($scope.selectedEnrollment); - - var dhis2Events = EventUtils.autoGenerateEvents(tei.trackedEntityInstance, $scope.selectedProgram, $scope.selectedOrgUnit, $scope.selectedEnrollment); - - $scope.showEnrollmentDiv = false; - $scope.outerForm.submitted = false; - - CurrentSelection.set({tei: tei, te: $scope.selectedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: $scope.enrollments, selectedEnrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets}); - if(dhis2Events.events.length > 0){ - DHIS2EventFactory.create(dhis2Events).then(function(data) { - $scope.broadCastSelections('dashboardWidgets'); - }); - } - else{ - $scope.broadCastSelections('dashboardWidgets'); - } - }); - } - else{ - //update has failed - var dialogOptions = { - headerText: 'registration_error', - bodyText: updateResponse.description - }; - DialogService.showDialog({}, dialogOptions); - return; - } - }); - }; - $scope.broadCastSelections = function(listeners){ var selections = CurrentSelection.get(); var tei = selections.tei; @@ -213,24 +153,6 @@ $timeout(function() { $rootScope.$broadcast(listeners, {}); }, 100); - - $timeout(function() { - $rootScope.$broadcast('enrollmentEditing', {enrollmentEditing: $scope.showEnrollmentDiv}); - }, 100); - }; - - var getProcessedForm = function(){ - var tei = angular.copy(selections.tei); - tei.attributes = []; - var formEmpty = true; - for(var k in $scope.attributesById){ - if( $scope.selectedTei[k] ){ - tei.attributes.push({attribute: $scope.attributesById[k].id, value: $scope.selectedTei[k], displayName: $scope.attributesById[k].name, type: $scope.attributesById[k].valueType}); - formEmpty = false; - } - } - - return {tei: tei, formEmpty: formEmpty}; }; var processSelectedTei = function(){ === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html 2015-03-25 16:43:47 +0000 @@ -82,70 +82,7 @@ -
-
-
-
- - - - - - - - - -
- {{selectedProgram.dateOfEnrollmentDescription}} - - - {{'required'| translate}} -
- {{selectedProgram.dateOfIncidentDescription}} - - -
-
-
-
-
-
-
-
- -
-
{{'form_is_empty_fill_at_least_one'| translate}}
-
- -
- - -
-
-
+
@@ -189,4 +126,4 @@ - \ No newline at end of file + === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2015-03-09 16:23:47 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2015-03-25 16:43:47 +0000 @@ -1,11 +1,12 @@ +/* global trackerCapture, angular */ + trackerCapture.controller('ProfileController', function($rootScope, - $scope, + $scope, + $timeout, CurrentSelection, CustomFormService, TEFormService, - TEIService, - DialogService, AttributesFactory) { $scope.editingDisabled = true; @@ -47,6 +48,9 @@ }); } }); + $timeout(function() { + $rootScope.$broadcast('registrationWidget', {registrationMode: 'PROFILE', selectedTei: $scope.selectedTei, enrollment: $scope.selectedEnrollment}); + }, 100); }); //listen for enrollment editing @@ -60,50 +64,11 @@ $rootScope.profileWidget.expand = true; }; - $scope.save = function(){ - //check for form validity - $scope.outerForm.submitted = true; - if( $scope.outerForm.$invalid ){ - return false; - } - - //form is valid, continue the update process - //get tei attributes and their values - //but there could be a case where attributes are non-mandatory and - //form comes empty, in this case enforce at least one value - $scope.formEmpty = true; - var tei = angular.copy(selections.tei); - tei.attributes = []; - for(var k in $scope.attributesById){ - if( $scope.selectedTei.hasOwnProperty(k) && $scope.selectedTei[k] ){ - tei.attributes.push({attribute: $scope.attributesById[k].id, value: $scope.selectedTei[k], type: $scope.attributesById[k].valueType}); - $scope.formEmpty = false; - } - } - - if($scope.formEmpty){//form is empty - return false; - } - - TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){ - - if(updateResponse.status !== 'SUCCESS'){//update has failed - var dialogOptions = { - headerText: 'update_error', - bodyText: updateResponse.description - }; - DialogService.showDialog({}, dialogOptions); - return; - } - - $scope.editingDisabled = !$scope.editingDisabled; - CurrentSelection.set({tei: tei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets}); - $scope.outerForm.submitted = false; - }); - }; - $scope.cancel = function(){ $scope.selectedTei = $scope.teiOriginal; $scope.editingDisabled = !$scope.editingDisabled; + $timeout(function() { + $rootScope.$broadcast('registrationWidget', {registrationMode: 'PROFILE', selectedTei: $scope.selectedTei, enrollment: $scope.selectedEnrollment}); + }, 100); }; }); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2015-03-25 16:43:47 +0000 @@ -1,6 +1,5 @@
- {{profileWidget.title| translate}} | {{'edit'| translate}} @@ -16,26 +15,8 @@
-
-
-
-
-
-
-
- -
- - -
+
+
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-09 16:23:47 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-25 16:43:47 +0000 @@ -1,3 +1,5 @@ +/* global trackerCapture, angular */ + trackerCapture.controller('RegistrationController', function($rootScope, $scope, @@ -6,7 +8,6 @@ AttributesFactory, DHIS2EventFactory, TEService, - TEIService, TEFormService, CustomFormService, EnrollmentService, @@ -14,13 +15,16 @@ CurrentSelection, OptionSetService, EventUtils, + RegistrationService, DateUtils, storage) { $scope.today = DateUtils.getToday(); $scope.trackedEntityForm = null; $scope.customForm = null; - $scope.selectedTei = {}; + $scope.selectedTei = {}; + $scope.tei = {}; + $scope.registrationMode = null; $scope.attributesById = CurrentSelection.getAttributesById(); if(!$scope.attributesById){ @@ -59,10 +63,30 @@ $scope.$watch('selectedProgram', function() { $scope.trackedEntityForm = null; $scope.customForm = null; - $scope.getAttributes(); - }); - - $scope.getAttributes = function(){ + if($scope.registrationMode === 'REGISTRATION'){ + $scope.getAttributes($scope.registrationMode); + } + }); + + //listen to modes of registration + $scope.$on('registrationWidget', function(event, args){ + $scope.selectedTei = {}; + $scope.tei = {}; + $scope.registrationMode = args.registrationMode; + $scope.getAttributes($scope.registrationMode); + + if($scope.registrationMode !== 'REGISTRATION'){ + $scope.selectedTei = args.selectedTei; + $scope.tei = angular.copy(args.selectedTei); + } + + if($scope.registrationMode === 'PROFILE'){ + $scope.selectedEnrollment = args.enrollment; + } + }); + + $scope.getAttributes = function(_mode){ + var mode = _mode ? _mode : 'ENROLLMENT'; AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){ $scope.attributes = atts; $scope.customFormExists = false; @@ -70,59 +94,55 @@ if(angular.isObject(teForm)){ $scope.customFormExists = true; $scope.trackedEntityForm = teForm; - $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'ENROLLMENT'); + $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, mode); } }); }); }; $scope.registerEntity = function(destination){ + //check for form validity $scope.outerForm.submitted = true; if( $scope.outerForm.$invalid ){ return false; - } + } //form is valid, continue the registration - //get selected entity - var selectedTrackedEntity = $scope.trackedEntities.selected.id; - if($scope.selectedProgram){ - selectedTrackedEntity = $scope.selectedProgram.trackedEntity.id; + //get selected entity + if(!$scope.selectedTei.trackedEntityInstance){ + $scope.selectedTei.trackedEntity = $scope.tei.trackedEntity = $scope.selectedProgram && $scope.selectedProgram.trackedEntity && $scope.selectedProgram.trackedEntity.id ? $scope.selectedProgram.trackedEntity.id : $scope.trackedEntities.selected.id; + $scope.selectedTei.orgUnit = $scope.selectedTei.orgUnit = $scope.selectedOrgUnit.id; + $scope.selectedTei.attributes = $scope.selectedTei.attributes = []; } //get tei attributes and their values //but there could be a case where attributes are non-mandatory and //registration form comes empty, in this case enforce at least one value - $scope.formEmpty = true; - $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: [] }; - for(var k in $scope.attributesById){ - if( $scope.selectedTei.hasOwnProperty(k) && $scope.selectedTei[k] ){ - var val = $scope.selectedTei[k]; - $scope.tei.attributes.push({attribute: $scope.attributesById[k].id, value: val, type: $scope.attributesById[k].valueType}); - $scope.formEmpty = false; - } - } + + var result = RegistrationService.processForm($scope.tei, $scope.selectedTei, $scope.attributesById); + $scope.formEmpty = result.formEmpty; + $scope.tei = result.tei; if($scope.formEmpty){//registration form is empty return false; } - var teiId = ''; - TEIService.register($scope.tei, $scope.optionSets, $scope.attributesById).then(function(response){ - + RegistrationService.registerOrUpdate($scope.tei, $scope.optionSets, $scope.attributesById).then(function(response){ if(response.status === 'SUCCESS'){ - - teiId = response.reference; - - //registration is successful and check for enrollment - if($scope.selectedProgram){ + if( $scope.tei && !$scope.tei.trackedEntityInstance ){ + $scope.tei.trackedEntityInstance = response.reference; + } + + if($scope.selectedProgram && $scope.registrationMode !== 'PROFILE'){ //enroll TEI - var enrollment = {trackedEntityInstance: teiId, - program: $scope.selectedProgram.id, - status: 'ACTIVE', - dateOfEnrollment: $scope.selectedEnrollment.dateOfEnrollment, - dateOfIncident: $scope.selectedEnrollment.dateOfIncident === '' ? $scope.selectedEnrollment.dateOfEnrollment : $scope.selectedEnrollment.dateOfIncident - }; + var enrollment = {}; + enrollment.trackedEntityInstance = $scope.tei.trackedEntityInstance; + enrollment.program = $scope.selectedProgram.id; + enrollment.status = 'ACTIVE'; + enrollment.dateOfEnrollment = $scope.selectedEnrollment.dateOfEnrollment; + enrollment.dateOfIncident = $scope.selectedEnrollment.dateOfIncident === '' ? $scope.selectedEnrollment.dateOfEnrollment : $scope.selectedEnrollment.dateOfIncident; + EnrollmentService.enroll(enrollment).then(function(data){ if(data.status !== 'SUCCESS'){ //enrollment has failed @@ -135,35 +155,28 @@ } else{ enrollment.enrollment = data.reference; - var dhis2Events = EventUtils.autoGenerateEvents(teiId, $scope.selectedProgram, $scope.selectedOrgUnit, enrollment); + $scope.selectedEnrollment = enrollment; + var dhis2Events = EventUtils.autoGenerateEvents($scope.tei.trackedEntityInstance, $scope.selectedProgram, $scope.selectedOrgUnit, enrollment); if(dhis2Events.events.length > 0){ DHIS2EventFactory.create(dhis2Events).then(function(data){ - goToDashboard(destination, teiId); + notifyRegistrtaionCompletion(destination, $scope.tei.trackedEntityInstance); }); }else{ - goToDashboard(destination, teiId); + notifyRegistrtaionCompletion(destination, $scope.tei.trackedEntityInstance); } } }); - } - else{ - goToDashboard(destination, teiId); - } + } } - else{ - //registration has failed + else{//update/registration has failed var dialogOptions = { - headerText: 'registration_error', + headerText: $scope.tei && $scope.tei.trackedEntityInstance ? 'update_error' : 'registration_error', bodyText: response.description }; DialogService.showDialog({}, dialogOptions); return; - } - }); - }; - - $scope.resetRelationshipSource = function(){ - $scope.selectedRelationshipSource = ''; + } + }); }; $scope.broadCastSelections = function(){ @@ -194,4 +207,19 @@ $scope.broadCastSelections(); } }; + + var notifyRegistrtaionCompletion = function(destination, teiId){ + goToDashboard( destination ? destination : 'DASHBOARD', teiId ); + /*if($scope.registrationMode === 'REGISTRATION'){ + goToDashboard(destination, teiId); + } + else{ + + var selections = CurrentSelection.get(); + CurrentSelection.set({tei: $scope.selectedTei, te: $scope.selectedTei.trackedEntity, prs: selections.prs, pr: $scope.selectedProgram, prNames: selections.prNames, prStNames: selections.prStNames, enrollments: selections.enrollments.push($scope.selectedEnrollment), selectedEnrollment: $scope.selectedEnrollment, optionSets: selections.optionSets}); + $timeout(function() { + $rootScope.$broadcast('selectedItems', {programExists: selections.prs.length > 0}); + }, 100); + }*/ + }; }); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2015-03-25 16:43:47 +0000 @@ -1,10 +1,31 @@ -
+
+ + +
+

{{'category'| translate}}

+ + + + + +
+ {{'entity_type'| translate}} + + +
+
+
+ +
-
+ + +
@@ -40,42 +61,16 @@
-
- - - - - -
- {{'entity_type'| translate}} - - -
-
-
+ +
+
-
-
-

{{'category'| translate}}

- - - - - -
- {{'entity_type'| translate}} - - -
-
-
-
+
+
@@ -84,11 +79,22 @@
{{'form_is_empty_fill_at_least_one'| translate}}
-
+
+ + +
+ +
+ + +
+ +
+
\ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-03-10 08:57:34 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-03-25 16:43:47 +0000 @@ -1,3 +1,5 @@ +/* global trackerCapture, angular */ + trackerCapture.controller('RelationshipController', function($scope, $rootScope, === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2015-03-19 10:18:00 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2015-03-25 16:43:47 +0000 @@ -7,11 +7,13 @@ //Controller for settings page .controller('SelectionController', - function($scope, + function($rootScope, + $scope, $modal, $location, $translate, $filter, + $timeout, Paginator, storage, DateUtils, @@ -305,10 +307,15 @@ $scope.showRegistration = function(){ $scope.showRegistrationDiv = !$scope.showRegistrationDiv; - $scope.showTrackedEntityDiv = false; - $scope.showSearchDiv = false; - if(!$scope.showRegistrationDiv){ + if($scope.showRegistrationDiv){ + $scope.showTrackedEntityDiv = false; + $scope.showSearchDiv = false; + $timeout(function() { + $rootScope.$broadcast('registrationWidget', {registrationMode: 'REGISTRATION'}); + }, 100); + } + else{ $scope.doSearch = true; $scope.getProgramAttributes($scope.selectedProgram); } === 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 2015-03-19 10:18:00 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-03-25 16:43:47 +0000 @@ -436,6 +436,42 @@ }; }) +/* service to deal with TEI registration and update */ +.service('RegistrationService', function(DialogService, TEIService, $q){ + return { + registerOrUpdate: function(tei, optionSets, attributesById){ + if(tei){ + var def = $q.defer(); + if(tei.trackedEntityInstance){ + TEIService.update(tei, optionSets, attributesById).then(function(response){ + def.resolve(response); + }); + } + else{ + TEIService.register(tei, optionSets, attributesById).then(function(response){ + def.resolve(response); + }); + } + return def.promise; + } + }, + processForm: function(existingTei, formTei, attributesById){ + var tei = angular.copy(existingTei); + tei.attributes = []; + var formEmpty = true; + for(var k in attributesById){ + if( formTei[k] ){ + var att = attributesById[k]; + tei.attributes.push({attribute: att.id, value: formTei[k], displayName: att.name, type: att.valueType}); + formEmpty = false; + } + delete tei[k]; + } + return {tei: tei, formEmpty: formEmpty}; + } + }; +}) + /* Service to deal with enrollment */ .service('EnrollmentService', function($http, DateUtils) { @@ -843,7 +879,7 @@ }) /* factory for handling events */ -.factory('DHIS2EventFactory', function($http, $q) { +.factory('DHIS2EventFactory', function($http) { return { @@ -854,7 +890,12 @@ return promise; }, getEventsByProgram: function(entity, program){ - var promise = $http.get( '../api/events.json?' + 'trackedEntityInstance=' + entity + '&program=' + program + '&paging=false').then(function(response){ + + var url = '../api/events.json?' + 'trackedEntityInstance=' + entity + '&paging=false'; + if(program){ + url = url + '&program=' + program; + } + var promise = $http.get( url ).then(function(response){ return response.data.events; }); return promise;