'use strict'; angular.module('bahmni.common.domain') .factory('locationService', ['$http', '$bahmniCookieStore', function ($http, $bahmniCookieStore) { var getAllByTag = function (tags, operator) { return $http.get(Bahmni.Common.Constants.locationUrl, { params: {s: "byTags", tags: tags || "", v: "default", operator: operator || "ALL"}, cache: true }); }; var getByUuid = function (locationUuid) { return $http.get(Bahmni.Common.Constants.locationUrl + "/" + locationUuid, { cache: true }).then(function (response) { return response.data; }); }; var getLoggedInLocation = function () { var cookie = $bahmniCookieStore.get(Bahmni.Common.Constants.locationCookieName); return getByUuid(cookie.uuid); }; var getVisitLocation = function (locationUuid) { return $http.get(Bahmni.Common.Constants.bahmniVisitLocationUrl + "/" + locationUuid, { headers: {"Accept": "application/json"} }); }; return { getAllByTag: getAllByTag, getLoggedInLocation: getLoggedInLocation, getByUuid: getByUuid, getVisitLocation: getVisitLocation }; }]); 'use strict'; angular.module('bahmni.common.domain') .service('localeService', ['$http', function ($http) { this.allowedLocalesList = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'locale.allowed.list' }, withCredentials: true, headers: { Accept: 'text/plain' } }); }; this.defaultLocale = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'default_locale' }, withCredentials: true, headers: { Accept: 'text/plain' } }); }; this.serverDateTime = function () { return $http.get(Bahmni.Common.Constants.serverDateTimeUrl, { method: "GET", headers: { Accept: 'text/plain' } }); }; this.getLoginText = function () { return $http.get(Bahmni.Common.Constants.loginText, { method: "GET", headers: { Accept: 'text/plain' } }); }; this.getLocalesLangs = function () { return $http.get(Bahmni.Common.Constants.localeLangs, { method: "GET", headers: { Accept: 'text/plain' } }); }; }]); 'use strict'; angular.module('bahmni.common.domain') .factory('configurationService', ['$http', '$q', function ($http, $q) { var configurationFunctions = {}; configurationFunctions.encounterConfig = function () { return $http.get(Bahmni.Common.Constants.encounterConfigurationUrl, { params: {"callerContext": "REGISTRATION_CONCEPTS"}, withCredentials: true }); }; configurationFunctions.patientConfig = function () { var patientConfig = $http.get(Bahmni.Common.Constants.patientConfigurationUrl, { withCredentials: true }); return patientConfig; }; configurationFunctions.patientAttributesConfig = function () { return $http.get(Bahmni.Common.Constants.personAttributeTypeUrl, { params: {v: 'custom:(uuid,name,sortWeight,description,format,concept)'}, withCredentials: true }); }; configurationFunctions.dosageFrequencyConfig = function () { var dosageFrequencyConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.dosageFrequencyConceptName}, withCredentials: true }); return dosageFrequencyConfig; }; configurationFunctions.dosageInstructionConfig = function () { var dosageInstructionConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.dosageInstructionConceptName}, withCredentials: true }); return dosageInstructionConfig; }; configurationFunctions.stoppedOrderReasonConfig = function () { var stoppedOrderReasonConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.stoppedOrderReasonConceptName}, withCredentials: true }); return stoppedOrderReasonConfig; }; configurationFunctions.consultationNoteConfig = function () { var consultationNoteConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.consultationNoteConceptName}, withCredentials: true }); return consultationNoteConfig; }; configurationFunctions.radiologyObservationConfig = function () { var radiologyObservationConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: { v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.radiologyResultConceptName }, withCredentials: true }); return radiologyObservationConfig; }; configurationFunctions.labOrderNotesConfig = function () { var labOrderNotesConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.labOrderNotesConcept}, withCredentials: true }); return labOrderNotesConfig; }; configurationFunctions.defaultEncounterType = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { params: { property: 'bahmni.encounterType.default' }, withCredentials: true, transformResponse: [function (data) { return data; }] }); }; configurationFunctions.radiologyImpressionConfig = function () { var radiologyImpressionConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.impressionConcept}, withCredentials: true }); return radiologyImpressionConfig; }; configurationFunctions.addressLevels = function () { return $http.get(Bahmni.Common.Constants.openmrsUrl + "/module/addresshierarchy/ajax/getOrderedAddressHierarchyLevels.form", { withCredentials: true }); }; configurationFunctions.allTestsAndPanelsConcept = function () { var allTestsAndPanelsConcept = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: { v: 'custom:(uuid,name:(uuid,name),setMembers:(uuid,name:(uuid,name)))', name: Bahmni.Common.Constants.allTestsAndPanelsConceptName }, withCredentials: true }); return allTestsAndPanelsConcept; }; configurationFunctions.identifierTypesConfig = function () { return $http.get(Bahmni.Common.Constants.idgenConfigurationURL, { withCredentials: true }); }; configurationFunctions.genderMap = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'mrs.genders' }, withCredentials: true }); }; configurationFunctions.relationshipTypeMap = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'bahmni.relationshipTypeMap' }, withCredentials: true }); }; configurationFunctions.relationshipTypeConfig = function () { return $http.get(Bahmni.Common.Constants.relationshipTypesUrl, { withCredentials: true, params: {v: "custom:(aIsToB,bIsToA,uuid)"} }); }; configurationFunctions.loginLocationToVisitTypeMapping = function () { var url = Bahmni.Common.Constants.entityMappingUrl; return $http.get(url, { params: { mappingType: 'loginlocation_visittype', s: 'byEntityAndMappingType' } }); }; configurationFunctions.enableAuditLog = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'bahmni.enableAuditLog' }, withCredentials: true }); }; var existingPromises = {}; var configurations = {}; var getConfigurations = function (configurationNames) { var configurationsPromiseDefer = $q.defer(); var promises = []; configurationNames.forEach(function (configurationName) { if (!existingPromises[configurationName]) { existingPromises[configurationName] = configurationFunctions[configurationName]().then(function (response) { configurations[configurationName] = response.data; }); promises.push(existingPromises[configurationName]); } }); $q.all(promises).then(function () { configurationsPromiseDefer.resolve(configurations); }); return configurationsPromiseDefer.promise; }; return { getConfigurations: getConfigurations }; }]); 'use strict'; angular.module('bahmni.common.appFramework') .service('loadConfigService', ['$http', function ($http) { this.loadConfig = function (url) { return $http.get(url, {withCredentials: true}); }; }]); 'use strict'; angular.module('bahmni.common.logging') .service('loggingService', function () { var log = function (errorDetails) { $.ajax({ type: "POST", url: "/log", contentType: "application/json", data: angular.toJson(errorDetails) }); }; return { log: log }; }); 'use strict'; angular.module('bahmni.common.logging') .service('auditLogService', ['$http', '$translate', 'configurationService', function ($http, $translate, configurationService) { var DateUtil = Bahmni.Common.Util.DateUtil; var convertToLocalDate = function (date) { var localDate = DateUtil.parseLongDateToServerFormat(date); return DateUtil.getDateTimeInSpecifiedFormat(localDate, 'MMMM Do, YYYY [at] h:mm:ss A'); }; this.getLogs = function (params) { params = params || {}; return $http.get(Bahmni.Common.Constants.auditLogUrl, {params: params}).then(function (response) { return response.data.map(function (log) { log.dateCreated = convertToLocalDate(log.dateCreated); var entity = log.message ? log.message.split("~")[1] : undefined; log.params = entity ? JSON.parse(entity) : entity; log.message = log.message.split("~")[0]; log.displayMessage = $translate.instant(log.message, log); return log; }); }); }; this.log = function (patientUuid, eventType, messageParams, module) { return configurationService.getConfigurations(['enableAuditLog']).then(function (result) { if (result.enableAuditLog) { var params = {}; params.patientUuid = patientUuid; params.eventType = Bahmni.Common.AuditLogEventDetails[eventType].eventType; params.message = Bahmni.Common.AuditLogEventDetails[eventType].message; params.message = messageParams ? params.message + '~' + JSON.stringify(messageParams) : params.message; params.module = module; return $http.post(Bahmni.Common.Constants.auditLogUrl, params, {withCredentials: true}); } }); }; }]);