From 337545f853bafdaa4698981992fcbfd17517b96b Mon Sep 17 00:00:00 2001 From: josemp10 Date: Wed, 31 Aug 2016 20:53:28 +0200 Subject: [PATCH] Issue #75 --- core/dhis2Api.js | 1 + directives/orgunitgroupsets/orgunitGroupSetsController.js | 4 ++-- .../resourcesjsondatasetController.js | 5 ++++- modules/HealthService/healthServiceController.js | 8 ++++++-- services/commonservice.js | 5 ++++- services/healthserviceservice.js | 1 + 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/dhis2Api.js b/core/dhis2Api.js index d050099..29fe022 100644 --- a/core/dhis2Api.js +++ b/core/dhis2Api.js @@ -96,6 +96,7 @@ Dhis2Api.factory("commonvariable", function () { userDirective:"", users: usersMSF, healhservicesCodeOUG: "", + refreshDataSets:false, clearForm:[] }; diff --git a/directives/orgunitgroupsets/orgunitGroupSetsController.js b/directives/orgunitgroupsets/orgunitGroupSetsController.js index 7ee1445..c3c017b 100644 --- a/directives/orgunitgroupsets/orgunitGroupSetsController.js +++ b/directives/orgunitgroupsets/orgunitGroupSetsController.js @@ -173,8 +173,8 @@ Dhis2Api.controller("d2DropdownorgunitgroupsetController", ['$q','$scope','$http //function to call when change of OU if ($scope.operation == "show") { - //console.log("Voy a ejecutar esto de la directiva"); - $scope.disabled = true; + + $scope.disabled = true; try{ getOrgUnitGroup(commonvariable.OrganisationUnit.id, $scope.uidgroupset).then(function (data) { $scope.ougName = data.name; diff --git a/directives/resourcesjsonDataset/resourcesjsondatasetController.js b/directives/resourcesjsonDataset/resourcesjsondatasetController.js index 177b79d..180782a 100644 --- a/directives/resourcesjsonDataset/resourcesjsondatasetController.js +++ b/directives/resourcesjsonDataset/resourcesjsondatasetController.js @@ -41,6 +41,7 @@ Dhis2Api.controller("d2ResourcejsondatasetController", ['$scope', '$filter', '$i $scope.operation = 'show'; $scope.prevOu = undefined; } + $scope.editOrgUnit = function (datasets) { try { commonvariable.OrganisationUnit.dataSets = datasets; @@ -56,11 +57,13 @@ Dhis2Api.controller("d2ResourcejsondatasetController", ['$scope', '$filter', '$i } $scope.$watch(function () { - if (commonvariable.OrganisationUnit && commonvariable.OrganisationUnit.id != $scope.prevOu) { + if ((commonvariable.OrganisationUnit && commonvariable.OrganisationUnit.id != $scope.prevOu) || + commonvariable.refreshDataSets) { $scope.initForm(); $scope.prevOu = commonvariable.OrganisationUnit.id; $scope.pdatasets = commonvariable.OrganisationUnit.dataSets; $scope.loadDataSet(); + commonvariable.refreshDataSets = false; //$scope.finddatasetSelected(); } }); diff --git a/modules/HealthService/healthServiceController.js b/modules/HealthService/healthServiceController.js index b479e0a..e337242 100644 --- a/modules/HealthService/healthServiceController.js +++ b/modules/HealthService/healthServiceController.js @@ -137,8 +137,12 @@ appConfigProjectMSF.controller('healthServiceController', ["$scope",'$filter',"c if (commonvariable.orgUnitGroupSet[commonvariable.ouGroupsetId.HealthService].name == "Vaccination") { //Assocate Vacc datasets - commonService.assignVaccinationDataSet(orgUnit); - } + commonService.assignVaccinationDataSet(orgUnit).$promise.then(function(data){ + + commonvariable.refreshDataSets = true; + + }); + } else commonvariable.refreshDataSets = true; }); diff --git a/services/commonservice.js b/services/commonservice.js index 253ca4a..bbb01ca 100644 --- a/services/commonservice.js +++ b/services/commonservice.js @@ -196,6 +196,8 @@ Dhis2Api.service('commonService', ['$q', 'commonvariable', 'OrgUnitGroupByOrgUni var promises = []; var variable = {}; + commonvariable.OrganisationUnit.dataSets = []; + angular.forEach(orgUnit.dataSets, function (ds, key){ var deferred = $q.defer(); promises.push(deferred.promise); @@ -205,7 +207,7 @@ Dhis2Api.service('commonService', ['$q', 'commonvariable', 'OrgUnitGroupByOrgUni variable=data; deferred.resolve(variable); }); - } else deferred.resolve(-1); + } else { commonvariable.OrganisationUnit.dataSets.push(ds); deferred.resolve(-1); } }); @@ -226,6 +228,7 @@ Dhis2Api.service('commonService', ['$q', 'commonvariable', 'OrgUnitGroupByOrgUni if (response.dataSets.length > 0) { var dataSet = response.dataSets[0]; + commonvariable.OrganisationUnit.dataSets.push(dataSet); DataSetsOrgUnit.POST({ uidorgunit: orgUnit.id, uiddataset: dataSet.id }); } diff --git a/services/healthserviceservice.js b/services/healthserviceservice.js index bad4185..b1d0b5d 100644 --- a/services/healthserviceservice.js +++ b/services/healthserviceservice.js @@ -52,6 +52,7 @@ Dhis2Api.service('healthserviceService', ['$q', 'commonvariable', 'OrgUnitOrgUni commonService.deleteOrgUnitGroup(commonvariable.OrganisationUnit.id, commonvariable.ouGroupsetId.HealthServiceType).then(function (data) { OrgUnitOrgUnitGroups.POST({ uidorgunit: commonvariable.OrganisationUnit.id, uidgroup: commonvariable.orgUnitGroupSet[commonvariable.ouGroupsetId.HealthService].id }); + commonvariable.healhservicesCodeOUG = commonvariable.orgUnitGroupSet[commonvariable.ouGroupsetId.HealthService].code; var sitePrefix = commonvariable.OrganisationUnit.name.slice(0,3); var healthServiceName = sitePrefix + commonvariable.orgUnitGroupSet[commonvariable.ouGroupsetId.HealthService].name;