diff --git a/Rdmp.Dicom/PipelineComponents/DicomSources/DicomSource.cs b/Rdmp.Dicom/PipelineComponents/DicomSources/DicomSource.cs index fd5d4eca..a34c56a4 100644 --- a/Rdmp.Dicom/PipelineComponents/DicomSources/DicomSource.cs +++ b/Rdmp.Dicom/PipelineComponents/DicomSources/DicomSource.cs @@ -9,7 +9,6 @@ using System.Data; using System.IO; using System.Linq; -using System.Reflection.Metadata.Ecma335; using System.Text.RegularExpressions; using Rdmp.Core.Curation.Data; using Rdmp.Core.DataFlowPipeline; @@ -104,10 +103,19 @@ public void Check(ICheckNotifier notifier) notifier.OnCheckPerformed(new CheckEventArgs("Could not deserialize TagElevationConfigurationFile", CheckResult.Fail, e)); } - if (string.IsNullOrWhiteSpace(ArchiveRoot)) return; - if (!Path.IsPathRooted(ArchiveRoot)) + // Fail if a non-absolute ArchiveRoot is set: + if (!string.IsNullOrWhiteSpace(ArchiveRoot) && !Path.IsPathFullyQualified(ArchiveRoot)) notifier.OnCheckPerformed(new CheckEventArgs("ArchiveRoot is not rooted, it must be an absolute path e.g. c:\\temp\\MyImages\\", CheckResult.Fail)); + } + + private IEnumerable SquashTree(DicomDataset ds, DicomTag t) + { + if (ds.TryGetSingleValue(t, out string value)) yield return value; + foreach (var datum in ds) + if (datum is DicomSequence seq) + foreach (var d in seq.SelectMany(i => SquashTree(i, t))) + yield return d; } /// @@ -128,6 +136,12 @@ protected void ProcessDataset(string filename, DicomDataset ds, DataTable dt, ID var rowValues = new Dictionary(); + // First collect all CodeMeaning and CodeValue values as strings: + var meanings = string.Join('\n', SquashTree(ds, DicomTag.CodeMeaning)); + if (!string.IsNullOrWhiteSpace(meanings)) rowValues.Add("CodeMeanings", meanings); + var values = string.Join('\n', SquashTree(ds, DicomTag.CodeValue)); + if (!string.IsNullOrWhiteSpace(values)) rowValues.Add("CodeValues", values); + foreach (var item in ds) { // First special-case Sequences such as ICD11 diagnostic codes: @@ -141,10 +155,6 @@ protected void ProcessDataset(string filename, DicomDataset ds, DataTable dt, ID rowValues.Add("ICD11code", code.GetSingleValueOrDefault(DicomTag.CodeValue, "missing")); rowValues.Add("ICD11meaning", code.GetSingleValueOrDefault(DicomTag.CodeMeaning, "missing")); } - else - { - // TODO: Handle other code pairs - } continue; }