diff OrthancFramework/Sources/DicomFormat/DicomPath.cpp @ 4683:7182f5732480

use of DicomPath in ParsedDicomFile
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jun 2021 12:37:48 +0200
parents d38a7040474a
children 693f049729ba
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomPath.cpp	Mon Jun 07 18:35:46 2021 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomPath.cpp	Tue Jun 08 12:37:48 2021 +0200
@@ -141,6 +141,27 @@
   }
 
 
+  DicomPath::DicomPath(const std::vector<Orthanc::DicomTag>& parentTags,
+                       const std::vector<size_t> parentIndexes,
+                       const Orthanc::DicomTag& finalTag) :
+    finalTag_(finalTag)
+  {
+    if (parentTags.size() != parentIndexes.size())
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      prefix_.reserve(parentTags.size());
+
+      for (size_t i = 0; i < prefix_.size(); i++)
+      {
+        prefix_.push_back(PrefixItem::CreateIndexed(parentTags[i], parentIndexes[i]));        
+      }
+    }
+  }
+
+
   void DicomPath::AddIndexedTagToPrefix(const Orthanc::DicomTag& tag,
                                         size_t index)
   {
@@ -259,4 +280,39 @@
 
     return path;
   }
+
+
+  bool DicomPath::IsMatch(const DicomPath& pattern,
+                          const DicomPath& path)
+  {
+    if (path.HasUniversal())
+    {
+      throw OrthancException(ErrorCode_BadParameterType);
+    }
+    else if (path.GetPrefixLength() < pattern.GetPrefixLength())
+    {
+      return false;
+    }
+    else
+    {
+      for (size_t i = 0; i < pattern.GetPrefixLength(); i++)
+      {
+        if (path.GetPrefixTag(i) != pattern.GetPrefixTag(i) ||
+            (!pattern.IsPrefixUniversal(i) &&
+             path.GetPrefixIndex(i) != pattern.GetPrefixIndex(i)))
+        {
+          return false;
+        }
+      }
+
+      if (path.GetPrefixLength() == pattern.GetPrefixLength())
+      {
+        return (path.GetFinalTag() == pattern.GetFinalTag());
+      }
+      else
+      {
+        return (path.GetPrefixTag(pattern.GetPrefixLength()) == pattern.GetFinalTag());
+      }
+    }
+  }
 }