protected virtual IEnumerable <IWadoRsResponse> CreateRetrieveInstanceResponse
        (
            IWadoRequestHeader header,
            IObjectID objectID,
            out string mimeType
        )
        {
            List <IWadoRsResponse>          responses = new List <IWadoRsResponse> ( );
            MediaTypeWithQualityHeaderValue mediaType = null;


            mimeType = null;

            MimeMediaType jsMime = MimeMediaTypes.MultipartRelated;

            if (jsMime.IsIn(header.AcceptHeader, out mediaType))
            {
                mimeType = ProcessMultipartRequest(objectID, responses, mediaType);
            }
            //TODO: all requests for retrieve is multipart except for "metadata in json format"
            //e.g:
            //Instances:
            //Accept - A comma-separated list of representation schemes, in preference order, which will be accepted by the service in theresponse to this request. The types allowed for this request header are as follows:
            //multipart/related; type=application/dicom; [transfer-syntax={TransferSyntaxUID}]
            //Specifies that the response can be DICOM Instances encoded in PS3.10 format. If transfer-syntax is not specified the servercan freely choose which Transfer Syntax to use for each Instance.
            //multipart/related; type=application/octet-stream
            //Specifies that the response can be Little Endian uncompressed bulk data.
            //multipart/related; type={MediaType}
            //Specifies that the response can be pixel data encoded using a {MediaType} listed in Table 6.5-1 (including parameters).

            //Bulk Data:
            //multipart/related; type=application/octet-stream
            //multipart/related; type={MediaType}

            //metadata:
            //multipart/related; type=application/dicom+xml
            //application/json

            //else
            //if ( ((MimeMediaType)MimeMediaTypes.Json).IsIn (header.AcceptHeader, out mediaType))
            //{
            //    mimeType = ProcessJsonRequest ( objectID, responses ) ;
            //}
            //else
            //if ( ((MimeMediaType)MimeMediaTypes.Jpeg).IsIn (header.AcceptHeader, out mediaType))
            //{
            //    //.... and so on
            //}

            //return json metadata by default
            if (null == mimeType)
            {
                mimeType = ProcessJsonRequest(objectID, responses);
            }

            return(responses);
        }
        public DicomMediaId(DicomAttributeCollection dataset, int frame, string mediaType)
        {
            DicomObject = new ObjectID( )
            {
                StudyInstanceUID  = dataset[DicomTags.StudyInstanceUid].GetString(0, ""),
                SeriesInstanceUID = dataset[DicomTags.SeriesInstanceUid].GetString(0, ""),
                SopInstanceUID    = dataset[DicomTags.SopInstanceUid].GetString(0, ""),
                Frame             = frame
            };

            MediaType = mediaType;
        }
        public DicomMediaId(string [] parts)
        {
            if (parts == null || parts.Length != 5)
            {
                throw new ArgumentOutOfRangeException("parts array must be 5");
            }

            MediaType   = parts[0];
            DicomObject = new ObjectID( )
            {
                StudyInstanceUID = parts[1], SeriesInstanceUID = parts[2], SopInstanceUID = parts[3], Frame = int.Parse(parts[4])
            };
        }
        protected virtual IEnumerable <IStorageLocation> GetLocations(IObjectID request, string mediaType)
        {
            if (null != request.Frame)
            {
                List <IStorageLocation> result = new List <IStorageLocation> ( );


                result.Add(RetrieveService.RetrieveSopInstance(request, mediaType));

                return(result);
            }
            else
            {
                return(RetrieveService.RetrieveSopInstances(request, mediaType));
            }
        }
Exemple #5
0
        public IDbCommand CreateGetMetadataCommand(IObjectID instance)
        {
            IDbCommand command  = CreateCommand( );
            var        sopParam = new System.Data.SqlClient.SqlParameter("@" + DB.Schema.StorageDbSchemaProvider.MetadataTable.SopInstanceColumn, instance.SopInstanceUID);


            command.CommandText = string.Format("SELECT {0} FROM {1} WHERE {2}=@{2}",
                                                DB.Schema.StorageDbSchemaProvider.MetadataTable.MetadataColumn,
                                                DB.Schema.StorageDbSchemaProvider.MetadataTable.TableName,
                                                DB.Schema.StorageDbSchemaProvider.MetadataTable.SopInstanceColumn);

            command.Parameters.Add(sopParam);

            SetConnectionIfNull(command);

            return(command);
        }
        public string GetInstanceMetadata(IObjectID instance)
        {
            DicomSqlDataAdapter dbAdapter = new DicomSqlDataAdapter(ConnectionString);


            var cmd = dbAdapter.CreateGetMetadataCommand(instance);

            cmd.Connection.Open( );

            try
            {
                object result = cmd.ExecuteScalar( );

                return(result as string);
            }
            finally
            {
                cmd.Connection.Close( );
            }
        }
        private MimeMediaType ProcessJsonRequest(IObjectID objectID, List <IWadoRsResponse> responses)
        {
            //IDicomConverter<string> jsonConverter = CreateDicomConverter<string> (MimeMediaTypes.Json) ;
            IWadoRsResponse response         = new WadoResponse( );
            StringBuilder   fullJsonResponse = new StringBuilder("[");
            StringBuilder   jsonArray        = new StringBuilder( );
            bool            exists           = false;

            foreach (IStorageLocation storage in GetLocations(objectID, MimeMediaTypes.Json))
            {
                exists = true;

                using (var memoryStream = new MemoryStream())
                {
                    storage.Download(memoryStream);
                    jsonArray.Append(System.Text.Encoding.UTF8.GetString(memoryStream.ToArray( )));
                    jsonArray.Append(",");
                }
            }

            fullJsonResponse.Append(jsonArray.ToString().TrimEnd(','));
            fullJsonResponse.Append("]");

            //TEST CODE
            //dynamic jsonObj = fullJsonResponse.ToString().FromJson ( ) ;

            //var fff = jsonObj[0];

            //var attrib = fff["00080008"];
            //TEST CODE

            if (exists)
            {
                response.Content  = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(fullJsonResponse.ToString()));
                response.MimeType = MimeMediaTypes.Json;

                responses.Add(response);
            }

            return(MimeMediaTypes.Json);
        }
        private string ProcessMultipartRequest
        (
            IObjectID objectID,
            List <IWadoRsResponse> responses,
            MediaTypeWithQualityHeaderValue mediaType
        )
        {
            var mediaTypeHeader = mediaType.Parameters.Where(n => n.Name == "type").FirstOrDefault();

            MimeMediaType requestedMimeType = (mediaTypeHeader != null) ? mediaTypeHeader.Value.Trim('"') : MimeMediaTypes.UncompressedData;


            foreach (IStorageLocation location in GetLocations(objectID, requestedMimeType))
            {
                IWadoRsResponse response = new WadoResponse(location, requestedMimeType);


                responses.Add(response);
            }

            return(requestedMimeType);
        }
