diff OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp @ 4953:60cb4b379485

added FromDcmtkBridge::LookupStringValue()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Mar 2022 12:37:24 +0100
parents e100fd9db29b
children e1495a34cd39
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;
+    }
+  }
 }