Skip to content

Commit

Permalink
Start converting to fo-dicom 5 API
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Feb 3, 2022
1 parent 37b47ca commit 61a0b1b
Show file tree
Hide file tree
Showing 31 changed files with 255 additions and 411 deletions.
15 changes: 7 additions & 8 deletions DicomTypeTranslation.Tests/BsonTranslationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Linq;
using System.Text;

using Dicom;
using Dicom.IO.Buffer;
using FellowOakDicom;
using FellowOakDicom.IO.Buffer;
using DicomTypeTranslation.Helpers;
using DicomTypeTranslation.Tests.Helpers;

Expand Down Expand Up @@ -525,7 +525,7 @@ public void BsonRoundTrip_MaskedTags_ConvertedCorrectly()
"\"60020040\":{\"vr\":\"CS\",\"val\":\"H\"},\"60020050\":{\"vr\":\"SS\",\"val\":[1,2]},\"60020100\":{\"vr\":\"US\",\"val\":[3]}," +
"\"60020102\":{\"vr\":\"US\",\"val\":[4]}}";

DicomDataset maskDataset = DicomTypeTranslater.DeserializeJsonToDataset(rawJson);
DicomDataset maskDataset = DicomTypeTranslater.DeserializeJsonToDataset(rawJson,true);

Assert.AreEqual(12, maskDataset.Count());

