From 5b259af9b91ac1f56cb27ccaed6af38c5762722a Mon Sep 17 00:00:00 2001 From: Thomas Nind Date: Tue, 20 Jul 2021 13:39:05 +0100 Subject: [PATCH 1/2] Added ExecuteCommandAddModality --- .../ExecuteCommandAddModality.cs | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs diff --git a/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs b/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs new file mode 100644 index 00000000..4ffcfdc5 --- /dev/null +++ b/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs @@ -0,0 +1,110 @@ +using DicomTypeTranslation.TableCreation; +using FAnsi.Discovery; +using Rdmp.Core.CommandExecution; +using Rdmp.Core.CommandExecution.AtomicCommands; +using Rdmp.Core.Curation.Data; +using Rdmp.Core.Curation.Data.DataLoad; +using System; +using System.IO; +using System.Linq; + +namespace Rdmp.Dicom.CommandExecution +{ + public class ExecuteCommandAddModality : BasicCommandExecution + { + private readonly DiscoveredDatabase _live; + private readonly LoadMetadata _lmd; + private readonly string _prefix; + private ExecuteCommandCreateNewImagingDatasetSuite _schemaCreationCommand; + + private const string StudyTable = "StudyTable"; + private const string SeriesTable = "SeriesTable"; + private const string ImageTable = "ImageTable"; + + public ExecuteCommandAddModality(IBasicActivateItems activator, + [DemandsInitialization("The schema template (.it) file that will be used to determine image tables' columns")] + FileInfo template, + [DemandsInitialization("The prefix name for the new modality e.g. CT")] + string modality, + [DemandsInitialization("The existing imaging load you want to update to load these new tables. Must closely match expectations of this command")] + LoadMetadata lmd) : base(activator) + { + _lmd = lmd; + try + { + _live = lmd.GetDistinctLiveDatabaseServer().GetCurrentDatabase(); + } + catch(Exception ex) + { + SetImpossible($"Could not get single live server from the LoadMetadata {lmd} :" + ex); + return; + } + + if(_live == null || !_live.Exists()) + { + SetImpossible($"Live database for {lmd} was null or did not exist, cannot update it for a new modality"); + return; + } + + if(modality.EndsWith("_")) + { + _prefix = modality; + } + else + { + _prefix = modality + "_"; + } + + // the underlying command that does most of the work (creating tables), the rest is tinkering (join creation for study/series/image etc) + _schemaCreationCommand = new ExecuteCommandCreateNewImagingDatasetSuite(activator.RepositoryLocator, _live, null, null, _prefix, template, false, false); + + if (_schemaCreationCommand.IsImpossible) + { + SetImpossible(_schemaCreationCommand.ReasonCommandImpossible); + return; + } + + ValidateTemplate(_schemaCreationCommand.Template); + } + + private void ValidateTemplate(ImageTableTemplateCollection template) + { + if(template.Tables.Count != 3) + { + SetImpossible("Expected template to contain exactly 3 tables (StudyTable, SeriesTable and ImageTable)"); + return; + } + + foreach(var n in new[] { StudyTable,SeriesTable,ImageTable}) + { + if (template.Tables.Any(t => t.TableName.Equals(n))) + { + SetImpossible($"Template did not contain an expected table name: {n}. Table names in template were {string.Join(",",template.Tables.Select(t=>t.TableName))}"); + return; + } + } + } + + public override void Execute() + { + base.Execute(); + + _schemaCreationCommand.Execute(); + + var studyCata = (Catalogue) _schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(StudyTable)); + var seriesCata = (Catalogue)_schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(SeriesTable)); + var imageCata = (Catalogue)_schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(ImageTable)); + + var cmdAssoc = new ExecuteCommandAssociateCatalogueWithLoadMetadata(BasicActivator, _lmd, new[] { studyCata, seriesCata, imageCata }); + cmdAssoc.Execute(); + + // TODO: create JoinInfos + // TODO: mark study TableInfo IsPrimary + // TODO: update Distincters in load + // TODO: update Coalsecers in load + // TODO: update/add a new Isolation mutilation if lmd has them already + + } + } +} + From a17a04beb9a1c19d6946b0f8b6eabfab1a0705c2 Mon Sep 17 00:00:00 2001 From: Thomas Nind Date: Wed, 28 Jul 2021 11:11:50 +0100 Subject: [PATCH 2/2] Added more todo to command --- .../ExecuteCommandAddModality.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs b/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs index 4ffcfdc5..c71e7cf7 100644 --- a/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs +++ b/Rdmp.Dicom/CommandExecution/ExecuteCommandAddModality.cs @@ -34,19 +34,19 @@ public ExecuteCommandAddModality(IBasicActivateItems activator, { _live = lmd.GetDistinctLiveDatabaseServer().GetCurrentDatabase(); } - catch(Exception ex) + catch (Exception ex) { SetImpossible($"Could not get single live server from the LoadMetadata {lmd} :" + ex); return; } - if(_live == null || !_live.Exists()) + if (_live == null || !_live.Exists()) { SetImpossible($"Live database for {lmd} was null or did not exist, cannot update it for a new modality"); return; } - if(modality.EndsWith("_")) + if (modality.EndsWith("_")) { _prefix = modality; } @@ -54,7 +54,7 @@ public ExecuteCommandAddModality(IBasicActivateItems activator, { _prefix = modality + "_"; } - + // the underlying command that does most of the work (creating tables), the rest is tinkering (join creation for study/series/image etc) _schemaCreationCommand = new ExecuteCommandCreateNewImagingDatasetSuite(activator.RepositoryLocator, _live, null, null, _prefix, template, false, false); @@ -69,20 +69,26 @@ public ExecuteCommandAddModality(IBasicActivateItems activator, private void ValidateTemplate(ImageTableTemplateCollection template) { - if(template.Tables.Count != 3) + if (template.Tables.Count != 3) { SetImpossible("Expected template to contain exactly 3 tables (StudyTable, SeriesTable and ImageTable)"); return; } - foreach(var n in new[] { StudyTable,SeriesTable,ImageTable}) + foreach (var n in new[] { StudyTable, SeriesTable, ImageTable }) { if (template.Tables.Any(t => t.TableName.Equals(n))) { - SetImpossible($"Template did not contain an expected table name: {n}. Table names in template were {string.Join(",",template.Tables.Select(t=>t.TableName))}"); + SetImpossible($"Template did not contain an expected table name: {n}. Table names in template were {string.Join(",", template.Tables.Select(t => t.TableName))}"); return; } } + + var study = template.Tables.Single(t => t.TableName.Equals(StudyTable)); + var series = template.Tables.Single(t => t.TableName.Equals(SeriesTable)); + var image = template.Tables.Single(t => t.TableName.Equals(ImageTable)); + + // TODO: validate schemas more } public override void Execute() @@ -91,7 +97,7 @@ public override void Execute() _schemaCreationCommand.Execute(); - var studyCata = (Catalogue) _schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(StudyTable)); + var studyCata = (Catalogue)_schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(StudyTable)); var seriesCata = (Catalogue)_schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(SeriesTable)); var imageCata = (Catalogue)_schemaCreationCommand.NewCataloguesCreated.Single(c => c.Name.Contains(ImageTable));