1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
"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.registration").service("patientServiceStrategy",["$http","$q","$rootScope",function($http,$q,$rootScope){var openmrsUrl=Bahmni.Registration.Constants.openmrsUrl,baseOpenMRSRESTURL=Bahmni.Registration.Constants.baseOpenMRSRESTURL,search=function(config){var defer=$q.defer(),patientSearchUrl=Bahmni.Common.Constants.bahmniSearchUrl+"/patient";config&&config.params.identifier&&(patientSearchUrl=Bahmni.Common.Constants.bahmniSearchUrl+"/patient/lucene");var onResults=function(result){defer.resolve(result)};return $http.get(patientSearchUrl,config).success(onResults).error(function(error){defer.reject(error)}),defer.promise},getByUuid=function(uuid){var url=openmrsUrl+"/ws/rest/v1/patientprofile/"+uuid,config={method:"GET",params:{v:"full"},withCredentials:!0},defer=$q.defer();return $http.get(url,config).success(function(result){defer.resolve(result)}),defer.promise},create=function(patient,jumpAccepted){var data=new Bahmni.Registration.CreatePatientRequestMapper(moment()).mapFromPatient($rootScope.patientConfiguration.attributeTypes,patient),url=baseOpenMRSRESTURL+"/bahmnicore/patientprofile";return $http.post(url,data,{withCredentials:!0,headers:{Accept:"application/json","Content-Type":"application/json","Jump-Accepted":jumpAccepted}})},update=function(patient,openMRSPatient,attributeTypes){var deferred=$q.defer(),data=new Bahmni.Registration.UpdatePatientRequestMapper(moment()).mapFromPatient(attributeTypes,openMRSPatient,patient),url=baseOpenMRSRESTURL+"/bahmnicore/patientprofile/"+openMRSPatient.uuid,config={withCredentials:!0,headers:{Accept:"application/json","Content-Type":"application/json"}};return $http.post(url,data,config).then(function(result){deferred.resolve(result)},function(reason){deferred.resolve(reason)}),deferred.promise},generateIdentifier=function(patient){var data={identifierSourceName:patient.identifierPrefix?patient.identifierPrefix.prefix:""},url=openmrsUrl+"/ws/rest/v1/idgen",config={withCredentials:!0,headers:{Accept:"text/plain","Content-Type":"application/json"}};return $http.post(url,data,config)};return{search:search,get:getByUuid,create:create,update:update,generateIdentifier:generateIdentifier}}]),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.domain").service("visitService",["$http",function($http){this.getVisit=function(uuid,params){var parameters=params?params:"custom:(uuid,visitId,visitType,patient,encounters:(uuid,encounterType,voided,orders:(uuid,orderType,voided,concept:(uuid,set,name),),obs:(uuid,value,concept,obsDatetime,groupMembers:(uuid,concept:(uuid,name),obsDatetime,value:(uuid,name),groupMembers:(uuid,concept:(uuid,name),value:(uuid,name),groupMembers:(uuid,concept:(uuid,name),value:(uuid,name)))))))";return $http.get(Bahmni.Common.Constants.visitUrl+"/"+uuid,{params:{v:parameters}})},this.endVisit=function(visitUuid){return $http.post(Bahmni.Common.Constants.endVisitUrl+"?visitUuid="+visitUuid,{withCredentials:!0})},this.endVisitAndCreateEncounter=function(visitUuid,bahmniEncounterTransaction){return $http.post(Bahmni.Common.Constants.endVisitAndCreateEncounterUrl+"?visitUuid="+visitUuid,bahmniEncounterTransaction,{withCredentials:!0})},this.updateVisit=function(visitUuid,attributes){return $http.post(Bahmni.Common.Constants.visitUrl+"/"+visitUuid,attributes,{withCredentials:!0})},this.createVisit=function(visitDetails){return $http.post(Bahmni.Common.Constants.visitUrl,visitDetails,{withCredentials:!0})},this.getVisitSummary=function(visitUuid){return $http.get(Bahmni.Common.Constants.visitSummaryUrl,{params:{visitUuid:visitUuid},withCredentials:!0})},this.search=function(parameters){return $http.get(Bahmni.Common.Constants.visitUrl,{params:parameters,withCredentials:!0})},this.getVisitType=function(){return $http.get(Bahmni.Common.Constants.visitTypeUrl,{withCredentials:!0})}}]),Bahmni.Common.Util.DateTimeFormatter={getDateWithoutTime:function(datetime){return datetime?moment(datetime).format("YYYY-MM-DD"):null}},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.domain").service("observationsService",["$http",function($http){this.fetch=function(patientUuid,conceptNames,scope,numberOfVisits,visitUuid,obsIgnoreList,filterObsWithOrders,patientProgramUuid){var params={concept:conceptNames};return obsIgnoreList&&(params.obsIgnoreList=obsIgnoreList),null!=filterObsWithOrders&&(params.filterObsWithOrders=filterObsWithOrders),visitUuid?(params.visitUuid=visitUuid,params.scope=scope):(params.patientUuid=patientUuid,params.numberOfVisits=numberOfVisits,params.scope=scope,params.patientProgramUuid=patientProgramUuid),$http.get(Bahmni.Common.Constants.observationsUrl,{params:params,withCredentials:!0})},this.getByUuid=function(observationUuid){return $http.get(Bahmni.Common.Constants.observationsUrl,{params:{observationUuid:observationUuid},withCredentials:!0})},this.getRevisedObsByUuid=function(observationUuid){return $http.get(Bahmni.Common.Constants.observationsUrl,{params:{observationUuid:observationUuid,revision:"latest"},withCredentials:!0})},this.fetchForEncounter=function(encounterUuid,conceptNames){return $http.get(Bahmni.Common.Constants.observationsUrl,{params:{encounterUuid:encounterUuid,concept:conceptNames},withCredentials:!0})},this.fetchForPatientProgram=function(patientProgramUuid,conceptNames,scope,obsIgnoreList){return $http.get(Bahmni.Common.Constants.observationsUrl,{params:{patientProgramUuid:patientProgramUuid,concept:conceptNames,scope:scope,obsIgnoreList:obsIgnoreList},withCredentials:!0})},this.getObsRelationship=function(targetObsUuid){return $http.get(Bahmni.Common.Constants.obsRelationshipUrl,{params:{targetObsUuid:targetObsUuid},withCredentials:!0})},this.getObsInFlowSheet=function(patientUuid,conceptSet,groupByConcept,orderByConcept,conceptNames,numberOfVisits,initialCount,latestCount,groovyExtension,startDate,endDate,patientProgramUuid,formNames){var params={patientUuid:patientUuid,conceptSet:conceptSet,groupByConcept:groupByConcept,orderByConcept:orderByConcept,conceptNames:conceptNames,numberOfVisits:numberOfVisits,initialCount:initialCount,latestCount:latestCount,name:groovyExtension,startDate:Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(startDate),endDate:Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(endDate),enrollment:patientProgramUuid,formNames:formNames};return $http.get(Bahmni.Common.Constants.observationsUrl+"/flowSheet",{params:params,withCredentials:!0})}}]),angular.module("bahmni.common.domain").service("encounterService",["$http","$q","$rootScope","configurations","$bahmniCookieStore",function($http,$q,$rootScope,configurations,$bahmniCookieStore){function isObsConceptClassVideoOrImage(obs){return"Video"===obs.concept.conceptClass||"Image"===obs.concept.conceptClass}this.buildEncounter=function(encounter){encounter.observations=encounter.observations||[],encounter.observations.forEach(function(obs){stripExtraConceptInfo(obs)});var bacterilogyMembers=getBacteriologyGroupMembers(encounter);bacterilogyMembers=bacterilogyMembers.reduce(function(mem1,mem2){return mem1.concat(mem2)},[]),bacterilogyMembers.forEach(function(mem){deleteIfImageOrVideoObsIsVoided(mem)}),encounter.providers=encounter.providers||[];var providerData=$bahmniCookieStore.get(Bahmni.Common.Constants.grantProviderAccessDataCookieName);return _.isEmpty(encounter.providers)&&(providerData&&providerData.uuid?encounter.providers.push({uuid:providerData.uuid}):$rootScope.currentProvider&&$rootScope.currentProvider.uuid&&encounter.providers.push({uuid:$rootScope.currentProvider.uuid})),encounter};var getBacteriologyGroupMembers=function(encounter){var addBacteriologyMember=function(bacteriologyGroupMembers,member){return bacteriologyGroupMembers=member.groupMembers.length?bacteriologyGroupMembers.concat(member.groupMembers):bacteriologyGroupMembers.concat(member)};return encounter.extensions&&encounter.extensions.mdrtbSpecimen?encounter.extensions.mdrtbSpecimen.map(function(observation){var bacteriologyGroupMembers=[];return observation.sample.additionalAttributes&&observation.sample.additionalAttributes.groupMembers.forEach(function(member){bacteriologyGroupMembers=addBacteriologyMember(bacteriologyGroupMembers,member)}),observation.report.results&&observation.report.results.groupMembers.forEach(function(member){bacteriologyGroupMembers=addBacteriologyMember(bacteriologyGroupMembers,member)}),bacteriologyGroupMembers}):[]},getDefaultEncounterType=function(){var url=Bahmni.Common.Constants.encounterTypeUrl;return $http.get(url+"/"+configurations.defaultEncounterType()).then(function(response){return response.data})},getEncounterTypeBasedOnLoginLocation=function(loginLocationUuid){return $http.get(Bahmni.Common.Constants.entityMappingUrl,{params:{entityUuid:loginLocationUuid,mappingType:"location_encountertype",s:"byEntityAndMappingType"},withCredentials:!0})},getEncounterTypeBasedOnProgramUuid=function(programUuid){return $http.get(Bahmni.Common.Constants.entityMappingUrl,{params:{entityUuid:programUuid,mappingType:"program_encountertype",s:"byEntityAndMappingType"},withCredentials:!0})},getDefaultEncounterTypeIfMappingNotFound=function(entityMappings){var encounterType=entityMappings.data.results[0]&&entityMappings.data.results[0].mappings[0];return encounterType||(encounterType=getDefaultEncounterType()),encounterType};this.getEncounterType=function(programUuid,loginLocationUuid){return programUuid?getEncounterTypeBasedOnProgramUuid(programUuid).then(function(response){return getDefaultEncounterTypeIfMappingNotFound(response)}):loginLocationUuid?getEncounterTypeBasedOnLoginLocation(loginLocationUuid).then(function(response){return getDefaultEncounterTypeIfMappingNotFound(response)}):getDefaultEncounterType()},this.create=function(encounter){return encounter=this.buildEncounter(encounter),$http.post(Bahmni.Common.Constants.bahmniEncounterUrl,encounter,{withCredentials:!0})},this.delete=function(encounterUuid,reason){return $http.delete(Bahmni.Common.Constants.bahmniEncounterUrl+"/"+encounterUuid,{params:{reason:reason}})};var deleteIfImageOrVideoObsIsVoided=function(obs){if(obs.voided&&obs.groupMembers&&!obs.groupMembers.length&&obs.value&&isObsConceptClassVideoOrImage(obs)){var url=Bahmni.Common.Constants.RESTWS_V1+"/bahmnicore/visitDocument?filename="+obs.value;$http.delete(url,{withCredentials:!0})}},stripExtraConceptInfo=function(obs){deleteIfImageOrVideoObsIsVoided(obs),obs.concept={uuid:obs.concept.uuid,name:obs.concept.name,dataType:obs.concept.dataType},obs.groupMembers=obs.groupMembers||[],obs.groupMembers.forEach(function(groupMember){stripExtraConceptInfo(groupMember)})},searchWithoutEncounterDate=function(visitUuid){return $http.post(Bahmni.Common.Constants.bahmniEncounterUrl+"/find",{visitUuids:[visitUuid],includeAll:Bahmni.Common.Constants.includeAllObservations},{withCredentials:!0})};this.search=function(visitUuid,encounterDate){return encounterDate?$http.get(Bahmni.Common.Constants.emrEncounterUrl,{params:{visitUuid:visitUuid,encounterDate:encounterDate,includeAll:Bahmni.Common.Constants.includeAllObservations},withCredentials:!0}):searchWithoutEncounterDate(visitUuid)},this.find=function(params){return $http.post(Bahmni.Common.Constants.bahmniEncounterUrl+"/find",params,{withCredentials:!0})},this.findByEncounterUuid=function(encounterUuid,params){return params=params||{includeAll:!0},$http.get(Bahmni.Common.Constants.bahmniEncounterUrl+"/"+encounterUuid,{params:params,withCredentials:!0})},this.getEncountersForEncounterType=function(patientUuid,encounterTypeUuid){return $http.get(Bahmni.Common.Constants.encounterUrl,{params:{patient:patientUuid,encounterType:encounterTypeUuid,v:"custom:(uuid,provider,visit:(uuid,startDatetime,stopDatetime),obs:(uuid,concept:(uuid,name),groupMembers:(id,uuid,obsDatetime,value,comment)))"},withCredentials:!0})},this.getDigitized=function(patientUuid){var patientDocumentEncounterTypeUuid=configurations.encounterConfig().getPatientDocumentEncounterTypeUuid();return $http.get(Bahmni.Common.Constants.encounterUrl,{params:{patient:patientUuid,encounterType:patientDocumentEncounterTypeUuid,v:"custom:(uuid,obs:(uuid))"},withCredentials:!0})},this.discharge=function(encounterData){var encounter=this.buildEncounter(encounterData);return $http.post(Bahmni.Common.Constants.dischargeUrl,encounter,{withCredentials:!0})}}]),angular.module("bahmni.common.conceptSet").factory("conceptSetService",["$http","$q","$bahmniTranslate",function($http,$q,$bahmniTranslate){var getConcept=function(params,cache){return params.locale=params.locale||$bahmniTranslate.use(),$http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl,{params:params,cache:cache})},getComputedValue=function(encounterData){var url=Bahmni.Common.Constants.encounterModifierUrl;return $http.post(url,encounterData,{withCredentials:!0,headers:{Accept:"application/json","Content-Type":"application/json"}})},getObsTemplatesForProgram=function(programUuid){var url=Bahmni.Common.Constants.entityMappingUrl;return $http.get(url,{params:{entityUuid:programUuid,mappingType:"program_obstemplate",s:"byEntityAndMappingType"}})};return{getConcept:getConcept,getComputedValue:getComputedValue,getObsTemplatesForProgram:getObsTemplatesForProgram}}]),Bahmni.Registration.StateNameEvenTypeMap={search:"VIEWED_REGISTRATION_PATIENT_SEARCH",newpatient:"VIEWED_NEW_PATIENT_PAGE","newpatient.save":"REGISTER_NEW_PATIENT","patient.edit":"EDIT_PATIENT_DETAILS","patient.visit":"ACCESSED_REGISTRATION_SECOND_PAGE","patient.view":"VIEWED_PATIENT_DETAILS","patient.printSticker":"PRINT_PATIENT_STICKER"},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})}})}}]); |