comparison 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
comparison
equal deleted inserted replaced
4680:898e8ac8c453 4681:c5528c7847a6
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #pragma once
24
25 #include "../OrthancFramework.h"
26 #include "../DicomFormat/DicomTag.h"
27
28 #include <vector>
29
30 namespace Orthanc
31 {
32 class DicomPath
33 {
34 private:
35 class PrefixItem
36 {
37 private:
38 DicomTag tag_;
39 bool isUniversal_; // Matches any index
40 size_t index_;
41
42 PrefixItem(DicomTag tag,
43 bool isUniversal,
44 size_t index);
45
46 public:
47 static PrefixItem CreateUniversal(const DicomTag& tag)
48 {
49 return PrefixItem(tag, true, 0 /* dummy value */);
50 }
51
52 static PrefixItem CreateIndexed(const DicomTag& tag,
53 size_t index)
54 {
55 return PrefixItem(tag, false, index);
56 }
57
58 const DicomTag& GetTag() const
59 {
60 return tag_;
61 }
62
63 bool IsUniversal() const
64 {
65 return isUniversal_;
66 }
67
68 size_t GetIndex() const;
69 };
70
71 std::vector<PrefixItem> prefix_;
72 Orthanc::DicomTag finalTag_;
73
74 static DicomTag ParseTag(const std::string& token);
75
76 const PrefixItem& GetLevel(size_t i) const;
77
78 public:
79 explicit DicomPath(const Orthanc::DicomTag& tag) :
80 finalTag_(tag)
81 {
82 }
83
84 DicomPath(const Orthanc::DicomTag& sequence,
85 size_t index,
86 const Orthanc::DicomTag& tag);
87
88 DicomPath(const Orthanc::DicomTag& sequence1,
89 size_t index1,
90 const Orthanc::DicomTag& sequence2,
91 size_t index2,
92 const Orthanc::DicomTag& tag);
93
94 DicomPath(const Orthanc::DicomTag& sequence1,
95 size_t index1,
96 const Orthanc::DicomTag& sequence2,
97 size_t index2,
98 const Orthanc::DicomTag& sequence3,
99 size_t index3,
100 const Orthanc::DicomTag& tag);
101
102 void AddIndexedTagToPrefix(const Orthanc::DicomTag& tag,
103 size_t index);
104
105 void AddUniversalTagToPrefix(const Orthanc::DicomTag& tag);
106
107 size_t GetPrefixLength() const
108 {
109 return prefix_.size();
110 }
111
112 const Orthanc::DicomTag& GetFinalTag() const
113 {
114 return finalTag_;
115 }
116
117 const Orthanc::DicomTag& GetPrefixTag(size_t level) const
118 {
119 return GetLevel(level).GetTag();
120 }
121
122 bool IsPrefixUniversal(size_t level) const
123 {
124 return GetLevel(level).IsUniversal();
125 }
126
127 size_t GetPrefixIndex(size_t level) const
128 {
129 return GetLevel(level).GetIndex();
130 }
131
132 std::string Format() const;
133
134 static DicomPath Parse(const std::string& s,
135 bool allowUniversal);
136 };
137 }