comparison OrthancFramework/Sources/DicomFormat/DicomMap.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/DicomFormat/DicomMap.h@f9863630ec7f
children bf7b9edf6b81
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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 General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "DicomTag.h"
37 #include "DicomValue.h"
38 #include "../Enumerations.h"
39
40 #include <set>
41 #include <map>
42 #include <json/json.h>
43
44 namespace Orthanc
45 {
46 class ORTHANC_PUBLIC DicomMap : public boost::noncopyable
47 {
48 public:
49 typedef std::map<DicomTag, DicomValue*> Content;
50
51 private:
52 friend class DicomArray;
53 friend class FromDcmtkBridge;
54 friend class ParsedDicomFile;
55
56 Content content_;
57
58 // Warning: This takes the ownership of "value"
59 void SetValueInternal(uint16_t group,
60 uint16_t element,
61 DicomValue* value);
62
63 static void GetMainDicomTagsInternal(std::set<DicomTag>& result,
64 ResourceType level);
65
66 public:
67 DicomMap()
68 {
69 }
70
71 ~DicomMap()
72 {
73 Clear();
74 }
75
76 size_t GetSize() const
77 {
78 return content_.size();
79 }
80
81 DicomMap* Clone() const;
82
83 void Assign(const DicomMap& other);
84
85 void Clear();
86
87 void SetNullValue(uint16_t group,
88 uint16_t element)
89 {
90 SetValueInternal(group, element, new DicomValue);
91 }
92
93 void SetNullValue(const DicomTag& tag)
94 {
95 SetValueInternal(tag.GetGroup(), tag.GetElement(), new DicomValue);
96 }
97
98 void SetValue(uint16_t group,
99 uint16_t element,
100 const DicomValue& value)
101 {
102 SetValueInternal(group, element, value.Clone());
103 }
104
105 void SetValue(const DicomTag& tag,
106 const DicomValue& value)
107 {
108 SetValueInternal(tag.GetGroup(), tag.GetElement(), value.Clone());
109 }
110
111 void SetValue(const DicomTag& tag,
112 const std::string& str,
113 bool isBinary)
114 {
115 SetValueInternal(tag.GetGroup(), tag.GetElement(), new DicomValue(str, isBinary));
116 }
117
118 void SetValue(uint16_t group,
119 uint16_t element,
120 const std::string& str,
121 bool isBinary)
122 {
123 SetValueInternal(group, element, new DicomValue(str, isBinary));
124 }
125
126 bool HasTag(uint16_t group, uint16_t element) const
127 {
128 return HasTag(DicomTag(group, element));
129 }
130
131 bool HasTag(const DicomTag& tag) const
132 {
133 return content_.find(tag) != content_.end();
134 }
135
136 const DicomValue& GetValue(uint16_t group, uint16_t element) const
137 {
138 return GetValue(DicomTag(group, element));
139 }
140
141 const DicomValue& GetValue(const DicomTag& tag) const;
142
143 // DO NOT delete the returned value!
144 const DicomValue* TestAndGetValue(uint16_t group, uint16_t element) const
145 {
146 return TestAndGetValue(DicomTag(group, element));
147 }
148
149 // DO NOT delete the returned value!
150 const DicomValue* TestAndGetValue(const DicomTag& tag) const;
151
152 void Remove(const DicomTag& tag);
153
154 void ExtractPatientInformation(DicomMap& result) const;
155
156 void ExtractStudyInformation(DicomMap& result) const;
157
158 void ExtractSeriesInformation(DicomMap& result) const;
159
160 void ExtractInstanceInformation(DicomMap& result) const;
161
162 static void SetupFindPatientTemplate(DicomMap& result);
163
164 static void SetupFindStudyTemplate(DicomMap& result);
165
166 static void SetupFindSeriesTemplate(DicomMap& result);
167
168 static void SetupFindInstanceTemplate(DicomMap& result);
169
170 void CopyTagIfExists(const DicomMap& source,
171 const DicomTag& tag);
172
173 static bool IsMainDicomTag(const DicomTag& tag, ResourceType level);
174
175 static bool IsMainDicomTag(const DicomTag& tag);
176
177 static void GetMainDicomTags(std::set<DicomTag>& result, ResourceType level);
178
179 static void GetMainDicomTags(std::set<DicomTag>& result);
180
181 void GetTags(std::set<DicomTag>& tags) const;
182
183 static bool IsDicomFile(const void* dicom,
184 size_t size);
185
186 static bool ParseDicomMetaInformation(DicomMap& result,
187 const void* dicom,
188 size_t size);
189
190 void LogMissingTagsForStore() const;
191
192 bool LookupStringValue(std::string& result,
193 const DicomTag& tag,
194 bool allowBinary) const;
195
196 bool ParseInteger32(int32_t& result,
197 const DicomTag& tag) const;
198
199 bool ParseInteger64(int64_t& result,
200 const DicomTag& tag) const;
201
202 bool ParseUnsignedInteger32(uint32_t& result,
203 const DicomTag& tag) const;
204
205 bool ParseUnsignedInteger64(uint64_t& result,
206 const DicomTag& tag) const;
207
208 bool ParseFloat(float& result,
209 const DicomTag& tag) const;
210
211 bool ParseFirstFloat(float& result,
212 const DicomTag& tag) const;
213
214 bool ParseDouble(double& result,
215 const DicomTag& tag) const;
216
217 void FromDicomAsJson(const Json::Value& dicomAsJson);
218
219 void Merge(const DicomMap& other);
220
221 void MergeMainDicomTags(const DicomMap& other,
222 ResourceType level);
223
224 void ExtractMainDicomTags(const DicomMap& other);
225
226 bool HasOnlyMainDicomTags() const;
227
228 void Serialize(Json::Value& target) const;
229
230 void Unserialize(const Json::Value& source);
231
232 void FromDicomWeb(const Json::Value& source);
233
234 std::string GetStringValue(const DicomTag& tag,
235 const std::string& defaultValue,
236 bool allowBinary) const;
237
238 void RemoveBinaryTags();
239
240 void DumpMainDicomTags(Json::Value& target,
241 ResourceType level) const;
242
243 void ParseMainDicomTags(const Json::Value& source,
244 ResourceType level);
245
246 void Print(FILE* fp) const; // For debugging only
247 };
248 }