Spaces:
Running
Running
webpackChunkviewer=self.webpackChunkviewer||[]).push([[391],{6708:(K,R,a)=>{a.d(R,{W:()=>u});var u=function(m){return m.LAST_MODIFIED_ASC="_lastUpdated",m.LAST_MODIFIED_DESC="-_lastUpdated",m}(u||{})},9625:(K,R,a)=>{a.d(R,{s:()=>m});var u=a(4438);let m=(()=>{class v{transform(E){return{id:E}}static{this.\u0275fac=function($){return new($||v)}}static{this.\u0275pipe=u.EJ8({name:"DICOMUriToSlideDescriptorPipe",type:v,pure:!0})}}return v})()},2024:(K,R,a)=>{a.d(R,{S:()=>le});var u=a(4412),m=a(2771),v=a(6648),j=a(9030),E=a(7673),$=a(7468),C=a(983),L=a(8294),D=a(3738),U=a(6977),w=a(6354),T=a(9437),A=a(6365),O=a(6594),J=a(9901),H=a(5558),P=a(980),Y=a(8141),M=function(f){return f.CASE_ID="caseId",f.PATIENT_ID="patientId",f}(M||{}),y=a(4119),G=a(4907),g=a(4438),ne=a(9423),Q=a(6708),se=a(8375),ie=a(8472),oe=a(1626),F=a(2840),X=a(3266),b=function(f){return f.SEARCH="search",f.NEXT="next",f}(b||{});let ae=(()=>{class f{constructor(n,i,o,s){this.authService=n,this.http=i,this.logService=o,this.windowService=s,this.diagnosticReports$=new u.t([]),this.loadingDiagnosticReports$=new u.t(!1),this.loadingMoreDiagnosticReports$=new u.t(!1),this.nextDiagnosticReportLink$=new u.t(""),this.searchResults$=new u.t(void 0),this.totalDiagnosticReports$=new u.t(0),this.destroyed$=new m.m(1)}ngOnDestroy(){this.destroyed$.next(!0),this.destroyed$.complete()}searchDiagnosticReport(n){if(!n.nextPageToken&&!n.searchText&&!n.sortByParams){const i=`Invalid call to searchDiagnosticReport: ${JSON.stringify(n)}`;throw this.logService.error({name:"searchDiagnosticReport",message:i}),new Error(i)}return this.authService.getOAuthToken().pipe((0,U.Q)(this.destroyed$),(0,H.n)(i=>{const o={authorization:"Bearer "+i,prefer:"handling=strict"};(0,g.naY)()||delete o.prefer;const s=this.computeSearchDiagnosticReportURL(n);return this.loadingMoreDiagnosticReports$.getValue()||this.loadingDiagnosticReports$.next(!0),this.http.get(s,{headers:o,withCredentials:!1}).pipe((0,U.Q)(this.destroyed$),(0,w.T)(l=>(l.entry=l.entry?this.sanitizeDiagnosticReports(l.entry,n.searchKeywords??new Set):[],l)),(0,Y.M)(l=>{this.updateDiagnosticReportSearchResults(l,n.nextPageToken)}),(0,T.W)(l=>{this.resetSearchResults(),l=JSON.stringify(l),this.logService.error({name:`httpRequest: "${s}"`,message:l});let h="Error while fetching search results from FHIR store.";throw n.nextPageToken&&(h="Error while fetching next page search results from FHIR store."),new Error(h)}),(0,P.j)(()=>{this.loadingDiagnosticReports$.next(!1)}))}))}diagnosticReportNextPage(n,i){if(!n){const s="Invalid next page token";throw this.logService.error({name:`nextDiagnosticReportLink: "${n}"`,message:s}),new Error(s)}const o=this.parseUrlParams(n);return this.loadingMoreDiagnosticReports$.next(!0),this.searchDiagnosticReport({nextPageToken:o,searchKeywords:i}).pipe((0,P.j)(()=>{this.loadingMoreDiagnosticReports$.next(!1)}))}diagnosticReportBySort(n,i){const o=(this.searchResults$?.getValue()??{}).link.find(({relation:N})=>N===b.SEARCH)?.url??"";if(!o){const N="Invalid call to diagnosticReportBySort - cannot find previous search link.";throw this.logService.error({name:"searchDiagnosticReport",message:N}),new Error(N)}const s=o.slice(o.indexOf("&_sort=")+7),l=s.slice(0,s.indexOf("&")),h=o.indexOf(l),B=o.slice(0,h),q=o.slice(h+l.length),k=this.parseUrlParams(`${B}${n}${q}`);return this.searchDiagnosticReport({sortByParams:k,searchKeywords:i})}computeSearchDiagnosticReportURL({searchText:n,nextPageToken:i,pageSize:o,sort:s,sortByParams:l}){n&&(o=o??20,s=s??Q.W.LAST_MODIFIED_DESC);let h="";return h=l||(i?this.parseUrlParams(i):Object.entries({_text:n,_elements:"text,identifier",_count:o,_sort:s}).reduce((z,k)=>`${z}&${k.join("=")}`,"")),`${y.c.FHIR_STORE_BASE_URL}DiagnosticReport?${h}${y.c.FHIR_STORE_SEARCH_QUERY_PARAMETERS}`}parseUrlParams(n){return n.slice(n.indexOf("DiagnosticReport/?")+18)}resetSearchResults(){this.searchResults$.next(void 0),this.nextDiagnosticReportLink$.next(""),this.totalDiagnosticReports$.next(0)}sanitizeDiagnosticReports(n,i){return n.map(o=>{const s=o.resource.text;return s&&(s.sanitizedHtml=s.div,s.tagsRemovedSanitized=this.windowService.extractContent(s.sanitizedHtml),s.snippet=(0,se.An)(i,s.tagsRemovedSanitized,380)),o.resource.caseAccessionId=(o.resource?.identifier??[])[0]?.value??"",o})}updateDiagnosticReportSearchResults(n,i){if(i){const s=this.diagnosticReports$.getValue();this.diagnosticReports$.next([...s,...n.entry])}else this.diagnosticReports$.next(n.entry),this.totalDiagnosticReports$.next(n.total);this.searchResults$.next(n);const o=n.link.find(({relation:s})=>s===b.NEXT)?.url??"";this.nextDiagnosticReportLink$.next(o)}static{this.\u0275fac=function(i){return new(i||f)(g.KVO(ie.u),g.KVO(oe.Qq),g.KVO(F.K),g.KVO(X.s))}}static{this.\u0275prov=g.jDH({token:f,factory:f.\u0275fac,providedIn:"root"})}}return f})(),le=(()=>{class f{constructor(n,i,o,s){this.dialogService=n,this.dicomwebService=i,this.fhirStoreService=o,this.logService=s,this.cases$=new u.t([]),this.casesByCaseId$=new u.t(new Map),this.diagnosticReports$=new u.t([]),this.loading$=new u.t(!1),this.loadingMore$=new u.t(!1),this.loadingText$=new u.t(""),this.nextDiagnosticReportLink$=new u.t(""),this.patient$=new u.t(void 0),this.searchText$=new u.t(""),this.searchKeywords$=new u.t(new Set),this.totalResults$=new u.t(0),this.enableFhirSearch=!!y.c.FHIR_STORE_BASE_URL,this.destroyed$=new m.m(1),this.initializeSearchService()}initializeSearchService(){this.diagnosticReports$=this.fhirStoreService.diagnosticReports$,this.nextDiagnosticReportLink$=this.fhirStoreService.nextDiagnosticReportLink$,this.searchText$.pipe((0,U.Q)(this.destroyed$)).subscribe(n=>{const i=n.replaceAll("|"," ").split(" ").map(s=>s.trim()).filter(s=>!s.startsWith("-")).filter(s=>s),o=new Set([...i]);this.searchKeywords$.next(o)})}ngOnDestroy(){this.destroyed$.next(!0),this.destroyed$.complete()}getSlideDicomPathFromListOfRecordIds(n,i){return(0,v.H)(new Set(n)).pipe((0,w.T)(s=>(0,j.v)(()=>this.dicomwebService.searchSeriesById(s,i).pipe((0,T.W)(()=>(0,E.of)([])),(0,w.T)(l=>({recordId:s,slideIds:l?l.map(h=>(0,D.Lk)(y.c.IMAGE_DICOM_STORE_BASE_URL,h)):[]}))))),(0,A.U)(5),(0,O.$)())}getCasesByIds(n){let i=this.casesByCaseId$.getValue();const o=n.filter(s=>!i.has(s)).map(s=>this.searchCases(s));(0,$.p)(o).pipe((0,U.Q)(this.destroyed$)).subscribe(s=>{const l=s.flat(1);i=new Map(l.map(h=>[h.accessionNumber,h])),this.casesByCaseId$.next(i)})}resetSearchResults(){this.cases$.next([]),this.diagnosticReports$.next([]),this.patient$.next(void 0),this.totalResults$.next(0),this.casesByCaseId$.next(new Map),this.nextDiagnosticReportLink$.next("")}searchCasesAndFhirStore(n){this.searchText$.next(n),this.loading$.next(!0),this.resetSearchResults();const i=n.split(" ").filter(s=>""!==s).length;let o=C.w;return 1===i?o=this.searchPatient(n).pipe((0,J.U)(void 0),(0,H.n)(s=>s?.patient?(this.handleSuccessfulPatient(s.patient,s.cases),(0,E.of)(s)):this.searchCases(n).pipe((0,H.n)(l=>l.length?(this.handleSuccessfulCases(l),l):this.enableFhirSearch?this.searchFhirStore(n):[])))):this.enableFhirSearch&&(o=this.searchFhirStore(n)),o.pipe((0,P.j)(()=>{this.loading$.next(!1)}))}searchFhirDiagnosticReportNextPage(n){if(!n)throw new Error(`Invalid token for next page: ${n}`);return this.loadingMore$.next(!0),this.fhirStoreService.searchDiagnosticReport({nextPageToken:n,searchKeywords:this.searchKeywords$.getValue()}).pipe((0,P.j)(()=>{this.loadingMore$.next(!1)}))}searchSortBy(n){return this.loading$.next(!0),this.fhirStoreService.diagnosticReportBySort(n,this.searchKeywords$.getValue()).pipe((0,P.j)(()=>{this.loading$.next(!1)}))}handleSuccessfulCases(n){const i=this.casesByCaseId$.getValue();n.forEach(o=>{o.caseId&&i.set(o.caseId,o)}),this.casesByCaseId$.next(i),this.cases$.next(n),this.totalResults$.next(n.length)}handleSuccessfulPatient(n,i){this.patient$.next(n??void 0),this.handleSuccessfulCases(i)}searchCases(n){return this.loadingText$.next("cases"),this.dicomwebService.searchSeriesById(n,M.CASE_ID).pipe((0,w.T)(i=>{if(!i)return[];const o=new Map;for(const l of i)(0,D.N2)(y.c.IMAGE_DICOM_STORE_BASE_URL,l,o);return[...o.values()]}),(0,T.W)(i=>{const o=("string"==typeof i?i:"Error ")+" while looking up "+L.H.caseId.displayText;return this.logService.error({name:"Error dialog",message:o,stack:"SearchService/searchCases"}),this.dialogService.error(o),C.w}))}searchPatient(n){return"*"===n?C.w:(this.loadingText$.next("patient"),this.dicomwebService.searchSeriesById(n,M.PATIENT_ID).pipe((0,w.T)(i=>{if(!i||0===i.length)return{patient:void 0,cases:[]};const o=new Map,s={};for(const l of i)(0,D.Z6)(l,s),(0,D.N2)(y.c.IMAGE_DICOM_STORE_BASE_URL,l,o);return s.name??="Unknown Patient Name",s.patientId??="Unknown Patient ID",s.latestCaseDate=(0,G.Yq)(s.latestCaseDate),s.latestCaseAccessionNumber??="Unknown Case ID",{patient:s,cases:Array.from(o.values())}}),(0,T.W)(i=>{const o=("string"==typeof i?i:"Error ")+" while looking up "+L.H.patientId.displayText;return this.logService.error({name:"Error dialog",message:o,stack:"SearchService/searchPatient"}),this.dialogService.error(o),C.w})))}searchFhirStore(n){return this.loadingText$.next("FHIR store"),this.fhirStoreService.searchDiagnosticReport({searchText:n,searchKeywords:this.searchKeywords$.getValue()}).pipe((0,Y.M)(()=>{this.totalResults$.next(this.fhirStoreService.totalDiagnosticReports$.getValue()),this.nextDiagnosticReportLink$.next(this.fhirStoreService.nextDiagnosticReportLink$.getValue());const i=new Set(this.fhirStoreService.diagnosticReports$.getValue().map(o=>o.resource.caseAccessionId??o.resource.id));this.getCasesByIds([...i])}))}static{this.\u0275fac=function(i){return new(i||f)(g.KVO(ne.o),g.KVO(D.w),g.KVO(ae),g.KVO(F.K))}}static{this.\u0275prov=g.jDH({token:f,factory:f.\u0275fac,providedIn:"root"})}}return f})()},1524:(K,R,a)=>{a.d(R,{N9:()=>L});const v=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function L(e,t){const r=function $(e){return function E(e){if(!function j(e){return!v.test(e)}(e))return e}(e)}(t);void 0!==r&&(e.href=r)}globalThis,Error}}]); | ;(self.