public string GetDicomJSON(string authenticationCookie, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID, string userData)
        {
            var user = ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            ExtraOptions extraOptions = new ExtraOptions();
            ObjectUID    uid          = new ObjectUID();

            extraOptions.UserData = userData;
            uid.StudyInstanceUID  = studyInstanceUID;
            uid.SeriesInstanceUID = seriesInstanceUID;

            if (string.IsNullOrEmpty(sopInstanceUID))
            {
                var options = new QueryOptions();
                options.StudiesOptions = new StudiesQueryOptions();
                options.StudiesOptions.StudyInstanceUID = studyInstanceUID;
                options.SeriesOptions = new SeriesQueryOptions();
                options.SeriesOptions.SeriesInstanceUID = seriesInstanceUID;
                var objectsFound = AddinsFactory.CreateQueryAddin().FindInstances(user, options, 1, true);
                if (objectsFound.Length > 0)
                {
                    var objects = objectsFound.Where(o => o != null).ToArray();
                    if (objects.Length > 0)
                    {
                        sopInstanceUID = objects[0].SOPInstanceUID;
                    }
                }
            }

            uid.SOPInstanceUID = sopInstanceUID;

            return(AddinsFactory.CreateObjectRetrieveAddin().GetDicomJSON(uid));
        }
