diff OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp @ 5044:6fed78e13233

Refactored DicomMap to handle sequences when needed
author Alain Mazy <am@osimis.io>
date Tue, 28 Jun 2022 17:45:09 +0200
parents c014ab79fca5
children ea9e2680da6f
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Mon Jun 27 15:22:19 2022 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Tue Jun 28 17:45:09 2022 +0200
@@ -564,6 +564,26 @@
                                 ConvertLeafElement(*element, DicomToJsonFlags_Default,
                                                    maxStringLength, encoding, hasCodeExtensions, ignoreTagLength));
       }
+      else
+      {
+        DcmSequenceOfItems* sequence = dynamic_cast<DcmSequenceOfItems*>(element);
+        
+        if (sequence)
+        {
+          Json::Value jsonSequence = Json::arrayValue;
+          for (unsigned long i = 0; i < sequence->card(); i++)
+          {
+            DcmItem* child = sequence->getItem(i);
+            Json::Value& v = jsonSequence.append(Json::objectValue);
+            DatasetToJson(v, *child, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 
+                          maxStringLength, encoding, hasCodeExtensions,
+                          ignoreTagLength, 1);
+          }
+
+          target.SetValue(DicomTag(element->getTag().getGTag(), element->getTag().getETag()),
+                          jsonSequence);
+        }
+      }
     }
   }
 
@@ -1417,6 +1437,18 @@
           {
             result[tagName] = Json::nullValue;
           }
+          else if (it->second->IsSequence())
+          {
+            result[tagName] = Json::arrayValue;
+            const Json::Value& jsonSequence = it->second->GetSequenceContent();
+
+            for (Json::Value::ArrayIndex i = 0; i < jsonSequence.size(); ++i)
+            {
+              Json::Value target = Json::objectValue;
+              Toolbox::SimplifyDicomAsJson(target, jsonSequence[i], DicomToJsonFormat_Human);
+              result[tagName].append(target);
+            }
+          }
           else
           {
             // TODO IsBinary
@@ -1439,6 +1471,11 @@
             value["Type"] = "Null";
             value["Value"] = Json::nullValue;
           }
+          else if (it->second->IsSequence())
+          {
+            value["Type"] = "Sequence";
+            value["Value"] = it->second->GetSequenceContent();
+          }
           else
           {
             // TODO IsBinary
@@ -1458,6 +1495,18 @@
           {
             result[hex] = Json::nullValue;
           }
+          else if (it->second->IsSequence())
+          {
+            result[hex] = Json::arrayValue;
+            const Json::Value& jsonSequence = it->second->GetSequenceContent();
+
+            for (Json::Value::ArrayIndex i = 0; i < jsonSequence.size(); ++i)
+            {
+              Json::Value target = Json::objectValue;
+              Toolbox::SimplifyDicomAsJson(target, jsonSequence[i], DicomToJsonFormat_Short);
+              result[hex].append(target);
+            }
+          }
           else
           {
             // TODO IsBinary