Ejemplo n.º 1
0
        private async Task <(DicomFile dicomFile, Stream stream)> StreamAndStoredFileFromDataset(PhotometricInterpretation photometricInterpretation, bool is8BitPixelData, DicomTransferSyntax transferSyntax)
        {
            var dicomFile = is8BitPixelData ?
                            Samples.CreateRandomDicomFileWith8BitPixelData(transferSyntax: transferSyntax.UID.UID, photometricInterpretation: photometricInterpretation.Value, frames: 2)
                : Samples.CreateRandomDicomFileWith16BitPixelData(transferSyntax: transferSyntax.UID.UID, photometricInterpretation: photometricInterpretation.Value, frames: 2);

            MemoryStream stream = _recyclableMemoryStreamManager.GetStream();
            await dicomFile.SaveAsync(stream);

            stream.Position = 0;

            return(dicomFile, stream);
        }
        public async Task GivenSupported16bitTransferSyntax_WhenRetrievingStudyAndAskingForConversion_OKIsReturned(
            string tsFrom,
            string tsTo)
        {
            DicomFile dicomFile     = Samples.CreateRandomDicomFileWith16BitPixelData(transferSyntax: ((DicomTransferSyntax)typeof(DicomTransferSyntax).GetField(tsFrom).GetValue(null)).UID.UID);
            var       dicomInstance = dicomFile.Dataset.ToInstanceIdentifier();

            try
            {
                await _client.StoreAsync(new[] { dicomFile });

                var expectedTransferSyntax = (DicomTransferSyntax)typeof(DicomTransferSyntax).GetField(tsTo).GetValue(null);

                DicomWebResponse <IReadOnlyList <DicomFile> > retrieveResponse = await _client.RetrieveInstanceAsync(
                    dicomInstance.StudyInstanceUid,
                    dicomInstance.SeriesInstanceUid,
                    dicomInstance.SopInstanceUid,
                    expectedTransferSyntax.UID.UID);

                Assert.Equal(HttpStatusCode.OK, retrieveResponse.StatusCode);
                Assert.Equal(expectedTransferSyntax, retrieveResponse.Value.Single().Dataset.InternalTransferSyntax);

                DicomWebResponse <IReadOnlyList <Stream> > framesResponse = await _client.RetrieveFramesAsync(
                    dicomInstance.StudyInstanceUid,
                    dicomInstance.SeriesInstanceUid,
                    dicomInstance.SopInstanceUid,
                    expectedTransferSyntax.UID.UID,
                    frames : new[] { 1 });

                Assert.Equal(HttpStatusCode.OK, retrieveResponse.StatusCode);
                Assert.NotEqual(0, framesResponse.Value.Single().Length);
            }
            finally
            {
                await _client.DeleteInstanceAsync(dicomInstance.StudyInstanceUid, dicomInstance.SeriesInstanceUid, dicomInstance.SopInstanceUid);
            }
        }