Пример #1
0
        public async Task GivenDicomFileWithFrames_WhenRetrievingFrameWithOriginalTransferSyntax_ThenExpectedFramesAreReturned(params int[] frames)
        {
            (DicomFile file, Stream stream) = StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(), 3).Result;
            IReadOnlyCollection <Stream> framesStream = await _frameHandler.GetFramesResourceAsync(stream, frames, true, "*");

            var framesOutput = framesStream.ToArray();

            for (int i = 0; i < frames.Length; i++)
            {
                AssertPixelDataEqual(DicomPixelData.Create(file.Dataset).GetFrame(frames[i]), framesOutput[i]);
            }
        }
Пример #2
0
        public async Task <RetrieveResourceResponse> GetInstanceResourceAsync(RetrieveResourceRequest message, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(message, nameof(message));

            try
            {
                AcceptHeaderDescriptor acceptHeaderDescriptor;
                string transferSyntax = _retrieveTransferSyntaxHandler.GetTransferSyntax(message.ResourceType, message.AcceptHeaders, out acceptHeaderDescriptor);
                bool   isOriginalTransferSyntaxRequested = DicomTransferSyntaxUids.IsOriginalTransferSyntaxRequested(transferSyntax);

                IEnumerable <VersionedInstanceIdentifier> retrieveInstances = await _instanceStore.GetInstancesToRetrieve(
                    message.ResourceType, message.StudyInstanceUid, message.SeriesInstanceUid, message.SopInstanceUid, cancellationToken);

                if (!retrieveInstances.Any())
                {
                    throw new InstanceNotFoundException();
                }

                Stream[] resultStreams = await Task.WhenAll(
                    retrieveInstances.Select(x => _blobDataStore.GetFileAsync(x, cancellationToken)));

                if (message.ResourceType == ResourceType.Frames)
                {
                    return(new RetrieveResourceResponse(
                               await _frameHandler.GetFramesResourceAsync(
                                   resultStreams.Single(), message.Frames, isOriginalTransferSyntaxRequested, transferSyntax),
                               acceptHeaderDescriptor.MediaType));
                }
                else
                {
                    if (!isOriginalTransferSyntaxRequested)
                    {
                        resultStreams = await Task.WhenAll(resultStreams.Select(x => _transcoder.TranscodeFileAsync(x, transferSyntax)));
                    }

                    resultStreams = resultStreams.Select(stream =>
                                                         new LazyTransformReadOnlyStream <Stream>(
                                                             stream,
                                                             s => ResetDicomFileStream(s))).ToArray();
                }

                return(new RetrieveResourceResponse(resultStreams, acceptHeaderDescriptor.MediaType));
            }
            catch (DataStoreException e)
            {
                // Log request details associated with exception. Note that the details are not for the store call that failed but for the request only.
                _logger.LogError(
                    e,
                    string.Format(
                        "Error retrieving dicom resource. StudyInstanceUid: {0} SeriesInstanceUid: {1} SopInstanceUid: {2}",
                        message.StudyInstanceUid,
                        message.SeriesInstanceUid,
                        message.SopInstanceUid));

                throw;
            }
        }
Пример #3
0
        public async Task GivenStoredInstancesWithoutFrames_WhenRetrieveRequestForFrame_ThenNotFoundIsThrown()
        {
            // Add multiple instances to validate that we evaluate the requested instance and ignore the other(s).
            List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Frames);
            var framesToRequest = new List <int> {
                0
            };

            // For the instance, set up the fileStore to return a stream containing the file associated with the identifier with 3 frames.
            Stream streamOfStoredFiles = StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(versionedInstanceIdentifiers.First()), frames: 0).Result.Value;

            _fileStore.GetFileAsync(versionedInstanceIdentifiers.First(), DefaultCancellationToken).Returns(streamOfStoredFiles);

            var retrieveResourceRequest = new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, framesToRequest, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetFrame() });

            _dicomFrameHandler.GetFramesResourceAsync(streamOfStoredFiles, retrieveResourceRequest.Frames, true, "*").Throws(new FrameNotFoundException());

            // Request for a specific frame on the instance.
            await Assert.ThrowsAsync <FrameNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync(
                                                                  retrieveResourceRequest,
                                                                  DefaultCancellationToken));

            streamOfStoredFiles.Dispose();
        }