Exemplo n.º 1
0
        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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public async void GivenRequestForInstances_WhenRetrievingQueriableExtendedQueryTags_ReturnsAllTags(QueryResource resourceType)
        {
            var request = new QueryResourceRequest(
                Substitute.For <IEnumerable <KeyValuePair <string, StringValues> > >(),
                resourceType,
                TestUidGenerator.Generate(),
                TestUidGenerator.Generate());

            List <ExtendedQueryTagStoreEntry> storeEntries = new List <ExtendedQueryTagStoreEntry>()
            {
                new ExtendedQueryTagStoreEntry(1, "00741000", "CS", null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Ready),
                new ExtendedQueryTagStoreEntry(2, "0040A121", "DA", null, QueryTagLevel.Series, ExtendedQueryTagStatus.Ready),
                new ExtendedQueryTagStoreEntry(3, "00101005", "PN", null, QueryTagLevel.Study, ExtendedQueryTagStatus.Ready),
            };

            var list = QueryTagService.CoreQueryTags.Concat(storeEntries.Select(item => new QueryTag(item))).ToList();

            _queryTagService.GetQueryTagsAsync().ReturnsForAnyArgs(list);
            _queryStore.QueryAsync(Arg.Any <QueryExpression>(), Arg.Any <CancellationToken>()).ReturnsForAnyArgs(new QueryResult(new List <VersionedInstanceIdentifier>()));
            await _queryService.QueryAsync(request, CancellationToken.None);

            _queryParser.Received().Parse(request, Arg.Do <IReadOnlyCollection <QueryTag> >(x => Assert.Equal(x, list, QueryTagComparer.Default)));
        }