diff --git a/src/WorkflowManager/Storage/Services/DicomService.cs b/src/WorkflowManager/Storage/Services/DicomService.cs index 975984cf0..53c6f53ce 100644 --- a/src/WorkflowManager/Storage/Services/DicomService.cs +++ b/src/WorkflowManager/Storage/Services/DicomService.cs @@ -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 { @@ -87,20 +88,11 @@ public async Task GetPayloadPatientDetailsAsync(string payloadId var jsonStr = Encoding.UTF8.GetString(((MemoryStream)stream).ToArray()); var dict = JsonConvert.DeserializeObject>(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; } } } @@ -204,6 +196,11 @@ public async Task GetDcmJsonFileValueAtIndexAsync(int index, var dict = JsonConvert.DeserializeObject>(jsonStr); + return GetValue(dict, keyId); + } + + private static string GetValue(Dictionary? dict, string keyId) + { if (dict is null) { return string.Empty; @@ -213,7 +210,14 @@ public async Task 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(); + if (str is not null) { return string.Concat(str); @@ -222,5 +226,29 @@ public async Task GetDcmJsonFileValueAtIndexAsync(int index, return string.Empty; } + + private static string GetPatientName(object[] values) + { + var resultStr = new List(); + + foreach (var value in values) + { + var valueStr = JObject.FromObject(value)? + .GetValue("Alphabetic", StringComparison.OrdinalIgnoreCase)? + .Value(); + + if (valueStr is not null) + { + resultStr.Add(valueStr); + } + } + + if(resultStr.Any() is true) + { + return string.Concat(resultStr); + } + + return string.Empty; + } } } diff --git a/src/WorkflowManager/Storage/Services/IDicomService.cs b/src/WorkflowManager/Storage/Services/IDicomService.cs index eab6c36f8..3c4957b16 100644 --- a/src/WorkflowManager/Storage/Services/IDicomService.cs +++ b/src/WorkflowManager/Storage/Services/IDicomService.cs @@ -41,8 +41,8 @@ public interface IDicomService /// 'null' /// /// - /// - /// + /// + /// /// Task GetAllValueAsync(string keyId, string payloadId, string bucketId); @@ -51,7 +51,8 @@ public interface IDicomService /// if no matchs return 'null' /// /// example of keyId 00100040 - /// + /// + /// /// Task GetAnyValueAsync(string keyId, string payloadId, string bucketId); } diff --git a/tests/IntegrationTests/WorkflowExecutor.IntegrationTests/DICOMs/full_patient_metadata/dcm/07051db3-3c1d-4bf2-8764-ba45dc918e74.dcm.json b/tests/IntegrationTests/WorkflowExecutor.IntegrationTests/DICOMs/full_patient_metadata/dcm/07051db3-3c1d-4bf2-8764-ba45dc918e74.dcm.json index deba78343..7784186dd 100644 --- a/tests/IntegrationTests/WorkflowExecutor.IntegrationTests/DICOMs/full_patient_metadata/dcm/07051db3-3c1d-4bf2-8764-ba45dc918e74.dcm.json +++ b/tests/IntegrationTests/WorkflowExecutor.IntegrationTests/DICOMs/full_patient_metadata/dcm/07051db3-3c1d-4bf2-8764-ba45dc918e74.dcm.json @@ -56,9 +56,9 @@ }, "00100010": { "vr": "PN", - "Value": [ - "Patient_Full_Patient" - ] + "Value": [{ + "Alphabetic": "Patient_Full_Patient" + }] }, "00100020": { "vr": "LO", diff --git a/tests/UnitTests/Storage.Tests/Services/DicomServiceTests.cs b/tests/UnitTests/Storage.Tests/Services/DicomServiceTests.cs index b9a3647b9..77c1f1bb6 100644 --- a/tests/UnitTests/Storage.Tests/Services/DicomServiceTests.cs +++ b/tests/UnitTests/Storage.Tests/Services/DicomServiceTests.cs @@ -126,7 +126,7 @@ public async Task GetPayloadPatientDetails_ValidPayloadIdAndBucket_ReturnsValues var fileContents = new Dictionary { - { 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" } },