import{$ as e,L as t,N as n,P as r,Y as i,_ as a,d as o,h as s,i as c,j as l,m as u,p as d,t as f,y as p}from"./store-DlBzmDOw.js";var m={props:[],async created(){let e=new URLSearchParams(window.location.search);e.has(`StudyInstanceUID`)?this.studyInstanceUid=e.get(`StudyInstanceUID`):e.has(`study`)?this.studyInstanceUid=e.get(`study`):console.error(`No study defined.  Use StudyInstanceUID=1.2.3.... in your url`);let t=e.get(`modality`);e.has(`viewer`)&&(this.viewer=e.get(`viewer`));let n=await c.findStudy(this.studyInstanceUid);if(n==null){if(this.state=`finding-remotely`,(await c.remoteDicomFind(`Study`,t,{StudyInstanceUID:this.studyInstanceUid},!0)).length==0)this.state=`not-found`;else if(this.remoteMode==`dicom`){let e={StudyInstanceUID:this.studyInstanceUid},n=await c.remoteDicomRetrieveResource(`Study`,t,e);this.state=`retrieving`,this.startMonitoringJob(n)}}else this.studyOrthancId=n.ID,this.openViewer()},setup(){return{}},data(){return{state:`finding-locally`,remoteMode:`dicom`,viewer:`stone-viewer`,retrievedInstancesCount:0,studyInstanceUid:null,studyOrthancId:null,jobProgressComplete:0,jobProgressFailed:0,jobProgressRemaining:100,jobRefreshTimeout:200,jobIsComplete:!1,jobIsRunning:!1,jobIsSuccess:!1}},mounted(){},methods:{startMonitoringJob(e){this.jobRefreshTimeout=200,setTimeout(this.monitorJob,this.jobRefreshTimeout,[e])},openViewer(){this.viewer==`stone-viewer`?window.location.href=c.getStoneViewerUrl(`study`,this.studyInstanceUid):this.viewer==`osimis-viewer`?window.location.href=c.getOsimisViewerUrl(`study`,this.studyOrthancId):this.viewer==`ohif-viewer`?window.location.href=c.getOh(`study`,this.studyOrthancId):console.error(`unsupported viewer: `,this.viewer)},async monitorJob(e){let t=await c.getJobStatus(e);if(this.jobIsComplete=t.State==`Success`||t.State==`Failure`,this.jobIsRunning=t.State==`Running`,this.jobIsSuccess=t.State==`Success`,this.jobIsComplete)this.jobProgressRemaining=0,this.jobIsSuccess?(this.jobProgressComplete=100,this.jobProgressFailed=0):(this.jobProgressComplete=0,this.jobProgressFailed=100);else{if(this.studyOrthancId==null){let e=await c.findStudy(this.studyInstanceUid);e!=null&&(this.studyOrthancId=e.ID)}else{let e=await c.getStudyInstancesIds(this.studyOrthancId);this.retrievedInstancesCount=e.length}this.jobProgressFailed=0,this.jobProgressComplete=t.Progress,this.jobProgressRemaining=100-this.jobProgressComplete}this.jobIsComplete?this.openViewer():(this.jobRefreshTimeout=Math.min(this.jobRefreshTimeout+200,2e3),setTimeout(this.monitorJob,this.jobRefreshTimeout,[e]))}},computed:{...d({system:e=>e.configuration.system})},components:{}},h={class:`d-flex flex-column min-vh-100 justify-content-center align-items-center h4 text-center`},g=[`innerHTML`],_=[`innerHTML`],v=[`innerHTML`],y=[`innerHTML`],b=[`innerHTML`];function x(e,t,a,o,s,c){return i(),r(`div`,h,[l(`span`,null,[s.state==`finding-locally`?(i(),r(`p`,{key:0,innerHTML:e.$t(`retrieve_and_view.finding_locally`)},null,8,g)):n(``,!0),s.state==`finding-remotely`?(i(),r(`p`,{key:1,innerHTML:e.$t(`retrieve_and_view.finding_remotely`)},null,8,_)):n(``,!0),s.state==`not-found`?(i(),r(`p`,{key:2,innerHTML:e.$t(`retrieve_and_view.not_found`)},null,8,v)):n(``,!0),s.state==`retrieving`?(i(),r(`p`,{key:3,innerHTML:e.$t(`retrieve_and_view.retrieving`)},null,8,y)):n(``,!0),s.state==`retrieving`?(i(),r(`p`,{key:4,innerHTML:e.$t(`retrieve_and_view.retrieved_html`,{count:s.retrievedInstancesCount})},null,8,b)):n(``,!0),t[0]||=l(`div`,{class:`spinner-border`,role:`status`},[l(`span`,{class:`visually-hidden`},`Loading...`)],-1)])])}var S={async created(){console.log(`Creating RetrieveAndView App...`),await this.$store.dispatch(`configuration/load`),console.log(`RetrieveAndView App created`)},components:{RetrieveAndView:a(m,[[`render`,x]])}},C={class:`full-page`};function w(n,a,o,s,c,l){let u=e(`RetrieveAndView`);return i(),r(`div`,C,[t(u)])}var T=a(S,[[`render`,w]]);u();var E=[`token`,`auth-token`,`authorization`];o.get(`../api/pre-login-configuration`).then(e=>{let t=p(T);t.use(f),t.use(s);let n=new URLSearchParams(window.location.search);for(let e of E){let t=n.get(e);t&&(localStorage.setItem(e,t),c.updateAuthHeader(e))}t.mount(`#app-retrieve-and-view`)});