Skip to content

Commit

Permalink
BAH-4037 | Add. Configuration to support specifying orderTypeClassMap (
Browse files Browse the repository at this point in the history
…#988)

* BAH-4037 | Add. Configuration to support specifying orderTypeClassMap

* BAH-4037 | Fix. Eslint errors

* BAH-4037 | Add. Set default locale in localStorage

* BAH-4037 | Refactor. Match config key by FSN in default locale

* BAH-4037 | Fix. Use var instead of let

* BAH-4037 | Fix. Use native function instead of arrow functions

* BAH-4037 | Fix. Tests by mocking defaultLocale

* BAH-4037 | WIP. Debug tests

* BAH-4037 | Fx. Flaky test by checking for name

* BAH-4037 | Fix. Remove filtering order category by orderable count

* BAH-4037 | Fix. esLint

* BAH-4037 | Refactor. Remove redundant ternary operator
  • Loading branch information
mohan-13 authored Jul 23, 2024
1 parent d2650be commit 7e687c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
34 changes: 32 additions & 2 deletions ui/app/clinical/consultation/controllers/orderController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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();
}]);
2 changes: 1 addition & 1 deletion ui/app/clinical/ordersTabInitialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down
4 changes: 4 additions & 0 deletions ui/app/home/controllers/loginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion ui/test/unit/home/controllers/loginController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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']);
Expand Down

0 comments on commit 7e687c1

Please sign in to comment.