Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: Lillie Dae <lillie.dae@answerdigital.com>
  • Loading branch information
lillie-dae committed Nov 20, 2023
1 parent 9539f18 commit 759051b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
26 changes: 25 additions & 1 deletion src/Api/Hl7ApplicationConfigEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using FellowOakDicom;
using Monai.Deploy.InformaticsGateway.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Monai.Deploy.InformaticsGateway.Api
{
Expand Down Expand Up @@ -101,13 +102,36 @@ public class StringKeyValuePair : IKeyValuePair<string, string>
[Key]
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;

public static implicit operator StringKeyValuePair(KeyValuePair<string, string> kvp)
{
return new StringKeyValuePair { Key = kvp.Key, Value = kvp.Value };
}

[EditorBrowsable(EditorBrowsableState.Never)]
public void Deconstruct(out string key, out string value)
{
key = Key;
value = Value;
}
public static List<StringKeyValuePair> FromDictionary(Dictionary<string, string> dictionary) =>
dictionary.Select(kvp => new StringKeyValuePair { Key = kvp.Key, Value = kvp.Value }).ToList();

}

public class DataKeyValuePair : IKeyValuePair<string, DataLinkType>
{
[Key]
public string Key { get; set; } = string.Empty;
public DataLinkType Value { get; set; }

public static implicit operator DataKeyValuePair(KeyValuePair<string, DataLinkType> kvp)
{
return new DataKeyValuePair { Key = kvp.Key, Value = kvp.Value };
}

public static List<DataKeyValuePair> FromDictionary(Dictionary<string, DataLinkType> dictionary) =>
dictionary.Select(kvp => new DataKeyValuePair { Key = kvp.Key, Value = kvp.Value }).ToList();
}

public interface IKeyValuePair<TKey, TValue>
Expand Down
21 changes: 10 additions & 11 deletions src/Api/Test/Hl7ApplicationConfigEntityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Xunit;

Expand All @@ -32,7 +31,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenSendingIdKeyIsNotSet_ExpectVali
{
SendingId = new KeyValuePair<string, string>(string.Empty, "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } })
};

var errors = entity.Validate();
Expand All @@ -48,7 +47,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenSendingIdValueIsNotSet_ExpectVa
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", string.Empty),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } })
};

var errors = entity.Validate();
Expand All @@ -64,7 +63,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataLinkKeyIsNotSet_ExpectValid
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>(string.Empty, DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } })
};

var errors = entity.Validate();
Expand All @@ -80,7 +79,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingIsNotSet_ExpectValid
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string>()
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string>())
};

var errors = entity.Validate();
Expand All @@ -96,7 +95,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingKeyIsNotSet_ExpectVa
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { string.Empty, "DataMappingValue" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { string.Empty, "DataMappingValue" } })
};

var errors = entity.Validate();
Expand All @@ -112,7 +111,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsNotSet_Expect
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", string.Empty } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", string.Empty } })
};

var errors = entity.Validate();
Expand All @@ -128,7 +127,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsNotAValidDico
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } })
};

var errors = entity.Validate();
Expand All @@ -144,7 +143,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsAValidDicomTa
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } })
};

var errors = entity.Validate();
Expand All @@ -159,7 +158,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsEmpty_ExpectV
{
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "" } })
};

var errors = entity.Validate();
Expand All @@ -179,7 +178,7 @@ public void GivenAHl7ApplicationConfigEntity_WhenToStringIsCalled_ExpectToString
DateTimeCreated = dt,
SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"),
DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId),
DataMapping = new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } }
DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } })
};

var result = entity.ToString();
Expand Down
6 changes: 6 additions & 0 deletions src/Api/Test/Monai.Deploy.InformaticsGateway.Api.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
<Folder Include="Shared\" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Core">
<HintPath>..\..\..\..\..\..\..\..\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\6.0.24\ref\net6.0\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

0 comments on commit 759051b

Please sign in to comment.