Example #1
0
        public async Task GivenUnsupportedTransferSyntax_WhenRetrieveFrameWithOriginalTransferSyntax_ThenOriginalContentReturned()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();
            var sopInstanceUid    = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID,
                encode: false);

            await InternalStoreAsync(new[] { dicomFile });

            // Check for series
            using DicomWebAsyncEnumerableResponse <Stream> response = await _client.RetrieveFramesAsync(
                      studyInstanceUid,
                      seriesInstanceUid,
                      sopInstanceUid,
                      dicomTransferSyntax : "*",
                      frames : new[] { 1 });

            Stream[] results = await response.ToArrayAsync();

            Assert.Collection(
                results,
                item => Assert.Equal(item.ToByteArray(), DicomPixelData.Create(dicomFile.Dataset).GetFrame(0).Data));
        }
        public async Task GivenMultipleInstances_WhenRetrieveStudy_ThenServerShouldReturnExpectedInstances()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var studyInstanceUid2 = TestUidGenerator.Generate();

            DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile3 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid2,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            await _instancesManager.StoreAsync(new[] { dicomFile1, dicomFile2, dicomFile3 });

            using DicomWebAsyncEnumerableResponse <DicomFile> response = await _client.RetrieveStudyAsync(studyInstanceUid);

            DicomFile[] instancesInStudy = await response.ToArrayAsync();

            Assert.Equal(2, instancesInStudy.Length);

            byte[][] actual = instancesInStudy.Select(item => item.ToByteArray()).ToArray();

            Assert.Contains(dicomFile1.ToByteArray(), actual);
            Assert.Contains(dicomFile2.ToByteArray(), actual);
        }
        public async Task GivenMultipleInstances_WhenRetrieveSeries_ThenServerShouldReturnExpectedInstances()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();

            DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile3 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            await InternalStoreAsync(new[] { dicomFile1, dicomFile2, dicomFile3 });

            DicomWebResponse <IReadOnlyList <DicomFile> > instancesInStudy = await _client.RetrieveSeriesAsync(studyInstanceUid, seriesInstanceUid);

            Assert.Equal(2, instancesInStudy.Value.Count);
            var actual = instancesInStudy.Value.Select(item => item.ToByteArray());

            Assert.Contains(dicomFile1.ToByteArray(), actual);
            Assert.Contains(dicomFile2.ToByteArray(), actual);
        }
        public async Task GivenMultipleInstancesWithMixTransferSyntax_WhenRetrieveSeriesWithOriginalTransferSyntax_ThenServerShouldReturnOrignialContents()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();

            DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.MPEG2.UID.UID,
                encode: false);

            await _instancesManager.StoreAsync(new[] { dicomFile1, dicomFile2 });

            using DicomWebAsyncEnumerableResponse <DicomFile> response = await _client.RetrieveSeriesAsync(studyInstanceUid, seriesInstanceUid, dicomTransferSyntax : "*");

            DicomFile[] instancesInStudy = await response.ToArrayAsync();

            Assert.Equal(2, instancesInStudy.Length);

            byte[][] actual = instancesInStudy.Select(item => item.ToByteArray()).ToArray();

            Assert.Contains(dicomFile1.ToByteArray(), actual);
            Assert.Contains(dicomFile2.ToByteArray(), actual);
        }
        public async Task GivenAMixOfTransferSyntaxes_WhenSomeAreSupported_NotAcceptableIsReturned()
        {
            var seriesInstanceUid = TestUidGenerator.Generate();
            var studyInstanceUid  = TestUidGenerator.Generate();

            DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID,
                encode: false);

            DicomFile dicomFile3 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.ImplicitVRLittleEndian.UID.UID);

            await _client.StoreAsync(new[] { dicomFile1, dicomFile2, dicomFile3 });

            DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveSeriesAsync(
                                                                                           studyInstanceUid,
                                                                                           seriesInstanceUid,
                                                                                           DicomTransferSyntax.JPEG2000Lossy.UID.UID));

            Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode);
        }
        public async Task GivenSupportedTransferSyntax_WhenSupportedWildcardTsIsSpecified_OriginalTsReturned()
        {
            var seriesInstanceUid = TestUidGenerator.Generate();
            var studyInstanceUid  = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                transferSyntax: DicomTransferSyntax.DeflatedExplicitVRLittleEndian.UID.UID);

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

                DicomWebResponse <IReadOnlyList <DicomFile> > retrieveResponse = await _client.RetrieveSeriesAsync(
                    studyInstanceUid,
                    seriesInstanceUid,
                    dicomTransferSyntax : "*");

                Assert.Equal(HttpStatusCode.OK, retrieveResponse.StatusCode);
                Assert.Equal(DicomTransferSyntax.DeflatedExplicitVRLittleEndian, retrieveResponse.Value.Single().Dataset.InternalTransferSyntax);
            }
            finally
            {
                await _client.DeleteSeriesAsync(studyInstanceUid, seriesInstanceUid);
            }
        }
        public async Task GivenAnUnsupportedTransferSyntax_WhenWildCardTsSpecified_OriginalImageReturned()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();
            var sopInstanceUid    = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID,
                encode: false);

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

            // Check for series
            DicomWebResponse <IReadOnlyList <DicomFile> > seriesResponse = await _client.RetrieveSeriesAsync(
                studyInstanceUid,
                seriesInstanceUid,
                "*");

            Assert.Equal(HttpStatusCode.OK, seriesResponse.StatusCode);
            Assert.Equal(DicomTransferSyntax.HEVCH265Main10ProfileLevel51, seriesResponse.Value.Single().Dataset.InternalTransferSyntax);

            // Check for frame
            DicomWebResponse <IReadOnlyList <Stream> > frameResponse = await _client.RetrieveFramesAsync(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                dicomTransferSyntax : "*",
                frames : new[] { 1 });

            Assert.Equal(HttpStatusCode.OK, frameResponse.StatusCode);
            Assert.NotEqual(0, frameResponse.Value.Single().Length);
        }