Exemple #9
0
        public IDbCommand CreateUpdateMetadataCommand(IObjectID instance, string metadata)
        {
            IDbCommand insertCommand = CreateCommand( );

            insertCommand = CreateCommand( );

            insertCommand.CommandText = string.Format(@"
UPDATE {0} SET {2}=@{2} WHERE {1}=@{1}

IF @@ROWCOUNT = 0
   INSERT INTO {0} ({2}) VALUES (@{2})
", DB.Schema.StorageDbSchemaProvider.MetadataTable.TableName, DB.Schema.StorageDbSchemaProvider.MetadataTable.SopInstanceColumn, DB.Schema.StorageDbSchemaProvider.MetadataTable.MetadataColumn);

            var sopParam  = new System.Data.SqlClient.SqlParameter("@" + DB.Schema.StorageDbSchemaProvider.MetadataTable.SopInstanceColumn, instance.SopInstanceUID);
            var metaParam = new System.Data.SqlClient.SqlParameter("@" + DB.Schema.StorageDbSchemaProvider.MetadataTable.MetadataColumn, metadata);

            insertCommand.Parameters.Add(sopParam);
            insertCommand.Parameters.Add(metaParam);

            SetConnectionIfNull(insertCommand);

            return(insertCommand);
        }
        public void StoreInstanceMetadata(IObjectID instance, string metadata)
        {
            DicomSqlDataAdapter dbAdapter = new DicomSqlDataAdapter(ConnectionString);
            //TODO: use transaction
            //dbAdapter.CreateTransaction ( )

            var cmd = dbAdapter.CreateUpdateMetadataCommand(instance, metadata);

            cmd.Connection.Open( );

            try
            {
                int rowsInserted = cmd.ExecuteNonQuery( );

                if (rowsInserted <= 0)
                {
                    //TODO: return duplicate instance?!!!
                }
            }
            finally
            {
                cmd.Connection.Close( );
            }
        }
 public DicomMediaId(IObjectID objectId, string mediaType)
 {
     DicomObject = objectId;
     MediaType   = mediaType;
 }
        public virtual HttpResponseMessage RetrieveInstance(IWadoRequestHeader header, IObjectID request)
        {
            //IWadoRsMimeResponseCreator mimeResponseHandler = new WadoRsMimeResponseCreator ( ) ;
            IWadoResponseService responseService = new WadoResponseService( );
            HttpResponseMessage  response        = new HttpResponseMessage( );
            string mimeType      = null;
            var    wadoResponses = CreateRetrieveInstanceResponse(header, request, out mimeType);

            //System.Net.Http.Headers.MediaTypeWithQualityHeaderValue mediaType ;
            //if ( ((MimeMediaType)MimeMediaTypes.MultipartRelated).IsIn ( request.AcceptHeader, out mediaType ))

            MultipartContent multiContent = new MultipartContent("related", "DICOM DATA BOUNDARY");

            multiContent.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", "\"" + mimeType + "\""));

            response.Content = multiContent;


            foreach (var wadoResponse in wadoResponses)
            {
                StreamContent sContent = new StreamContent(wadoResponse.Content);
                sContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(wadoResponse.MimeType);

                multiContent.Add(sContent);
            }

            if (wadoResponses.Count( ) == 0)
            {
                response.StatusCode = System.Net.HttpStatusCode.NotFound;
            }


            return(response);
        }
 public IEnumerable <IStorageLocation> RetrieveSopInstances(IObjectID query, string mimeType = null)
 {
     return(__Storage.EnumerateLocation(new DicomMediaId(query, mimeType)));
 }
 public IStorageLocation RetrieveSopInstance(IObjectID query, string mimeType = null)
 {
     return(__Storage.GetLocation(new DicomMediaId(query, mimeType)));
 }