diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index ebeee3f456..26cb898c8e 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -94,7 +94,10 @@ angular.module('bahmni.clinical') $scope.tabs = []; _.forEach($scope.allOrdersTemplates, function (item) { var conceptName = $scope.getName(item); - $scope.tabs.push({name: conceptName ? conceptName : item.name.name, topLevelConcept: item.name.name}); + var tabName = conceptName || item.name.name; + var key = '\'' + tabName + '\''; + $scope.allOrdersTemplates[key] = $scope.filterOrderTemplateByClassMap(item); + $scope.tabs.push({name: tabName, topLevelConcept: item.name.name}); }); if ($scope.tabs) { $scope.activateTab($scope.tabs[0]); @@ -145,11 +148,33 @@ angular.module('bahmni.clinical') return $scope.allOrdersTemplates[key]; }; + $scope.filterOrderTemplateByClassMap = function (orderTemplate) { + var orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); + var orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; + var orderTypeName = $scope.getNameInDefaultLocale(orderTemplate); + + if (orderTypeClassMap[orderTypeName]) { + var orderClasses = orderTypeClassMap[orderTypeName]; + var filteredOrderTemplate = angular.copy(orderTemplate); + + filteredOrderTemplate.setMembers = filteredOrderTemplate.setMembers + .map(function (category) { + category.setMembers = category.setMembers.filter(function (test) { + return orderClasses.includes(test.conceptClass.name); + }); + return category; + }); + + return filteredOrderTemplate; + } + + return orderTemplate; + }; + $scope.showLeftCategoryTests = function (leftCategory) { collapseExistingActiveSection($scope.activeTab.leftCategory); $scope.activeTab.leftCategory = leftCategory; $scope.activeTab.leftCategory.klass = "active"; - $scope.activeTab.leftCategory.groups = $scope.getConceptClassesInSet(leftCategory); }; @@ -275,5 +300,10 @@ angular.module('bahmni.clinical') return name && name.name; }; + $scope.getNameInDefaultLocale = function (sample) { + var name = _.find(sample.names, { conceptNameType: "FULLY_SPECIFIED", locale: localStorage.getItem("openmrsDefaultLocale") || "en" }); + return name ? name.name : sample.name.name; + }; + init(); }]); diff --git a/ui/app/clinical/ordersTabInitialization.js b/ui/app/clinical/ordersTabInitialization.js index 882a993726..fb508952c7 100644 --- a/ui/app/clinical/ordersTabInitialization.js +++ b/ui/app/clinical/ordersTabInitialization.js @@ -3,7 +3,7 @@ angular.module('bahmni.clinical').factory('ordersTabInitialization', ['conceptSetService', 'spinner', function (conceptSetService, spinner) { return function () { - var allOrderables = spinner.forPromise(conceptSetService.getConcept({name: "All Orderables", v: "custom:(uuid,name:(display,uuid),names:(display,conceptNameType,name),set,setMembers:(uuid,name:(display,uuid),names:(display,conceptNameType,name),set,setMembers:(uuid,name:(display,uuid),names:(display,conceptNameType,name),set,conceptClass:(uuid,name,description),setMembers:(uuid,name:(display,uuid),names:(display,conceptNameType,name),set,conceptClass:(uuid,name,description),setMembers:(uuid,name:(display,uuid),names:(display,conceptNameType,name),set,conceptClass:(uuid,name,description))))))"})).then(function (response) { + var allOrderables = spinner.forPromise(conceptSetService.getConcept({name: "All Orderables", v: "custom:(uuid,name:(display,uuid,locale),names:(display,conceptNameType,name,locale),set,setMembers:(uuid,name:(display,uuid,locale),names:(display,conceptNameType,name,locale),set,setMembers:(uuid,name:(display,uuid,locale),names:(display,conceptNameType,name,locale),set,conceptClass:(uuid,name,description),setMembers:(uuid,name:(display,uuid,locale),names:(display,conceptNameType,name,locale),set,conceptClass:(uuid,name,description),setMembers:(uuid,name:(display,uuid,locale),names:(display,conceptNameType,name,locale),set,conceptClass:(uuid,name,description))))))"})).then(function (response) { var allOrderables = {}; _.forEach(response.data.results[0].setMembers, function (orderable) { var conceptName = _.find(orderable.names, {conceptNameType: "SHORT"}) || _.find(orderable.names, {conceptNameType: "FULLY_SPECIFIED"}); diff --git a/ui/app/home/controllers/loginController.js b/ui/app/home/controllers/loginController.js index 39c5122858..333415f3bb 100644 --- a/ui/app/home/controllers/loginController.js +++ b/ui/app/home/controllers/loginController.js @@ -72,6 +72,10 @@ angular.module('bahmni.home') }); }); + localeService.defaultLocale().then(function (response) { + localStorage.setItem("openmrsDefaultLocale", response.data || "en"); + }); + $scope.isSupportedBrowser = function () { var userAgent = $window.navigator.userAgent; if (userAgent.indexOf("Chrome") !== -1 || userAgent.indexOf("Firefox") !== -1) { diff --git a/ui/test/unit/home/controllers/loginController.spec.js b/ui/test/unit/home/controllers/loginController.spec.js index 196bb25516..b904371ba7 100644 --- a/ui/test/unit/home/controllers/loginController.spec.js +++ b/ui/test/unit/home/controllers/loginController.spec.js @@ -6,7 +6,7 @@ describe('loginController', function () { beforeEach(module('bahmni.home')); beforeEach(function () { - localeService = jasmine.createSpyObj('localeService', ['getLoginText', 'allowedLocalesList', 'serverDateTime', 'getLocalesLangs']); + localeService = jasmine.createSpyObj('localeService', ['getLoginText', 'allowedLocalesList', 'serverDateTime', 'getLocalesLangs', 'defaultLocale']); sessionService = jasmine.createSpyObj('sessionService', ['loginUser', 'loadCredentials', 'updateSession']); auditLogService = jasmine.createSpyObj('auditLogService', ['log']); currentUser = jasmine.createSpyObj('currentUser', ['addDefaultLocale', 'toContract']); @@ -24,6 +24,7 @@ describe('loginController', function () { localeService.getLocalesLangs.and.returnValue(specUtil.createFakePromise( {locales: [{code: "en", nativeName: "English"}, {code: "es", nativeName: "EspaƱol"}] })); + localeService.defaultLocale.and.returnValue(specUtil.simplePromise({data: "en"})); $bahmniCookieStore = jasmine.createSpyObj('$bahmniCookieStore', ['get', 'remove', 'put']); $bahmniCookieStore.get.and.callFake(function () { return {}; }); $window = jasmine.createSpyObj('$window', ['location']);