Exemple #2
0
        public Task <string> GetDicomJSON(string authenticationCookie, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID, string userData)
        {
            AuthHandler.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            var uid = new ObjectUID();

            uid.StudyInstanceUID  = studyInstanceUID;
            uid.SeriesInstanceUID = seriesInstanceUID;

            if (string.IsNullOrEmpty(sopInstanceUID))
            {
                var options = new QueryOptions();
                options.StudiesOptions = new StudiesQueryOptions();
                options.StudiesOptions.StudyInstanceUID = studyInstanceUID;
                options.SeriesOptions = new SeriesQueryOptions();
                options.SeriesOptions.SeriesInstanceUID = seriesInstanceUID;
                var objectsFound = _query.Value.FindInstances(authenticationCookie, options, 1, true);
                if (objectsFound.Length > 0)
                {
                    var objects = objectsFound.Where(o => o != null).ToArray();
                    if (objects.Length > 0)
                    {
                        sopInstanceUID = objects[0].SOPInstanceUID;
                    }
                }
            }

            uid.SOPInstanceUID = sopInstanceUID;

            return(Task.Factory.StartNew <string>(() => _ret.Value.GetDicomJSON(uid)));
        }
        /// <summary>
        /// Gets the raw DICOM object as XML
        /// </summary>
        /// <param name="authenticationCookie">Cookie</param>
        /// <param name="uid">UIDs. Only SOPInstanceUID is used</param>
        /// <param name="options">Query options</param>
        /// <param name="extraOptions">Extra options</param>
        /// <returns>The DICOM as XML</returns>
        /// <remarks>
        /// <para>RoleName:CanRetrieve</para>
        /// </remarks>
        public XmlElement GetDicomXml(string authenticationCookie, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID, string userData)
        {
            ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            ObjectUID uid = new ObjectUID();

            uid.StudyInstanceUID  = studyInstanceUID;
            uid.SeriesInstanceUID = seriesInstanceUID;
            uid.SOPInstanceUID    = sopInstanceUID;

            return(AddinsFactory.CreateObjectRetrieveAddin().GetDicomXml(uid));
        }
        /// <summary>
        /// this is the main function in the class. It returns the DICOM image data wrapped inside a PNG image
        /// </summary>
        /// <param name="authenticationCookie"></param>
        /// <param name="studyInstanceUID"></param>
        /// <param name="seriesInstanceUID"></param>
        /// <param name="sopInstanceUID"></param>
        /// <param name="frame"></param>
        /// <param name="userData"></param>
        /// <returns></returns>
        public Stream GetDicomImageDataAsPNG(string authenticationCookie, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID, int frame, string userData)
        {
            ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            //must get the encoding accepted by the browser before encoding it. if browser doesn't support some encoding then do not encode
            string acceptEncoding = "Accept-Encoding";
            string encoding       = WebOperationContext.Current.IncomingRequest.Headers[acceptEncoding];


            HttpStatusCode statusCode        = HttpStatusCode.OK;
            string         statusDescription = "";
            Stream         outStream         = null;
            Exception      error             = null;

            try
            {
                if (string.IsNullOrEmpty(sopInstanceUID))
                {
                    statusCode        = System.Net.HttpStatusCode.BadRequest;
                    statusDescription = "Invalid SOPInstanceUID";
                }

                if (frame <= 0)
                {
                    frame = 1;
                }

                if (statusCode == HttpStatusCode.OK)
                {
                    ObjectUID uid = new ObjectUID();
                    uid.StudyInstanceUID  = studyInstanceUID;
                    uid.SeriesInstanceUID = seriesInstanceUID;
                    uid.SOPInstanceUID    = sopInstanceUID;

                    //returns the raw image data as PNG
                    byte[] data = AddinsFactory.CreateObjectRetrieveAddin().GetBinaryDicomImageDataAsPNG(uid, frame);

                    if (null != data)
                    {
                        outStream = new MemoryStream(data);
                    }

                    if (null != outStream && outStream.Length > 0)
                    {
                        //add the right content type so the browser won't try to mess with the data
                        WebOperationContext.Current.OutgoingResponse.ContentType = "image/png";
                    }
                    else
                    {
                        statusCode        = System.Net.HttpStatusCode.NotFound;
                        statusDescription = "No data was found";

                        outStream = null;
                    }
                }

                return(outStream);
            }
            catch (Exception ex)
            {
                statusCode        = System.Net.HttpStatusCode.InternalServerError;
                statusDescription = ex.Message;
                error             = ex;
                return(null);
            }
            finally
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode        = statusCode;
                WebOperationContext.Current.OutgoingResponse.StatusDescription = statusDescription;

                if (error != null || statusCode != HttpStatusCode.OK)
                {
                    WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";


                    if (error == null)
                    {
                        throw new ApplicationException(statusDescription);
                    }
                    else
                    {
                        throw error;
                    }
                }
            }
        }
        private DataInfo GetImageData(string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID, int frame, string userData)
        {
            //must get the encoding accepted by the browser before encoding it. if browser doesn't support some encoding then do not encode
            string   acceptEncoding = "Accept-Encoding";
            string   encoding       = WebOperationContext.Current.IncomingRequest.Headers[acceptEncoding];
            bool     deflate        = (encoding != null) && (encoding.Contains("deflate"));
            bool     gzip           = (encoding != null) && (encoding.Contains("gzip"));
            DataInfo dataInfo       = new DataInfo();
            Stream   result         = null;

            dataInfo.StatusCode        = HttpStatusCode.OK;
            dataInfo.StatusDescription = "";

            if (string.IsNullOrEmpty(sopInstanceUID))
            {
                dataInfo.StatusCode        = System.Net.HttpStatusCode.BadRequest;
                dataInfo.StatusDescription = "Invalid SOPInstanceUID";
            }

            if (frame <= 0)
            {
                frame = 1;
            }

            if (dataInfo.StatusCode == HttpStatusCode.OK)
            {
                ObjectUID uid = new ObjectUID();

                uid.StudyInstanceUID  = studyInstanceUID;
                uid.SeriesInstanceUID = seriesInstanceUID;
                uid.SOPInstanceUID    = sopInstanceUID;

                //returns the raw image data as binary (no compression, no base 64)
                byte[] data = AddinsFactory.CreateObjectRetrieveAddin().GetBinaryDicomImageData(uid, frame);

                if (null != data)
                {
                    result = new MemoryStream(data);
                }

                if (null != result && result.Length > 0)
                {
                    Stream outStream;

                    //check if can do deflate compression first
                    if (deflate)
                    {
                        outStream = CompressDeflate(result);

                        WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Encoding", "deflate");
                    }
                    //then check the gzip compression
                    else if (gzip)
                    {
                        outStream = CompressGZip(result);

                        WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Encoding", "gzip");
                    }
                    //if neither is supported then don't compress
                    else
                    {
                        outStream = result;
                    }

                    //add the right content type so the browser won't try to mess with the data
                    WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain; charset=x-user-defined";

                    dataInfo.Stream = outStream;
                    return(dataInfo);
                }
                else
                {
                    dataInfo.StatusCode        = System.Net.HttpStatusCode.NotFound;
                    dataInfo.StatusDescription = "No data was found";

                    result = null;
                }
            }
            dataInfo.Stream = result;
            return(dataInfo);
        }
        /// <summary>
        /// Gets the raw DICOM object for an object
        /// </summary>
        /// <param name="authenticationCookie">Cookie</param>
        /// <param name="uid">UIDs. Only SOPInstanceUID is used</param>
        /// <param name="options">Query options</param>
        /// <param name="extraOptions">Extra options</param>
        /// <returns>The DICOM as stream</returns>
        /// <remarks>
        /// <para>RoleName:CanRetrieve</para>
        /// </remarks>
        public Stream GetDicom(string authenticationCookie, ObjectUID uid, GetDicomOptions options, ExtraOptions extraOptions)
        {
            ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            return(AddinsFactory.CreateObjectRetrieveAddin().GetDicom(uid, options));
        }
 /// <summary>
 /// Gets the raw DICOM object for an object
 /// </summary>
 /// <param name="authenticationCookie">Cookie</param>
 /// <param name="uid">UIDs. Only SOPInstanceUID is used</param>
 /// <param name="options">Query options</param>
 /// <returns>The DICOM as stream</returns>
 /// <remarks>
 /// <para>RoleName:CanRetrieve</para>
 /// </remarks>
 public Stream GetDicom(string authenticationCookie, ObjectUID uid, GetDicomOptions options)
 {
     return(null);
 }
Exemple #8
0
 public void method_41(ObjectUID objectUID_0)
 {
     this.method_45(objectUID_0.method_0());
 }
Exemple #9
0
        public Stream GetDicom(string authenticationCookie, ObjectUID uid, GetDicomOptions options)
        {
            AuthHandler.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve);

            return(_ret.Value.GetDicom(uid, options));
        }