Example #8
0
        public async Task GivenUnsupportedTransferSyntax_WhenRetrieveFrameWithOriginalTransferSyntax_ThenOriginalContentReturned()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();
            var sopInstanceUid    = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID,
                encode: false);

            await InternalStoreAsync(new[] { dicomFile });

            // Check for series
            DicomWebResponse <IReadOnlyList <Stream> > response = await _client.RetrieveFramesAsync(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                dicomTransferSyntax : "*",
                frames : new[] { 1 });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(response.Value[0].ToByteArray(), DicomPixelData.Create(dicomFile.Dataset).GetFrame(0).Data);
        }
        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 GivenUnsupportedInternalTransferSyntax_WhenRetrieveInstance_ThenServerShouldReturnNotAcceptable()
        {
            var       studyInstanceUid  = TestUidGenerator.Generate();
            var       seriesInstanceUid = TestUidGenerator.Generate();
            var       sopInstanceUid    = TestUidGenerator.Generate();
            DicomFile dicomFile         = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.MPEG2.UID.UID,
                encode: false);

            await InternalStoreAsync(new[] { dicomFile });

            DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid, dicomTransferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID));

            Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode);
        }
        public async Task GivenUnsupportedInternalTransferSyntax_WhenRetrieveInstanceWithOriginalTransferSyntax_ThenServerShouldReturnOriginalContent()
        {
            var studyInstanceUid  = TestUidGenerator.Generate();
            var seriesInstanceUid = TestUidGenerator.Generate();
            var sopInstanceUid    = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.MPEG2.UID.UID,
                encode: false);

            await InternalStoreAsync(new[] { dicomFile });

            using DicomWebResponse <DicomFile> instancesInStudy = await _client.RetrieveInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid, dicomTransferSyntax : "*");

            Assert.Equal(dicomFile.ToByteArray(), (await instancesInStudy.GetValueAsync()).ToByteArray());
        }
        public async Task GivenMultipleInstancesWithMixTransferSyntax_WhenRetrieveStudy_ThenServerShouldReturnNotAcceptable()
        {
            var studyInstanceUid = TestUidGenerator.Generate();

            DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID);

            DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                TestUidGenerator.Generate(),
                transferSyntax: DicomTransferSyntax.MPEG2.UID.UID,
                encode: false);

            await _instancesManager.StoreAsync(new[] { dicomFile1, dicomFile2 });

            DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveStudyAsync(studyInstanceUid, dicomTransferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID));

            Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode);
        }
Example #13
0
        public async Task GivenUnsupportedTransferSyntax_WhenRetrieveFrame_ThenServerShouldReturnNotAcceptable()
        {
            string studyInstanceUid  = TestUidGenerator.Generate();
            string seriesInstanceUid = TestUidGenerator.Generate();
            string sopInstanceUid    = TestUidGenerator.Generate();

            DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData(
                studyInstanceUid,
                seriesInstanceUid,
                sopInstanceUid,
                transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID,
                encode: false);

            await InternalStoreAsync(new[] { dicomFile });

            DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveFramesAsync(
                                                                                           studyInstanceUid,
                                                                                           seriesInstanceUid,
                                                                                           sopInstanceUid,
                                                                                           dicomTransferSyntax: DicomTransferSyntax.JPEG2000Lossless.UID.UID,
                                                                                           frames: new[] { 1 }));

            Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode);
        }