From 1e85fa7bc19f019b7f92cd143c65eee7330ff358 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Fri, 19 Jul 2024 12:09:07 +0530 Subject: [PATCH 01/12] BAH-4037 | Add. Configuration to support specifying orderTypeClassMap --- .../consultation/controllers/orderController.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index ebeee3f456..c2a4741339 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -150,7 +150,9 @@ angular.module('bahmni.clinical') $scope.activeTab.leftCategory = leftCategory; $scope.activeTab.leftCategory.klass = "active"; - $scope.activeTab.leftCategory.groups = $scope.getConceptClassesInSet(leftCategory); + var conceptClasses = $scope.getConceptClassesInSet(leftCategory); + var conceptClassesFilteredForOrderType = $scope.filterConceptClassesForOrderType(conceptClasses, $scope.activeTab.name); + $scope.activeTab.leftCategory.groups = conceptClassesFilteredForOrderType; }; $scope.getConceptClassesInSet = function (conceptSet) { @@ -163,6 +165,18 @@ angular.module('bahmni.clinical') return conceptClasses; }; + $scope.filterConceptClassesForOrderType = function (conceptClasses,orderTypeName) { + var orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); + var orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; + if (!_.isEmpty(orderTypeClassMap[orderTypeName])) { + return _.filter(conceptClasses, function (conceptClass) { + return _.includes(orderTypeClassMap[orderTypeName], conceptClass.name); + }); + } + return conceptClasses; + + } + $scope.$watchCollection('consultation.orders', $scope.updateSelectedOrdersForActiveTab); $scope.handleOrderClick = function (order) { From eb45549eb528fbf494843367a7858f58b78331e4 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Fri, 19 Jul 2024 12:28:20 +0530 Subject: [PATCH 02/12] BAH-4037 | Fix. Eslint errors --- ui/app/clinical/consultation/controllers/orderController.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index c2a4741339..dfaf3b99d5 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -165,7 +165,7 @@ angular.module('bahmni.clinical') return conceptClasses; }; - $scope.filterConceptClassesForOrderType = function (conceptClasses,orderTypeName) { + $scope.filterConceptClassesForOrderType = function (conceptClasses, orderTypeName) { var orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); var orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; if (!_.isEmpty(orderTypeClassMap[orderTypeName])) { @@ -174,8 +174,7 @@ angular.module('bahmni.clinical') }); } return conceptClasses; - - } + }; $scope.$watchCollection('consultation.orders', $scope.updateSelectedOrdersForActiveTab); From 240a77e0d777893ff7f4c1737ef90daf834dbba0 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Mon, 22 Jul 2024 23:18:56 +0530 Subject: [PATCH 03/12] BAH-4037 | Add. Set default locale in localStorage --- ui/app/home/controllers/loginController.js | 4 ++++ 1 file changed, 4 insertions(+) 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) { From b8ab8e4420b5969a3a52e6ea9bdedd168ab12415 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Mon, 22 Jul 2024 23:19:42 +0530 Subject: [PATCH 04/12] BAH-4037 | Refactor. Match config key by FSN in default locale --- .../controllers/orderController.js | 45 ++++++++++++------- ui/app/clinical/ordersTabInitialization.js | 2 +- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index dfaf3b99d5..cdd413ce6e 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -94,6 +94,8 @@ angular.module('bahmni.clinical') $scope.tabs = []; _.forEach($scope.allOrdersTemplates, function (item) { var conceptName = $scope.getName(item); + var key = '\'' + conceptName + '\''; + $scope.allOrdersTemplates[key] = $scope.filterOrderTemplateByClassMap(item); $scope.tabs.push({name: conceptName ? conceptName : item.name.name, topLevelConcept: item.name.name}); }); if ($scope.tabs) { @@ -145,14 +147,33 @@ angular.module('bahmni.clinical') return $scope.allOrdersTemplates[key]; }; + $scope.filterOrderTemplateByClassMap = function (orderTemplate) { + const orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); + const orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; + const orderTypeName = $scope.getNameInDefaultLocale(orderTemplate); + + if (orderTypeClassMap[orderTypeName]) { + const orderClasses = orderTypeClassMap[orderTypeName]; + let filteredOrderTemplate = angular.copy(orderTemplate); + + filteredOrderTemplate.setMembers = filteredOrderTemplate.setMembers + .map(category => { + category.setMembers = category.setMembers.filter(test => orderClasses.includes(test.conceptClass.name)); + return category; + }) + .filter(category => category.setMembers.length > 0); + + return filteredOrderTemplate; + } + + return orderTemplate; + }; + $scope.showLeftCategoryTests = function (leftCategory) { collapseExistingActiveSection($scope.activeTab.leftCategory); $scope.activeTab.leftCategory = leftCategory; $scope.activeTab.leftCategory.klass = "active"; - - var conceptClasses = $scope.getConceptClassesInSet(leftCategory); - var conceptClassesFilteredForOrderType = $scope.filterConceptClassesForOrderType(conceptClasses, $scope.activeTab.name); - $scope.activeTab.leftCategory.groups = conceptClassesFilteredForOrderType; + $scope.activeTab.leftCategory.groups = $scope.getConceptClassesInSet(leftCategory); }; $scope.getConceptClassesInSet = function (conceptSet) { @@ -165,17 +186,6 @@ angular.module('bahmni.clinical') return conceptClasses; }; - $scope.filterConceptClassesForOrderType = function (conceptClasses, orderTypeName) { - var orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); - var orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; - if (!_.isEmpty(orderTypeClassMap[orderTypeName])) { - return _.filter(conceptClasses, function (conceptClass) { - return _.includes(orderTypeClassMap[orderTypeName], conceptClass.name); - }); - } - return conceptClasses; - }; - $scope.$watchCollection('consultation.orders', $scope.updateSelectedOrdersForActiveTab); $scope.handleOrderClick = function (order) { @@ -288,5 +298,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; + }; + 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"}); From fed353f6f20d3724e624241a7cab0c05e878eb66 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Mon, 22 Jul 2024 23:27:57 +0530 Subject: [PATCH 05/12] BAH-4037 | Fix. Use var instead of let --- ui/app/clinical/consultation/controllers/orderController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index cdd413ce6e..9af4db4965 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -154,7 +154,7 @@ angular.module('bahmni.clinical') if (orderTypeClassMap[orderTypeName]) { const orderClasses = orderTypeClassMap[orderTypeName]; - let filteredOrderTemplate = angular.copy(orderTemplate); + var filteredOrderTemplate = angular.copy(orderTemplate); filteredOrderTemplate.setMembers = filteredOrderTemplate.setMembers .map(category => { From 8865a0099366750dd5e5ad03e556458a07f11d0c Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Mon, 22 Jul 2024 23:38:18 +0530 Subject: [PATCH 06/12] BAH-4037 | Fix. Use native function instead of arrow functions --- .../controllers/orderController.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index 9af4db4965..189aecbdb9 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -148,20 +148,24 @@ angular.module('bahmni.clinical') }; $scope.filterOrderTemplateByClassMap = function (orderTemplate) { - const orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); - const orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; - const orderTypeName = $scope.getNameInDefaultLocale(orderTemplate); + var orderTypeClassMapConfig = appService.getAppDescriptor().getConfig("orderTypeClassMap"); + var orderTypeClassMap = orderTypeClassMapConfig ? orderTypeClassMapConfig.value : {}; + var orderTypeName = $scope.getNameInDefaultLocale(orderTemplate); if (orderTypeClassMap[orderTypeName]) { - const orderClasses = orderTypeClassMap[orderTypeName]; + var orderClasses = orderTypeClassMap[orderTypeName]; var filteredOrderTemplate = angular.copy(orderTemplate); filteredOrderTemplate.setMembers = filteredOrderTemplate.setMembers - .map(category => { - category.setMembers = category.setMembers.filter(test => orderClasses.includes(test.conceptClass.name)); + .map(function (category) { + category.setMembers = category.setMembers.filter(function (test) { + return orderClasses.includes(test.conceptClass.name); + }); return category; }) - .filter(category => category.setMembers.length > 0); + .filter(function (category) { + return category.setMembers.length > 0; + }); return filteredOrderTemplate; } From 664f5c689ce94b3bdcf698d5f147f15070016b2c Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 05:56:31 +0530 Subject: [PATCH 07/12] BAH-4037 | Fix. Tests by mocking defaultLocale --- ui/test/unit/home/controllers/loginController.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/test/unit/home/controllers/loginController.spec.js b/ui/test/unit/home/controllers/loginController.spec.js index 196bb25516..f40ef8d880 100644 --- a/ui/test/unit/home/controllers/loginController.spec.js +++ b/ui/test/unit/home/controllers/loginController.spec.js @@ -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']); From 43697fbb02f99bc2e947c811ff0cb9e08d758193 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 06:20:41 +0530 Subject: [PATCH 08/12] BAH-4037 | WIP. Debug tests --- ui/test/unit/clinical/controllers/orderController.spec.js | 1 + ui/test/unit/home/controllers/loginController.spec.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/test/unit/clinical/controllers/orderController.spec.js b/ui/test/unit/clinical/controllers/orderController.spec.js index 64cd118a91..403e5b4a15 100644 --- a/ui/test/unit/clinical/controllers/orderController.spec.js +++ b/ui/test/unit/clinical/controllers/orderController.spec.js @@ -54,6 +54,7 @@ describe("OrderController", function () { it("should fetch ordersConfig and set in tabs", function () { scope.$digest(); + console.log(scope.tabs); expect(scope.tabs.length).toBe(2); expect(scope.tabs[0].name).toBe("Lab Samples"); expect(scope.tabs[0].topLevelConcept).toBe("Lab Samples"); diff --git a/ui/test/unit/home/controllers/loginController.spec.js b/ui/test/unit/home/controllers/loginController.spec.js index f40ef8d880..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']); From 27748ce0c4ff4dd71d377215a2ff7b0aa6670571 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 07:21:01 +0530 Subject: [PATCH 09/12] BAH-4037 | Fx. Flaky test by checking for name --- .../clinical/consultation/controllers/orderController.js | 7 ++++--- ui/test/unit/clinical/controllers/orderController.spec.js | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index 189aecbdb9..af7b7a3f47 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -94,9 +94,10 @@ angular.module('bahmni.clinical') $scope.tabs = []; _.forEach($scope.allOrdersTemplates, function (item) { var conceptName = $scope.getName(item); - var key = '\'' + conceptName + '\''; + var tabName = conceptName ? conceptName : item.name.name + var key = '\'' + tabName + '\''; $scope.allOrdersTemplates[key] = $scope.filterOrderTemplateByClassMap(item); - $scope.tabs.push({name: conceptName ? conceptName : item.name.name, topLevelConcept: item.name.name}); + $scope.tabs.push({name: tabName, topLevelConcept: item.name.name}); }); if ($scope.tabs) { $scope.activateTab($scope.tabs[0]); @@ -304,7 +305,7 @@ angular.module('bahmni.clinical') $scope.getNameInDefaultLocale = function (sample) { var name = _.find(sample.names, { conceptNameType: "FULLY_SPECIFIED", locale: localStorage.getItem("openmrsDefaultLocale") || "en" }); - return name && name.name; + return name ? name.name : sample.name.name; }; init(); diff --git a/ui/test/unit/clinical/controllers/orderController.spec.js b/ui/test/unit/clinical/controllers/orderController.spec.js index 403e5b4a15..64cd118a91 100644 --- a/ui/test/unit/clinical/controllers/orderController.spec.js +++ b/ui/test/unit/clinical/controllers/orderController.spec.js @@ -54,7 +54,6 @@ describe("OrderController", function () { it("should fetch ordersConfig and set in tabs", function () { scope.$digest(); - console.log(scope.tabs); expect(scope.tabs.length).toBe(2); expect(scope.tabs[0].name).toBe("Lab Samples"); expect(scope.tabs[0].topLevelConcept).toBe("Lab Samples"); From 2e522f28cf4e7447d82d6e09df486eaa5b997979 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 07:22:20 +0530 Subject: [PATCH 10/12] BAH-4037 | Fix. Remove filtering order category by orderable count --- ui/app/clinical/consultation/controllers/orderController.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index af7b7a3f47..46e8a793f6 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -163,9 +163,6 @@ angular.module('bahmni.clinical') return orderClasses.includes(test.conceptClass.name); }); return category; - }) - .filter(function (category) { - return category.setMembers.length > 0; }); return filteredOrderTemplate; From 6d1a8749dc9c40acdcb05ce6162c1ae94e1600ad Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 07:29:55 +0530 Subject: [PATCH 11/12] BAH-4037 | Fix. esLint --- ui/app/clinical/consultation/controllers/orderController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index 46e8a793f6..dba787f1b2 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -94,7 +94,7 @@ angular.module('bahmni.clinical') $scope.tabs = []; _.forEach($scope.allOrdersTemplates, function (item) { var conceptName = $scope.getName(item); - var tabName = conceptName ? conceptName : item.name.name + var tabName = conceptName ? conceptName : item.name.name; var key = '\'' + tabName + '\''; $scope.allOrdersTemplates[key] = $scope.filterOrderTemplateByClassMap(item); $scope.tabs.push({name: tabName, topLevelConcept: item.name.name}); From 6f807b890c364154acbe693a69934d229a86129b Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 23 Jul 2024 09:21:42 +0530 Subject: [PATCH 12/12] BAH-4037 | Refactor. Remove redundant ternary operator --- ui/app/clinical/consultation/controllers/orderController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index dba787f1b2..26cb898c8e 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -94,7 +94,7 @@ angular.module('bahmni.clinical') $scope.tabs = []; _.forEach($scope.allOrdersTemplates, function (item) { var conceptName = $scope.getName(item); - var tabName = conceptName ? conceptName : 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});