changeset 4953:60cb4b379485

added FromDcmtkBridge::LookupStringValue()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Mar 2022 12:37:24 +0100
parents 15ce7af202f1
children e1495a34cd39 1610e56cadfb
files OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h OrthancFramework/Sources/DicomParsing/IDicomTranscoder.cpp
diffstat 3 files changed, 50 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 22 10:20:25 2022 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 22 12:37:24 2022 +0100
@@ -3226,6 +3226,49 @@
     IDicomPathVisitor::Apply(visitor, dataset, path);
     return visitor.HasFound();
   }
+
+
+  bool FromDcmtkBridge::LookupStringValue(std::string& target,
+                                          DcmDataset& dataset,
+                                          const DicomTag& key)
+  {
+    DcmTagKey dcmkey(key.GetGroup(), key.GetElement());
+    
+    const char* str = NULL;
+    const Uint8* data = NULL;
+    unsigned long size = 0;
+
+    if (dataset.findAndGetString(dcmkey, str).good() &&
+        str != NULL)
+    {
+      target.assign(str);
+      return true;
+    }
+    else if (dataset.findAndGetUint8Array(dcmkey, data, &size).good() &&
+             data != NULL &&
+             size > 0)
+    {
+      /**
+       * This special case is necessary for borderline DICOM files
+       * that have DICOM tags have the "UN" value representation. New
+       * in Orthanc 1.10.1.
+       * https://groups.google.com/g/orthanc-users/c/86fobx3ZyoM/m/KBG17un6AQAJ
+       **/
+      unsigned long l = 0;
+      while (l < size &&
+             data[l] != 0)
+      {
+        l++;
+      }
+
+      target.assign(reinterpret_cast<const char*>(data), l);
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
 }
 
 
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Tue Mar 22 10:20:25 2022 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Tue Mar 22 12:37:24 2022 +0100
@@ -283,5 +283,9 @@
                                    DcmDataset& dataset,
                                    const DicomPath& path,
                                    size_t sequenceIndex);
+
+    static bool LookupStringValue(std::string& target,
+                                  DcmDataset& dataset,
+                                  const DicomTag& key);
   };
 }
--- a/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.cpp	Tue Mar 22 10:20:25 2022 +0100
+++ b/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.cpp	Tue Mar 22 12:37:24 2022 +0100
@@ -75,13 +75,11 @@
     }
     
     DcmDataset& dataset = *dicom.getDataset();
-    
-    const char* v = NULL;
 
-    if (dataset.findAndGetString(DCM_SOPInstanceUID, v).good() &&
-        v != NULL)
+    std::string s;
+    if (FromDcmtkBridge::LookupStringValue(s, dataset, DICOM_TAG_SOP_INSTANCE_UID))
     {
-      return std::string(v);
+      return s;
     }
     else
     {