Expand All @@ -540,7 +540,7 @@ public void BsonRoundTrip_Utf8Encoding_ConvertedCorrectly()
{
var ds = new DicomDataset
{
new DicomUnlimitedText(DicomTag.TextValue, Encoding.UTF8, "¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹")
new DicomUnlimitedText(DicomTag.TextValue, "¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹")
};

VerifyBsonTripleTrip(ds);
Expand Down Expand Up @@ -593,7 +593,7 @@ public void BsonRoundTrip_EmptyElements_ConvertedCorrectly()
{
new DicomAttributeTag(DicomTag.SelectorATValue), // DicomAttributeTag
new DicomCodeString(DicomTag.SelectorCSValue), // DicomMultiStringElement
new DicomLongText(DicomTag.SelectorLTValue, DicomEncoding.Default, EmptyBuffer.Value), // DicomStringElement
new DicomLongText(DicomTag.SelectorLTValue, EmptyBuffer.Value.ToString()), // DicomStringElement
new DicomOtherLong(DicomTag.SelectorOLValue), // DicomValueElement<uint>
new DicomOtherWord(DicomTag.SelectorOWValue), // DicomValueElement<ushort>
new DicomSequence(DicomTag.SelectorCodeSequenceValue) // DicomSequence
Expand All @@ -614,16 +614,15 @@ public void BsonRoundTrip_StringEncoding_ConvertedCorrectly()
{
var ds = new DicomDataset
{
new DicomShortString(DicomTag.SelectorSHValue, Encoding.ASCII, "simples"),
new DicomLongString(DicomTag.SelectorLOValue, Encoding.UTF8, "(╯°□°)╯︵ ┻━┻")
new DicomShortString(DicomTag.SelectorSHValue, "simples"),
new DicomLongString(DicomTag.SelectorLOValue, "(╯°□°)╯︵ ┻━┻")
};

DicomDataset recoDs = DicomTypeTranslaterWriter.BuildDicomDataset(DicomTypeTranslaterReader.BuildBsonDocument(ds));

foreach (DicomStringElement stringElement in recoDs.Select(x => x as DicomStringElement))
{
Assert.NotNull(stringElement);
Assert.AreEqual(Encoding.UTF8, stringElement.Encoding);
}
}

Expand Down
3 changes: 1 addition & 2 deletions DicomTypeTranslation.Tests/DatabaseExamples.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dicom;
using FellowOakDicom;
using DicomTypeTranslation.TableCreation;
using FAnsi.Discovery.TypeTranslation;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand Down
13 changes: 7 additions & 6 deletions DicomTypeTranslation.Tests/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public void CheckFiles()

var root = doc.Element("TestDatabases");
if(root == null)
throw new Exception("Missing element 'TestDatabases' in " + TestFilename);
throw new Exception($"Missing element 'TestDatabases' in {TestFilename}");

var settings = root.Element("Settings");

if (settings == null)
throw new Exception("Missing element 'Settings' in " + TestFilename);
throw new Exception($"Missing element 'Settings' in {TestFilename}");

var e = settings.Element("AllowDatabaseCreation");
if (e == null)
throw new Exception("Missing element 'AllowDatabaseCreation' in " + TestFilename);
throw new Exception($"Missing element 'AllowDatabaseCreation' in {TestFilename}");

AllowDatabaseCreation = Convert.ToBoolean(e.Value);

e = settings.Element("TestScratchDatabase");
if (e == null)
throw new Exception("Missing element 'TestScratchDatabase' in " + TestFilename);
throw new Exception($"Missing element 'TestScratchDatabase' in {TestFilename}");

_testScratchDatabase = e.Value;

Expand All @@ -70,7 +70,7 @@ public void CheckFiles()
DatabaseType databaseType;

if(!DatabaseType.TryParse(type, out databaseType))
throw new Exception("Could not parse DatabaseType " + type);
throw new Exception($"Could not parse DatabaseType {type}");

var constr = element.Element("ConnectionString").Value;

Expand Down Expand Up @@ -100,7 +100,8 @@ protected DiscoveredDatabase GetTestDatabase(DatabaseType type, bool cleanDataba
db.Create();
else
{
Assert.Inconclusive("Database " + _testScratchDatabase + " did not exist on server " + server + " and AllowDatabaseCreation was false in " + TestFilename);
Assert.Inconclusive(
$"Database {_testScratchDatabase} did not exist on server {server} and AllowDatabaseCreation was false in {TestFilename}");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<AssemblyTitle>DicomTypeTranslation.Tests</AssemblyTitle>
<Product>DicomTypeTranslation.Tests</Product>
<Copyright>Copyright © 2018</Copyright>
Expand Down Expand Up @@ -83,7 +84,6 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="fo-dicom.Json" Version="4.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
8 changes: 4 additions & 4 deletions DicomTypeTranslation.Tests/DicomTypeTranslatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Dicom;
using FellowOakDicom;
using DicomTypeTranslation.Helpers;
using DicomTypeTranslation.Tests.Helpers;
using NLog;
Expand Down Expand Up @@ -191,16 +191,16 @@ public void PrintValueTypesForVrs()
if (vr == DicomVR.SQ)
continue;

_logger.Info("VR: " + vr.Code + "\t Type: " + vr.ValueType.Name + "\t IsString: " + vr.IsString);
_logger.Info($"VR: {vr.Code}\t Type: {vr.ValueType.Name}\t IsString: {vr.IsString}");
uniqueTypes.Add(vr.ValueType.Name.TrimEnd(']', '['));
}

var sb = new StringBuilder();
foreach (string str in uniqueTypes)
sb.Append(str + ", ");
sb.Append($"{str}, ");

sb.Length -= 2;
_logger.Info("Unique underlying types: " + sb);
_logger.Info($"Unique underlying types: {sb}");
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion DicomTypeTranslation.Tests/ExampleUsages.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dicom;
using FellowOakDicom;
using FAnsi.Discovery.TypeTranslation;
using FAnsi.Implementations.MicrosoftSQL;
using FAnsi.Implementations.Oracle;
Expand Down
8 changes: 4 additions & 4 deletions DicomTypeTranslation.Tests/Helpers/TranslationTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Dicom;
using FellowOakDicom;
using MongoDB.Bson;
using Newtonsoft.Json;

Expand Down Expand Up @@ -227,12 +227,12 @@ public static string PrettyPrintBsonDocument(BsonDocument document)

foreach (BsonElement item in document)
{
sb.Append("" + item.Name);
sb.Append($"{item.Name}");

if (item.Value is BsonDocument)
sb.AppendLine(PrettyPrintBsonDocument((BsonDocument)item.Value));
else if (item.Value is BsonArray)
sb.AppendLine(":\t" + item.Value);
sb.AppendLine($":\t{item.Value}");
else
{
object value;
Expand All @@ -242,7 +242,7 @@ public static string PrettyPrintBsonDocument(BsonDocument document)
else
value = item.Value;

sb.AppendLine(":\t\"" + value + "\"");
sb.AppendLine($":\t\"{value}\"");
}
}

Expand Down
Loading

0 comments on commit 61a0b1b

Please sign in to comment.