public void StrangeConfigUploadServiceTest() { var segmentationClient = GetMockInnerEyeSegmentationClient(); var testAETConfigModel = GetTestAETConfigModel(); var newTestAETConfigModel = testAETConfigModel.With( aetConfig: new ClientAETConfig( new AETConfig( AETConfigType.Model, new[] { new ModelConstraintsConfig( "b033d049-0233-4068-bc0f-c64cec48e8fa", new [] { new ModelChannelConstraints("ct", new GroupConstraint(new DicomConstraint[0], LogicalOperator.And), new GroupConstraint(new DicomConstraint[0], LogicalOperator.And), -1, -1) }, new TagReplacement[0]), new ModelConstraintsConfig( "b033d049-0233-4068-bc0f-c64cec48e8fa", new [] { new ModelChannelConstraints("ct", new GroupConstraint(new DicomConstraint[0], LogicalOperator.And), new GroupConstraint(new DicomConstraint[0], LogicalOperator.And), -1, -1) }, new TagReplacement[0]), }), testAETConfigModel.AETConfig.Destination, false)); var aetConfigProvider = new MockAETConfigProvider(newTestAETConfigModel); using (var deleteService = CreateDeleteService()) using (var uploadService = CreateUploadService(segmentationClient, aetConfigProvider.AETConfigModels)) using (var uploadQueue = uploadService.UploadQueue) using (var downloadQueue = uploadService.DownloadQueue) { deleteService.Start(); uploadService.Start(); var tempFolder = CreateTemporaryDirectory(); foreach (var file in new DirectoryInfo(@"Images\1ValidSmall\").GetFiles()) { file.CopyTo(Path.Combine(tempFolder.FullName, file.Name)); } Enqueue( uploadQueue, new UploadQueueItem( calledApplicationEntityTitle: newTestAETConfigModel.CalledAET, callingApplicationEntityTitle: newTestAETConfigModel.CallingAET, associationFolderPath: tempFolder.FullName, rootDicomFolderPath: tempFolder.FullName, associationGuid: Guid.NewGuid(), associationDateTime: DateTime.UtcNow), true); // Leave enough time to allow upload SpinWait.SpinUntil(() => new DirectoryInfo(tempFolder.FullName).Exists == false, TimeSpan.FromSeconds(300)); Assert.IsFalse(new DirectoryInfo(tempFolder.FullName).Exists); TransactionalDequeue <DownloadQueueItem>(downloadQueue); } }
public async Task GenerateAndTestDeAnonymisedStructureSetFile() { var image = @"Images\LargeSeriesWithContour"; var tempFolder = CreateTemporaryDirectory(); var segmentationClient = GetMockInnerEyeSegmentationClient(); var configType = AETConfigType.ModelWithResultDryRun; var dryRunFolder = DryRunFolders.GetFolder(configType); var testAETConfigModel = GetTestAETConfigModel(); var newTestAETConfigModel = testAETConfigModel.With( aetConfig: new ClientAETConfig( new AETConfig( configType, testAETConfigModel.AETConfig.Config.ModelsConfig), testAETConfigModel.AETConfig.Destination, false)); var aetConfigProvider = new MockAETConfigProvider(newTestAETConfigModel); var receivePort = 160; using (var deleteService = CreateDeleteService()) using (var pushService = CreatePushService(aetConfigProvider.AETConfigModels)) using (var downloadService = CreateDownloadService(segmentationClient)) using (var uploadService = CreateUploadService(segmentationClient, aetConfigProvider.AETConfigModels)) using (var receiveService = CreateReceiveService(receivePort, tempFolder)) { deleteService.Start(); pushService.Start(); downloadService.Start(); uploadService.Start(); receiveService.Start(); DcmtkHelpers.SendFolderUsingDCMTK( image, receivePort, ScuProfile.LEExplicitCT, TestContext, applicationEntityTitle: newTestAETConfigModel.CallingAET, calledAETitle: newTestAETConfigModel.CalledAET); SpinWait.SpinUntil(() => tempFolder.GetDirectories().FirstOrDefault(x => x.FullName.Contains(dryRunFolder)) != null); var dryRunFolderDirectory = tempFolder.GetDirectories().First(x => x.FullName.Contains(dryRunFolder)).GetDirectories().First(); // Wait until we have all image files. SpinWait.SpinUntil(() => dryRunFolderDirectory.GetFiles().Length == 1); // Wait for all files to save. await Task.Delay(1000); var originalSlice = DicomFile.Open(new DirectoryInfo(image).GetFiles().First().FullName); Assert.IsNotNull(originalSlice); foreach (var file in dryRunFolderDirectory.GetFiles()) { var dicomFile = DicomFile.Open(file.FullName, FileReadOption.ReadAll); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.StudyDate), dicomFile.Dataset.GetSingleValue <string>(DicomTag.StudyDate)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.AccessionNumber), dicomFile.Dataset.GetSingleValue <string>(DicomTag.AccessionNumber)); Assert.AreEqual("RTSTRUCT", dicomFile.Dataset.GetSingleValue <string>(DicomTag.Modality)); Assert.AreEqual("Microsoft Corporation", dicomFile.Dataset.GetSingleValue <string>(DicomTag.Manufacturer)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.ReferringPhysicianName), dicomFile.Dataset.GetSingleValue <string>(DicomTag.ReferringPhysicianName)); Assert.AreEqual(originalSlice.Dataset.GetSingleValueOrDefault(DicomTag.StudyDescription, string.Empty), dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.StudyDescription, string.Empty)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.PatientName), dicomFile.Dataset.GetSingleValue <string>(DicomTag.PatientName)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.PatientID), dicomFile.Dataset.GetSingleValue <string>(DicomTag.PatientID)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.PatientBirthDate), dicomFile.Dataset.GetSingleValue <string>(DicomTag.PatientBirthDate)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID), dicomFile.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID)); Assert.AreEqual(originalSlice.Dataset.GetSingleValue <string>(DicomTag.StudyID), dicomFile.Dataset.GetSingleValue <string>(DicomTag.StudyID)); Assert.IsTrue(dicomFile.Dataset.GetString(DicomTag.SoftwareVersions).StartsWith("Microsoft InnerEye Gateway:")); Assert.IsTrue(dicomFile.Dataset.GetValue <string>(DicomTag.SoftwareVersions, 1).StartsWith("InnerEye AI Model:")); Assert.IsTrue(dicomFile.Dataset.GetValue <string>(DicomTag.SoftwareVersions, 2).StartsWith("InnerEye AI Model ID:")); Assert.IsTrue(dicomFile.Dataset.GetValue <string>(DicomTag.SoftwareVersions, 3).StartsWith("InnerEye Model Created:")); Assert.IsTrue(dicomFile.Dataset.GetValue <string>(DicomTag.SoftwareVersions, 4).StartsWith("InnerEye Version:")); Assert.AreEqual("1.2.840.10008.5.1.4.1.1.481.3", dicomFile.Dataset.GetSingleValue <string>(DicomTag.SOPClassUID)); Assert.AreEqual($"{DateTime.UtcNow.Year}{DateTime.UtcNow.Month.ToString("D2")}{DateTime.UtcNow.Day.ToString("D2")}", dicomFile.Dataset.GetSingleValue <string>(DicomTag.SeriesDate)); Assert.IsTrue(dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.SeriesInstanceUID, string.Empty).StartsWith("1.2.826.0.1.3680043.2")); Assert.AreEqual("511091532", dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.SeriesNumber, string.Empty)); Assert.AreEqual("NOT FOR CLINICAL USE", dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.SeriesDescription, string.Empty)); Assert.IsTrue(dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.SOPInstanceUID, string.Empty).StartsWith("1.2.826.0.1.3680043.2")); Assert.AreEqual("ANONYM", dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.OperatorsName, string.Empty)); VerifyDicomFile(file.FullName); } } }
public async Task GenerateAndTestAnonymisedRTFile() { var tempFolder = CreateTemporaryDirectory(); { var configType = AETConfigType.ModelDryRun; var dryRunFolder = DryRunFolders.GetFolder(configType); var segmentationClient = GetMockInnerEyeSegmentationClient(); var testAETConfigModel = GetTestAETConfigModel(); var newTestAETConfigModel = testAETConfigModel.With( aetConfig: new ClientAETConfig( new AETConfig( configType, null), testAETConfigModel.AETConfig.Destination, false)); var aetConfigProvider = new MockAETConfigProvider(newTestAETConfigModel); var receivePort = 162; using (var deleteService = CreateDeleteService()) using (var pushService = CreatePushService(aetConfigProvider.AETConfigModels)) using (var downloadService = CreateDownloadService(segmentationClient)) using (var uploadService = CreateUploadService(segmentationClient, aetConfigProvider.AETConfigModels)) using (var receiveService = CreateReceiveService(receivePort, tempFolder)) { deleteService.Start(); pushService.Start(); downloadService.Start(); uploadService.Start(); receiveService.Start(); DcmtkHelpers.SendFolderUsingDCMTK( @"Images\1ValidSmall", receivePort, ScuProfile.LEExplicitRTCT, TestContext, applicationEntityTitle: newTestAETConfigModel.CallingAET, calledAETitle: newTestAETConfigModel.CalledAET); SpinWait.SpinUntil(() => tempFolder.GetDirectories().FirstOrDefault(x => x.FullName.Contains(dryRunFolder)) != null); var dryRunFolderDirectory = tempFolder.GetDirectories().First(x => x.FullName.Contains(dryRunFolder)).GetDirectories().First(); // Wait until we have all image files. SpinWait.SpinUntil(() => dryRunFolderDirectory.GetFiles().Length == 1); // Wait for all files to save. await Task.Delay(1000); var savedSampleFile = false; foreach (var file in dryRunFolderDirectory.GetFiles()) { var dicomFile = DicomFile.Open(file.FullName); AssertDicomFileIsAnonymised(dicomFile); if (!savedSampleFile) { WriteDicomFileForBuildPackage("AnonymisedRT.dcm", dicomFile); savedSampleFile = true; } } } } }
public void UploadServiceLiveSendImageTest() { var tempFolder = CreateTemporaryDirectory(); foreach (var file in new DirectoryInfo(@"Images\1ValidSmall\").GetFiles()) { file.CopyTo(Path.Combine(tempFolder.FullName, file.Name)); } var testAETConfigModel = GetTestAETConfigModel(); var newTestAETConfigModel = testAETConfigModel.With( aetConfig: testAETConfigModel.AETConfig.With( config: new AETConfig( AETConfigType.Model, new[] { new ModelConstraintsConfig( "b033d049-0233-4068-bc0f-c64cec48e8fa", new [] { new ModelChannelConstraints("ct", new GroupConstraint(Array.Empty <DicomConstraint>(), LogicalOperator.And), new GroupConstraint(Array.Empty <DicomConstraint>(), LogicalOperator.And), -1, -1) }, Array.Empty <TagReplacement>()), }), shouldReturnImage: true)); var aetConfigProvider = new MockAETConfigProvider(newTestAETConfigModel); var resultDirectory = CreateTemporaryDirectory(); using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultDirectory.FullName))) { var eventCount = 0; var folderPath = string.Empty; dicomDataReceiver.DataReceived += (sender, e) => { folderPath = e.FolderPath; Interlocked.Increment(ref eventCount); }; StartDicomDataReceiver(dicomDataReceiver, newTestAETConfigModel.AETConfig.Destination.Port); using (var segmentationClient = GetMockInnerEyeSegmentationClient()) using (var deleteService = CreateDeleteService()) using (var uploadService = CreateUploadService(segmentationClient, aetConfigProvider.AETConfigModels)) using (var uploadQueue = uploadService.UploadQueue) using (var downloadService = CreateDownloadService(segmentationClient)) using (var downloadQueue = downloadService.DownloadQueue) using (var pushService = CreatePushService(aetConfigProvider.AETConfigModels)) using (var pushQueue = pushService.PushQueue) { deleteService.Start(); uploadService.Start(); downloadService.Start(); pushService.Start(); Enqueue( uploadQueue, new UploadQueueItem( calledApplicationEntityTitle: newTestAETConfigModel.CalledAET, callingApplicationEntityTitle: newTestAETConfigModel.CallingAET, associationFolderPath: tempFolder.FullName, rootDicomFolderPath: CreateTemporaryDirectory().FullName, associationGuid: Guid.NewGuid(), associationDateTime: DateTime.UtcNow), true); // Leave enough time to allow upload SpinWait.SpinUntil(() => new DirectoryInfo(tempFolder.FullName).Exists == false, TimeSpan.FromSeconds(90)); // Check the association folder is deleted. Assert.IsFalse(new DirectoryInfo(tempFolder.FullName).Exists); // Wait for all events to finish on the data received SpinWait.SpinUntil(() => eventCount >= 3, TimeSpan.FromMinutes(3)); // Make sure the item was dequeued Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue)); Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <DownloadQueueItem>(downloadQueue)); Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <PushQueueItem>(pushQueue)); #pragma warning disable CA1508 // Avoid dead conditional code Assert.IsFalse(string.IsNullOrWhiteSpace(folderPath)); #pragma warning restore CA1508 // Avoid dead conditional code // Check we received the image in the result Assert.AreEqual(21, new DirectoryInfo(folderPath).GetFiles().Length); } } }