Beispiel #1
0
        public async Task <RetrieveMetadataResponse> RetrieveStudyInstanceMetadataAsync(string studyInstanceUid, string ifNoneMatch = null, CancellationToken cancellationToken = default)
        {
            IEnumerable <VersionedInstanceIdentifier> retrieveInstances = await _instanceStore.GetInstancesToRetrieve(
                ResourceType.Study,
                studyInstanceUid,
                seriesInstanceUid : null,
                sopInstanceUid : null,
                cancellationToken);

            string eTag         = _eTagGenerator.GetETag(ResourceType.Study, retrieveInstances);
            bool   isCacheValid = IsCacheValid(eTag, ifNoneMatch);

            return(await RetrieveMetadata(retrieveInstances, isCacheValid, eTag, cancellationToken));
        }
Beispiel #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;
            }
        }