diff OrthancFramework/Sources/DicomFormat/DicomPath.h @ 4681:c5528c7847a6

new class DicomPath
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Jun 2021 17:05:48 +0200
parents
children d38a7040474a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DicomFormat/DicomPath.h	Mon Jun 07 17:05:48 2021 +0200
@@ -0,0 +1,137 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2021 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../OrthancFramework.h"
+#include "../DicomFormat/DicomTag.h"
+
+#include <vector>
+
+namespace Orthanc
+{
+  class DicomPath
+  {
+  private:
+    class PrefixItem
+    {
+    private:
+      DicomTag  tag_;
+      bool      isUniversal_;  // Matches any index
+      size_t    index_;
+
+      PrefixItem(DicomTag tag,
+                 bool isUniversal,
+                 size_t index);
+      
+    public:
+      static PrefixItem CreateUniversal(const DicomTag& tag)
+      {
+        return PrefixItem(tag, true, 0 /* dummy value */);
+      }
+
+      static PrefixItem CreateIndexed(const DicomTag& tag,
+                                      size_t index)
+      {
+        return PrefixItem(tag, false, index);
+      }
+
+      const DicomTag& GetTag() const
+      {
+        return tag_;
+      }
+
+      bool IsUniversal() const
+      {
+        return isUniversal_;
+      }
+
+      size_t GetIndex() const;
+    };
+
+    std::vector<PrefixItem>  prefix_;
+    Orthanc::DicomTag        finalTag_;
+
+    static DicomTag ParseTag(const std::string& token);
+    
+    const PrefixItem& GetLevel(size_t i) const;
+    
+  public:
+    explicit DicomPath(const Orthanc::DicomTag& tag) :
+      finalTag_(tag)
+    {
+    }
+
+    DicomPath(const Orthanc::DicomTag& sequence,
+              size_t index,
+              const Orthanc::DicomTag& tag);
+
+    DicomPath(const Orthanc::DicomTag& sequence1,
+              size_t index1,
+              const Orthanc::DicomTag& sequence2,
+              size_t index2,
+              const Orthanc::DicomTag& tag);
+
+    DicomPath(const Orthanc::DicomTag& sequence1,
+              size_t index1,
+              const Orthanc::DicomTag& sequence2,
+              size_t index2,
+              const Orthanc::DicomTag& sequence3,
+              size_t index3,
+              const Orthanc::DicomTag& tag);
+
+    void AddIndexedTagToPrefix(const Orthanc::DicomTag& tag,
+                               size_t index);
+
+    void AddUniversalTagToPrefix(const Orthanc::DicomTag& tag);
+
+    size_t GetPrefixLength() const
+    {
+      return prefix_.size();
+    }
+
+    const Orthanc::DicomTag& GetFinalTag() const
+    {
+      return finalTag_;
+    }
+
+    const Orthanc::DicomTag& GetPrefixTag(size_t level) const
+    {
+      return GetLevel(level).GetTag();
+    }
+
+    bool IsPrefixUniversal(size_t level) const
+    {
+      return GetLevel(level).IsUniversal();
+    }
+
+    size_t GetPrefixIndex(size_t level) const
+    {
+      return GetLevel(level).GetIndex();
+    }
+
+    std::string Format() const;
+
+    static DicomPath Parse(const std::string& s,
+                           bool allowUniversal);
+  };
+}