dicomweb-proxy
Version:
A proxy to translate between dicomweb and dimse
2 lines • 29.2 kB
JavaScript
;(self.webpackChunk=self.webpackChunk||[]).push([[810,8402],{57289:(e,t,a)=>{a.r(t),a.d(t,{default:()=>pe});const n=JSON.parse('{"UU":"@ohif/extension-tmtv"}').UU,o=e=>({type:"cameraPosition",id:e,source:!0,target:!0}),i={type:"hydrateseg",id:"sameFORId",source:!0,target:!0,options:{matchingRules:["sameFOR"]}},r={viewportOptions:{viewportId:"ctAXIAL",viewportType:"volume",orientation:"axial",toolGroupId:"ctToolGroup",initialImageOptions:{preset:"first"},syncGroups:[o("axialSync"),{type:"voi",id:"ctWLSync",source:!0,target:!0,options:{syncColormap:!0}},i]},displaySets:[{id:"ctDisplaySet"}]},s={viewportOptions:{viewportId:"ctSAGITTAL",viewportType:"volume",orientation:"sagittal",toolGroupId:"ctToolGroup",syncGroups:[o("sagittalSync"),{type:"voi",id:"ctWLSync",source:!0,target:!0,options:{syncColormap:!0}},i]},displaySets:[{id:"ctDisplaySet"}]},l={viewportOptions:{viewportId:"ctCORONAL",viewportType:"volume",orientation:"coronal",toolGroupId:"ctToolGroup",syncGroups:[o("coronalSync"),{type:"voi",id:"ctWLSync",source:!0,target:!0,options:{syncColormap:!0}},i]},displaySets:[{id:"ctDisplaySet"}]},c={viewportOptions:{viewportId:"ptAXIAL",viewportType:"volume",background:[1,1,1],orientation:"axial",toolGroupId:"ptToolGroup",initialImageOptions:{preset:"first"},syncGroups:[o("axialSync"),{type:"voi",id:"ptWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!0,target:!1,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{options:{voi:{custom:"getPTVOIRange"},voiInverted:!0},id:"ptDisplaySet"}]},p={viewportOptions:{viewportId:"ptSAGITTAL",viewportType:"volume",orientation:"sagittal",background:[1,1,1],toolGroupId:"ptToolGroup",syncGroups:[o("sagittalSync"),{type:"voi",id:"ptWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!0,target:!1,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{options:{voi:{custom:"getPTVOIRange"},voiInverted:!0},id:"ptDisplaySet"}]},m={viewportOptions:{viewportId:"ptCORONAL",viewportType:"volume",orientation:"coronal",background:[1,1,1],toolGroupId:"ptToolGroup",syncGroups:[o("coronalSync"),{type:"voi",id:"ptWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!0,target:!1,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{options:{voi:{custom:"getPTVOIRange"},voiInverted:!0},id:"ptDisplaySet"}]},u={viewportOptions:{viewportId:"fusionAXIAL",viewportType:"volume",orientation:"axial",toolGroupId:"fusionToolGroup",initialImageOptions:{preset:"first"},syncGroups:[o("axialSync"),{type:"voi",id:"ctWLSync",source:!1,target:!0},{type:"voi",id:"fusionWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!1,target:!0,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{id:"ctDisplaySet"},{id:"ptDisplaySet",options:{colormap:{name:"hsv",opacity:[{value:0,opacity:0},{value:.1,opacity:.8},{value:1,opacity:.9}]},voi:{custom:"getPTVOIRange"}}}]},d={viewportOptions:{viewportId:"fusionSAGITTAL",viewportType:"volume",orientation:"sagittal",toolGroupId:"fusionToolGroup",syncGroups:[o("sagittalSync"),{type:"voi",id:"ctWLSync",source:!1,target:!0},{type:"voi",id:"fusionWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!1,target:!0,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{id:"ctDisplaySet"},{id:"ptDisplaySet",options:{colormap:{name:"hsv",opacity:[{value:0,opacity:0},{value:.1,opacity:.8},{value:1,opacity:.9}]},voi:{custom:"getPTVOIRange"}}}]},g={viewportOptions:{viewportId:"fusionCoronal",viewportType:"volume",orientation:"coronal",toolGroupId:"fusionToolGroup",syncGroups:[o("coronalSync"),{type:"voi",id:"ctWLSync",source:!1,target:!0},{type:"voi",id:"fusionWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!1,target:!0,options:{syncColormap:!1,syncInvertState:!1}},i]},displaySets:[{id:"ctDisplaySet"},{id:"ptDisplaySet",options:{colormap:{name:"hsv",opacity:[{value:0,opacity:0},{value:.1,opacity:.8},{value:1,opacity:.9}]},voi:{custom:"getPTVOIRange"}}}]},y={viewportOptions:{viewportId:"mipSagittal",viewportType:"volume",orientation:"sagittal",background:[1,1,1],toolGroupId:"mipToolGroup",syncGroups:[{type:"voi",id:"ptWLSync",source:!0,target:!0,options:{syncColormap:!0}},{type:"voi",id:"ptFusionWLSync",source:!0,target:!1,options:{syncColormap:!1,syncInvertState:!1}},i],customViewportProps:{hideOverlays:!0}},displaySets:[{options:{blendMode:"MIP",slabThickness:"fullVolume",voi:{custom:"getPTVOIRange"},voiInverted:!0},id:"ptDisplaySet"}]},S={id:"@ohif/extension-tmtv.hangingProtocolModule.ptCT",locked:!0,name:"Default",createdDate:"2021-02-23T19:22:08.894Z",modifiedDate:"2022-10-04T19:22:08.894Z",availableTo:{},editableBy:{},imageLoadStrategy:"interleaveTopToBottom",protocolMatchingRules:[{attribute:"ModalitiesInStudy",constraint:{contains:["CT","PT"]}},{attribute:"StudyDescription",constraint:{contains:"PETCT"}},{attribute:"StudyDescription",constraint:{contains:"PET/CT"}}],displaySetSelectors:{ctDisplaySet:{seriesMatchingRules:[{attribute:"Modality",constraint:{equals:{value:"CT"}},required:!0},{attribute:"isReconstructable",constraint:{equals:{value:!0}},required:!0},{attribute:"SeriesDescription",constraint:{contains:"CT"}},{attribute:"SeriesDescription",constraint:{contains:"CT WB"}}]},ptDisplaySet:{seriesMatchingRules:[{attribute:"Modality",constraint:{equals:"PT"},required:!0},{attribute:"isReconstructable",constraint:{equals:{value:!0}},required:!0},{attribute:"SeriesDescription",constraint:{contains:"Corrected"}},{weight:2,attribute:"SeriesDescription",constraint:{doesNotContain:{value:"Uncorrected"}}}]}},stages:[{name:"default",id:"default",viewportStructure:{layoutType:"grid",properties:{rows:3,columns:4,layoutOptions:[{x:0,y:0,width:1/4,height:1/3},{x:1/4,y:0,width:1/4,height:1/3},{x:.5,y:0,width:1/4,height:1/3},{x:0,y:1/3,width:1/4,height:1/3},{x:1/4,y:1/3,width:1/4,height:1/3},{x:.5,y:1/3,width:1/4,height:1/3},{x:0,y:2/3,width:1/4,height:1/3},{x:1/4,y:2/3,width:1/4,height:1/3},{x:.5,y:2/3,width:1/4,height:1/3},{x:3/4,y:0,width:1/4,height:1}]}},viewports:[r,s,l,c,p,m,u,d,g,y],createdDate:"2021-02-23T18:32:42.850Z"},{name:"Fusion 2x2",id:"Fusion-2x2",viewportStructure:{layoutType:"grid",properties:{rows:2,columns:2}},viewports:[r,u,c,y]},{name:"2x3-layout",id:"2x3-layout",viewportStructure:{layoutType:"grid",properties:{rows:2,columns:3}},viewports:[r,s,l,c,p,m]},{name:"2x4-layout",id:"2x4-layout",viewportStructure:{layoutType:"grid",properties:{rows:2,columns:4,layoutOptions:[{x:0,y:0,width:1/4,height:.5},{x:1/4,y:0,width:1/4,height:.5},{x:.5,y:0,width:1/4,height:.5},{x:3/4,y:0,width:1/4,height:1},{x:0,y:.5,width:1/4,height:.5},{x:1/4,y:.5,width:1/4,height:.5},{x:.5,y:.5,width:1/4,height:.5}]}},viewports:[m,p,c,y,g,d,u]}],numberOfPriorsReferenced:-1};const h=function(){return[{name:S.id,protocol:S}]};var v=a(86326),f=a(97598),I=a.n(f),T=a(62037),E=a(99993),R=a(2836);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)({}).hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},w.apply(null,arguments)}const b={PatientWeight:null,PatientSex:null,SeriesTime:null,RadiopharmaceuticalInformationSequence:{RadionuclideTotalDose:null,RadionuclideHalfLife:null,RadiopharmaceuticalStartTime:null}},D=({children:e,className:t,...a})=>v.createElement("div",w({className:`flex flex-row items-center space-x-4 ${t||""}`},a),e);function x({servicesManager:e}){const{commandsManager:t}=(0,T.Jg)(),{t:a}=(0,E.Bd)("PanelSUV"),{displaySetService:n,toolGroupService:o,toolbarService:i,hangingProtocolService:r}=e.services,[s,l]=(0,v.useState)(b),[c,p]=(0,v.useState)(null),m=e=>{l((t=>{const a={...t};return Object.keys(e).forEach((n=>{"object"==typeof e[n]?a[n]={...t[n],...e[n]}:a[n]=e[n]})),a}))},u=e=>{const a=t.runCommand("getMatchingPTDisplaySet",{viewportMatchDetails:e});if(!a)return;return{ptDisplaySet:a,metadata:t.runCommand("getPTMetadata",{ptDisplaySet:a})}};return(0,v.useEffect)((()=>{const e=n.getActiveDisplaySets(),{viewportMatchDetails:t}=r.getMatchDetails();if(!e.length)return;const a=u(t);if(!a)return;const{ptDisplaySet:o,metadata:i}=a;p(o),l(i)}),[]),(0,v.useEffect)((()=>{const{unsubscribe:e}=r.subscribe(r.EVENTS.PROTOCOL_CHANGED,(({viewportMatchDetails:e})=>{const t=u(e);if(!t)return;const{ptDisplaySet:a,metadata:n}=t;p(a),l(n)}));return()=>{e()}}),[]),v.createElement(v.Fragment,null,v.createElement("div",{className:"ohif-scrollbar flex min-h-0 flex-auto select-none flex-col justify-between overflow-auto"},v.createElement("div",{className:"flex min-h-0 flex-1 flex-col bg-black text-base"},v.createElement(R.aUM,{defaultOpen:!0},v.createElement(R.aUM.Header,null,a("Patient Information")),v.createElement(R.aUM.Content,null,v.createElement("div",{className:"bg-primary-dark flex flex-col gap-3 p-2"},v.createElement(D,null,v.createElement(D.Label,null,a("Patient Sex")),v.createElement(D.Input,{value:s.PatientSex||"",onChange:e=>{m({PatientSex:e.target.value})}})),v.createElement(D,null,v.createElement(D.Label,{unit:"kg"},a("Weight")),v.createElement(D.Input,{value:s.PatientWeight||"",onChange:e=>{m({PatientWeight:e.target.value})},id:"weight-input"})),v.createElement(D,null,v.createElement(D.Label,{unit:"bq"},a("Total Dose")),v.createElement(D.Input,{value:s.RadiopharmaceuticalInformationSequence.RadionuclideTotalDose||"",onChange:e=>{m({RadiopharmaceuticalInformationSequence:{RadionuclideTotalDose:e.target.value}})}})),v.createElement(D,null,v.createElement(D.Label,{unit:"s"},a("Half Life")),v.createElement(D.Input,{value:s.RadiopharmaceuticalInformationSequence.RadionuclideHalfLife||"",onChange:e=>{m({RadiopharmaceuticalInformationSequence:{RadionuclideHalfLife:e.target.value}})}})),v.createElement(D,null,v.createElement(D.Label,{unit:"s"},a("Injection Time")),v.createElement(D.Input,{value:s.RadiopharmaceuticalInformationSequence.RadiopharmaceuticalStartTime||"",onChange:e=>{m({RadiopharmaceuticalInformationSequence:{RadiopharmaceuticalStartTime:e.target.value}})}})),v.createElement(D,null,v.createElement(D.Label,{unit:"s"},a("Acquisition Time")),v.createElement(D.Input,{value:s.SeriesTime||"",onChange:()=>{}})),v.createElement(R.$nd,{variant:"default",size:"sm",className:"w-28 self-end",onClick:function(){if(!c)throw new Error("No ptDisplaySet found");T.H8.updateMetadataForSeries(c.StudyInstanceUID,c.SeriesInstanceUID,s),n.setDisplaySetMetadataInvalidated(c.displaySetInstanceUID),setTimeout((()=>{t.runCommand("resetCrosshairs")}),0)}},"Reload Data")))))))}D.Label=({children:e,unit:t,className:a,...n})=>v.createElement(R.JU7,w({className:`min-w-32 flex-shrink-0 ${a||""}`},n),e,t&&v.createElement("span",{className:"text-muted-foreground"}," ",t)),D.Input=({className:e,...t})=>v.createElement(R.pde,w({className:`h-7 flex-1 ${e||""}`},t)),D.Label.displayName="InputRow.Label",D.Input.displayName="InputRow.Input",x.propTypes={servicesManager:I().shape({services:I().shape({measurementService:I().shape({getMeasurements:I().func.isRequired,subscribe:I().func.isRequired,EVENTS:I().object.isRequired,VALUE_TYPES:I().object.isRequired}).isRequired}).isRequired}).isRequired};var M=a(7241);const O=async({commandsManager:e,segmentationService:t})=>{const a=t.getSegmentations(),n=await e.run("calculateTMTV",{segmentations:a});a.forEach((e=>{e.cachedStats={...e.cachedStats,tmtv:n},t.addOrUpdateSegmentation(e)}))};var C=a(80735);function N(){const{commandsManager:e,servicesManager:t}=(0,T.Jg)(),{segmentationService:a}=t.services,{segmentationsWithRepresentations:n}=(0,M.useActiveViewportSegmentationRepresentations)({servicesManager:t}),o=n?.map((e=>e.segmentation.segmentationId))||[],i=n?.map((e=>e.segmentation))||[];(0,v.useEffect)((()=>{(async()=>{for(const t of o)await O({segmentationId:t,commandsManager:e,segmentationService:a})})()}),[]),(0,v.useEffect)((()=>{const t=(0,C.sg)((async t=>{const{segmentationId:n}=t;await O({segmentationId:n,commandsManager:e,segmentationService:a})}),100),n=a.subscribe(a.EVENTS.SEGMENTATION_DATA_MODIFIED,(e=>{t(e)}));return()=>{n.unsubscribe()}}),[e,a]);const r=a.getSegmentationGroupStats(o),s=r?.tmtv;return v.createElement("div",{className:"mb-1 flex flex-col"},v.createElement("div",{className:"invisible-scrollbar overflow-y-auto overflow-x-hidden"},v.createElement("div",{className:"bg-secondary-dark flex items-baseline justify-between px-2 py-1"},v.createElement("div",{className:"py-1"},v.createElement("span",{className:"text-muted-foreground text-base font-bold uppercase"},"TMTV: "),v.createElement("span",{className:"text-foreground"},s?`${s.toFixed(3)} mL`:"")),v.createElement("div",{className:"flex items-center"},v.createElement(R.$nd,{size:"sm",variant:"ghost",className:"text-blue-500",onClick:()=>{i.length&&e.runCommand("exportTMTVReportCSV",{segmentations:i,tmtv:s,config:{}})}},v.createElement("span",{className:"pl-1"},"CSV"))))))}const L=N;var U=a(43984);function P({configuration:e}){return v.createElement(v.Fragment,null,v.createElement(M.PanelSegmentation,{configuration:e},v.createElement(N,null)))}const F=function({commandsManager:e,extensionManager:t,servicesManager:a}){return[{name:"petSUV",iconName:"tab-patient-info",iconLabel:"Patient Info",label:"Patient Info",component:()=>v.createElement(x,null)},{name:"tmtv",iconName:"tab-segmentation",iconLabel:"Segmentation",component:()=>v.createElement(v.Fragment,null,v.createElement(U.Toolbox,{buttonSectionId:"ROIThresholdToolbox",title:"Threshold Tools"}),v.createElement(P,{commandsManager:e,servicesManager:a}))},{name:"tmtvBox",iconName:"tab-segmentation",iconLabel:"Segmentation",label:"Segmentation Toolbox",component:()=>v.createElement(U.Toolbox,{buttonSectionId:"ROIThresholdToolbox",title:"Threshold Tools"})},{name:"tmtvExport",iconName:"tab-segmentation",iconLabel:"Segmentation",label:"Segmentation Export",component:()=>v.createElement(L,null)}]};var V=a(4667);const A=["RectangleROIStartEndThreshold","CircleROIStartEndThreshold"],G={toAnnotation:(e,t)=>{},toMeasurement:(e,t,a)=>{const{annotation:n,viewportId:o}=e,{metadata:i,data:r,annotationUID:s}=n;if(!i||!r)return console.warn("Length tool: Missing metadata or data"),null;const{toolName:l,referencedImageId:c,FrameOfReferenceUID:p}=i;if(!A.includes(l))throw new Error("Tool not supported");const{SOPInstanceUID:m,SeriesInstanceUID:u,StudyInstanceUID:d}=(0,M.getSOPInstanceAttributes)(c,a,o);let g;return g=m?t.getDisplaySetForSOPInstanceUID(m,u):t.getDisplaySetsForSeries(u),{uid:s,SOPInstanceUID:m,FrameOfReferenceUID:p,metadata:i,referenceSeriesUID:u,referenceStudyUID:d,toolName:i.toolName,displaySetInstanceUID:g.displaySetInstanceUID,label:i.label,data:r.cachedStats,type:"RectangleROIStartEndThreshold"}}},k={toAnnotation:(e,t)=>{},toMeasurement:(e,t,a)=>{const{annotation:n,viewportId:o}=e,{metadata:i,data:r,annotationUID:s}=n;if(!i||!r)return console.warn("Length tool: Missing metadata or data"),null;const{toolName:l,referencedImageId:c,FrameOfReferenceUID:p}=i;if(!A.includes(l))throw new Error("Tool not supported");const{SOPInstanceUID:m,SeriesInstanceUID:u,StudyInstanceUID:d}=(0,M.getSOPInstanceAttributes)(c,a,o);let g;g=m?t.getDisplaySetForSOPInstanceUID(m,u):t.getDisplaySetsForSeries(u);const{cachedStats:y}=r;return{uid:s,SOPInstanceUID:m,FrameOfReferenceUID:p,metadata:i,referenceSeriesUID:u,referenceStudyUID:d,toolName:i.toolName,displaySetInstanceUID:g.displaySetInstanceUID,label:i.label,data:r.cachedStats,type:"CircleROIStartEndThreshold"}}},W=(e,t,a)=>({RectangleROIStartEndThreshold:{toAnnotation:G.toAnnotation,toMeasurement:e=>G.toMeasurement(e,t,a),matchingCriteria:[{valueType:e.VALUE_TYPES.ROI_THRESHOLD_MANUAL}]},CircleROIStartEndThreshold:{toAnnotation:k.toAnnotation,toMeasurement:e=>k.toMeasurement(e,t,a),matchingCriteria:[{valueType:e.VALUE_TYPES.ROI_THRESHOLD_MANUAL}]}}),{CORNERSTONE_3D_TOOLS_SOURCE_NAME:q,CORNERSTONE_3D_TOOLS_SOURCE_VERSION:j}=M.Enums;var _=a(15327),B=a(16076);function $(e,t){const{imageIds:a}=e,n=_.cache.getVolumeContainingImageId(a[0]);if(!n)throw new Error("No volume found for display set");const{volume:o}=n,{voxelManager:i}=o,{fn:r,baseValue:s}=function(e){const t=-1/0,a=(e,t)=>(e>t&&(t=e),t);return{fn:a,baseValue:t}}();let l=s;const c=V.utilities.rectangleROITool.getBoundsIJKFromRectangleAnnotations(t,o);return i.forEach((({value:e})=>{l=r(e,l)}),{boundsIJK:c}),l}const H=function(e,t,a){if("range"===a.strategy)return{ptLower:Number(a.ptLower),ptUpper:Number(a.ptUpper),ctLower:Number(a.ctLower),ctUpper:Number(a.ctUpper)};const{weight:n}=a;return{ctLower:-1/0,ctUpper:1/0,ptLower:n*$(t,e.map((e=>V.annotation.state.getAnnotation(e)))),ptUpper:1/0}};var J=a(5842),X=a(59874);const{datasetToBlob:Y}=J.Ay.data,Z=T.Ly.MetadataProvider;const z=function(e){const t=X.f_.Cornerstone3D.RTSS.generateRTSSFromAnnotations(e,Z,T.H8),a=Y(t);var n=URL.createObjectURL(a);window.location.assign(n)},{SegmentationRepresentations:K}=V.Enums,{formatPN:Q}=T.Wp,ee=T.Ly.MetadataProvider,te=["RectangleROIStartEndThreshold","RectangleROIThreshold","CircleROIStartEndThreshold"],ae=({servicesManager:e,commandsManager:t,extensionManager:a})=>{const{viewportGridService:n,uiNotificationService:o,displaySetService:i,hangingProtocolService:r,toolGroupService:s,cornerstoneViewportService:l,segmentationService:c}=e.services,p=a.getModuleEntry("@ohif/extension-cornerstone.utilityModule.common"),{getEnabledElement:m}=p.exports;function u(){const{activeViewportId:e}=n.getState(),{element:t}=m(e)||{};return _.getEnabledElement(t)}function d(e){return e.reduce(((e,t)=>{const a=V.annotation.selection.getAnnotationsSelectedByToolName(t);return e.concat(a)}),[])}const g={getMatchingPTDisplaySet:({viewportMatchDetails:e})=>{let t=null;for(const[,a]of e){const{displaySetsInfo:e}=a,n=e.map((({displaySetInstanceUID:e})=>i.getDisplaySetByUID(e)));if(n&&0!==n.length&&(t=n.find((e=>"PT"===e.Modality)),t))break}return t},getPTMetadata:({ptDisplaySet:e})=>{const t=a.getDataSources()[0].getImageIdsForDisplaySet(e)[0],n=ee.get("instance",t);if("PT"!==n.Modality)return;return{SeriesTime:n.SeriesTime,Modality:n.Modality,PatientSex:n.PatientSex,PatientWeight:n.PatientWeight,RadiopharmaceuticalInformationSequence:{RadionuclideTotalDose:n.RadiopharmaceuticalInformationSequence[0].RadionuclideTotalDose,RadionuclideHalfLife:n.RadiopharmaceuticalInformationSequence[0].RadionuclideHalfLife,RadiopharmaceuticalStartTime:n.RadiopharmaceuticalInformationSequence[0].RadiopharmaceuticalStartTime,RadiopharmaceuticalStartDateTime:n.RadiopharmaceuticalInformationSequence[0].RadiopharmaceuticalStartDateTime}}},createNewLabelmapFromPT:async({label:e})=>{const{viewportMatchDetails:t}=r.getMatchDetails(),a=g.getMatchingPTDisplaySet({viewportMatchDetails:t});let n=null;for(const[e,{displaySetsInfo:o}]of t.entries()){if(o.some((({displaySetInstanceUID:e})=>e===a.displaySetInstanceUID))){n=e;break}}if(!a)return void o.error("No matching PT display set found");const s=c.getSegmentationRepresentations(n),l=i.getDisplaySetByUID(a.displaySetInstanceUID),p=await c.createLabelmapForDisplaySet(l,{label:`Segmentation ${s.length+1}`,segments:{1:{label:`${B.A.t("Segment")} 1`,active:!0}}});return c.addSegmentationRepresentation(n,{segmentationId:p}),p},thresholdSegmentationByRectangleROITool:({segmentationId:e,config:t,segmentIndex:a})=>{const n=V.segmentation.state.getSegmentation(e),{representationData:s}=n,{displaySetMatchDetails:l}=r.getMatchDetails(),c=l.get("ctDisplaySet"),p=l.get("ptDisplaySet"),m=i.getDisplaySetByUID(c.displaySetInstanceUID),u=i.getDisplaySetByUID(p.displaySetInstanceUID),{volumeId:g}=s[K.Labelmap],y=_.cache.getVolume(g),S=d(te);if(0===S.length)return void o.show({title:"Commands Module",message:"No ROIThreshold Tool is Selected",type:"error"});const{ptLower:h,ptUpper:v,ctLower:f,ctUpper:I}=H(S,u,t),{imageIds:T}=u,E=_.cache.getVolumeContainingImageId(T[0]);if(!E)return void o.error("No PT volume found");const{imageIds:R}=m,w=_.cache.getVolumeContainingImageId(R[0]);if(!w)return void o.error("No CT volume found");const b=E.volume,D=w.volume;return V.utilities.segmentation.rectangleROIThresholdVolumeByRange(S,y,[{volume:b,lower:h,upper:v},{volume:D,lower:f,upper:I}],{overwrite:!0,segmentIndex:a,segmentationId:e})},calculateTMTV:async({segmentations:e})=>{const t=e.map((e=>e.segmentationId)),a=await V.utilities.segmentation.computeMetabolicStats({segmentationIds:t,segmentIndex:1});return c.setSegmentationGroupStats(t,a),a},exportTMTVReportCSV:async({segmentations:e,tmtv:a,config:n,options:o})=>{const i=t.runCommand("getSegmentationCSVReport",{segmentations:e});let r=0;for(const e in i){r+=i[e].namedStats_lesionGlycolysis.value}const s=[{key:"Total Lesion Glycolysis",value:{tlg:r.toFixed(4)}},{key:"Threshold Configuration",value:{...n}}];void 0!==a&&s.unshift({key:"Total Metabolic Tumor Volume",value:{tmtv:a}}),function(e,t,a={}){const n=e[Object.keys(e)[0]],o=Object.keys(n),i=[o.join(",")];Object.values(e).forEach((e=>{const t=[];o.forEach((a=>{t.push(Array.isArray(e[a])?e[a].join(" "):e[a])})),i.push(t.join(","))})),i.push(""),i.push(""),i.push(""),i.push(`Patient ID,${n.PatientID}`),i.push(`Study Date,${n.StudyDate}`),i.push(""),t.forEach((({key:e,value:t})=>{const a=[];a.push(`${e}`),Object.keys(t).forEach((e=>{a.push(`${e}`),a.push(`${t[e]}`)})),i.push(a.join(","))}));const r=new Blob([i.join("\n")],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(r),l=document.createElement("a");l.href=s,l.download=a.filename??`${n.PatientID}_tmtv.csv`,l.click()}(i,s,o)},setStartSliceForROIThresholdTool:()=>{const{viewport:e}=u(),{focalPoint:t}=e.getCamera(),a=d(te)[0],n=V.annotation.state.getAnnotation(a);n.data.startCoordinate=t,n.invalidated=!0,e.render()},setEndSliceForROIThresholdTool:()=>{const{viewport:e}=u(),t=d(te)[0],a=V.annotation.state.getAnnotation(t),n=e.getCamera().focalPoint;a.data.endCoordinate=n,a.invalidated=!0,e.render()},createTMTVRTReport:()=>{const e=V.annotation.state.getAnnotationManager(),a=[];Object.keys(e.annotations).forEach((t=>{const n=e.annotations[t],o=te.reduce(((e,t)=>[...e,...n[t]??[]]),[]);a.push(...o)})),t.runCommand("exportRTReportForAnnotations",{annotations:a})},getSegmentationCSVReport:({segmentations:e})=>{e&&e.length||(e=c.getSegmentations());const t={};for(const a of e){const{label:e,segmentationId:n,representationData:o}=a,i=n,r={id:i,label:e};if(!o){t[i]=r;continue}const{cachedStats:s}=a.segments[1]||{};s&&Object.entries(s).forEach((([e,t])=>{"object"!=typeof t?r[e]=t:Object.entries(t).forEach((([t,a])=>{r[`${e}_${t}`]=a}))}));if(!a.representationData[K.Labelmap]){t[i]=r;continue}const l=V.utilities.segmentation.getReferenceVolumeForSegmentationVolume(n);if(!l){t[i]=r;continue}if(!l.imageIds||!l.imageIds.length){t[i]=r;continue}const c=l.imageIds[0],p=T.Ay.classes.MetadataProvider.get("instance",c);p?t[i]={...r,PatientID:p.PatientID??"000000",PatientName:Q(p.PatientName),StudyInstanceUID:p.StudyInstanceUID,SeriesInstanceUID:p.SeriesInstanceUID,StudyDate:p.StudyDate}:t[i]=r}return t},exportRTReportForAnnotations:({annotations:e})=>{z(e)},setFusionPTColormap:({toolGroupId:e,colormap:a})=>{const n=s.getToolGroup(e);if(!n)return;const{viewportMatchDetails:o}=r.getMatchDetails(),i=g.getMatchingPTDisplaySet({viewportMatchDetails:o});if(!i)return;const c=n.getViewportIds(),p=[];c.forEach((e=>{t.runCommand("setViewportColormap",{viewportId:e,displaySetInstanceUID:i.displaySetInstanceUID,colormap:{name:a}}),p.push(l.getCornerstoneViewport(e))})),p.forEach((e=>{e.render()}))}},y={setEndSliceForROIThresholdTool:{commandFn:g.setEndSliceForROIThresholdTool},setStartSliceForROIThresholdTool:{commandFn:g.setStartSliceForROIThresholdTool},getMatchingPTDisplaySet:{commandFn:g.getMatchingPTDisplaySet},getPTMetadata:{commandFn:g.getPTMetadata},createNewLabelmapFromPT:{commandFn:g.createNewLabelmapFromPT},thresholdSegmentationByRectangleROITool:{commandFn:g.thresholdSegmentationByRectangleROITool},calculateTMTV:{commandFn:g.calculateTMTV},exportTMTVReportCSV:{commandFn:g.exportTMTVReportCSV},createTMTVRTReport:{commandFn:g.createTMTVRTReport},getSegmentationCSVReport:{commandFn:g.getSegmentationCSVReport},exportRTReportForAnnotations:{commandFn:g.exportRTReportForAnnotations},setFusionPTColormap:{commandFn:g.setFusionPTColormap}};return{actions:g,definitions:y,defaultContext:"TMTV:CORNERSTONE"}},ne="roi_stat",oe=[{value:ne,label:"Max",placeHolder:"Max"},{value:"range",label:"Range",placeHolder:"Range"}];const ie=function({config:e,dispatch:t,runCommand:a}){const{t:n}=(0,E.Bd)("ROIThresholdConfiguration");return v.createElement("div",{className:"bg-primary-dark flex flex-col space-y-4 p-px"},v.createElement("div",{className:"flex items-end space-x-3"},v.createElement("div",{className:"flex min-w-0 flex-1 flex-col"},v.createElement(R.l6P,{value:e.strategy,onValueChange:e=>{t({type:"setStrategy",payload:{strategy:e}})}},v.createElement(R.bqE,{className:"w-full"},v.createElement(R.yvm,{placeholder:oe.find((t=>t.value===e.strategy))?.placeHolder})),v.createElement(R.gCo,{className:""},oe.map((e=>v.createElement(R.ebT,{key:e.value,value:e.value},e.label)))))),v.createElement("div",{className:"flex-shrink-0"},v.createElement("div",{className:"flex justify-end space-x-2"},v.createElement(R.$nd,{variant:"secondary",onClick:()=>a("setStartSliceForROIThresholdTool")},n("Start")),v.createElement(R.$nd,{variant:"secondary",onClick:()=>a("setEndSliceForROIThresholdTool")},n("End"))))),e.strategy===ne&&v.createElement("div",{className:"mr-0"},v.createElement("div",{className:"mb-2"},v.createElement(R.JU7,null,n("Percentage of Max SUV"))),v.createElement(R.pde,{className:"w-full",type:"text",value:e.weight,onChange:e=>{t({type:"setWeight",payload:{weight:e.target.value}})}})),e.strategy!==ne&&v.createElement("div",{className:"mr-2 text-sm"},v.createElement("div",{className:"flex flex-col space-y-2"},v.createElement(R.JU7,null,"Lower & Upper Ranges"),v.createElement("div",{className:"flex items-center"},v.createElement("div",{className:"w-10 text-left"},v.createElement(R.JU7,null,"CT")),v.createElement("div",{className:"flex flex-1 space-x-2"},v.createElement("div",{className:"flex-1"},v.createElement(R.pde,{className:"w-full",type:"text",value:e.ctLower,onChange:e=>{t({type:"setThreshold",payload:{ctLower:e.target.value}})}})),v.createElement("div",{className:"flex-1"},v.createElement(R.pde,{className:"w-full",type:"text",value:e.ctUpper,onChange:e=>{t({type:"setThreshold",payload:{ctUpper:e.target.value}})}})))),v.createElement("div",{className:"flex items-center"},v.createElement("div",{className:"w-10 text-left"},v.createElement(R.JU7,null,"PT")),v.createElement("div",{className:"flex flex-1 space-x-2"},v.createElement("div",{className:"flex-1"},v.createElement(R.pde,{className:"w-full",type:"text",value:e.ptLower,onChange:e=>{t({type:"setThreshold",payload:{ptLower:e.target.value}})}})),v.createElement("div",{className:"flex-1"},v.createElement(R.pde,{className:"w-full",type:"text",value:e.ptUpper,onChange:e=>{t({type:"setThreshold",payload:{ptUpper:e.target.value}})}})))))))},re=ne;function se(e,t){const{payload:a}=t,{strategy:n,ctLower:o,ctUpper:i,ptLower:r,ptUpper:s,weight:l}=a;switch(t.type){case"setStrategy":return{...e,strategy:n};case"setThreshold":return{...e,ctLower:o||e.ctLower,ctUpper:i||e.ctUpper,ptLower:r||e.ptLower,ptUpper:s||e.ptUpper};case"setWeight":return{...e,weight:l};default:return e}}const le=function(){const{commandsManager:e}=(0,T.Jg)(),t=(0,M.useSegmentations)()[0],a=(0,v.useCallback)(((t,a={})=>e.runCommand(t,a)),[e]),[n,o]=(0,v.useReducer)(se,{strategy:re,ctLower:-1024,ctUpper:1024,ptLower:2.5,ptUpper:100,weight:.41}),i=(0,v.useCallback)((()=>{if(!t)return;const e=t.segmentationId,o=V.segmentation.segmentIndex.getActiveSegmentIndex(e);a("thresholdSegmentationByRectangleROITool",{segmentationId:e,config:n,segmentIndex:o})}),[t,n]);return v.createElement("div",{className:"invisible-scrollbar mb-1 flex flex-col overflow-y-auto overflow-x-hidden"},v.createElement(ie,{config:n,dispatch:o,runCommand:a}),t&&v.createElement(R.$nd,{variant:"default",className:"my-3 mr-auto w-20",onClick:i},"Run"))};const ce={id:n,preRegistration({servicesManager:e,commandsManager:t,extensionManager:a,configuration:n={}}){!function({servicesManager:e}){const{measurementService:t,displaySetService:a,cornerstoneViewportService:n}=e.services;(0,V.addTool)(V.RectangleROIStartEndThresholdTool),(0,V.addTool)(V.CircleROIStartEndThresholdTool);const{RectangleROIStartEndThreshold:o,CircleROIStartEndThreshold:i}=W(t,a,n),r=t.getSource(q,j);t.addMapping(r,"RectangleROIStartEndThreshold",o.matchingCriteria,o.toAnnotation,o.toMeasurement),t.addMapping(r,"CircleROIStartEndThreshold",i.matchingCriteria,i.toAnnotation,i.toMeasurement)}({servicesManager:e,commandsManager:t,extensionManager:a,configuration:n})},getToolbarModule:function(){return[{name:"tmtv.RectangleROIThresholdOptions",defaultComponent:le}]},getPanelModule:F,getHangingProtocolModule:h,getCommandsModule:({servicesManager:e,commandsManager:t,extensionManager:a})=>ae({servicesManager:e,commandsManager:t,extensionManager:a})},pe=ce}}]);
//# sourceMappingURL=810.bundle.7f7af7cdaf9e7d2389dc.js.map