Skip to content

Commit

Permalink
Update DicomSource.cs
Browse files Browse the repository at this point in the history
Implement simple meanings + values squashing plus ICD11 extraction
  • Loading branch information
jas88 committed Jan 24, 2024
1 parent 71381f0 commit f90568b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Rdmp.Dicom/PipelineComponents/DicomSources/DicomSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> 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;

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.
}

/// <summary>
Expand All @@ -128,6 +136,12 @@ protected void ProcessDataset(string filename, DicomDataset ds, DataTable dt, ID

var rowValues = new Dictionary<string, object>();

// 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:
Expand All @@ -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;
}
Expand Down

0 comments on commit f90568b

Please sign in to comment.