diff --git a/core/dhis2Api.js b/core/dhis2Api.js index 5933117..e74601d 100644 --- a/core/dhis2Api.js +++ b/core/dhis2Api.js @@ -269,11 +269,13 @@ Dhis2Api.factory("DataSets", ['$resource', 'commonvariable', function ($resource return $resource(commonvariable.url + "dataSets/:uid", { uid: '@uid', - fields: 'name,id,code,periodType,dataElements,organisationUnits' + fields: ':all' + //fields: 'name,id,code,periodType,dataElements,organisationUnits' }, { Get:{method:"GET"}, Post: { method: "POST" }, - Put: { method: "PUT" } + Put: { method: "PUT" }, + Patch: {method: "PATCH"} }); }]); @@ -330,6 +332,32 @@ Dhis2Api.factory("DataSetsOrgUnit",['$resource','commonvariable', function ($res DELETE: {method: "DELETE"}}); }]); +Dhis2Api.factory("UserRoles", ['$resource', 'commonvariable', function ($resource, commonvariable) { + + return $resource(commonvariable.url + "userRoles/:uid", + { + uid: '@uid' + }, + { Get:{method:"GET"}, + Post: { method: "POST" }, + Put: { method: "PUT" }, + Patch: {method: "PATCH"} + }); +}]); + + +Dhis2Api.factory("DataSetUserRole",['$resource','commonvariable', function ($resource,commonvariable) { + + return $resource(commonvariable.url+"userRoles/:uiduserrole/dataSets/:uiddataset", + { + uiduserrole:'@uiduserrole', + uiddataset: '@uiddataset' + }, + { POST: { method: "POST"}, + GET: {method: "GET"}, + DELETE: {method: "DELETE"}}); +}]); + Dhis2Api.factory("OrganisationUnitChildren",['$resource','commonvariable', function ($resource,commonvariable) { return $resource(commonvariable.url+"organisationUnits/:uid", { diff --git a/directives/resourcesjsonDataset/resourcesjsondatasetController.js b/directives/resourcesjsonDataset/resourcesjsondatasetController.js index 180782a..b1409ba 100644 --- a/directives/resourcesjsonDataset/resourcesjsondatasetController.js +++ b/directives/resourcesjsonDataset/resourcesjsondatasetController.js @@ -75,7 +75,9 @@ Dhis2Api.controller("d2ResourcejsondatasetController", ['$scope', '$filter', '$i } $scope.editHealtServiceDataset = function () { angular.forEach($scope.datasetforsave, function (dvalue,dkey) { - DataSets.Put({ uid: dvalue.id }, dvalue) + + if (dvalue.code != "DS_DEM"){ + DataSets.Put({ uid: dvalue.id }, dvalue) .$promise.then(function (data) { if (data.response.status == "SUCCESS") { @@ -87,6 +89,7 @@ Dhis2Api.controller("d2ResourcejsondatasetController", ['$scope', '$filter', '$i $scope.messages.push({ type: "danger", text: $translate('DATASET_NOSAVED') }); } }); + } }); }; diff --git a/directives/resourcesjsonVaccination/resourcesjsonvaccinationController.js b/directives/resourcesjsonVaccination/resourcesjsonvaccinationController.js index 3f3ead8..f47774b 100644 --- a/directives/resourcesjsonVaccination/resourcesjsonvaccinationController.js +++ b/directives/resourcesjsonVaccination/resourcesjsonvaccinationController.js @@ -26,8 +26,8 @@ Dhis2Api.directive('d2Resourcejsonvaccination', function(){ } }); -Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', '$interval', "commonvariable", "loadjsonresource", "DataElements", "DataSets", "OrgUnit", "validatorService", "Section", "$q", - function ($scope, $filter, $interval, commonvariable, loadjsonresource, DataElements, DataSets, OrgUnit, validatorService, Section, $q) { +Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', '$interval', "commonvariable", "loadjsonresource", "DataElements", "DataSets", "OrgUnit", "validatorService", "Section", "$q", "UserRoles", "DataSetUserRole", + function ($scope, $filter, $interval, commonvariable, loadjsonresource, DataElements, DataSets, OrgUnit, validatorService, Section, $q, UserRoles, DataSetUserRole) { $scope.style=[]; var $translate = $filter('translate'); @@ -86,13 +86,14 @@ Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', $scope.GetChildrenOU = function () { $scope.childOU = []; - OrgUnit.get({ id: commonvariable.OrganisationUnit.id, includeDescendants: true, fields: 'name,id,level,closedDate', filter: 'level:eq:' + commonvariable.level.HealthService }) + OrgUnit.get({ id: commonvariable.OrganisationUnit.id, includeDescendants: true, fields: 'name,id,level,closedDate,organisationUnitGroups', filter: 'level:eq:' + commonvariable.level.HealthService }) .$promise.then(function (childOU) { angular.forEach(childOU.organisationUnits, function (ou, key) { - if(ou.id!=commonvariable.OrganisationUnit.id && ou.closedDate==undefined){ - $scope.childOU.push({ id: ou.id }); - } - + if(ou.id!=commonvariable.OrganisationUnit.id && ou.closedDate==undefined) + angular.forEach(ou.organisationUnitGroups, function (oug, key){ + if (oug.code=="OUG_HSV_VAC") + $scope.childOU.push({ id: ou.id }); + }); }); }); @@ -219,6 +220,7 @@ Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', $scope.dataSetDescription = "" commonvariable.PeriodSelected = []; commonvariable.DataElementSelected = []; + $scope.checkingDEGroup(); }; ///get if there exist a Dataset for this Mission. @@ -242,6 +244,18 @@ Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', $scope.CreateDatasetVaccination = true; }); } + + $scope.assignUserRoles = function (uidDataSet) { + + UserRoles.Get({}).$promise.then (function(data){ + + angular.forEach(data.userRoles, function(userRole, key) { + DataSetUserRole.POST({uiduserrole:userRole.id,uiddataset:uidDataSet}); + }); + + }); + + } // $scope.saveDatasetVaccination = function () { @@ -272,6 +286,7 @@ Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', .$promise.then(function (data) { if (data.response.status == "SUCCESS") { $scope.dataSetUid = data.response.lastImported; + $scope.assignUserRoles(data.response.lastImported); $scope.createSectionsToDataSet().then(function(data){ $scope.dhisSectionsToRemove=$scope.dhisSections; $scope.dhisSections=[]; @@ -364,7 +379,7 @@ Dhis2Api.controller("d2ResourcejsonvaccinationController", ['$scope', '$filter', $scope.GetDataelement=function(codes){ $scope.ListnameDataelement=[]; - DataElements.Get({filter:'code:in:['+codes+"]"}) + DataElements.Get({paging:'no',filter:'code:in:'+codes}) .$promise.then(function(response){ angular.forEach(response.dataElements, function(dvalue,dkey){ $scope.ListnameDataelement[dvalue.code] = { id: dvalue.id, name: dvalue.name }; diff --git a/services/projectservice.js b/services/projectservice.js index d13c726..6ba357b 100644 --- a/services/projectservice.js +++ b/services/projectservice.js @@ -142,7 +142,7 @@ Dhis2Api.service('projectService', ['$q', 'commonvariable', 'User', 'OrgUnitOrgU if (orgUnit.level == commonvariable.level.HealthSite || orgUnit.level == commonvariable.level.HealthService) { var textToUpdate = "OU_" + commonvariable.ouDirectiveCode.slice(2, 7); - var newCode = textToUpdate + orgUnit.code.slice(7); + var newCode = textToUpdate + orgUnit.code.slice(8); OrgUnit.PATCH({id:orgUnit.id},{code:newCode}).$promise.then(function(data){ defered.resolve(data); @@ -241,11 +241,10 @@ Dhis2Api.service('projectService', ['$q', 'commonvariable', 'User', 'OrgUnitOrgU var defered = $q.defer(); var promise = defered.promise; var projectEdited = false; - + OrgUnit.PATCH({id:idOu},editOu).$promise.then(function(data){ if (data.response.status=="SUCCESS") { - //projectEdited=true; //asign OU selected commonvariable.EditOrganisationUnit = commonvariable.OrganisationUnit;