NINS_CODE/bahmniapps/document-upload/document-upload.min.74e3c13a.js

5 lines
138 KiB
JavaScript
Raw Permalink Normal View History

2024-12-12 22:37:39 +06:00
"use strict";angular.module("bahmni.common.routeErrorHandler",["ui.router"]).run(["$rootScope",function($rootScope){$rootScope.$on("$stateChangeError",function(event){event.preventDefault()})}]),angular.module("httpErrorInterceptor",[]).config(["$httpProvider",function($httpProvider){var interceptor=["$rootScope","$q",function($rootScope,$q){function stringAfter(value,searchString){var indexOfFirstColon=value.indexOf(searchString);return value.substr(indexOfFirstColon+1).trim()}function getServerError(message){return stringAfter(message,":")}function success(response){return response}function shouldRedirectToLogin(response){var errorMessage=response.data.error?response.data.error.message:response.data;if(errorMessage.search("HTTP Status 403 - Session timed out")>0)return!0}function error(response){var data=response.data,unexpectedError="There was an unexpected issue on the server. Please try again";if(500===response.status){var errorMessage=data.error&&data.error.message?getServerError(data.error.message):unexpectedError;showError(errorMessage)}else if(409===response.status){var errorMessage=data.error&&data.error.message?getServerError(data.error.message):"Duplicate entry error";showError(errorMessage)}else if(0===response.status)showError("Could not connect to the server. Please check your connection and try again");else if(405===response.status)showError(unexpectedError);else if(400===response.status){var errorMessage=data.error&&data.error.message?data.error.message:data.localizedMessage||"Could not connect to the server. Please check your connection and try again";showError(errorMessage)}else if(403===response.status){var errorMessage=data.error&&data.error.message?data.error.message:unexpectedError;shouldRedirectToLogin(response)?$rootScope.$broadcast("event:auth-loginRequired"):showError(errorMessage)}else 404===response.status&&(_.includes(response.config.url,"implementation_config")||_.includes(response.config.url,"locale_")||_.includes(response.config.url,"offlineMetadata")||showError("The requested information does not exist"));return $q.reject(response)}var serverErrorMessages=Bahmni.Common.Constants.serverErrorMessages,showError=function(errorMessage){var result=_.find(serverErrorMessages,function(listItem){return listItem.serverMessage===errorMessage});_.isEmpty(result)&&$rootScope.$broadcast("event:serverError",errorMessage)};return{response:success,responseError:error}}];$httpProvider.interceptors.push(interceptor)}]);var Bahmni=Bahmni||{};Bahmni.Common=Bahmni.Common||{},Bahmni.Common.Models=Bahmni.Common.Models||{},angular.module("bahmni.common.models",[]);var Bahmni=Bahmni||{};Bahmni.Auth=Bahmni.Auth||{},angular.module("authentication",["ui.router"]),Bahmni.Auth.User=function(user){angular.extend(this,user),this.userProperties=user.userProperties||{},this.favouriteObsTemplates=this.userProperties.favouriteObsTemplates?this.userProperties.favouriteObsTemplates.split("###"):[],this.favouriteWards=this.userProperties.favouriteWards?this.userProperties.favouriteWards.split("###"):[],this.recentlyViewedPatients=this.userProperties.recentlyViewedPatients?JSON.parse(this.userProperties.recentlyViewedPatients):[],this.toContract=function(){var user=angular.copy(this);return user.userProperties.favouriteObsTemplates=this.favouriteObsTemplates.join("###"),user.userProperties.favouriteWards=this.favouriteWards.join("###"),user.userProperties.recentlyViewedPatients=JSON.stringify(this.recentlyViewedPatients),delete user.favouriteObsTemplates,delete user.favouriteWards,delete user.recentlyViewedPatients,user},this.addDefaultLocale=function(locale){this.userProperties.defaultLocale=locale},this.addToRecentlyViewed=function(patient,maxPatients){_.some(this.recentlyViewedPatients,{uuid:patient.uuid})||(this.recentlyViewedPatients.unshift({uuid:patient.uuid,name:patient.name,identifier:patient.identifier}),_.size(this.recentlyViewedPatients)>=maxPatients&&(this.recentlyViewedPatients=_.take(this.recentlyViewedPatients,maxPatients)))},this.isFavouriteObsTemplate=function(conceptName){return _.includes(this.favouriteObsT
"/openmrs/ws/rest/v1/entitymapping?mappingType=loginlocation_visittype&s=byEntityAndMappingType":"LoginLocationToVisitTypeMapping","/openmrs/ws/rest/v1/bahmnicore/config/patient":"PatientConfig","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Consultation+Note&v=custom:(uuid,name,answers)":"ConsultationNote","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Lab+Order+Notes&v=custom:(uuid,name)":"LabOrderNotes","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Impression&v=custom:(uuid,name)":"RadiologyImpressionConfig","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=All_Tests_and_Panels&v=custom:(uuid,name:(uuid,name),setMembers:(uuid,name:(uuid,name)))":"AllTestsAndPanelsConcept","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Dosage+Frequency&v=custom:(uuid,name,answers)":"DosageFrequencyConfig","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Dosage+Instructions&v=custom:(uuid,name,answers)":"DosageInstructionConfig","/openmrs/ws/rest/v1/bahmnicore/sql/globalproperty?property=bahmni.encounterType.default":"DefaultEncounterType","/openmrs/ws/rest/v1/concept?s=byFullySpecifiedName&name=Stopped+Order+Reason&v=custom:(uuid,name,answers)":"StoppedOrderReasonConfig","/openmrs/ws/rest/v1/ordertype":"OrderType","/openmrs/ws/rest/v1/bahmnicore/config/drugOrders":"DrugOrderConfig","/openmrs/ws/rest/v1/bahmnicore/sql/globalproperty?property=drugOrder.drugOther":"NonCodedDrugConcept"};authenticatedReferenceDataMap["/openmrs/ws/rest/v1/entitymapping?mappingType=location_encountertype&s=byEntityAndMappingType&entityUuid="+(localStorage.getItem("LoginInformation")?JSON.parse(localStorage.getItem("LoginInformation")).currentLocation.uuid:"")]="LoginLocationToEncounterTypeMapping",Bahmni.Common.Constants={hostURL:hostUrl,dateFormat:"dd/mm/yyyy",dateDisplayFormat:"DD-MMM-YYYY",timeDisplayFormat:"hh:mm",emrapiDiagnosisUrl:EMRAPI+"/diagnosis",bahmniDiagnosisUrl:BAHMNI_CORE+"/diagnosis/search",bahmniDeleteDiagnosisUrl:BAHMNI_CORE+"/diagnosis/delete",diseaseTemplateUrl:BAHMNI_CORE+"/diseaseTemplates",AllDiseaseTemplateUrl:BAHMNI_CORE+"/diseaseTemplate",emrapiConceptUrl:EMRAPI+"/concept",encounterConfigurationUrl:BAHMNI_CORE+"/config/bahmniencounter",patientConfigurationUrl:BAHMNI_CORE+"/config/patient",drugOrderConfigurationUrl:BAHMNI_CORE+"/config/drugOrders",emrEncounterUrl:EMRAPI+"/encounter",encounterUrl:RESTWS_V1+"/encounter",locationUrl:RESTWS_V1+"/location",bahmniVisitLocationUrl:BAHMNI_CORE+"/visitLocation",bahmniOrderUrl:BAHMNI_CORE+"/orders",bahmniDrugOrderUrl:BAHMNI_CORE+"/drugOrders",bahmniDispositionByVisitUrl:BAHMNI_CORE+"/disposition/visitWithLocale",bahmniDispositionByPatientUrl:BAHMNI_CORE+"/disposition/patientWithLocale",bahmniSearchUrl:BAHMNI_CORE+"/search",bahmniLabOrderResultsUrl:BAHMNI_CORE+"/labOrderResults",bahmniEncounterUrl:BAHMNI_CORE+"/bahmniencounter",conceptUrl:RESTWS_V1+"/concept",bahmniConceptAnswerUrl:RESTWS_V1+"/bahmniconceptanswer",conceptSearchByFullNameUrl:RESTWS_V1+"/concept?s=byFullySpecifiedName",visitUrl:RESTWS_V1+"/visit",endVisitUrl:BAHMNI_CORE+"/visit/endVisit",endVisitAndCreateEncounterUrl:BAHMNI_CORE+"/visit/endVisitAndCreateEncounter",visitTypeUrl:RESTWS_V1+"/visittype",patientImageUrlByPatientUuid:RESTWS_V1+"/patientImage?patientUuid=",labResultUploadedFileNameUrl:"/uploaded_results/",visitSummaryUrl:BAHMNI_CORE+"/visit/summary",encounterModifierUrl:BAHMNI_CORE+"/bahmniencountermodifier",openmrsUrl:hostUrl+"/openmrs",loggingUrl:hostUrl+"/log/",idgenConfigurationURL:RESTWS_V1+"/idgen/identifiertype",bahmniRESTBaseURL:BAHMNI_CORE+"",observationsUrl:BAHMNI_CORE+"/observations",obsRelationshipUrl:BAHMNI_CORE+"/obsrelationships",encounterImportUrl:BAHMNI_CORE+"/admin/upload/encounter",programImportUrl:BAHMNI_CORE+"/admin/upload/program",conceptImportUrl:BAHMNI_CORE+"/admin/upload/concept",conceptSetImportUrl:BAHMNI_CORE+"/admin/upload/conceptset",drugImportUrl:BAHMNI_CORE+"/admin/upload/drug",labResultsImportUrl:BAHMNI_CORE+"/admin/upload/labResults",referenceTermsImportUrl:BAHMNI_CORE+"/admin/upload/referenceterms",updateReferenceTermsImportUrl:BA
$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.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:i
return value?addNonBlankAttrs():removeNonBlankAttrs()}):addNonBlankAttrs(element)}}).directive("datepicker",function(){var link=function($scope,element,attrs,ngModel){var maxDate=attrs.maxDate,minDate=attrs.minDate||"-120y",format=attrs.dateFormat||"dd-mm-yy";element.datepicker({changeYear:!0,changeMonth:!0,maxDate:maxDate,minDate:minDate,yearRange:"c-120:c+120",dateFormat:format,onSelect:function(dateText){$scope.$apply(function(){ngModel.$setViewValue(dateText)})}})};return{require:"ngModel",link:link}}).directive("myAutocomplete",["$parse",function($parse){var link=function(scope,element,attrs,ngModelCtrl){var source=($parse(attrs.ngModel),scope.source()),responseMap=scope.responseMap(),onSelect=scope.onSelect();element.autocomplete({autofocus:!0,minLength:2,source:function(request,response){source(attrs.id,request.term,attrs.itemType).then(function(data){var results=responseMap?responseMap(data.data):data.data;response(results)})},select:function(event,ui){return scope.$apply(function(scope){ngModelCtrl.$setViewValue(ui.item.value),scope.$eval(attrs.ngChange),null!=onSelect&&onSelect(ui.item)}),!0},search:function(event){var searchTerm=$.trim(element.val());searchTerm.length<2&&event.preventDefault()}})};return{link:link,require:"ngModel",scope:{source:"&",responseMap:"&",onSelect:"&"}}}]).directive("bmForm",["$timeout",function($timeout){var link=function(scope,elem,attrs){$timeout(function(){$(elem).unbind("submit").submit(function(e){var formScope=scope.$parent,formName=attrs.name;e.preventDefault(),scope.autofillable&&$(elem).find("input").trigger("change"),formScope[formName].$valid?(formScope.$apply(attrs.ngSubmit),$(elem).removeClass("submitted-with-error")):$(elem).addClass("submitted-with-error")})},0)};return{link:link,require:"form",scope:{autofillable:"="}}}]).directive("patternValidate",["$timeout",function($timeout){return function($scope,element,attrs){var addPatternToElement=function(){$scope.fieldValidation&&$scope.fieldValidation[attrs.id]&&element.attr({pattern:$scope.fieldValidation[attrs.id].pattern,title:$scope.fieldValidation[attrs.id].errorMessage,type:"text"})};$timeout(addPatternToElement)}}]).directive("validateOn",function(){var link=function(scope,element,attrs,ngModelCtrl){var validationMessage=attrs.validationMessage||"Please enter a valid detail",setValidity=function(value){var valid=!!value;ngModelCtrl.$setValidity("blank",valid),element[0].setCustomValidity(valid?"":validationMessage)};scope.$watch(attrs.validateOn,setValidity,!0)};return{link:link,require:"ngModel"}}),angular.module("bahmni.common.uiHelper").directive("bahmniAutocomplete",["$translate",function($translate){var link=function(scope,element,attrs,ngModelCtrl){var source=scope.source(),responseMap=scope.responseMap&&scope.responseMap(),onSelect=scope.onSelect(),onEdit=scope.onEdit&&scope.onEdit(),minLength=scope.minLength||2,formElement=element[0],validationMessage=scope.validationMessage||$translate.instant("SELECT_VALUE_FROM_AUTOCOMPLETE_DEFAULT_MESSAGE"),validateIfNeeded=function(value){scope.strictSelect&&(scope.isInvalid=value!==scope.selectedValue,_.isEmpty(value)&&(scope.isInvalid=!1))};scope.$watch("initialValue",function(){scope.initialValue&&(scope.selectedValue=scope.initialValue,scope.isInvalid=!1)}),element.autocomplete({autofocus:!0,minLength:minLength,source:function(request,response){source({elementId:attrs.id,term:request.term,elementType:attrs.type}).then(function(data){var results=responseMap?responseMap(data):data;response(results)})},select:function(event,ui){return scope.selectedValue=ui.item.value,ngModelCtrl.$setViewValue(ui.item.value),null!=onSelect&&onSelect(ui.item),validateIfNeeded(ui.item.value),scope.blurOnSelect&&element.blur(),scope.$apply(),scope.$eval(attrs.ngDisabled),scope.$apply(),!0},search:function(event,ui){null!=onEdit&&onEdit(ui.item);var searchTerm=$.trim(element.val());validateIfNeeded(searchTerm),searchTerm.length<minLength&&event.preventDefault()}});var changeHanlder=function(e){validateIfNeeded(element.val())},keyUpHandler=function(e){validateIfNeeded(element.val()),scope
var imageIndex=this.getNoOfImages()-1;this.files.map(function(file){return file.encodedValue.indexOf(".pdf")>0||(file.imageIndex=imageIndex,imageIndex--),file})},this.getNoOfImages=function(){var imageFiles=_.filter(this.files,function(file){return!(file.encodedValue.indexOf(".pdf")>0)});return imageFiles.length},this.isNew=function(){return null===this.uuid},this.hasFiles=function(){return this.files.length>0},this.startDate=function(){return this.isNew()?this.parseDate(this.startDatetime):moment(this.startDatetime).toDate()},this.endDate=function(){return this.stopDatetime?this.parseDate(this.stopDatetime):void 0},this.parseDate=function(date){if(date instanceof Date)return date;var dateFormat=date&&date.indexOf("-")!==-1?androidDateFormat:Bahmni.Common.Constants.dateFormat;return moment(date,dateFormat).toDate()},this.addFile=function(file){var savedImage=null,alreadyPresent=this.files.filter(function(img){return img.encodedValue===file});return 0===alreadyPresent.length&&(savedImage=new DocumentImage({encodedValue:file,new:!0}),this.files.push(savedImage)),this.assignImageIndex(),this.markAsUpdated(),savedImage},this.markAsUpdated=function(){this.changed=this.files.some(function(file){return file.changed||!file.obsUuid||file.voided})},this.isSaved=function(file){return!!file.obsUuid},this.removeFile=function(file){this.isSaved(file)?this.toggleVoidingOfFile(file):this.removeNewAddedFile(file)},this.removeNewAddedFile=function(file){var i=this.files.indexOf(file);this.files.splice(i,1),this.assignImageIndex(),this.markAsUpdated()},this.toggleVoidingOfFile=function(file){file.voided=!file.voided,this.markAsUpdated()},this.hasErrors=function(){var imageHasError=_.find(this.files,function(file){return!(file.voided||file.concept&&file.concept.editableName&&file.concept.uuid)});return!!imageHasError},this.hasVisitType=function(){return!(!this.visitType||!this.visitType.uuid)}},angular.module("opd.documentupload").directive("fileUpload",[function(){var link=function(scope,element){element.bind("change",function(){var files=element[0].files;angular.forEach(files,function(file,index){var reader=new FileReader;reader.onload=function(event){scope.onSelect()(event.target.result,scope.visit,file.name,file.type)},reader.readAsDataURL(file)})})};return{restrict:"A",scope:{visit:"=",onSelect:"&"},link:link}}]),angular.module("opd.documentupload").directive("dateValidator",function(){var DateUtil=Bahmni.Common.Util.DateUtil,isVisitDateFromFuture=function(visitDate){return!(!visitDate.startDatetime&&!visitDate.stopDatetime)&&(DateUtil.getDate(visitDate.startDatetime)>new Date||DateUtil.getDate(visitDate.stopDatetime)>new Date)},isStartDateBeforeEndDate=function(visitDate){return!visitDate.startDatetime||!visitDate.stopDatetime||DateUtil.getDate(visitDate.startDatetime)<=DateUtil.getDate(visitDate.stopDatetime)};return{restrict:"A",require:"ngModel",link:function(scope,element,attrs,ngModel){function validate(){ngModel.$setValidity("overlap",scope.isNewVisitDateValid()),ngModel.$setValidity("future",!isVisitDateFromFuture(scope.newVisit)),ngModel.$setValidity("dateSequence",isStartDateBeforeEndDate(scope.newVisit))}scope.$watch(attrs.ngModel,validate),scope.$watch(attrs.dependentModel,validate)}}}),angular.module("opd.documentupload").controller("DocumentController",["$scope","$stateParams","visitService","patientService","encounterService","spinner","visitDocumentService","$rootScope","$http","$q","$timeout","sessionService","$anchorScroll","$translate","messagingService",function($scope,$stateParams,visitService,patientService,encounterService,spinner,visitDocumentService,$rootScope,$http,$q,$timeout,sessionService,$anchorScroll,$translate,messagingService){var encounterTypeUuid,topLevelConceptUuid,customVisitParams=Bahmni.DocumentUpload.Constants.visitRepresentation,DateUtil=Bahmni.Common.Util.DateUtil,patientMapper=new Bahmni.PatientMapper($rootScope.patientConfig,$rootScope,$translate),activeEncounter={},locationUuid=sessionService.getLoginLocationUuid();$scope.visits=[],$scope.fileTypeConcepts=[],$scope.toggleGallery=!0,$scope.c