Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions src/WorkflowManager/Storage/Services/DicomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Newtonsoft.Json;
using Monai.Deploy.Storage.API;
using System.Globalization;
using Newtonsoft.Json.Linq;

namespace Monai.Deploy.WorkflowManager.Storage.Services
{
Expand Down Expand Up @@ -87,20 +88,11 @@ public async Task<PatientDetails> GetPayloadPatientDetailsAsync(string payloadId
var jsonStr = Encoding.UTF8.GetString(((MemoryStream)stream).ToArray());

var dict = JsonConvert.DeserializeObject<Dictionary<string, DicomValue>>(jsonStr);
if (dict is not null)
var value = GetValue(dict, keyId);

if (!string.IsNullOrWhiteSpace(value))
{
dict.TryGetValue(keyId, out var value);
if (value is null || value.Value is null)
{
continue;
}

var firstValue = value.Value.FirstOrDefault()?.ToString();

if (!string.IsNullOrWhiteSpace(firstValue))
{
return firstValue;
}
return value;
}
}
}
Expand Down Expand Up @@ -204,6 +196,11 @@ public async Task<string> GetDcmJsonFileValueAtIndexAsync(int index,

var dict = JsonConvert.DeserializeObject<Dictionary<string, DicomValue>>(jsonStr);

return GetValue(dict, keyId);
}

private static string GetValue(Dictionary<string, DicomValue>? dict, string keyId)
{
if (dict is null)
{
return string.Empty;
Expand All @@ -213,7 +210,14 @@ public async Task<string> GetDcmJsonFileValueAtIndexAsync(int index,

if (value is not null && value.Value is not null)
{

if (string.Equals(keyId, DicomTagConstants.PatientNameTag))
{
return GetPatientName(value.Value);
}

var str = value?.Value.Cast<string>();

if (str is not null)
{
return string.Concat(str);
Expand All @@ -222,5 +226,29 @@ public async Task<string> GetDcmJsonFileValueAtIndexAsync(int index,

return string.Empty;
}

private static string GetPatientName(object[] values)
{
var resultStr = new List<string>();

foreach (var value in values)
{
var valueStr = JObject.FromObject(value)?
.GetValue("Alphabetic", StringComparison.OrdinalIgnoreCase)?
.Value<string>();

if (valueStr is not null)
{
resultStr.Add(valueStr);
}
}

if(resultStr.Any() is true)
{
return string.Concat(resultStr);
}

return string.Empty;
}
}
}
7 changes: 4 additions & 3 deletions src/WorkflowManager/Storage/Services/IDicomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public interface IDicomService
/// 'null'
/// </summary>
/// <param name="keyId"></param>
/// <param name="matchValue"></param>
/// <param name="workflowInstance"></param>
/// <param name="payloadId"></param>
/// <param name="bucketId"></param>
/// <returns></returns>
Task<string> GetAllValueAsync(string keyId, string payloadId, string bucketId);

Expand All @@ -51,7 +51,8 @@ public interface IDicomService
/// if no matchs return 'null'
/// </summary>
/// <param name="keyId">example of keyId 00100040</param>
/// <param name="workflowInstance"></param>
/// <param name="payloadId"></param>
/// <param name="bucketId"></param>
/// <returns></returns>
Task<string> GetAnyValueAsync(string keyId, string payloadId, string bucketId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
},
"00100010": {
"vr": "PN",
"Value": [
"Patient_Full_Patient"
]
"Value": [{
"Alphabetic": "Patient_Full_Patient"
}]
},
"00100020": {
"vr": "LO",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task GetPayloadPatientDetails_ValidPayloadIdAndBucket_ReturnsValues

var fileContents = new Dictionary<string, DicomValue>
{
{ DicomTagConstants.PatientNameTag, new DicomValue{ Value = new object[] { "Jack" }, Vr = "RR" } },
{ DicomTagConstants.PatientNameTag, new DicomValue{ Value = new object[] { new { Alphabetic = "Jack" } }, Vr = "RR" } },
{ DicomTagConstants.PatientSexTag, new DicomValue{ Value = new object[] { "Male" }, Vr = "RR" } },
{ DicomTagConstants.PatientIdTag, new DicomValue{ Value = new object[] { "patientid" }, Vr = "RR" } },
{ DicomTagConstants.PatientDateOfBirthTag, new DicomValue{ Value = new object[] { "19960120" }, Vr = "RR" } },
Expand Down