diff OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp @ 4771:9f207131c7f4

added ParsedDicomFile::LookupSubSequence()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Aug 2021 17:20:21 +0200
parents 248408d2b336
children 3b78ba359db3
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Aug 25 15:42:34 2021 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Aug 25 17:20:21 2021 +0200
@@ -3162,6 +3162,56 @@
       IDicomPathVisitor::Apply(visitor, dataset, path);
     }
   }
+
+
+  bool FromDcmtkBridge::LookupSubSequence(DicomMap& target,
+                                          DcmDataset& dataset,
+                                          const DicomPath& path,
+                                          size_t sequenceIndex)
+  {
+    class Visitor : public FromDcmtkBridge::IDicomPathVisitor
+    {
+    private:
+      bool       found_;
+      DicomMap&  target_;
+      size_t     sequenceIndex_;
+      
+    public:
+      Visitor(DicomMap& target,
+              size_t sequenceIndex) :
+        found_(false),
+        target_(target),
+        sequenceIndex_(sequenceIndex)
+      {
+      }
+      
+      virtual void Visit(DcmItem& item,
+                         const DicomPath& path) ORTHANC_OVERRIDE
+      {
+        DcmTagKey tag(path.GetFinalTag().GetGroup(), path.GetFinalTag().GetElement());
+
+        DcmSequenceOfItems *sequence = NULL;
+        
+        if (item.findAndGetSequence(tag, sequence).good() &&
+            sequence != NULL &&
+            sequenceIndex_ < sequence->card())
+        {
+          std::set<DicomTag> ignoreTagLength;
+          ExtractDicomSummary(target_, *sequence->getItem(sequenceIndex_), 0, ignoreTagLength);
+          found_ = true;
+        }
+      }
+
+      bool HasFound() const
+      {
+        return found_;
+      }
+    };
+
+    Visitor visitor(target, sequenceIndex);
+    IDicomPathVisitor::Apply(visitor, dataset, path);
+    return visitor.HasFound();
+  }
 }