dcmjs-dimse
Version:
DICOM DIMSE implementation for Node.js using dcmjs
2 lines • 88.4 kB
JavaScript
/*! dcmjs-dimse - 0.3.3 - 2026-04-17 | (c) 2021-2026 Pantelis Georgiadis | https://github.com/PantelisGeorgiadis/dcmjs-dimse */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("async-event-emitter2"),require("dcmjs"),require("dcmjs-codecs"),require("loglevel"),require("loglevel-plugin-prefix"),require("memorystream"),require("smart-buffer"),require("ts-mixer")):"function"==typeof define&&define.amd?define("dcmjs-dimse",["async-event-emitter2","dcmjs","dcmjs-codecs","loglevel","loglevel-plugin-prefix","memorystream","smart-buffer","ts-mixer"],t):"object"==typeof exports?exports["dcmjs-dimse"]=t(require("async-event-emitter2"),require("dcmjs"),require("dcmjs-codecs"),require("loglevel"),require("loglevel-plugin-prefix"),require("memorystream"),require("smart-buffer"),require("ts-mixer")):e["dcmjs-dimse"]=t(e["async-event-emitter2"],e.dcmjs,e["dcmjs-codecs"],e.loglevel,e["loglevel-plugin-prefix"],e.memorystream,e["smart-buffer"],e["ts-mixer"])}(global,(e,t,s,n,i,r,o,a)=>{return c={570(e,t,s){const{CGetRequest:n,CStoreRequest:i}=s(940),{CommandFieldType:r,PresentationContextResult:o,SopClass:a,StorageClass:c,TransferSyntax:d,Uid:u,UserIdentityType:h}=s(492),m=s(139),{EOL:g}=s(857);class l{constructor(e,t,s,n,i,r){this.pcId=e,this.abstractSyntaxUid=t,this.userRole=i,this.providerRole=r,this.transferSyntaxes=[],s&&this.transferSyntaxes.push(s),this.result=n||o.Proposed}getPresentationContextId(){return this.pcId}getAbstractSyntaxUid(){return this.abstractSyntaxUid}getTransferSyntaxUids(){return this.transferSyntaxes}addTransferSyntaxUid(e){this.transferSyntaxes.includes(e)||this.transferSyntaxes.push(e)}removeTransferSyntaxUid(e){if(!this.transferSyntaxes.includes(e))return;const t=this.transferSyntaxes.indexOf(e);-1!==t&&this.transferSyntaxes.splice(t,1)}hasTransferSyntaxUid(e){return this.transferSyntaxes.includes(e)}getAcceptedTransferSyntaxUid(){return this.transferSyntaxes.length>0?this.transferSyntaxes[0]:void 0}getResult(){return this.result}setResult(e,t){this.result=e;const s=[...this.transferSyntaxes];this.transferSyntaxes.length=0,t?this.transferSyntaxes.push(t):s.length>0&&this.transferSyntaxes.push(s[0])}getUserRole(){return this.userRole}setUserRole(e){this.userRole=e}getProviderRole(){return this.providerRole}setProviderRole(e){this.providerRole=e}getResultDescription(){switch(this.result){case o.Accept:return"Accept";case o.Proposed:return"Proposed";case o.RejectAbstractSyntaxNotSupported:return"Reject - Abstract Syntax Not Supported";case o.RejectNoReason:return"Reject - No Reason";case o.RejectTransferSyntaxesNotSupported:return"Reject - Transfer Syntaxes Not Supported";case o.RejectUser:return"Reject - User";default:return"Unknown"}}toString(){const e=[];return e.push(`Presentation Context: ${this.getPresentationContextId()} [${this.getResultDescription()}]`),e.push(` Abstract: ${this.getAbstractSyntaxUid()}`),this.getTransferSyntaxUids().forEach(t=>{e.push(` Transfer: ${t}`)}),e.join(g)}}e.exports={Association:class{constructor(e,t){this.callingAeTitle=e,this.calledAeTitle=t,this.maxPduLength=m.getMaxPduLength(),this.applicationContextName=u.ApplicationContextName,this.implementationClassUid=m.getImplementationClassUid(),this.implementationVersion=m.getImplementationVersion(),this.presentationContexts=[],this.negotiateAsyncOps=!1,this.maxAsyncOpsInvoked=1,this.maxAsyncOpsPerformed=1,this.negotiateUserIdentity=!1,this.userIdentityType=h.Username,this.userIdentityPositiveResponseRequested=!1,this.userIdentityPrimaryField="",this.userIdentitySecondaryField="",this.negotiateUserIdentityServerResponse=!1,this.userIdentityServerResponse=""}getCallingAeTitle(){return this.callingAeTitle}setCallingAeTitle(e){this.callingAeTitle=e}getCalledAeTitle(){return this.calledAeTitle}setCalledAeTitle(e){this.calledAeTitle=e}getMaxPduLength(){return this.maxPduLength}setMaxPduLength(e){this.maxPduLength=e}getApplicationContextName(){return this.applicationContextName}getImplementationClassUid(){return this.implementationClassUid}setImplementationClassUid(e){this.implementationClassUid=e}getImplementationVersion(){return this.implementationVersion}setImplementationVersion(e){this.implementationVersion=e}getNegotiateAsyncOps(){return this.negotiateAsyncOps}setNegotiateAsyncOps(e){this.negotiateAsyncOps=e}getMaxAsyncOpsInvoked(){return this.maxAsyncOpsInvoked}setMaxAsyncOpsInvoked(e){this.maxAsyncOpsInvoked=e}getMaxAsyncOpsPerformed(){return this.maxAsyncOpsPerformed}setMaxAsyncOpsPerformed(e){this.maxAsyncOpsPerformed=e}getNegotiateUserIdentity(){return this.negotiateUserIdentity}setNegotiateUserIdentity(e){this.negotiateUserIdentity=e}getUserIdentityType(){return this.userIdentityType}setUserIdentityType(e){this.userIdentityType=e}getUserIdentityPositiveResponseRequested(){return this.userIdentityPositiveResponseRequested}setUserIdentityPositiveResponseRequested(e){this.userIdentityPositiveResponseRequested=e}getUserIdentityPrimaryField(){return this.userIdentityPrimaryField}setUserIdentityPrimaryField(e){this.userIdentityPrimaryField=e}getUserIdentitySecondaryField(){return this.userIdentitySecondaryField}setUserIdentitySecondaryField(e){this.userIdentitySecondaryField=e}getNegotiateUserIdentityServerResponse(){return this.negotiateUserIdentityServerResponse}setNegotiateUserIdentityServerResponse(e){this.negotiateUserIdentityServerResponse=e}getUserIdentityServerResponse(){return this.userIdentityServerResponse}setUserIdentityServerResponse(e){this.userIdentityServerResponse=e}addPresentationContext(e,t){let s=t||1;return this.presentationContexts.forEach(e=>{const t=e.id;t>=s&&(s=t+2)}),this.presentationContexts.push({id:s,context:new l(s,e)}),s}addOrGetPresentationContext(e){const t=this.getPresentationContexts();for(let s=0;s<t.length;s++){const n=t[s];if(n.context.getAbstractSyntaxUid()===e)return n.context.getPresentationContextId()}return this.addPresentationContext(e)}addTransferSyntaxToPresentationContext(e,t){this.getPresentationContext(e).addTransferSyntaxUid(t)}findPresentationContextByAbstractSyntaxAndTransferSyntax(e,t){const s=this.getPresentationContexts();for(let n=0;n<s.length;n++){const i=s[n];if(i.context.getAbstractSyntaxUid()===e&&i.context.hasTransferSyntaxUid(t))return i.context.getPresentationContextId()}}getPresentationContext(e){const t=this.presentationContexts.find(t=>t.id===e);if(!t)throw new Error(`Invalid presentation context ID: ${e}`);return t.context}getPresentationContexts(){return this.presentationContexts}clearPresentationContexts(){this.presentationContexts.length=0}addPresentationContextFromRequest(e,t){let s=t||d.ImplicitVRLittleEndian;s=Array.isArray(s)?s:[s];const r=this._sopClassFromRequest(e);let o;if(e instanceof i){o=this.addOrGetPresentationContext(r),s.forEach(e=>{this.addTransferSyntaxToPresentationContext(o,e)}),e.getAdditionalTransferSyntaxes().forEach(e=>{this.addTransferSyntaxToPresentationContext(o,e)});const t=e.getDataset().getTransferSyntaxUid();t!==d.ImplicitVRLittleEndian&&t!==d.ExplicitVRLittleEndian&&(o=this.findPresentationContextByAbstractSyntaxAndTransferSyntax(r,t),void 0===o&&(o=this.addPresentationContext(r),this.addTransferSyntaxToPresentationContext(o,t)))}else e instanceof n?(o=this.addOrGetPresentationContext(r),s.forEach(e=>{this.addTransferSyntaxToPresentationContext(o,e)}),!0===e.getAddStorageSopClassesToAssociation()&&Object.keys(c).forEach(e=>{const t=c[e],n=this.addOrGetPresentationContext(t);this.getPresentationContext(n).setProviderRole(!0),s.forEach(e=>{this.addTransferSyntaxToPresentationContext(n,e)})})):(o=this.addOrGetPresentationContext(r),s.forEach(e=>{this.addTransferSyntaxToPresentationContext(o,e)}));return o}getAcceptedPresentationContextFromRequest(e){let t;const s=this.getPresentationContexts();return e.getDataset()&&s.forEach(s=>{const n=this.getPresentationContext(s.id);n.getAbstractSyntaxUid()===this._sopClassFromRequest(e)&&n.getAcceptedTransferSyntaxUid()===e.getDataset().getTransferSyntaxUid()&&n.getResult()===o.Accept&&(t=n)}),void 0===t&&s.forEach(s=>{const n=this.getPresentationContext(s.id);n.getAbstractSyntaxUid()===this._sopClassFromRequest(e)&&n.getResult()===o.Accept&&(t=n)}),t}toString(){const e=[];return e.push(`Application Context: ${this.getApplicationContextName()}`),e.push(`Implementation Class: ${this.getImplementationClassUid()}`),e.push(`Implementation Version: ${this.getImplementationVersion()}`),e.push(`Maximum PDU Length: ${this.getMaxPduLength()}`),e.push(`Called AE Title: ${this.getCalledAeTitle()}`),e.push(`Calling AE Title: ${this.getCallingAeTitle()}`),this.getNegotiateAsyncOps()&&e.push(`Asynchronous Operations: Invoked: ${this.getMaxAsyncOpsInvoked()} Performed:${this.getMaxAsyncOpsPerformed()}`),this.getNegotiateUserIdentity()&&e.push(`User Identity: ${this._userIdentityTypeToString(this.getUserIdentityType())||""}`),e.push(`Presentation Contexts: ${this.presentationContexts.length}`),this.presentationContexts.forEach(t=>{const s=this.getPresentationContext(t.id);e.push(` Presentation Context: ${t.id} [${s.getResultDescription()}]`),e.push(` Abstract: ${this._uidNameFromValue([a,c],s.getAbstractSyntaxUid())||s.getAbstractSyntaxUid()}`),e.push(` SCU/SCP Role: ${this._getScuScpRole(s.getUserRole(),s.getProviderRole())}`),s.getTransferSyntaxUids().forEach(t=>{e.push(` Transfer: ${this._uidNameFromValue(d,t)||t}`)})}),e.push(""),e.join(g)}_getScuScpRole(e,t){return!0!==e||void 0!==t&&!1!==t?void 0!==e&&!1!==e||!0!==t?!0===e&&!0===t?"SCU/SCP":"Default":"SCP":"SCU"}_uidNameFromValue(e,t){const s=Array.isArray(e)?Object.assign({},...e):e;return Object.keys(s).find(e=>s[e]===t)}_sopClassFromRequest(e){switch(e.getCommandFieldType()){case r.NGetRequest:case r.NSetRequest:case r.NActionRequest:case r.NDeleteRequest:return void 0!==e.getMetaSopClassUid()?e.getMetaSopClassUid():e.getRequestedSopClassUid();case r.CStoreRequest:case r.CFindRequest:case r.CGetRequest:case r.CMoveRequest:case r.CEchoRequest:return e.getAffectedSopClassUid();case r.NEventReportRequest:case r.NCreateRequest:return void 0!==e.getMetaSopClassUid()?e.getMetaSopClassUid():e.getAffectedSopClassUid();default:return e.getAffectedSopClassUid()}}_userIdentityTypeToString(e){switch(e){case h.Username:return"Username";case h.UsernameAndPasscode:return"Username and Passcode";case h.Kerberos:return"Kerberos Service Ticket";case h.Saml:return"SAML Assertion";case h.Jwt:return"JSON Web Token";default:return`${e}`}}},PresentationContext:l}},422(e,t,s){const{Association:n,PresentationContext:i}=s(570),{TransferSyntax:r,UserIdentityType:o}=s(492),{Request:a}=s(940),c=s(371),d=s(906),u=s(547),h=s(0),m=s(278),g=s(756);e.exports=class extends h{constructor(){super(),this.requests=[],this.additionalPresentationContexts=[],this.network=void 0,this.statistics=new d}addRequest(e){if(!(e instanceof a))throw new Error(`${e.toString()} is not a request`);this.requests.includes(e)?u.warn(`${e.toString()} request has already been added. Ignoring...`):this.requests.push(e)}clearRequests(){this.requests.length=0}addAdditionalPresentationContext(e,t){if(t=t||!1,!(e instanceof i))throw new Error(`${e.toString()} is not a presentation context`);this.additionalPresentationContexts.some(t=>t.context===e)?u.warn(`${e.toString()} context has already been added. Ignoring...`):this.additionalPresentationContexts.push({context:e,addAsNew:t})}send(e,t,s,i,a){if(a=a||{},this.associationLingerTimeout=a.associationLingerTimeout||0,0===this.requests.length)throw new Error("There are no requests to perform");const d=new n(s,i);a.asyncOps&&(d.setMaxAsyncOpsInvoked(a.asyncOps.maxAsyncOpsInvoked||1),d.setMaxAsyncOpsPerformed(a.asyncOps.maxAsyncOpsPerformed||1),d.setNegotiateAsyncOps(1!==d.getMaxAsyncOpsInvoked()||1!==d.getMaxAsyncOpsPerformed())),a.userIdentity&&(d.setUserIdentityType(a.userIdentity.type||o.Username),d.setUserIdentityPositiveResponseRequested(a.userIdentity.positiveResponseRequested||!1),d.setUserIdentityPrimaryField(a.userIdentity.primaryField||""),d.setUserIdentitySecondaryField(a.userIdentity.secondaryField||""),d.setNegotiateUserIdentity(!0)),this.requests.forEach(e=>{d.addPresentationContextFromRequest(e,[r.ImplicitVRLittleEndian,r.ExplicitVRLittleEndian])}),this.additionalPresentationContexts.forEach(e=>{const t=e.addAsNew?d.addPresentationContext(e.context.getAbstractSyntaxUid()):d.addOrGetPresentationContext(e.context.getAbstractSyntaxUid());e.context.getTransferSyntaxUids().forEach(e=>{d.addTransferSyntaxToPresentationContext(t,e)})});let h={};a.securityOptions&&(h={key:a.securityOptions.key,cert:a.securityOptions.cert,ca:a.securityOptions.ca,requestCert:a.securityOptions.requestCert,rejectUnauthorized:a.securityOptions.rejectUnauthorized,minVersion:a.securityOptions.minVersion,maxVersion:a.securityOptions.maxVersion,ciphers:a.securityOptions.ciphers}),u.info(`Connecting to ${e}:${t} ${a.securityOptions?"(TLS)":""}`);const l=(a.securityOptions?g:m).connect({host:e,port:t,...h}),p=new c(l,a);p.on("connect",()=>{this.emit("connected"),p.sendAssociationRequest(d)}),p.on("associationAccepted",e=>{this.emit("associationAccepted",e),p.sendRequests(this.requests)}),p.on("associationReleaseResponse",()=>{this.emit("associationReleased"),l.end()}),p.on("associationRejected",e=>{this.emit("associationRejected",e),l.end()}),p.on("done",()=>{setTimeout(()=>p.sendAssociationReleaseRequest(),this.associationLingerTimeout)}),p.on("cStoreRequest",(e,t)=>{this.emit("cStoreRequest",e,t)}),p.on("nEventReportRequest",(e,t)=>{this.emit("nEventReportRequest",e,t)}),p.on("networkError",e=>{l.end(),this.emit("networkError",e)}),p.on("close",()=>{this.statistics.addFromOtherStatistics(p.getStatistics()),this.network=void 0,this.emit("closed")}),this.network=p}getStatistics(){return this.statistics}abort(e,t){if(!this.network)throw new Error("Network has not been initialized");this.network.sendAbort(e,t)}cancel(e){if(!this.network)throw new Error("Network has not been initialized");this.network.sendCancel(e)}}},940(e,t,s){const{CommandFieldType:n,Priority:i,SopClass:r,Status:o}=s(492),a=s(825),{Mixin:c}=s(429),{EOL:d}=s(857),u=s(0),h=s(111),{DicomMetaDictionary:m}=h.data;class g{constructor(e,t){this.commandDataset=e||new a,this.dataset=t}getCommandDataset(){return this.commandDataset}setCommandDataset(e){this.commandDataset=e}getDataset(){return this.dataset}setDataset(e){this.dataset=e,this.commandDataset.setElement("CommandDataSetType",this.dataset?514:257)}getCommandFieldType(){return this.commandDataset.getElement("CommandField")}hasDataset(){return 257!==this.commandDataset.getElement("CommandDataSetType")}toString(e){const t=e||{},s=t.includeCommandDataset||!1,n=t.includeDataset||!1,i=[];return i.push(`${this._typeToString(this.getCommandFieldType())} [HasDataset: ${this.hasDataset()}]`),s&&(i.push("DIMSE Command Dataset:"),i.push("=".repeat(50)),i.push(JSON.stringify(this.commandDataset.getElements()))),n&&this.dataset&&(i.push("DIMSE Dataset:"),i.push("=".repeat(50)),i.push(JSON.stringify(this.dataset.getElements()))),i.join(d)}_typeToString(e){switch(e){case n.CCancelRequest:return"C-CANCEL RQ";case n.CEchoRequest:return"C-ECHO RQ";case n.CEchoResponse:return"C-ECHO RSP";case n.CFindRequest:return"C-FIND RQ";case n.CFindResponse:return"C-FIND RSP";case n.CGetRequest:return"C-GET RQ";case n.CGetResponse:return"C-GET RSP";case n.CMoveRequest:return"C-MOVE RQ";case n.CMoveResponse:return"C-MOVE RSP";case n.CStoreRequest:return"C-STORE RQ";case n.CStoreResponse:return"C-STORE RSP";case n.NActionRequest:return"N-ACTION RQ";case n.NActionResponse:return"N-ACTION RSP";case n.NCreateRequest:return"N-CREATE RQ";case n.NCreateResponse:return"N-CREATE RSP";case n.NDeleteRequest:return"N-DELETE RQ";case n.NDeleteResponse:return"N-DELETE RSP";case n.NEventReportRequest:return"N-EVENT-REPORT RQ";case n.NEventReportResponse:return"N-EVENT-REPORT RSP";case n.NGetRequest:return"N-GET RQ";case n.NGetResponse:return"N-GET RSP";case n.NSetRequest:return"N-SET RQ";case n.NSetResponse:return"N-SET RSP";default:return`${e}`}}}class l extends(c(g,u)){constructor(e,t,s,i){switch(super(new a({CommandField:e,CommandDataSetType:s?514:257})),e){case n.NGetRequest:case n.NSetRequest:case n.NActionRequest:case n.NDeleteRequest:this.setRequestedSopClassUid(t);break;default:this.setAffectedSopClassUid(t)}this.metaSopClassUid=i}getAffectedSopClassUid(){return this.getCommandDataset().getElement("AffectedSOPClassUID")}setAffectedSopClassUid(e){this.getCommandDataset().setElement("AffectedSOPClassUID",e)}getRequestedSopClassUid(){return this.getCommandDataset().getElement("RequestedSOPClassUID")}setRequestedSopClassUid(e){this.getCommandDataset().setElement("RequestedSOPClassUID",e)}getMetaSopClassUid(){return this.metaSopClassUid}setMetaSopClassUid(e){this.metaSopClassUid=e}getAffectedSopInstanceUid(){return this.getCommandDataset().getElement("AffectedSOPInstanceUID")}setAffectedSopInstanceUid(e){this.getCommandDataset().setElement("AffectedSOPInstanceUID",e)}getRequestedSopInstanceUid(){return this.getCommandDataset().getElement("RequestedSOPInstanceUID")}setRequestedSopInstanceUid(e){this.getCommandDataset().setElement("RequestedSOPInstanceUID",e)}getMessageId(){return this.getCommandDataset().getElement("MessageID")}setMessageId(e){this.getCommandDataset().setElement("MessageID",e)}raiseResponseEvent(e){this.emit("response",e)}raiseInstanceEvent(e){this.emit("instance",e)}raiseDoneEvent(){this.emit("done")}toString(e){return`${super.toString(e)} [id: ${this.getMessageId()||""}]`}}class p extends g{constructor(e,t,s,i,r){switch(super(new a({CommandField:e,CommandDataSetType:s?514:257,Status:i,ErrorComment:r})),e){case n.NGetRequest:case n.NSetRequest:case n.NActionRequest:case n.NDeleteRequest:this.setRequestedSopClassUid(t);break;default:this.setAffectedSopClassUid(t)}}getAffectedSopClassUid(){return this.getCommandDataset().getElement("AffectedSOPClassUID")}setAffectedSopClassUid(e){this.getCommandDataset().setElement("AffectedSOPClassUID",e)}getRequestedSopClassUid(){return this.getCommandDataset().getElement("RequestedSOPClassUID")}setRequestedSopClassUid(e){this.getCommandDataset().setElement("RequestedSOPClassUID",e)}getAffectedSopInstanceUid(){return this.getCommandDataset().getElement("AffectedSOPInstanceUID")}setAffectedSopInstanceUid(e){this.getCommandDataset().setElement("AffectedSOPInstanceUID",e)}getRequestedSopInstanceUid(){return this.getCommandDataset().getElement("RequestedSOPInstanceUID")}setRequestedSopInstanceUid(e){this.getCommandDataset().setElement("RequestedSOPInstanceUID",e)}getStatus(){return this.getCommandDataset().getElement("Status")}setStatus(e){this.getCommandDataset().setElement("Status",e)}getErrorComment(){return this.getCommandDataset().getElement("ErrorComment")}setErrorComment(e){this.getCommandDataset().setElement("ErrorComment",e)}getMessageIdBeingRespondedTo(){return this.getCommandDataset().getElement("MessageIDBeingRespondedTo")}setMessageIdBeingRespondedTo(e){this.getCommandDataset().setElement("MessageIDBeingRespondedTo",e)}toString(e){return`${super.toString(e)} [id: ${this.getMessageIdBeingRespondedTo()||""}; status: ${this._statusToString(this.getStatus())}]`}_statusToString(e){switch(e){case o.Success:return"Success";case o.Cancel:return"Cancel";case o.Pending:return"Pending";case o.SopClassNotSupported:return"SOP Class Not Supported";case o.ClassInstanceConflict:return"Class Instance Conflict";case o.DuplicateSOPInstance:return"Duplicate SOP Instance";case o.DuplicateInvocation:return"Duplicate Invocation";case o.InvalidArgumentValue:return"Invalid Argument Value";case o.InvalidAttributeValue:return"Invalid Attribute Value";case o.InvalidObjectInstance:return"Invalid Object Instance";case o.MissingAttribute:return"Missing Attribute";case o.MissingAttributeValue:return"Missing Attribute Value";case o.MistypedArgument:return"Mistyped Argument";case o.NoSuchArgument:return"No Such Argument";case o.NoSuchEventType:return"No Such Event Type";case o.NoSuchObjectInstance:return"No Such Object Instance";case o.NoSuchSopClass:return"No Such SOP Class";case o.ProcessingFailure:return"Processing Failure";case o.ResourceLimitation:return"Resource Limitation";case o.UnrecognizedOperation:return"Unrecognized Operation";case o.NoSuchActionType:return"No Such Action Type";default:return`${e}`}}}class R extends l{constructor(){super(n.CEchoRequest,r.Verification,!1)}}class S extends p{constructor(e,t){super(n.CEchoResponse,r.Verification,!1,e,t)}static fromRequest(e){if(!(e instanceof R))throw new Error("Request should be an instance of CEchoRequest");const t=new S(o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class y extends l{constructor(e){super(n.CFindRequest,r.StudyRootQueryRetrieveInformationModelFind,!1),this.setPriority(e||i.Medium)}getPriority(){return this.getCommandDataset().getElement("Priority")}setPriority(e){this.getCommandDataset().setElement("Priority",e)}static createStudyFindRequest(e,t){const s={PatientID:"",PatientName:"",IssuerOfPatientID:"",PatientSex:"",PatientBirthDate:"",StudyInstanceUID:"",ModalitiesInStudy:"",StudyID:"",AccessionNumber:"",StudyDate:"",StudyTime:"",StudyDescription:"",NumberOfStudyRelatedSeries:"",NumberOfStudyRelatedInstances:"",...e};s.QueryRetrieveLevel="STUDY";const n=new y(t);return n.setDataset(new a(s)),n}static createSeriesFindRequest(e,t){const s={StudyInstanceUID:"",SeriesInstanceUID:"",SeriesNumber:"",SeriesDescription:"",Modality:"",SeriesDate:"",SeriesTime:"",NumberOfSeriesRelatedInstances:"",...e};s.QueryRetrieveLevel="SERIES";const n=new y(t);return n.setDataset(new a(s)),n}static createImageFindRequest(e,t){const s={StudyInstanceUID:"",SeriesInstanceUID:"",SOPInstanceUID:"",InstanceNumber:"",Modality:"",...e};s.QueryRetrieveLevel="IMAGE";const n=new y(t);return n.setDataset(new a(s)),n}static createWorklistFindRequest(e,t){const s={PatientID:"",PatientName:"",IssuerOfPatientID:"",PatientSex:"",PatientWeight:"",PatientBirthDate:"",MedicalAlerts:"",PregnancyStatus:"",Allergies:"",PatientComments:"",SpecialNeeds:"",PatientState:"",CurrentPatientLocation:"",InstitutionName:"",AdmissionID:"",AccessionNumber:"",ReferringPhysicianName:"",AdmittingDiagnosesDescription:"",RequestingPhysician:"",StudyInstanceUID:"",StudyDescription:"",StudyID:"",ReasonForTheRequestedProcedure:"",StudyDate:"",StudyTime:"",RequestedProcedureID:"",RequestedProcedureDescription:"",RequestedProcedurePriority:"",RequestedProcedureCodeSequence:[],ReferencedStudySequence:[],ProcedureCodeSequence:[],ScheduledProcedureStepSequence:[{ScheduledStationAETitle:"",ScheduledStationName:"",ScheduledProcedureStepStartDate:"",ScheduledProcedureStepStartTime:"",Modality:"",ScheduledPerformingPhysicianName:"",ScheduledProcedureStepDescription:"",ScheduledProtocolCodeSequence:[],ScheduledProcedureStepLocation:"",ScheduledProcedureStepID:"",RequestedContrastAgent:"",PreMedication:"",AnatomicalOrientationType:""}],...e};s.QueryRetrieveLevel="";const n=new y(t);return n.setAffectedSopClassUid(r.ModalityWorklistInformationModelFind),n.setDataset(new a(s)),n}}class f extends p{constructor(e,t){super(n.CFindResponse,r.StudyRootQueryRetrieveInformationModelFind,!1,e,t)}static fromRequest(e){if(!(e instanceof y))throw new Error("Request should be an instance of CFindRequest");const t=new f(o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class I extends l{constructor(e,t){if(super(n.CStoreRequest,"",!1),this.setPriority(t||i.Medium),this.additionalTransferSyntaxes=[],e instanceof a)return this.setAffectedSopClassUid(e.getElement("SOPClassUID")),this.setAffectedSopInstanceUid(e.getElement("SOPInstanceUID")),void this.setDataset(e);if("string"==typeof e||e instanceof String){const t=a.fromFile(e,void 0,{untilTag:"00080018",includeUntilTagValue:!0});this.setAffectedSopClassUid(t.getElement("SOPClassUID")),this.setAffectedSopInstanceUid(t.getElement("SOPInstanceUID")),this.setDataset(t),this.needsFullDatasetLoading=!0,this.datasetOrFile=e}}getPriority(){return this.getCommandDataset().getElement("Priority")}setPriority(e){this.getCommandDataset().setElement("Priority",e)}getAdditionalTransferSyntaxes(){return this.additionalTransferSyntaxes}setAdditionalTransferSyntaxes(e){const t=Array.isArray(e)?e:[e];this.additionalTransferSyntaxes.push(...t)}loadFullDatasetIfNeeded(){void 0!==this.needsFullDatasetLoading&&!0===this.needsFullDatasetLoading&&void 0!==this.datasetOrFile&&""!==this.datasetOrFile.trim()&&this.setDataset(a.fromFile(this.datasetOrFile))}}class C extends p{constructor(e,t){super(n.CStoreResponse,"",!1,e,t)}static fromRequest(e){if(!(e instanceof I))throw new Error("Request should be an instance of CStoreRequest");const t=new C(o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t.setAffectedSopClassUid(e.getAffectedSopClassUid()),t.setAffectedSopInstanceUid(e.getAffectedSopInstanceUid()),t}}class P extends l{constructor(e){super(n.CMoveRequest,r.StudyRootQueryRetrieveInformationModelMove,!1),this.setPriority(e||i.Medium)}getPriority(){return this.getCommandDataset().getElement("Priority")}setPriority(e){this.getCommandDataset().setElement("Priority",e)}static createStudyMoveRequest(e,t,s){const n={StudyInstanceUID:t,QueryRetrieveLevel:"STUDY"},i=new P(s);return i.setDataset(new a(n)),i.getCommandDataset().setElement("MoveDestination",e),i}static createSeriesMoveRequest(e,t,s,n){const i={StudyInstanceUID:t,SeriesInstanceUID:s,QueryRetrieveLevel:"SERIES"},r=new P(n);return r.setDataset(new a(i)),r.getCommandDataset().setElement("MoveDestination",e),r}static createImageMoveRequest(e,t,s,n,i){const r={StudyInstanceUID:t,SeriesInstanceUID:s,SOPInstanceUID:n,QueryRetrieveLevel:"IMAGE"},o=new P(i);return o.setDataset(new a(r)),o.getCommandDataset().setElement("MoveDestination",e),o}}class v extends p{constructor(e,t){super(n.CMoveResponse,r.StudyRootQueryRetrieveInformationModelMove,!1,e,t)}getRemaining(){return this.getCommandDataset().getElement("NumberOfRemainingSuboperations")}setRemaining(e){return this.getCommandDataset().setElement("NumberOfRemainingSuboperations",e)}getCompleted(){return this.getCommandDataset().getElement("NumberOfCompletedSuboperations")}setCompleted(e){return this.getCommandDataset().setElement("NumberOfCompletedSuboperations",e)}getWarnings(){return this.getCommandDataset().getElement("NumberOfWarningSuboperations")}setWarnings(e){return this.getCommandDataset().setElement("NumberOfWarningSuboperations",e)}getFailures(){return this.getCommandDataset().getElement("NumberOfFailedSuboperations")}setFailures(e){return this.getCommandDataset().setElement("NumberOfFailedSuboperations",e)}toString(e){return`${super.toString(e)} [Remaining: ${this.getRemaining()}; Completed: ${this.getCompleted()} Warnings: ${this.getWarnings()}; Failures: ${this.getFailures()}]`}static fromRequest(e){if(!(e instanceof P))throw new Error("Request should be an instance of CMoveRequest");const t=new v(o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class x extends l{constructor(e){super(n.CGetRequest,r.StudyRootQueryRetrieveInformationModelGet,!1),this.setPriority(e||i.Medium),this.addStorageSopClassesToAssociation=!0}getPriority(){return this.getCommandDataset().getElement("Priority")}setPriority(e){this.getCommandDataset().setElement("Priority",e)}getAddStorageSopClassesToAssociation(){return this.addStorageSopClassesToAssociation}setAddStorageSopClassesToAssociation(e){this.addStorageSopClassesToAssociation=e}static createStudyGetRequest(e,t){const s={StudyInstanceUID:e,QueryRetrieveLevel:"STUDY"},n=new x(t);return n.setDataset(new a(s)),n}static createSeriesGetRequest(e,t,s){const n={StudyInstanceUID:e,SeriesInstanceUID:t,QueryRetrieveLevel:"SERIES"},i=new x(s);return i.setDataset(new a(n)),i}static createImageGetRequest(e,t,s,n){const i={StudyInstanceUID:e,SeriesInstanceUID:t,SOPInstanceUID:s,QueryRetrieveLevel:"IMAGE"},r=new x(n);return r.setDataset(new a(i)),r}}class A extends p{constructor(e,t){super(n.CGetResponse,r.StudyRootQueryRetrieveInformationModelGet,!1,e,t)}getRemaining(){return this.getCommandDataset().getElement("NumberOfRemainingSuboperations")}setRemaining(e){return this.getCommandDataset().setElement("NumberOfRemainingSuboperations",e)}getCompleted(){return this.getCommandDataset().getElement("NumberOfCompletedSuboperations")}setCompleted(e){return this.getCommandDataset().setElement("NumberOfCompletedSuboperations",e)}getWarnings(){return this.getCommandDataset().getElement("NumberOfWarningSuboperations")}setWarnings(e){return this.getCommandDataset().setElement("NumberOfWarningSuboperations",e)}getFailures(){return this.getCommandDataset().getElement("NumberOfFailedSuboperations")}setFailures(e){return this.getCommandDataset().setElement("NumberOfFailedSuboperations",e)}toString(e){return`${super.toString(e)} [Remaining: ${this.getRemaining()}; Completed: ${this.getCompleted()} Warnings: ${this.getWarnings()}; Failures: ${this.getFailures()}]`}static fromRequest(e){if(!(e instanceof x))throw new Error("Request should be an instance of CGetRequest");const t=new A(o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class U extends l{constructor(e,t,s){super(n.NCreateRequest,e,!1),this.setAffectedSopInstanceUid(t),this.setMetaSopClassUid(s)}}class w extends p{constructor(e,t,s,i){super(n.NCreateResponse,e,!1,s,i),this.setAffectedSopInstanceUid(t)}static fromRequest(e){if(!(e instanceof U))throw new Error("Request should be an instance of NCreateRequest");const t=new w(e.getAffectedSopClassUid(),e.getAffectedSopInstanceUid(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class D extends l{constructor(e,t,s,i){super(n.NActionRequest,e,!1),this.setRequestedSopInstanceUid(t),this.setActionTypeId(s),this.setMetaSopClassUid(i)}getActionTypeId(){return this.getCommandDataset().getElement("ActionTypeID")}setActionTypeId(e){this.getCommandDataset().setElement("ActionTypeID",e)}}class q extends p{constructor(e,t,s,i,r){super(n.NActionResponse,e,!1,i,r),this.setAffectedSopInstanceUid(t),this.setActionTypeId(s)}getActionTypeId(){return this.getCommandDataset().getElement("ActionTypeID")}setActionTypeId(e){this.getCommandDataset().setElement("ActionTypeID",e)}static fromRequest(e){if(!(e instanceof D))throw new Error("Request should be an instance of NActionRequest");const t=new q(e.getRequestedSopClassUid(),e.getRequestedSopInstanceUid(),e.getActionTypeId(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class E extends l{constructor(e,t,s){super(n.NDeleteRequest,e,!1),this.setRequestedSopInstanceUid(t),this.setMetaSopClassUid(s)}}class T extends p{constructor(e,t,s,i){super(n.NDeleteResponse,e,!1,s,i),this.setAffectedSopInstanceUid(t)}static fromRequest(e){if(!(e instanceof E))throw new Error("Request should be an instance of NDeleteRequest");const t=new T(e.getRequestedSopClassUid(),e.getRequestedSopInstanceUid(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class b extends l{constructor(e,t,s,i){super(n.NEventReportRequest,e,!1),this.setAffectedSopInstanceUid(t),this.setEventTypeId(s),this.setMetaSopClassUid(i)}getEventTypeId(){return this.getCommandDataset().getElement("EventTypeID")}setEventTypeId(e){this.getCommandDataset().setElement("EventTypeID",e)}}class O extends p{constructor(e,t,s,i,r){super(n.NEventReportResponse,e,!1,i,r),this.setAffectedSopInstanceUid(t),this.setEventTypeId(s)}getEventTypeId(){return this.getCommandDataset().getElement("EventTypeID")}setEventTypeId(e){this.getCommandDataset().setElement("EventTypeID",e)}static fromRequest(e){if(!(e instanceof b))throw new Error("Request should be an instance of NEventReportRequest");const t=new O(e.getAffectedSopClassUid(),e.getAffectedSopInstanceUid(),e.getEventTypeId(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class N extends l{constructor(e,t,s,i){super(n.NGetRequest,e,!1),this.setRequestedSopInstanceUid(t),this.setAttributeIdentifierList(Array.isArray(s)?s:[s]),this.setMetaSopClassUid(i)}getAttributeIdentifierList(){const e=this.getCommandDataset().getElement("AttributeIdentifierList"),t=[];return void 0!==e&&Array.isArray(e)&&e.length>0&&e.forEach(e=>{const s=e>>16,n=65535&e,i=`(${this._getPaddedHexString(s,4)},${this._getPaddedHexString(n,4)})`,r=m.dictionary[i.toUpperCase()];r&&t.push(r.name)}),t}setAttributeIdentifierList(e){const t=[];e.forEach(e=>{const s=m.nameMap[e];if(void 0!==s&&void 0!==s.tag&&"DICOM"===s.version){const e=m.dictionary[s.tag],n=parseInt(e.tag.substring(1,5),16),i=parseInt(e.tag.substring(6,10),16);t.push(n<<16|65535&i)}}),this.getCommandDataset().setElement("AttributeIdentifierList",t)}_getPaddedHexString(e,t){const s=e.toString(16);return"0".repeat(t-s.length)+s}}class B extends p{constructor(e,t,s,i){super(n.NGetResponse,e,!1,s,i),this.setAffectedSopInstanceUid(t)}static fromRequest(e){if(!(e instanceof N))throw new Error("Request should be an instance of NGetRequest");const t=new B(e.getRequestedSopClassUid(),e.getRequestedSopInstanceUid(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class M extends l{constructor(e,t,s){super(n.NSetRequest,e,!1),this.setRequestedSopInstanceUid(t),this.setMetaSopClassUid(s)}}class L extends p{constructor(e,t,s,i){super(n.NSetResponse,e,!1,s,i),this.setAffectedSopInstanceUid(t)}static fromRequest(e){if(!(e instanceof M))throw new Error("Request should be an instance of NSetRequest");const t=new L(e.getRequestedSopClassUid(),e.getRequestedSopInstanceUid(),o.ProcessingFailure);return t.setMessageIdBeingRespondedTo(e.getMessageId()),t}}class F extends l{constructor(e,t){super(n.CCancelRequest,e,!1),this.setMessageIdBeingRespondedTo(t)}getMessageIdBeingRespondedTo(){return this.getCommandDataset().getElement("MessageIDBeingRespondedTo")}setMessageIdBeingRespondedTo(e){this.getCommandDataset().setElement("MessageIDBeingRespondedTo",e)}static fromRequest(e){if(!(e instanceof y||e instanceof P||e instanceof x))throw new Error("Request should be an instance of CFindRequest, CMoveRequest or CGetRequest");return new F(e.getAffectedSopClassUid(),e.getMessageId())}}e.exports={CCancelRequest:F,CEchoRequest:R,CEchoResponse:S,CFindRequest:y,CFindResponse:f,CGetRequest:x,CGetResponse:A,CMoveRequest:P,CMoveResponse:v,Command:g,CStoreRequest:I,CStoreResponse:C,NActionRequest:D,NActionResponse:q,NCreateRequest:U,NCreateResponse:w,NDeleteRequest:E,NDeleteResponse:T,NEventReportRequest:b,NEventReportResponse:O,NGetRequest:N,NGetResponse:B,NSetRequest:M,NSetResponse:L,Request:l,Response:p}},492(e){const t={AAbort:7,AAssociateAC:2,AAssociateRJ:3,AAssociateRQ:1,AReleaseRP:6,AReleaseRQ:5,PDataTF:4};Object.freeze(t);const s={CStoreRequest:1,CStoreResponse:32769,CGetRequest:16,CGetResponse:32784,CFindRequest:32,CFindResponse:32800,CMoveRequest:33,CMoveResponse:32801,CEchoRequest:48,CEchoResponse:32816,NEventReportRequest:256,NEventReportResponse:33024,NGetRequest:272,NGetResponse:33040,NSetRequest:288,NSetResponse:33056,NActionRequest:304,NActionResponse:33072,NCreateRequest:320,NCreateResponse:33088,NDeleteRequest:336,NDeleteResponse:33104,CCancelRequest:4095};Object.freeze(s);const n={Proposed:255,Accept:0,RejectUser:1,RejectNoReason:2,RejectAbstractSyntaxNotSupported:3,RejectTransferSyntaxesNotSupported:4};Object.freeze(n);const i={Username:1,UsernameAndPasscode:2,Kerberos:3,Saml:4,Jwt:5};Object.freeze(i);const r={ServiceUser:0,Unknown:1,ServiceProvider:2};Object.freeze(r);const o={NotSpecified:0,UnrecognizedPdu:1,UnexpectedPdu:2,UnrecognizedPduParameter:4,UnexpectedPduParameter:5,InvalidPduParameter:6};Object.freeze(o);const a={Permanent:1,Transient:2};Object.freeze(a);const c={ServiceUser:1,ServiceProviderAcse:2,ServiceProviderPresentation:3};Object.freeze(c);const d={NoReasonGiven:1,ApplicationContextNotSupported:2,CallingAeNotRecognized:3,CalledAeNotRecognized:7,ProtocolVersionNotSupported:2,TemporaryCongestion:1,LocalLimitExceeded:2};Object.freeze(d);const u={Low:2,Medium:0,High:1};Object.freeze(u);const h={Success:0,Cancel:65024,Pending:65280,ClassInstanceConflict:281,DataSetSopClassMismatch:43264,DuplicateSOPInstance:273,DuplicateInvocation:528,InvalidArgumentValue:277,InvalidAttributeValue:262,InvalidObjectInstance:279,MissingAttribute:288,MissingAttributeValue:289,MistypedArgument:530,MoveDestinationUnknown:43009,NoSuchActionType:291,NoSuchArgument:276,NoSuchEventType:275,NoSuchObjectInstance:274,NoSuchSopClass:280,NotAuthorized:292,OutOfResourcesNumberOfMatches:42753,OutOfResourcesSubOperations:42754,ProcessingFailure:272,ResourceLimitation:531,SopClassNotSupported:290,UnrecognizedOperation:529};Object.freeze(h);const m={ApplicationContextName:"1.2.840.10008.3.1.1.1"};Object.freeze(m);const g={BasicTextSrStorage:"1.2.840.10008.5.1.4.1.1.88.11",BreastProjectionXRayImageStorageForPresentation:"1.2.840.10008.5.1.4.1.1.13.1.4",BreastProjectionXRayImageStorageForProcessing:"1.2.840.10008.5.1.4.1.1.13.1.5",BreastTomosynthesisImageStorage:"1.2.840.10008.5.1.4.1.1.13.1.3",ChestCadSrStorage:"1.2.840.10008.5.1.4.1.1.88.65",ComprehensiveSrStorage:"1.2.840.10008.5.1.4.1.1.88.33",ComputedRadiographyImageStorage:"1.2.840.10008.5.1.4.1.1.1",CtImageStorage:"1.2.840.10008.5.1.4.1.1.2",DigitalIntraOralXRayImageStorageForPresentation:"1.2.840.10008.5.1.4.1.1.1.3",DigitalIntraOralXRayImageStorageForProcessing:"1.2.840.10008.5.1.4.1.1.1.3.1",DigitalMammographyXRayImageStorageForPresentation:"1.2.840.10008.5.1.4.1.1.1.2",DigitalMammographyXRayImageStorageForProcessing:"1.2.840.10008.5.1.4.1.1.1.2.1",DigitalXRayImageStorageForPresentation:"1.2.840.10008.5.1.4.1.1.1.1",DigitalXRayImageStorageForProcessing:"1.2.840.10008.5.1.4.1.1.1.1.1",EncapsulatedCdaStorage:"1.2.840.10008.5.1.4.1.1.104.2",EncapsulatedPdfStorage:"1.2.840.10008.5.1.4.1.1.104.1",EnhancedCtImageStorage:"1.2.840.10008.5.1.4.1.1.2.1",EnhancedMrColorImageStorage:"1.2.840.10008.5.1.4.1.1.4.3",EnhancedMrImageStorage:"1.2.840.10008.5.1.4.1.1.4.1",EnhancedPetImageStorage:"1.2.840.10008.5.1.4.1.1.130",EnhancedSrStorage:"1.2.840.10008.5.1.4.1.1.88.22",EnhancedXaImageStorage:"1.2.840.10008.5.1.4.1.1.12.1.1",EnhancedXrfImageStorage:"1.2.840.10008.5.1.4.1.1.12.2.1",IntravascularOpticalCoherenceTomographyImageStorageForPresentation:"1.2.840.10008.5.1.4.1.1.14.1",IntravascularOpticalCoherenceTomographyImageStorageForProcessing:"1.2.840.10008.5.1.4.1.1.14.2",LegacyConvertedEnhancedCTImageStorage:"1.2.840.10008.5.1.4.1.1.2.2",LegacyConvertedEnhancedMRImageStorage:"1.2.840.10008.5.1.4.1.1.4.4",LegacyConvertedEnhancedPETImageStorage:"1.2.840.10008.5.1.4.1.1.128.1",MammographyCadSrStorage:"1.2.840.10008.5.1.4.1.1.88.50",MrImageStorage:"1.2.840.10008.5.1.4.1.1.4",MultiframeGrayscaleByteSecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7.2",MultiframeGrayscaleWordSecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7.3",MultiframeSingleBitSecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7.1",MultiframeTrueColorSecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7.4",NuclearMedicineImageStorage:"1.2.840.10008.5.1.4.1.1.20",OphthalmicOpticalCoherenceTomographyEnFaceImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.7",OphthalmicPhotography16BitImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.2",OphthalmicPhotography8BitImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.1",OphthalmicTomographyImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.4",PositronEmissionTomographyImageStorage:"1.2.840.10008.5.1.4.1.1.128",RtImageStorage:"1.2.840.10008.5.1.4.1.1.481.1",SecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7",UltrasoundImageStorage:"1.2.840.10008.5.1.4.1.1.6.1",UltrasoundMultiframeImageStorage:"1.2.840.10008.5.1.4.1.1.3.1",VideoEndoscopicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.1.1",VideoMicroscopicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.2.1",VideoPhotographicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.4.1",VlEndoscopicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.1",VlMicroscopicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.2",VlPhotographicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.4",VlSlideCoordinatesMicroscopicImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.3",VlWholeSlideMicroscopyImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.6",WideFieldOphthalmicPhotography3dCoordinatesImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.6",WideFieldOphthalmicPhotographyStereographicProjectionImageStorage:"1.2.840.10008.5.1.4.1.1.77.1.5.5",XRay3dAngiographicImageStorage:"1.2.840.10008.5.1.4.1.1.13.1.1",XRay3dCraniofacialImageStorage:"1.2.840.10008.5.1.4.1.1.13.1.2",XRayAngiographicImageStorage:"1.2.840.10008.5.1.4.1.1.12.1",XRayRadiationDoseSRStorage:"1.2.840.10008.5.1.4.1.1.88.67",XRayRadiofluoroscopicImageStorage:"1.2.840.10008.5.1.4.1.1.12.2"};Object.freeze(g);const l={Verification:"1.2.840.10008.1.1",StudyRootQueryRetrieveInformationModelFind:"1.2.840.10008.5.1.4.1.2.2.1",ModalityWorklistInformationModelFind:"1.2.840.10008.5.1.4.31",ModalityPerformedProcedureStep:"1.2.840.10008.3.1.2.3.3",StudyRootQueryRetrieveInformationModelMove:"1.2.840.10008.5.1.4.1.2.2.2",StudyRootQueryRetrieveInformationModelGet:"1.2.840.10008.5.1.4.1.2.2.3",StorageCommitmentPushModel:"1.2.840.10008.1.20.1",BasicFilmSession:"1.2.840.10008.5.1.1.1",PrintJob:"1.2.840.10008.5.1.1.14",BasicAnnotationBox:"1.2.840.10008.5.1.1.15",Printer:"1.2.840.10008.5.1.1.16",PrinterConfigurationRetrieval:"1.2.840.10008.5.1.1.16.376",BasicGrayscalePrintManagementMeta:"1.2.840.10008.5.1.1.9",BasicColorPrintManagementMeta:"1.2.840.10008.5.1.1.18",BasicFilmBox:"1.2.840.10008.5.1.1.2",PresentationLut:"1.2.840.10008.5.1.1.23",BasicGrayscaleImageBox:"1.2.840.10008.5.1.1.4",BasicColorImageBox:"1.2.840.10008.5.1.1.4.1",InstanceAvailabilityNotification:"1.2.840.10008.5.1.4.33"};Object.freeze(l);const p={ImplicitVRLittleEndian:"1.2.840.10008.1.2",ExplicitVRLittleEndian:"1.2.840.10008.1.2.1",DeflatedExplicitVRLittleEndian:"1.2.840.10008.1.2.1.99",ExplicitVRBigEndian:"1.2.840.10008.1.2.2",RleLossless:"1.2.840.10008.1.2.5",JpegBaseline:"1.2.840.10008.1.2.4.50",JpegLossless:"1.2.840.10008.1.2.4.70",JpegLsLossless:"1.2.840.10008.1.2.4.80",JpegLsLossy:"1.2.840.10008.1.2.4.81",Jpeg2000Lossless:"1.2.840.10008.1.2.4.90",Jpeg2000Lossy:"1.2.840.10008.1.2.4.91",JpegXlLossless:"1.2.840.10008.1.2.4.110",JpegXlRecompression:"1.2.840.10008.1.2.4.111",JpegXlLossy:"1.2.840.10008.1.2.4.112",HtJpeg2000Lossless:"1.2.840.10008.1.2.4.201",HtJpeg2000LosslessRpcl:"1.2.840.10008.1.2.4.202",HtJpeg2000Lossy:"1.2.840.10008.1.2.4.203"};Object.freeze(p);const R=[p.ImplicitVRLittleEndian,p.ExplicitVRLittleEndian,p.ExplicitVRBigEndian,p.RleLossless,p.JpegBaseline,p.JpegLossless,p.JpegLsLossless,p.JpegLsLossy,p.Jpeg2000Lossless,p.Jpeg2000Lossy,p.JpegXlLossless,p.JpegXlLossy,p.HtJpeg2000Lossless,p.HtJpeg2000LosslessRpcl,p.HtJpeg2000Lossy];Object.freeze(R);const S={ImplementationClassUid:"1.2.826.0.1.3680043.10.854",ImplementationVersion:"DCMJS-DIMSE-V0.2",MaxPduLength:262144};Object.freeze(S),e.exports={AbortReason:o,AbortSource:r,CommandFieldType:s,DefaultImplementation:S,PresentationContextResult:n,Priority:u,RawPduType:t,RejectReason:d,RejectResult:a,RejectSource:c,SopClass:l,Status:h,StorageClass:g,TranscodableTransferSyntaxes:R,TransferSyntax:p,Uid:m,UserIdentityType:i}},825(e,t,s){const{StorageClass:n,TransferSyntax:i}=s(492),r=s(139),{readFile:o,readFileSync:a,writeFile:c,writeFileSync:d}=s(896),{EOL:u}=s(857),h=s(111),{DicomDict:m,DicomMessage:g,DicomMetaDictionary:l,ReadBufferStream:p,WriteBufferStream:R}=h.data,S=h.log;class y{constructor(e,t,s){s=s||{},s={ignoreErrors:!0,...s},S.level="error",this.transferSyntaxUid=t||i.ImplicitVRLittleEndian,Buffer.isBuffer(e)?this.elements=this._fromElementsBuffer(e,this.transferSyntaxUid,s):this.elements=e||{}}getElement(e){return this.elements[e]}setElement(e,t){this.elements[e]=t}getElements(){return this.elements}getTransferSyntaxUid(){return this.transferSyntaxUid}setTransferSyntaxUid(e){this.transferSyntaxUid=e}getDenaturalizedDataset(e,t){const s=t?l.denaturalizeDataset(this.getElements(),{...l.nameMap,...t}):l.denaturalizeDataset(this.getElements()),n=new R;return g.write(s,n,this.transferSyntaxUid,e),Buffer.from(n.getBuffer())}getDenaturalizedCommandDataset(e){const t=l.denaturalizeDataset(this.getElements()),s=new R,n=new R;return g.write(t,n,i.ImplicitVRLittleEndian,e),g.writeTagObject(s,"00000000","UL",n.size,i.ImplicitVRLittleEndian,e),s.concat(n),Buffer.from(s.getBuffer())}static fromFile(e,t,s){if(!(void 0!==t&&t instanceof Function))return this._fromP10Buffer(a(e),s);o(e,(e,n)=>{if(e)t(e,void 0);else try{t(void 0,this._fromP10Buffer(n,s))}catch(e){t(e,void 0)}})}toFile(e,t,s,i){const o={_meta:{FileMetaInformationVersion:new Uint8Array([0,1]).buffer,MediaStorageSOPClassUID:this.getElement("SOPClassUID")||n.SecondaryCaptureImageStorage,MediaStorageSOPInstanceUID:this.getElement("SOPInstanceUID")||y.generateDerivedUid(),TransferSyntaxUID:this.getTransferSyntaxUid(),ImplementationClassUID:r.getImplementationClassUid(),ImplementationVersionName:r.getImplementationVersion()},...this.getElements()},a=l.denaturalizeDataset(o._meta),u=new m(a);u.dict=s?l.denaturalizeDataset(o,{...l.nameMap,...s}):l.denaturalizeDataset(o),t instanceof Function?c(e,Buffer.from(u.write(i)),e=>{t(e||void 0)}):d(e,Buffer.from(u.write(i)))}static generateDerivedUid(){return l.uid()}toString(){const e=[];return e.push("Dataset:"),e.push("=".repeat(50)),e.push(JSON.stringify(this.getElements())),e.join(u)}static _fromP10Buffer(e,t){t=t||{},t={ignoreErrors:!0,...t};const s=g.readFile(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t),n=l.naturalizeDataset(s.meta).TransferSyntaxUID,i=l.naturalizeDataset(s.dict);return new y(i,n)}_fromElementsBuffer(e,t,s){const n=new p(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)),r=t===i.ImplicitVRLittleEndian?i.ImplicitVRLittleEndian:t===i.ExplicitVRBigEndian?i.ExplicitVRBigEndian:i.ExplicitVRLittleEndian,o=g._read(n,r,s);return l.naturalizeDataset(o)}}e.exports=y},139(e,t,s){const{DefaultImplementation:n}=s(492);e.exports=class{static getImplementationClassUid(){return this.implementationClassUid||n.ImplementationClassUid}static setImplementationClassUid(e){this.implementationClassUid=e}static getImplementationVersion(){return this.implementationVersion||n.ImplementationVersion}static setImplementationVersion(e){if("string"!=typeof e||e.length>16)throw new Error("Implementation version should be a string with less than 16 characters");this.implementationVersion=e}static getMaxPduLength(){return this.maxPduLength||n.MaxPduLength}static setMaxPduLength(e){this.maxPduLength=e}}},371(e,t,s){const{Association:n}=s(570),{AAbort:i,AAssociateAC:r,AAssociateRJ:o,AAssociateRQ:a,AReleaseRP:c,AReleaseRQ:d,PDataTF:u,Pdv:h,RawPdu:m}=s(942),{CommandFieldType:g,RawPduType:l,Status:p}=s(492),{CCancelRequest:R,CEchoRequest:S,CEchoResponse:y,CFindRequest:f,CFindResponse:I,CGetRequest:C,CGetResponse:P,CMoveRequest:v,CMoveResponse:x,Command:A,CStoreRequest:U,CStoreResponse:w,NActionRequest:D,NActionResponse:q,NCreateRequest:E,NCreateResponse:T,NDeleteRequest:b,NDeleteResponse:O,NEventReportRequest:N,NEventReportResponse:B,NGetRequest:M,NGetResponse:L,NSetRequest:F,NSetResponse:k,Response:$}=s(940),V=s(825),j=s(139),_=s(906),G=s(73),z=s(547),{SmartBuffer:Q}=s(766),{EOL:W}=s(857),J=s(0),X=s(235);class H extends J{constructor(){super()}accumulate(e){do{e=this._process(e)}while(void 0!==e)}_process(e){if(void 0===this.receiving){if(this.minimumReceived&&(e=Buffer.concat([this.minimumReceived,e],this.minimumReceived.length+e.length),this.minimumReceived=void 0),e.length<6)return void(this.minimumReceived=e);const t=Q.fromBuffer(e,"ascii"),s=t.readUInt8();if(s!==l.AAssociateRQ&&s!==l.AAssociateAC&&s!==l.AAssociateRJ&&s!==l.PDataTF&&s!==l.AReleaseRQ&&s!==l.AReleaseRP&&s!==l.AAbort)return void this.emit("error",new Error(`Unknown PDU type: ${s}`));t.readUInt8();const n=t.readUInt32BE();let i=e.length-6;if(n>i)this.receiving=e,this.receivedLength=n;else{let t,s=e;if(n<i&&(s=e.slice(0,n+6),t=e.slice(n+6,i+6)),this.receiving=void 0,this.receivedLength=void 0,this.emit("pdu",s),t)return t}}else{let t=Buffer.concat([this.receiving,e],this.receiving.length+e.length);const s=t.length-6;if(s<this.receivedLength)this.receiving=t;else{let e;if(s>this.receivedLength&&(e=t.slice(this.receivedLength+6,s+6),t=t.slice(0,this.receivedLength+6)),this.receiving=void 0,this.receivedLength=void 0,this.emit("pdu",t),e)return e}}}}e.exports=class extends J{constructor(e,t){super(),this.messageId=0,this.socket=e,this.requests=[],this.pending=[],this.dimseStream=void 0,this.dimseStoreStream=void 0,this.dimse=void 0,t=t||{},this.connectTimeout=t.connectTimeout||18e4,this.associationTimeout=t.associationTimeout||6e4,this.pduTimeout=t.pduTimeout||6e4,this.logCommandDatasets=t.logCommandDatasets||!1,this.logDatasets=t.logDatasets||!1,this.datasetReadOptions=t.datasetReadOptions||{},this.datasetWriteOptions=t.datasetWriteOptions||{},this.datasetNameMap=t.datasetNameMap||{},this.datasetTranscodeOptions=t.datasetTranscodeOptions||{},this.logId="",this.connected=!1,this.connectedTime=void 0,this.lastPduTime=void 0,this.timeoutIntervalId=void 0,this.statistics=new _,this._wrapSocket()}sendAssociationRequest(e){this.association=e;const t=new a(this.association).write();this.logId=this.association.getCalledAeTitle(),z.info(`${this.logId} -> Association request:${W}${this.association.toString()}`),this._sendPdu(t)}sendAssociationAccept(){this.association.setImplementationClassUid(j.getImplementationClassUid()),this.association.setImplementationVersion(j.getImplementationVersion()),this.association.setMaxPduLength(Math.min(this.association.getMaxPduLength(),j.getMaxPduLength()));const e=new r(this.association).write();z.info(`${this.logId} -> Association accept:${W}${this.association.toString()}`),this._sendPdu(e)}sendAssociationReject(e,t,s){const n=new o(e,t,s),i=n.write();z.info(`${this.logId} -> Association reject ${n.toString()}`),this._sendPdu(i)}sendAssociationReleaseRequest(){const e=(new d).write();z