public void Test_DodgyTagNames() { _helper.TruncateTablesIfExists(); DirectoryInfo d = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(Test_DodgyTagNames))); d.Create(); var fi = TestData.Create(new FileInfo(Path.Combine(d.FullName, "MyTestFile.dcm"))); var fi2 = TestData.Create(new FileInfo(Path.Combine(d.FullName, "MyTestFile2.dcm"))); DicomFile dcm; using (var stream = File.OpenRead(fi.FullName)) { dcm = DicomFile.Open(stream); dcm.Dataset.AddOrUpdate(DicomTag.PrintRETIRED, "FISH"); dcm.Dataset.AddOrUpdate(DicomTag.Date, new DateTime(2001, 01, 01)); dcm.Save(fi2.FullName); } var adder = new TagColumnAdder(DicomTypeTranslaterReader.GetColumnNameForTag(DicomTag.Date, false), "datetime2", _helper.ImageTableInfo, new AcceptAllCheckNotifier()); adder.Execute(); adder = new TagColumnAdder(DicomTypeTranslaterReader.GetColumnNameForTag(DicomTag.PrintRETIRED, false), "datetime2", _helper.ImageTableInfo, new AcceptAllCheckNotifier()); adder.Execute(); fi.Delete(); File.Move(fi2.FullName, fi.FullName); //creates the queues, exchanges and bindings var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions); tester.CreateExchange(_globals.RabbitOptions.FatalLoggingExchange, null); using (var host = new DicomRelationalMapperHost(_globals)) { host.Start(); using (var timeline = new TestTimeline(tester)) { timeline.SendMessage(_globals.DicomRelationalMapperOptions, _helper.GetDicomFileMessage(_globals.FileSystemOptions.FileSystemRoot, fi)); //start the timeline timeline.StartTimeline(); Thread.Sleep(TimeSpan.FromSeconds(10)); new TestTimelineAwaiter().Await(() => host.Consumer.AckCount >= 1, null, 30000, () => host.Consumer.DleErrors); Assert.AreEqual(1, _helper.SeriesTable.GetRowCount(), "SeriesTable did not have the expected number of rows in LIVE"); Assert.AreEqual(1, _helper.StudyTable.GetRowCount(), "StudyTable did not have the expected number of rows in LIVE"); Assert.AreEqual(1, _helper.ImageTable.GetRowCount(), "ImageTable did not have the expected number of rows in LIVE"); host.Stop("Test end"); } } tester.Shutdown(); }
private void cbxTag_SelectedIndexChanged(object sender, EventArgs e) { ragSmiley1.Reset(); try { var keyword = cbxTag.Text; var type = TagColumnAdder.GetDataTypeForTag(keyword, _tableInfo.GetQuerySyntaxHelper().TypeTranslater); var multiplicity = TagColumnAdder.GetTag(keyword).ValueMultiplicity; if (multiplicity == null) { lblMultiplicity.Text = "(Multiplicity:None)"; } else { lblMultiplicity.Text = "(Multiplicity: Min " + multiplicity.Minimum + " Max " + multiplicity.Maximum + " M " + multiplicity.Multiplicity + ")"; } tbDataType.Text = type; } catch (Exception exception) { ragSmiley1.Fatal(exception); } }
public TagColumnAdderUI(TableInfo tableInfo) { _tableInfo = tableInfo; InitializeComponent(); cbxTag.AutoCompleteSource = AutoCompleteSource.ListItems; cbxTag.DataSource = TagColumnAdder.GetAvailableTags(); }
public ExecuteCommandAddTag(BasicActivateItems activator, ICatalogue catalogue, [DemandsInitialization("Name of the new column you want created.")] string column, [DemandsInitialization("Optional when column is the name of a Dicom Tag e.g. StudyInstanceUID")] string dataType) : base(activator) { var tables = catalogue.GetTableInfosIdeallyJustFromMainTables(); if (tables.Length != 1) { SetImpossible($"There are {tables.Length} tables mapped under Catalogue {catalogue}"); return; } if (string.IsNullOrWhiteSpace(column)) { SetImpossible("Column name must be supplied"); return; } var syntax = tables[0].GetQuerySyntaxHelper(); //if user hasn't listed a specific datatype, guess it from the column if (string.IsNullOrWhiteSpace(dataType)) { var available = TagColumnAdder.GetAvailableTags(); if (!available.Contains(column)) { var similar = available.Where(c => c.Contains(column)).ToArray(); if (similar.Any()) { SetImpossible($"Could not find a tag called '{column}'. Possibly you meant:" + Environment.NewLine + string.Join(Environment.NewLine, similar)); return; } SetImpossible($"Could not find a tag called '{column}' or any like it"); return; } try { dataType = TagColumnAdder.GetDataTypeForTag(column, syntax.TypeTranslater); } catch (Exception e) { throw new Exception("No dataType was specified and column name could not be resolved to a DicomTag", e); } } _adder = new TagColumnAdder(column, dataType, (TableInfo)tables[0], new AcceptAllCheckNotifier()); }
public override void Execute() { if (_tableInfo == null) { SetImpossible("No TableInfo has been set, use SetTarget(TableInfo or Catalogue)"); } base.Execute(); var ui = new TagColumnAdderUI(_tableInfo); if (ui.ShowDialog() == DialogResult.OK) { var popup = new PopupChecksUI("Adding Column", false); var columnAdder = new TagColumnAdder(ui.ColumnName, ui.ColumnDataType, _tableInfo, popup, _includeLoadedField); columnAdder.Execute(); Publish(_tableInfo); } }
public override void Execute() { if (_tableInfo == null) { SetImpossible("No TableInfo has been set, use SetTarget(TableInfo or Catalogue)"); } base.Execute(); var ui = new TagColumnAdderUI(_tableInfo); if (ui.ShowDialog() != DialogResult.OK) { return; } var checks = new PopupChecksUI("Adding Column", false); var columnAdder = new TagColumnAdder(ui.ColumnName, ui.ColumnDataType, _tableInfo, checks); columnAdder.Execute(); Publish(_tableInfo); //Checks have likely been popped up as a non modal dialogue by the execute action (allowing the user to review the events) if (checks.Visible) { checks.FormClosed += (s, e) => { //schedule disposal of the control for when the user closes it if (!checks.IsDisposed) { checks.Dispose(); } } } ; else { checks.Dispose(); // for some reason the checks were not spawned so explicitly dispose of the resources } }
public void SetupSuite(DiscoveredDatabase databaseToCreateInto, IRDMPPlatformRepositoryServiceLocator repositoryLocator, GlobalOptions globalOptions, Type pipelineDicomSourceType, string root = null, ImageTableTemplateCollection template = null, bool persistentRaw = false, string modalityPrefix = null) { ImageTable = databaseToCreateInto.ExpectTable(modalityPrefix + "ImageTable"); SeriesTable = databaseToCreateInto.ExpectTable(modalityPrefix + "SeriesTable"); StudyTable = databaseToCreateInto.ExpectTable(modalityPrefix + "StudyTable"); try { File.Copy(typeof(InvalidDataHandling).Assembly.Location, Path.Combine(TestContext.CurrentContext.TestDirectory, "Rdmp.Dicom.dll"), true); } catch (System.IO.IOException) { //nevermind, it's probably locked } //The Rdmp.Dicom assembly should be loaded as a plugin, this simulates it. foreach (var type in typeof(InvalidDataHandling).Assembly.GetTypes()) { repositoryLocator.CatalogueRepository.MEF.AddTypeToCatalogForTesting(type); } ICatalogueRepository catalogueRepository = repositoryLocator.CatalogueRepository; IDataExportRepository dataExportRepository = repositoryLocator.DataExportRepository; foreach (var t in new[] { ImageTable, SeriesTable, StudyTable }) { if (t.Exists()) { t.Drop(); } } var suite = new ExecuteCommandCreateNewImagingDatasetSuite(repositoryLocator, databaseToCreateInto, new DirectoryInfo(TestContext.CurrentContext.TestDirectory)); suite.Template = template ?? GetDefaultTemplate(databaseToCreateInto.Server.DatabaseType); suite.PersistentRaw = persistentRaw; suite.TablePrefix = modalityPrefix; suite.DicomSourceType = pipelineDicomSourceType; suite.CreateCoalescer = true; suite.Execute(); DicomSourcePipelineComponent = suite.DicomSourcePipelineComponent; //store the component created so we can inject/adjust the arguments e.g. adding ElevationRequests to it LoadMetadata = suite.NewLoadMetadata; var tableInfos = LoadMetadata.GetAllCatalogues().SelectMany(c => c.GetTableInfoList(false)).Distinct().ToArray(); ImageTableInfo = (TableInfo)tableInfos.Single(t => t.GetRuntimeName().Equals(ImageTable.GetRuntimeName())); SeriesTableInfo = (TableInfo)tableInfos.Single(t => t.GetRuntimeName().Equals(SeriesTable.GetRuntimeName())); StudyTableInfo = (TableInfo)tableInfos.Single(t => t.GetRuntimeName().Equals(StudyTable.GetRuntimeName())); // Override the options with stuff coming from Core RDMP DatabaseTests (TestDatabases.txt) globalOptions.FileSystemOptions.FileSystemRoot = root ?? TestContext.CurrentContext.TestDirectory; globalOptions.RDMPOptions.CatalogueConnectionString = ((TableRepository)catalogueRepository).DiscoveredServer.Builder.ConnectionString; globalOptions.RDMPOptions.DataExportConnectionString = ((TableRepository)dataExportRepository).DiscoveredServer.Builder.ConnectionString; globalOptions.DicomRelationalMapperOptions.LoadMetadataId = LoadMetadata.ID; globalOptions.DicomRelationalMapperOptions.MinimumBatchSize = 1; globalOptions.DicomRelationalMapperOptions.UseInsertIntoForRAWMigration = true; //Image table now needs all the UIDs in order to be extractable var adder = new TagColumnAdder("StudyInstanceUID", "varchar(100)", ImageTableInfo, new AcceptAllCheckNotifier()); adder.Execute(); }
public void TestLoadingOneImage_MileWideTest() { _helper.TruncateTablesIfExists(); DirectoryInfo d = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(TestLoadingOneImage_MileWideTest))); d.Create(); var r = new Random(5000); FileInfo[] files; using (var g = new DicomDataGenerator(r, d, "CT")) files = g.GenerateImageFiles(1, r).ToArray(); Assert.AreEqual(1, files.Length); var existingColumns = _helper.ImageTable.DiscoverColumns(); //Add 200 random tags foreach (string tag in TagColumnAdder.GetAvailableTags().OrderBy(a => r.Next()).Take(200)) { string dataType; try { dataType = TagColumnAdder.GetDataTypeForTag(tag, new MicrosoftSQLTypeTranslater()); } catch (Exception) { continue; } if (existingColumns.Any(c => c.GetRuntimeName().Equals(tag))) { continue; } var adder = new TagColumnAdder(tag, dataType, _helper.ImageTableInfo, new AcceptAllCheckNotifier()); adder.SkipChecksAndSynchronization = true; adder.Execute(); } new TableInfoSynchronizer(_helper.ImageTableInfo).Synchronize(new AcceptAllCheckNotifier()); //creates the queues, exchanges and bindings var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions); tester.CreateExchange(_globals.RabbitOptions.FatalLoggingExchange, null); using (var host = new DicomRelationalMapperHost(_globals)) { host.Start(); using (var timeline = new TestTimeline(tester)) { foreach (var f in files) { timeline.SendMessage(_globals.DicomRelationalMapperOptions, _helper.GetDicomFileMessage(_globals.FileSystemOptions.FileSystemRoot, f)); } //start the timeline timeline.StartTimeline(); new TestTimelineAwaiter().Await(() => host.Consumer.MessagesProcessed == 1, null, 30000, () => host.Consumer.DleErrors); Assert.GreaterOrEqual(1, _helper.SeriesTable.GetRowCount(), "SeriesTable did not have the expected number of rows in LIVE"); Assert.GreaterOrEqual(1, _helper.StudyTable.GetRowCount(), "StudyTable did not have the expected number of rows in LIVE"); Assert.AreEqual(1, _helper.ImageTable.GetRowCount(), "ImageTable did not have the expected number of rows in LIVE"); host.Stop("Test end"); } } tester.Shutdown(); }