Пример #1
0
        public async Task GivenSpecificTransferSyntax_WhenRetrieveRequestForStudy_ThenInstancesInStudyAreTranscodedSuccesfully()
        {
            // Add multiple instances to validate that we return the requested instance and ignore the other(s).
            List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Study);

            // For each instance identifier, set up the fileStore to return a stream containing a file associated with the identifier.
            var streamsAndStoredFiles = versionedInstanceIdentifiers.Select(
                x => StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(x)).Result).ToList();

            streamsAndStoredFiles.ForEach(x => _fileStore.GetFileAsync(x.Key.Dataset.ToVersionedInstanceIdentifier(0), DefaultCancellationToken).Returns(x.Value));

            string transferSyntax = "1.2.840.10008.1.2.1";

            streamsAndStoredFiles.ForEach(x => _retrieveTranscoder.TranscodeFileAsync(x.Value, transferSyntax).Returns(x.Value));

            RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync(
                new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy(transferSyntax: transferSyntax) }),
                DefaultCancellationToken);

            // Validate response status code and ensure response streams have expected files - they should be equivalent to what the store was set up to return.
            ValidateResponseStreams(streamsAndStoredFiles.Select(x => x.Key), response.ResponseStreams);

            // Validate dicom request is populated with correct transcode values
            ValidateDicomRequestIsPopulated(true, response.ResponseStreams.Sum(s => s.Length));

            // Dispose created streams.
            streamsAndStoredFiles.ToList().ForEach(x => x.Value.Dispose());
        }
Пример #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 GivenSupported16bitTransferSyntax_WhenRetrievingFileAndAskingForConversion_ReturnedFileHasExpectedTransferSyntax(
            DicomTransferSyntax tsFrom,
            DicomTransferSyntax tsTo,
            PhotometricInterpretation photometricInterpretation)
        {
            (DicomFile dicomFile, Stream stream) = await StreamAndStoredFileFromDataset(photometricInterpretation, false, tsFrom);

            dicomFile.Dataset.ToInstanceIdentifier();

            Stream transcodedFile = await _transcoder.TranscodeFileAsync(stream, tsTo.UID.UID);

            ValidateTransferSyntax(tsTo, transcodedFile);
        }
Пример #4
0
        private async Task <DicomFile> VerifyTranscodeFileAsync(TranscoderTestData testData, Stream fileStream, DicomFile inputFile)
        {
            Stream outputFileStream = await _transcoder.TranscodeFileAsync(fileStream, testData.MetaData.OutputSyntaxUid);

            DicomFile outputFile = await DicomFile.OpenAsync(outputFileStream);

            Assert.Equal(outputFile.Dataset.InternalTransferSyntax.UID.UID, testData.MetaData.OutputSyntaxUid);

            // Verify file metainfo
            VerifyDicomItems(inputFile.FileMetaInfo, outputFile.FileMetaInfo, DicomTag.FileMetaInformationGroupLength, DicomTag.TransferSyntaxUID);

            // Verify dataset
            VerifyDicomItems(inputFile.Dataset, outputFile.Dataset, DicomTag.PixelData, DicomTag.PhotometricInterpretation);

            VerifyFrames(outputFile, testData);
            return(outputFile);
        }