"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:!0})},getByUuid=function(locationUuid){return $http.get(Bahmni.Common.Constants.locationUrl+"/"+locationUuid,{cache:!0}).then(function(response){return response.data})},getLoggedInLocation=function(){var cookie=$bahmniCookieStore.get(Bahmni.Common.Constants.locationCookieName);return getByUuid(cookie.uuid)},getVisitLocation=function(locationUuid){return $http.get(Bahmni.Common.Constants.bahmniVisitLocationUrl+"/"+locationUuid,{headers:{Accept:"application/json"}})};return{getAllByTag:getAllByTag,getLoggedInLocation:getLoggedInLocation,getByUuid:getByUuid,getVisitLocation:getVisitLocation}}]),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:!0,headers:{Accept:"text/plain"}})},this.defaultLocale=function(){return $http.get(Bahmni.Common.Constants.globalPropertyUrl,{method:"GET",params:{property:"default_locale"},withCredentials:!0,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"}})}}]),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:!0})},configurationFunctions.patientConfig=function(){var patientConfig=$http.get(Bahmni.Common.Constants.patientConfigurationUrl,{withCredentials:!0});return patientConfig},configurationFunctions.patientAttributesConfig=function(){return $http.get(Bahmni.Common.Constants.personAttributeTypeUrl,{params:{v:"custom:(uuid,name,sortWeight,description,format,concept)"},withCredentials:!0})},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:!0});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:!0});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:!0});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:!0});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:!0});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:!0});return labOrderNotesConfig},configurationFunctions.defaultEncounterType=function(){return $http.get(Bahmni.Common.Constants.globalPropertyUrl,{params:{property:"bahmni.encounterType.default"},withCredentials:!0,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:!0});return radiologyImpressionConfig},configurationFunctions.addressLevels=function(){return $http.get(Bahmni.Common.Constants.openmrsUrl+"/module/addresshierarchy/ajax/getOrderedAddressHierarchyLevels.form",{withCredentials:!0})},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:!0});return allTestsAndPanelsConcept},configurationFunctions.identifierTypesConfig=function(){return $http.get(Bahmni.Common.Constants.idgenConfigurationURL,{withCredentials:!0})},configurationFunctions.genderMap=function(){return $http.get(Bahmni.Common.Constants.globalPropertyUrl,{method:"GET",params:{property:"mrs.genders"},withCredentials:!0})},configurationFunctions.relationshipTypeMap=function(){return $http.get(Bahmni.Common.Constants.globalPropertyUrl,{method:"GET",params:{property:"bahmni.relationshipTypeMap"},withCredentials:!0})},configurationFunctions.relationshipTypeConfig=function(){return $http.get(Bahmni.Common.Constants.relationshipTypesUrl,{withCredentials:!0,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:!0})};var existingPromises={},configurations={},getConfigurations=function(configurationNames){var configurationsPromiseDefer=$q.defer(),promises=[];return configurationNames.forEach(function(configurationName){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)}),configurationsPromiseDefer.promise};return{getConfigurations:getConfigurations}}]),angular.module("bahmni.common.appFramework").service("loadConfigService",["$http",function($http){this.loadConfig=function(url){return $http.get(url,{withCredentials:!0})}}]),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}}),angular.module("bahmni.common.logging").service("auditLogService",["$http","$translate","configurationService",function($http,$translate,configurationService){var DateUtil=Bahmni.Common.Util.DateUtil,convertToLocalDate=function(date){var localDate=DateUtil.parseLongDateToServerFormat(date);return DateUtil.getDateTimeInSpecifiedFormat(localDate,"MMMM Do, YYYY [at] h:mm:ss A")};this.getLogs=function(params){return params=params||{},$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]:void 0;return log.params=entity?JSON.parse(entity):entity,log.message=log.message.split("~")[0],log.displayMessage=$translate.instant(log.message,log),log})})},this.log=function(patientUuid,eventType,messageParams,module){return configurationService.getConfigurations(["enableAuditLog"]).then(function(result){if(result.enableAuditLog){var params={};return 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,$http.post(Bahmni.Common.Constants.auditLogUrl,params,{withCredentials:!0})}})}}]);