Beispiel #1
0
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveFrame_ThenServerShouldReturnExpectedContent(string testDataFolder, string mediaType, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = await DicomFile.OpenAsync(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            var instanceId = inputDicomFile.Dataset.ToInstanceIdentifier();

            _studiesToClean.Add(instanceId.StudyInstanceUid);

            DicomFile      outputDicomFile = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
            DicomPixelData pixelData       = DicomPixelData.Create(outputDicomFile.Dataset);

            using DicomWebAsyncEnumerableResponse <Stream> response = await _client.RetrieveFramesAsync(
                      instanceId.StudyInstanceUid,
                      instanceId.SeriesInstanceUid,
                      instanceId.SopInstanceUid,
                      mediaType,
                      transferSyntax,
                      frames : new[] { 1 });

            int frameIndex = 0;

            await foreach (Stream item in response)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                Assert.Equal(item.ToByteArray(), pixelData.GetFrame(frameIndex).Data);
                frameIndex++;
            }
        }
        private void VerifyTranscodeFrame(TranscoderTestData testData, DicomFile inputFile)
        {
            Stream result   = _transcoder.TranscodeFrame(inputFile, 0, testData.MetaData.OutputSyntaxUid);
            string hashcode = GetByteArrayHashCode(ToByteArray(result));

            Assert.Equal(testData.MetaData.Frame0HashCode, hashcode);
        }
Beispiel #3
0
        public async Task GivenSinglePartAcceptHeader_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            using DicomWebResponse <DicomFile> response = await _client.RetrieveInstanceAsync(instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.ApplicationDicomMediaType, response.ContentHeaders.ContentType.MediaType);

            var actual = await response.GetValueAsync();

            var expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);

            Assert.Equal(expected, actual, new DicomFileEqualityComparer(
                             ignoredTags: new[]
            {
                DicomTag.ImplementationVersionName,      // Version name is updated as we update fo-dicom
                DicomTag.StudyInstanceUID,
                DicomTag.SeriesInstanceUID,
                DicomTag.SOPInstanceUID
            }));
        }
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveStudy_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            using DicomWebAsyncEnumerableResponse <DicomFile> response = await _client.RetrieveStudyAsync(instanceId.StudyInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.MultipartRelatedMediaType, response.ContentHeaders.ContentType.MediaType);

            await foreach (DicomFile actual in response)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                var expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
                Assert.Equal(expected, actual, new DicomFileEqualityComparer(
                                 ignoredTags: new[]
                {
                    DicomTag.ImplementationVersionName,      // Version name is updated as we update fo-dicom
                    DicomTag.StudyInstanceUID,
                    DicomTag.SeriesInstanceUID,
                    DicomTag.SOPInstanceUID
                }));
            }
        }
Beispiel #5
0
        public async Task GivenMultipartAcceptHeader_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            var requestUri = new Uri(DicomApiVersions.Latest + string.Format(DicomWebConstants.BaseInstanceUriFormat, instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid), UriKind.Relative);

            using HttpRequestMessage request   = new HttpRequestMessageBuilder().Build(requestUri, singlePart: false, DicomWebConstants.ApplicationDicomMediaType, transferSyntax);
            using HttpResponseMessage response = await _client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        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);
        }
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveStudy_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            string studyInstanceUid = inputDicomFile.Dataset.GetString(DicomTag.StudyInstanceUID);
            var    response         = await _client.RetrieveStudyAsync(studyInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.MultipartRelatedMediaType, response.Content.Headers.ContentType.MediaType);
            foreach (DicomFile actual in response.Value)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                DicomFile expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
                Assert.Equal(expected, actual, new DicomFileEqualityComparer());
            }
        }
Beispiel #8
0
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            var instanceId = inputDicomFile.Dataset.ToInstanceIdentifier();

            var response = await _client.RetrieveInstanceAsync(instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.ApplicationDicomMediaType, response.Content.Headers.ContentType.MediaType);
            Assert.Equal(1, response.Value.Count);
            DicomFile actual   = response.Value[0];
            DicomFile expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);

            Assert.Equal(expected, actual, new DicomFileEqualityComparer());
        }
        private async Task <DicomFile> VerifyTranscoding(string testDataFolder)
        {
            TranscoderTestData testData = TranscoderTestDataHelper.GetTestData(testDataFolder);

            using (FileStream fileStream = File.OpenRead(testData.InputDicomFile))
            {
                DicomFile inputFile = DicomFile.Open(fileStream);

                // Verify if input file has correct input transfersyntax
                Assert.Equal(inputFile.Dataset.InternalTransferSyntax.UID.UID, testData.MetaData.InputSyntaxUid);

                // Reset stream position for trasncoder to consume
                fileStream.Seek(0, SeekOrigin.Begin);

                DicomFile outputFile = await VerifyTranscodeFileAsync(testData, fileStream, inputFile);

                VerifyTranscodeFrame(testData, inputFile);
                return(outputFile);
            }
        }
        public async Task GivenInputAndOutputTransferSyntax_WhenRetrieveFrame_ThenServerShouldReturnExpectedContent(string testDataFolder, string mediaType, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = await DicomFile.OpenAsync(transcoderTestData.InputDicomFile);

            int numberOfFrames = DicomPixelData.Create(inputDicomFile.Dataset).NumberOfFrames;

            string studyInstanceUid  = inputDicomFile.Dataset.GetString(DicomTag.StudyInstanceUID);
            string seriesInstanceUid = inputDicomFile.Dataset.GetString(DicomTag.SeriesInstanceUID);
            string sopInstanceUid    = inputDicomFile.Dataset.GetString(DicomTag.SOPInstanceUID);

            DicomWebResponse <IEnumerable <DicomDataset> > tryQuery = await _client.QueryAsync(
                $"/studies/{studyInstanceUid}/series/{seriesInstanceUid}/instances?SOPInstanceUID={sopInstanceUid}");

            if (tryQuery.StatusCode == HttpStatusCode.OK)
            {
                await _client.DeleteStudyAsync(studyInstanceUid);
            }

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

            DicomWebResponse <IReadOnlyList <Stream> > response = await _client.RetrieveFramesAsync(
                studyInstanceUid : studyInstanceUid,
                seriesInstanceUid : seriesInstanceUid,
                sopInstanceUid : sopInstanceUid,
                mediaType : mediaType,
                dicomTransferSyntax : transferSyntax,
                frames : GenerateFrames(numberOfFrames),
                cancellationToken : _defaultCancellationToken);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            string byteStreamHash = TranscoderTestDataHelper.GetHashFromStream(response.Value[0]);

            Assert.Equal(transcoderTestData.MetaData.OutputFramesHashCode, byteStreamHash);

            await _client.DeleteStudyAsync(studyInstanceUid);
        }
Beispiel #11
0
 private void VerifyFrames(DicomFile actual, TranscoderTestData testData)
 {
     Assert.Equal(actual.Dataset.InternalTransferSyntax.UID.UID, testData.MetaData.OutputSyntaxUid);
     Assert.Equal(testData.MetaData.OutputFramesHashCode, GetFramesHashCode(actual));
 }