Exemplo n.º 1
0
        public QueryExpression Parse(QueryResourceRequest request, IReadOnlyCollection <QueryTag> queryTags)
        {
            EnsureArg.IsNotNull(request, nameof(request));
            EnsureArg.IsNotNull(queryTags, nameof(queryTags));

            _parsedQuery = new QueryExpressionImp();
            queryTags    = GetQualifiedQueryTags(queryTags, request.QueryResourceType);

            foreach (KeyValuePair <string, StringValues> queryParam in request.RequestQuery)
            {
                var trimmedKey = queryParam.Key.Trim();

                // known keys
                if (_paramParsers.TryGetValue(trimmedKey, out Action <KeyValuePair <string, StringValues> > paramParser))
                {
                    paramParser(queryParam);
                    continue;
                }

                // filter conditions with attributeId as key
                if (ParseFilterCondition(queryParam, queryTags, out QueryFilterCondition condition))
                {
                    if (_parsedQuery.FilterConditions.Any(item => item.QueryTag.Tag == condition.QueryTag.Tag))
                    {
                        throw new QueryParseException(string.Format(DicomCoreResource.DuplicateQueryParam, queryParam.Key));
                    }

                    _parsedQuery.FilterConditions.Add(condition);

                    continue;
                }

                throw new QueryParseException(string.Format(DicomCoreResource.UnknownQueryParameter, queryParam.Key));
            }

            // add UIDs as filter conditions
            if (request.StudyInstanceUid != null)
            {
                var condition = new StringSingleValueMatchCondition(new QueryTag(DicomTag.StudyInstanceUID), request.StudyInstanceUid);
                _parsedQuery.FilterConditions.Add(condition);
            }

            if (request.SeriesInstanceUid != null)
            {
                var condition = new StringSingleValueMatchCondition(new QueryTag(DicomTag.SeriesInstanceUID), request.SeriesInstanceUid);
                _parsedQuery.FilterConditions.Add(condition);
            }

            PostProcessFilterConditions(_parsedQuery);

            return(new QueryExpression(
                       request.QueryResourceType,
                       new QueryIncludeField(_parsedQuery.AllValue, _parsedQuery.IncludeFields),
                       _parsedQuery.FuzzyMatch,
                       _parsedQuery.Limit,
                       _parsedQuery.Offset,
                       _parsedQuery.FilterConditions));
        }
Exemplo n.º 2
0
 private static void PostProcessFilterConditions(QueryExpressionImp parsedQuery)
 {
     // fuzzy match condition modification
     if (parsedQuery.FuzzyMatch == true)
     {
         for (int i = 0; i < parsedQuery.FilterConditions.Count; i++)
         {
             QueryFilterCondition cond = parsedQuery.FilterConditions[i];
             if (QueryLimit.IsValidFuzzyMatchingQueryTag(cond.QueryTag))
             {
                 var s = cond as StringSingleValueMatchCondition;
                 parsedQuery.FilterConditions[i] = new PersonNameFuzzyMatchCondition(s.QueryTag, s.Value);
             }
         }
     }
 }
Exemplo n.º 3
0
        private static void PostProcessFilterConditions(QueryExpressionImp parsedQuery)
        {
            // fuzzy match condition modification
            if (parsedQuery.FuzzyMatch == true)
            {
                IEnumerable <QueryFilterCondition> potentialFuzzyConds = parsedQuery.FilterConditions
                                                                         .Where(c => QueryLimit.IsValidFuzzyMatchingQueryTag(c.DicomTag)).ToList();
                foreach (QueryFilterCondition cond in potentialFuzzyConds)
                {
                    var singleValueCondition = cond as StringSingleValueMatchCondition;

                    // Remove existing stringvalue match and add fuzzymatch condition
                    var personNameFuzzyMatchCondition = new PersonNameFuzzyMatchCondition(singleValueCondition.DicomTag, singleValueCondition.Value);
                    parsedQuery.FilterConditions.Remove(singleValueCondition);
                    parsedQuery.FilterConditions.Add(personNameFuzzyMatchCondition);
                }
            }
        }