Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Feb 6, 2020
2 parents 586a075 + ba33ce3 commit 5031818
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 300 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

...

## [1.0.2] - 2020-02-06

### Added

- New option for DicomRepopulator to put images in root subfolders e.g. by PatientID

### Changed

- Improved GUI usability

## [1.0.1] - 2019-12-09

### Added
Expand All @@ -18,7 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Initial version


[Unreleased]: https://github.com/HicServices/DicomTemplateBuilder/compare/v1.0.1...develop
[Unreleased]: https://github.com/HicServices/DicomTemplateBuilder/compare/v1.0.2...develop
[1.0.2]: https://github.com/HicServices/DicomTemplateBuilder/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/HicServices/DicomTemplateBuilder/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/HicServices/DicomTemplateBuilder/tree/v1.0.0
[DicomTypeTranslation]: https://github.com/HicServices/DicomTypeTranslation
30 changes: 24 additions & 6 deletions Repopulator/CsvToDicomColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,38 @@

namespace Repopulator
{

public enum ColumnRole
{
None = 0,

/// <summary>
/// The column that contains the alleged location of dcm files on disk
/// </summary>
FilePath,

/// <summary>
/// The column should be a top level subfolder under which to create files e.g. PatientID
/// </summary>
SubFolder,
}

public class CsvToDicomColumn
{
public string Name { get; }
public int Index { get; }
public HashSet<DicomTag> TagsToPopulate { get; }
public bool IsFilePath { get; set; }


public ColumnRole Role { get; }

public CsvToDicomColumn(string colName, int index, bool isFileColumn,params DicomTag[] mappedTags)
public CsvToDicomColumn(string colName, int index, ColumnRole role,params DicomTag[] mappedTags)
{
if (mappedTags != null && mappedTags.Any() && isFileColumn)
//cannot be DicomTag AND FilePath
if (mappedTags != null && mappedTags.Any() && role == ColumnRole.FilePath)
throw new ArgumentException("Column has ambiguous role, it should either provide dicom tag substitutions or be the file path column not both");

if ((mappedTags == null || !mappedTags.Any())&& !isFileColumn)
//if you don't have DicomTags you must have some other role
if ((mappedTags == null || !mappedTags.Any())&& role == ColumnRole.None)
throw new ArgumentException("Column has no clear role, it should either provide dicom tag substitutions or be the file path column");

if (index < 0)
Expand All @@ -35,7 +53,7 @@ public CsvToDicomColumn(string colName, int index, bool isFileColumn,params Dico
Name = colName;
Index = index;
TagsToPopulate = new HashSet<DicomTag>(mappedTags?? new DicomTag[0]);
IsFilePath = isFileColumn;
Role = role;
}
}
}
36 changes: 27 additions & 9 deletions Repopulator/CsvToDicomTagMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class CsvToDicomTagMapping
/// relatively (i.e. not absolute path names)
/// </summary>
public CsvToDicomColumn FilenameColumn;


/// <summary>
/// The column of the CSV which records. The column should be a top level subfolder under which to create files e.g. PatientID
/// </summary>
public CsvToDicomColumn SubFolderColumn;

/// <summary>
/// Columns which contain dicom tag values. This is not all the columns in the CSV. It does not include <see cref="FilenameColumn"/>
Expand Down Expand Up @@ -84,19 +90,28 @@ public bool BuildMap(DicomRepopulatorOptions options, out string log)

if (match != null)
{
if(match.IsFilePath)
if(match.Role == ColumnRole.FilePath)
{
if (FilenameColumn != null)
throw new Exception("There are 2+ FilenameColumn in the CSV");
else
FilenameColumn = match;
else
}

if(match.Role == ColumnRole.SubFolder)
{
if(TagColumns.Any(c=>c.TagsToPopulate.Intersect(match.TagsToPopulate).Any()))
throw new Exception($"There are 2+ columns that both populate for one of the DicomTag(s) '{string.Join(",",match.TagsToPopulate)}'");

TagColumns.Add(match);
if (SubFolderColumn != null)
throw new Exception("There are 2+ SubFolderColumn in the CSV");
else
SubFolderColumn = match;
}

if(TagColumns.Any(c=>c.TagsToPopulate.Intersect(match.TagsToPopulate).Any()))
throw new Exception($"There are 2+ columns that both populate for one of the DicomTag(s) '{string.Join(",",match.TagsToPopulate)}'");

TagColumns.Add(match);


sb.AppendLine($"Validated header '{header}'");
}
else
Expand Down Expand Up @@ -173,20 +188,23 @@ public CsvToDicomColumn GetKeyDicomTagAndColumnName(DicomRepopulatorOptions stat
{
CsvToDicomColumn toReturn = null;
if(columnName.Equals(state.FileNameColumn,StringComparison.CurrentCultureIgnoreCase))
toReturn = new CsvToDicomColumn(columnName,index,true);
toReturn = new CsvToDicomColumn(columnName,index,ColumnRole.FilePath);

if(columnName.Equals(state.SubFolderColumn, StringComparison.CurrentCultureIgnoreCase))
toReturn = new CsvToDicomColumn(columnName,index,ColumnRole.SubFolder);

var found = DicomDictionary.Default.SingleOrDefault(entry => string.Equals(entry.Keyword ,columnName,StringComparison.CurrentCultureIgnoreCase));

if(found != null)
if (toReturn == null)
toReturn = new CsvToDicomColumn(columnName,index,false,found.Tag);
toReturn = new CsvToDicomColumn(columnName,index,ColumnRole.None,found.Tag);
else
toReturn.TagsToPopulate.Add(found.Tag); //it's a file path AND a tag! ok...


if (extraMappings != null && extraMappings.ContainsKey(columnName))
if(toReturn == null)
toReturn = new CsvToDicomColumn(columnName,index,false,extraMappings[columnName].ToArray());
toReturn = new CsvToDicomColumn(columnName,index,ColumnRole.None,extraMappings[columnName].ToArray());
else
toReturn.TagsToPopulate.UnionWith(extraMappings[columnName]);

Expand Down
10 changes: 6 additions & 4 deletions Repopulator/DicomRepopulator.cd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<Class Name="Repopulator.CsvToDicomColumn">
<Position X="9.25" Y="6.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAgAAAAQAAAAAAAAAAAEAABAAAAA=</HashCode>
<HashCode>AAAAAAAAAAAAAAAAEgAAAAQAAAAAAAAAAAEAAAAAAAA=</HashCode>
<FileName>CsvToDicomColumn.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -47,11 +47,13 @@
<AssociationLine Name="FilenameColumn" Type="Repopulator.CsvToDicomColumn" FixedToPoint="true">
<Path>
<Point X="7" Y="7.923" />
<Point X="7.698" Y="7.923" Type="JumpStart" />
<Point X="7.865" Y="7.923" Type="JumpEnd" />
<Point X="9.25" Y="7.923" />
</Path>
</AssociationLine>
<TypeIdentifier>
<HashCode>AAACAAGAAAAAAAAAAAAAAABAAAAAAAAABAAAAARBAAA=</HashCode>
<HashCode>AAACAAGAAAQAAAAAAAAAAABAAAAAAAAABAAAAARBAAA=</HashCode>
<FileName>CsvToDicomTagMapping.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
Expand All @@ -67,7 +69,7 @@
<Compartment Name="Properties" Collapsed="true" />
</Compartments>
<TypeIdentifier>
<HashCode>AAAAgQgABAAAAAAAQAECAAQQCAAAEAgEASAAAAACAAA=</HashCode>
<HashCode>AAAAgQgABAQAAAAAQAECAAQQCQAAEAgEASAAAAACAAA=</HashCode>
<FileName>DicomRepopulatorOptions.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -77,7 +79,7 @@
<Compartment Name="Fields" Collapsed="true" />
</Compartments>
<TypeIdentifier>
<HashCode>AAhAAAAIACAAQQAAAgAAAIBAMAAABACAAAAQAAAAgAA=</HashCode>
<HashCode>AAhAAAAIACAAQQAAAgAAAIBAMgAABACAAAAQAAAAgAA=</HashCode>
<FileName>DicomRepopulatorProcessor.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
Expand Down
7 changes: 6 additions & 1 deletion Repopulator/DicomRepopulatorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public class DicomRepopulatorOptions
public string FileNameColumn = DefaultFileNameColumn;
public bool Anonymise;
public int ErrorThreshold = 100;
public string CultureName;

[YamlIgnore]
public CultureInfo Culture = CultureInfo.CurrentCulture;


public string SubFolderColumn;

[YamlIgnore]
public DirectoryInfo OutputDirectoryInfo => new DirectoryInfo(OutputFolder);
Expand All @@ -34,6 +38,7 @@ public class DicomRepopulatorOptions

[YamlIgnore]
public FileInfo ExtraMappings => new FileInfo(InputExtraMappings);


}
}
11 changes: 5 additions & 6 deletions Repopulator/DicomRepopulatorProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Dicom;
using DicomTypeTranslation;
using DicomTypeTranslation.Helpers;
using FAnsi.Discovery.QuerySyntax.Update;
using NLog;
using NLog.Config;
using NLog.Targets;
using Repopulator.Matchers;
using Repopulator.TagUpdaters;
using TypeGuesser.Deciders;

namespace Repopulator
{
Expand Down Expand Up @@ -66,7 +62,7 @@ public DicomRepopulatorProcessor(string currentDirectory = null)

public int Process(DicomRepopulatorOptions options)
{
_parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = options.NumThreads };
_parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Math.Max(1,options.NumThreads) };
_tagUpdater = new ParseStringsUpdater(options.Culture);
_anonymizer = options.Anonymise ? new DicomAnonymizer() : null;

Expand Down Expand Up @@ -162,7 +158,10 @@ private void ProcessJob(RepopulatorJob job, DicomRepopulatorOptions options)
_logger.Debug("Saving output file");

// Preserves any sub-directory structures
var outPath = Path.Combine(options.OutputDirectoryInfo.FullName, inputRelativePath);
var outPath = job.Map.SubFolderColumn != null
? Path.Combine(options.OutputDirectoryInfo.FullName, job.Cells[job.Map.SubFolderColumn.Index],inputRelativePath)
: Path.Combine(options.OutputDirectoryInfo.FullName, inputRelativePath);

Directory.CreateDirectory(Path.GetDirectoryName(outPath));

job.File.Save(outPath);
Expand Down
6 changes: 3 additions & 3 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[assembly: AssemblyCulture("")]

// These should be replaced with correct values by the release process
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyInformationalVersion("1.0.2")]
Loading

0 comments on commit 5031818

Please sign in to comment.