class WadoRsProxy { public _baseUrl : string = "" ; constructor ( baseUrl = null ) { this . _baseUrl = baseUrl ; } public get BaseUrl ( ) { if ( this . _baseUrl === null ) { return DICOMwebJS . ServerConfiguration . getWadoRsUrl ( ) ; } else { return this . _baseUrl ; } } public set BaseUrl ( value ) { this . _baseUrl = value ; } public getStudy ( studyInstanceUid , mediaType , transferSyntax = null ) { return this . getBinaryDICOMMultipart ( "/studies/" + studyInstanceUid + "/" , mediaType , transferSyntax ) ; } public getSeries ( studyInstanceUid , seriesInstanceUid , mediaType , transferSyntax = null ) { return this . getBinaryDICOMMultipart ( "/studies/" + studyInstanceUid + "/" + "series" + "/" , mediaType , transferSyntax ) ; } public getObjectInstance ( studyInstanceUid , seriesInstanceUid , sopInstanceUID , mediaType , transferSyntax = null ) { return this . getBinaryDICOMMultipart ( "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/instances/" + sopInstanceUID + "/" , mediaType , transferSyntax ) ; } public getStudyMetadata ( studyInstanceUid , mediaType = null , transferSyntax = null ) { var urlParts = "/studies/" + studyInstanceUid + "/metadata" ; return this . getMetadata ( urlParts , mediaType , transferSyntax ) ; } public getSeriesMetadata ( studyInstanceUid , seriesInstanceUid , mediaType = null , transferSyntax = null ) { var urlParts = "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/metadata" ; return this . getMetadata ( urlParts , mediaType , transferSyntax ) ; } public getObjectInstanceMetadata ( studyInstanceUid , seriesInstanceUid , sopInstanceUid , mediaType , transferSyntax = null ) { var urlParts = "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/instances/" + sopInstanceUid + "/metadata" ; return this . getMetadata ( urlParts , mediaType , transferSyntax ) ; } public getMetadata ( urlParts , mediaType = null , transferSyntax = null ) { if ( mediaType === null || typeof ( mediaType ) === "undefined" ) { mediaType = MimeTypes . Json ; } if ( mediaType == MimeTypes . Json ) { return this . get ( urlParts , mediaType , transferSyntax ) ; } else if ( mediaType == MimeTypes . xmlDicom ) { return this . getMultipart ( urlParts , mediaType , transferSyntax ) ; } else { throw "Invalid mediaType for metadata request" ; } } public getFrame ( studyInstanceUid , seriesInstanceUid , sopInstanceUID , frameList , mediaType , transferSyntax = null ) { return this . getBinaryDICOMMultipart ( "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/instances/" + sopInstanceUID + "/frames/" + frameList , mediaType ) ; } public getBinaryDICOMMultipart ( urlRsPart , acceptDataType , transferSyntax = null ) { var deffered = $ . Deferred ( ) ; var url = this . BaseUrl + urlRsPart ; var xhr = new XMLHttpRequest ( ) ; var acceptHeader = MimeTypes . getMultiPartAcceptHeader ( acceptDataType ) ; if ( transferSyntax ) { acceptHeader += ";transfer-syntax=" + transferSyntax ; } xhr . overrideMimeType ( "application/octet-stream" ) ; xhr . open ( "GET" , url , true ) ; xhr . responseType = "arraybuffer" ; xhr . setRequestHeader ( "accept" , acceptHeader ) ; xhr . onreadystatechange = function ( ) { if ( xhr . readyState == 4 && xhr . status == 200 ) { var buffer = new Uint8Array ( xhr . response ) ; deffered . resolve ( buffer , xhr . statusText ) ; } } ; xhr . onerror = function ( error ) { deffered . reject ( error ) ; } ; if ( DICOMwebJS . ServerConfiguration . IncludeAuthorizationHeader ) { xhr . setRequestHeader ( "Authorization" , DICOMwebJS . ServerConfiguration . SecurityToken ) ; } xhr . send ( null ) ; return deffered . promise ( ) ; } public getMultipart ( urlRsPart , acceptDataType , transferSyntax = null ) { return this . get ( urlRsPart , MimeTypes . getMultiPartAcceptHeader ( acceptDataType ) , transferSyntax ) ; } public get ( urlRsPart , acceptHeader , transferSyntax = null ) { var deffered = $ . Deferred ( ) ; var url = this . BaseUrl + urlRsPart ; var xhr = new XMLHttpRequest ( ) ; if ( transferSyntax ) { acceptHeader += ";transfer-syntax=" + transferSyntax ; } xhr . open ( "GET" , url , true ) ; xhr . setRequestHeader ( "accept" , acceptHeader ) ; xhr . onreadystatechange = function ( ) { if ( xhr . readyState == 4 && xhr . status == 200 ) { deffered . resolve ( xhr . response , xhr . statusText ) ; } } ; xhr . onerror = function ( error ) { deffered . reject ( error ) ; } ; if ( DICOMwebJS . ServerConfiguration . IncludeAuthorizationHeader ) { xhr . setRequestHeader ( "Authorization" , DICOMwebJS . ServerConfiguration . SecurityToken ) ; } xhr . send ( null ) ; return deffered . promise ( ) ; } }