public async Task <QueryResourceResponse> QueryAsync(
            QueryResourceRequest message,
            CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(message);

            ValidateRequestIdentifiers(message);

            var queryTags = await _queryTagService.GetQueryTagsAsync(cancellationToken);

            QueryExpression queryExpression = _queryParser.Parse(message, queryTags);

            QueryResult queryResult = await _queryStore.QueryAsync(queryExpression, cancellationToken);

            if (!queryResult.DicomInstances.Any())
            {
                return(new QueryResourceResponse());
            }

            IEnumerable <DicomDataset> instanceMetadata = await Task.WhenAll(
                queryResult.DicomInstances
                .Select(x => _metadataStore.GetInstanceMetadataAsync(x, cancellationToken)));

            var responseBuilder = new QueryResponseBuilder(queryExpression);
            IEnumerable <DicomDataset> responseMetadata = instanceMetadata.Select(m => responseBuilder.GenerateResponseDataset(m));

            return(new QueryResourceResponse(responseMetadata));
        }
Example #2
0
        public async Task <QueryResourceResponse> QueryAsync(
            QueryParameters parameters,
            CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(parameters);

            ValidateRequestIdentifiers(parameters);

            var queryTags = await _queryTagService.GetQueryTagsAsync(cancellationToken : cancellationToken);

            QueryExpression queryExpression = _queryParser.Parse(parameters, queryTags);

            var partitionKey = _contextAccessor.RequestContext.GetPartitionKey();

            QueryResult queryResult = await _queryStore.QueryAsync(partitionKey, queryExpression, cancellationToken);

            if (!queryResult.DicomInstances.Any())
            {
                return(new QueryResourceResponse(Array.Empty <DicomDataset>(), queryExpression.ErroneousTags));
            }

            IEnumerable <DicomDataset> instanceMetadata = await Task.WhenAll(
                queryResult.DicomInstances.Select(x => _metadataStore.GetInstanceMetadataAsync(x, cancellationToken)));

            var responseBuilder = new QueryResponseBuilder(queryExpression);
            IEnumerable <DicomDataset> responseMetadata = instanceMetadata.Select(m => responseBuilder.GenerateResponseDataset(m));

            return(new QueryResourceResponse(responseMetadata, queryExpression.ErroneousTags));
        }