Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-4037 | Add. Configuration to support specifying orderTypeClassMap #988

Merged
merged 12 commits into from
Jul 23, 2024
Merged
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
Loading