Esempio n. 1
0
        private HttpResponseMessage SearchForDicomEntity
        (
            IQidoRequestModel request,
            DicomDataset dicomSource,
            DoQueryDelegate doQuery
        )
        {
            if (null != request.Query)
            {
                HttpResponseMessage response = null;
                var matchingParams           = request.Query.MatchingElements;
                var includeParams            = request.Query.IncludeElements;

                foreach (var returnParam in includeParams)
                {
                    InsertDicomElement(dicomSource, returnParam, "");
                }

                foreach (var queryParam in matchingParams)
                {
                    string paramValue = queryParam.Value;


                    InsertDicomElement(dicomSource, queryParam.Key, paramValue);
                }

                var results = doQuery(QueryService, dicomSource, request); //TODO: move configuration params into their own object

                if (MultipartResponseHelper.IsMultiPartRequest(request))
                {
                    response = CreateMultipartResponse(request, results.Result);
                }
                else
                {
                    response = CreateJsonResponse(results.Result);
                }

                AddResponseHeaders(request, dicomSource, response, results);

                return(response);
            }

            return(null);
        }
Esempio n. 2
0
 protected virtual bool IsMultiPartRequest(IWadoRequestHeader header)
 {
     return(MultipartResponseHelper.IsMultiPartRequest(header));
 }
Esempio n. 3
0
        private HttpResponseMessage SearchForDicomEntity
        (
            IQidoRequestModel request,
            fo.DicomDataset dicomSource,
            DoQueryDelegate doQuery
        )
        {
            if (null != request.Query)
            {
                var matchingParams = request.Query.MatchingElements;
                var includeParams  = request.Query.IncludeElements;

                foreach (var returnParam in includeParams)
                {
                    InsertDicomElement(dicomSource, returnParam, "");
                }

                foreach (var queryParam in  matchingParams)
                {
                    string paramValue = queryParam.Value;


                    InsertDicomElement(dicomSource, queryParam.Key, paramValue);
                }

                ICollection <fo.DicomDataset> results = doQuery(QueryService, dicomSource, request);  //TODO: move configuration params into their own object

                if (MultipartResponseHelper.IsMultiPartRequest(request))
                {
                    if (MultipartResponseHelper.GetSubMediaType(request.AcceptHeader.FirstOrDefault( )) == MimeMediaTypes.xmlDicom)
                    {
                        HttpResponseMessage response;
                        MultipartContent    multiContent;


                        response     = new HttpResponseMessage( );
                        multiContent = new MultipartContent("related", MultipartResponseHelper.DicomDataBoundary);

                        response.Content = multiContent;

                        foreach (var result in results)
                        {
                            XmlDicomConverter converter = new XmlDicomConverter( );

                            MultipartResponseHelper.AddMultipartContent(multiContent,
                                                                        new WadoResponse(new MemoryStream(Encoding.ASCII.GetBytes(converter.Convert(result))),
                                                                                         MimeMediaTypes.xmlDicom));
                        }

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

                        return(response);
                    }
                    else
                    {
                        return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    StringBuilder jsonReturn = new StringBuilder("[");

                    JsonDicomConverter converter = new JsonDicomConverter( )
                    {
                        IncludeEmptyElements = true
                    };

                    foreach (var response in results)
                    {
                        jsonReturn.AppendLine(converter.Convert(response));

                        jsonReturn.Append(",");
                    }

                    if (results.Count > 0)
                    {
                        jsonReturn.Remove(jsonReturn.Length - 1, 1);
                    }

                    jsonReturn.Append("]");

                    return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                    {
                        Content = new StringContent(jsonReturn.ToString( ),
                                                    Encoding.UTF8,
                                                    MimeMediaTypes.Json)
                    });
                }
            }

            return(null);
        }