private static void AddPaginationHeders(IQidoRequestModel request, HttpResponseMessage response, PagedResult <DicomDataset> results) { LinkHeaderBuilder headerBuilder = new LinkHeaderBuilder( ); response.Headers.Add("link", headerBuilder.GetLinkHeader(results, HttpContext.Current.Request.Url.AbsoluteUri)); response.Headers.Add("X-Total-Count", results.TotalCount.ToString()); response.Headers.Add("Access-Control-Expose-Headers", "link"); response.Headers.Add("Access-Control-Allow-Headers", "link"); response.Headers.Add("Access-Control-Expose-Headers", "X-Total-Count"); response.Headers.Add("Access-Control-Allow-Headers", "X-Total-Count"); if (results.TotalCount > results.Result.Count()) { if (!request.Limit.HasValue || (request.Limit.HasValue && request.Limit.Value > results.PageSize)) { response.Headers.Add("Warning", "299 " + "DICOMcloud" + " \"The number of results exceeded the maximum supported by the server. Additional results can be requested.\""); //DICOM: http://dicom.nema.org/dicom/2013/output/chtml/part18/sect_6.7.html //Warning: 299 {SERVICE}: "The number of results exceeded the maximum supported by the server. Additional results can be requested. } } }
private static HttpResponseMessage CreateMultipartResponse(IQidoRequestModel request, IEnumerable <DicomDataset> results) { HttpResponseMessage response; if (MultipartResponseHelper.GetSubMediaType(request.AcceptHeader.FirstOrDefault( )) == MimeMediaTypes.xmlDicom) { 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 + "\"")); } else { response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } return(response); }
public HttpResponseMessage SearchForSeries ( [ModelBinder(typeof(QidoRequestModelBinder))] IQidoRequestModel request ) { return(QidoService.SearchForSeries(request)); }
protected virtual IQueryOptions GetQueryOptions(IQidoRequestModel qidoRequest) { var queryOptions = CreateNewQueryOptions( ); queryOptions.Limit = Math.Min(MaximumResultsLimit, qidoRequest.Limit.HasValue ? qidoRequest.Limit.Value : MaximumResultsLimit); queryOptions.Offset = Math.Max(0, qidoRequest.Offset.HasValue ? qidoRequest.Offset.Value : 0); return(queryOptions); }
protected virtual IQueryOptions GetQueryOptions(IQidoRequestModel qidoRequest) { var queryOptions = CreateNewQueryOptions( ); queryOptions.Limit = qidoRequest.Limit; queryOptions.Offset = qidoRequest.Offset; return(queryOptions); }
private HttpResponseMessage SearchForDicomEntity ( IQidoRequestModel request, DicomAttributeCollection dicomSource, DoQueryDelegate doQuery ) { if (null != request.Query) { var matchingParams = request.Query.MatchingElements; var includeParams = request.Query.IncludeElements; foreach (var queryParam in matchingParams) { string paramValue = queryParam.Value; InsertDicomElement(dicomSource, queryParam.Key, paramValue); } foreach (var returnParam in includeParams) { InsertDicomElement(dicomSource, returnParam, ""); } ICollection <DicomAttributeCollection> results = doQuery(QueryService, dicomSource, request.Limit, request.Offset); //TODO: move configuration params into their own object 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); }
public virtual HttpResponseMessage SearchForSeries(IQidoRequestModel request) { return(SearchForDicomEntity(request, DefaultDicomQueryElements.GetDefaultSeriesQuery( ), delegate ( IObjectArchieveQueryService queryService, DicomDataset dicomRequest, IQidoRequestModel qidoResult ) { return queryService.FindSeriesPaged(dicomRequest, GetQueryOptions(qidoResult)); })); }
public HttpResponseMessage SearchForInstances(IQidoRequestModel request) { return(SearchForDicomEntity(request, DefaultDicomQueryElements.GetDefaultInstanceQuery( ), delegate ( IObjectArchieveQueryService queryService, fo.DicomDataset dicomRequest, IQidoRequestModel qidoResult ) { return queryService.FindObjectInstances(dicomRequest, GetQueryOptions(qidoResult)); })); }
public HttpResponseMessage SearchForInstances(IQidoRequestModel request) { return(SearchForDicomEntity(request, DefaultDicomQueryElements.GetDefaultInstanceQuery( ), delegate ( IObjectArchieveQueryService queryService, DicomAttributeCollection dicomRequest, int?limit, int?offset ) { return queryService.FindObjectInstances(dicomRequest, offset, limit); })); }
private void AddResponseHeaders ( IQidoRequestModel request, DicomDataset dicomSource, HttpResponseMessage response, PagedResult <DicomDataset> results ) { //special parameters, if included, a representative instance UID (first) will be returned in header for each DS result if (response.IsSuccessStatusCode && request.Query.CustomParameters.ContainsKey("_instance-header")) { AddPreviewInstanceHeader(results.Result, response); } AddPaginationHeders(request, response, results); }
/// <summary> /// If access Qido interface with URL http://localhost:44301/qidors/studies/1.3.12.2.1107.5.3.4.2373.1.20171103124622/series /// will get a 404 page, this method will check if the URL contains uid information. /// </summary> /// <param name="valueProvider"></param> /// <param name="wadoReq"></param> private void CheckAndFillUids(IValueProvider valueProvider, IQidoRequestModel wadoReq) { string studyInstanceUidKey = fo.DicomTag.StudyInstanceUID.DictionaryEntry.Keyword.ToLower(); string seriesInstanceUidKey = fo.DicomTag.SeriesInstanceUID.DictionaryEntry.Keyword.ToLower(); string sopInstanceUidKey = fo.DicomTag.SOPInstanceUID.DictionaryEntry.Keyword.ToLower(); if (!wadoReq.Query.MatchingElements.ContainsKey(studyInstanceUidKey)) { ValueProviderResult valueResult = valueProvider.GetValue(studyInstanceUidKey); if (valueResult != null) { string studyInstanceUid = valueResult.RawValue as string; if (!string.IsNullOrEmpty(studyInstanceUid)) { wadoReq.Query.MatchingElements.Add(studyInstanceUidKey, studyInstanceUid); } } } if (!wadoReq.Query.MatchingElements.ContainsKey(seriesInstanceUidKey)) { ValueProviderResult valueResult = valueProvider.GetValue(seriesInstanceUidKey); if (valueResult != null) { string seriesInstanceUid = valueResult.RawValue as string; if (!string.IsNullOrEmpty(seriesInstanceUid)) { wadoReq.Query.MatchingElements.Add(seriesInstanceUidKey, seriesInstanceUid); } } } if (!wadoReq.Query.MatchingElements.ContainsKey(sopInstanceUidKey)) { ValueProviderResult valueResult = valueProvider.GetValue(sopInstanceUidKey); if (valueResult != null) { string sopInstanceUid = valueResult.RawValue as string; if (!string.IsNullOrEmpty(sopInstanceUid)) { wadoReq.Query.MatchingElements.Add(sopInstanceUidKey, sopInstanceUid); } } } }
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); }
public HttpResponseMessage SearchForStudies ( IQidoRequestModel request ) { return(SearchForDicomEntity(request, DefaultDicomQueryElements.GetDefaultStudyQuery(), delegate ( IObjectArchieveQueryService queryService, fo.DicomDataset dicomRequest, IQidoRequestModel qidoRequest ) { IQueryOptions queryOptions = GetQueryOptions(qidoRequest); return queryService.FindStudies(dicomRequest, queryOptions); })); }
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); }
public bool TryParse(HttpRequestMessage request, out IQidoRequestModel result) { QidoRequestModel wadoReq = new QidoRequestModel( ); wadoReq.Query = new QidoQuery( ); wadoReq.AcceptHeader = request.Headers.Accept; wadoReq.AcceptCharsetHeader = request.Headers.AcceptCharset; var query = request.RequestUri.ParseQueryString( ); foreach (var key in query) { string queryKey = ((string)key).Trim( ).ToLower( ); switch (queryKey) { case QidoRequestKeys.FuzzyMatching: { bool fuzzy; if (bool.TryParse(query[QidoRequestKeys.FuzzyMatching], out fuzzy)) { wadoReq.FuzzyMatching = fuzzy; } } break; case QidoRequestKeys.Limit: { int limit; if (int.TryParse(query[QidoRequestKeys.Limit], out limit)) { wadoReq.Limit = limit; } } break; case QidoRequestKeys.Offset: { int offset; if (int.TryParse(query[QidoRequestKeys.Offset], out offset)) { wadoReq.Offset = offset; } } break; case QidoRequestKeys.IncludeField: { string includeFields = query[QidoRequestKeys.IncludeField]; if (!string.IsNullOrWhiteSpace(includeFields)) { wadoReq.Query.IncludeElements.AddRange(includeFields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } } break; default: { string matchingQuery = query[queryKey].Trim( ); //string[] matchingQueryValues = matchingQuery.Trim ( ).Split ( new char[] {','}, StringSplitOptions.RemoveEmptyEntries ) ; var matchingElements = wadoReq.Query.MatchingElements; //TODO: what if key exists //should return invalid request //foreach ( var matchingParam in matchingQueryValues ) { matchingElements.Add(queryKey, matchingQuery); } } break; } } result = wadoReq; return(true); }
public virtual bool TryParse(HttpRequestMessage request, ModelBindingContext bindingContext, out IQidoRequestModel result) { IQidoRequestModel wadoReq = CreateModel( ); wadoReq.AcceptHeader = request.Headers.Accept; wadoReq.AcceptCharsetHeader = request.Headers.AcceptCharset; var query = request.RequestUri.ParseQueryString(); foreach (var key in query) { string queryKey = ((string)key).Trim().ToLower(); if (queryKey == "") { continue; } switch (queryKey) { case QidoRequestKeys.FuzzyMatching: { bool fuzzy; if (bool.TryParse(query[QidoRequestKeys.FuzzyMatching], out fuzzy)) { wadoReq.FuzzyMatching = fuzzy; } } break; case QidoRequestKeys.Limit: { int limit; if (int.TryParse(query[QidoRequestKeys.Limit], out limit)) { wadoReq.Limit = limit; } } break; case QidoRequestKeys.Offset: { int offset; if (int.TryParse(query[QidoRequestKeys.Offset], out offset)) { wadoReq.Offset = offset; } } break; case QidoRequestKeys.IncludeField: { string includeFields = query[QidoRequestKeys.IncludeField]; if (!string.IsNullOrWhiteSpace(includeFields)) { wadoReq.Query.IncludeElements.AddRange(includeFields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } } break; default: { string queryValue = query[queryKey].Trim(); if (queryKey.StartsWith("_")) { wadoReq.Query.CustomParameters.Add(queryKey, queryValue); } else { wadoReq.Query.MatchingElements.Add(queryKey, queryValue); } } break; } } CheckAndFillUids(bindingContext.ValueProvider, wadoReq); result = wadoReq; return(true); }