Mercurial > hg > orthanc
annotate Core/SerializationToolbox.cpp @ 3757:a593c20bf79b Orthanc-1.5.4
closing branch Orthanc-1.5.4
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Mar 2020 12:16:52 +0100 |
parents | 972cc98959a3 |
children | ae866fc06df5 94f4a18a79cc |
rev | line source |
---|---|
2656 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2983
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
2656 | 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 #include "PrecompiledHeaders.h" | |
35 #include "SerializationToolbox.h" | |
36 | |
37 #include "OrthancException.h" | |
38 | |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
39 #if ORTHANC_ENABLE_DCMTK == 1 |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
40 # include "DicomParsing/FromDcmtkBridge.h" |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
41 #endif |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
42 |
2656 | 43 namespace Orthanc |
44 { | |
45 namespace SerializationToolbox | |
46 { | |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
47 static bool ParseTagInternal(DicomTag& tag, |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
48 const char* name) |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
49 { |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
50 #if ORTHANC_ENABLE_DCMTK == 1 |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
51 try |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
52 { |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
53 tag = FromDcmtkBridge::ParseTag(name); |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
54 return true; |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
55 } |
3128
972cc98959a3
fix build of civetweb for Visual Studio 2008 and LSB
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
56 catch (OrthancException&) |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
57 { |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
58 return false; |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
59 } |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
60 #else |
2983 | 61 return DicomTag::ParseHexadecimal(tag, name); |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
62 #endif |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
63 } |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
64 |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
65 |
2656 | 66 std::string ReadString(const Json::Value& value, |
67 const std::string& field) | |
68 { | |
69 if (value.type() != Json::objectValue || | |
70 !value.isMember(field.c_str()) || | |
71 value[field.c_str()].type() != Json::stringValue) | |
72 { | |
2966 | 73 throw OrthancException(ErrorCode_BadFileFormat, |
74 "String value expected in field: " + field); | |
2656 | 75 } |
76 else | |
77 { | |
78 return value[field.c_str()].asString(); | |
79 } | |
80 } | |
81 | |
82 | |
83 int ReadInteger(const Json::Value& value, | |
84 const std::string& field) | |
85 { | |
86 if (value.type() != Json::objectValue || | |
87 !value.isMember(field.c_str()) || | |
88 (value[field.c_str()].type() != Json::intValue && | |
89 value[field.c_str()].type() != Json::uintValue)) | |
90 { | |
2966 | 91 throw OrthancException(ErrorCode_BadFileFormat, |
92 "Integer value expected in field: " + field); | |
2656 | 93 } |
94 else | |
95 { | |
96 return value[field.c_str()].asInt(); | |
97 } | |
98 } | |
99 | |
100 | |
101 unsigned int ReadUnsignedInteger(const Json::Value& value, | |
102 const std::string& field) | |
103 { | |
104 int tmp = ReadInteger(value, field); | |
105 | |
106 if (tmp < 0) | |
107 { | |
2966 | 108 throw OrthancException(ErrorCode_BadFileFormat, |
109 "Unsigned integer value expected in field: " + field); | |
2656 | 110 } |
111 else | |
112 { | |
113 return static_cast<unsigned int>(tmp); | |
114 } | |
115 } | |
116 | |
117 | |
118 bool ReadBoolean(const Json::Value& value, | |
119 const std::string& field) | |
120 { | |
121 if (value.type() != Json::objectValue || | |
122 !value.isMember(field.c_str()) || | |
123 value[field.c_str()].type() != Json::booleanValue) | |
124 { | |
2966 | 125 throw OrthancException(ErrorCode_BadFileFormat, |
126 "Boolean value expected in field: " + field); | |
2656 | 127 } |
128 else | |
129 { | |
130 return value[field.c_str()].asBool(); | |
131 } | |
132 } | |
133 | |
134 | |
135 void ReadArrayOfStrings(std::vector<std::string>& target, | |
136 const Json::Value& value, | |
137 const std::string& field) | |
138 { | |
139 if (value.type() != Json::objectValue || | |
140 !value.isMember(field.c_str()) || | |
141 value[field.c_str()].type() != Json::arrayValue) | |
142 { | |
2966 | 143 throw OrthancException(ErrorCode_BadFileFormat, |
144 "List of strings expected in field: " + field); | |
2656 | 145 } |
146 | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
147 const Json::Value& arr = value[field.c_str()]; |
2656 | 148 |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
149 target.resize(arr.size()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
150 |
2656 | 151 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
152 { | |
153 if (arr[i].type() != Json::stringValue) | |
154 { | |
2966 | 155 throw OrthancException(ErrorCode_BadFileFormat, |
156 "List of strings expected in field: " + field); | |
2656 | 157 } |
158 else | |
159 { | |
160 target[i] = arr[i].asString(); | |
161 } | |
162 } | |
163 } | |
164 | |
165 | |
166 void ReadListOfStrings(std::list<std::string>& target, | |
167 const Json::Value& value, | |
168 const std::string& field) | |
169 { | |
170 std::vector<std::string> tmp; | |
171 ReadArrayOfStrings(tmp, value, field); | |
172 | |
173 target.clear(); | |
174 for (size_t i = 0; i < tmp.size(); i++) | |
175 { | |
176 target.push_back(tmp[i]); | |
177 } | |
178 } | |
179 | |
180 | |
181 void ReadSetOfStrings(std::set<std::string>& target, | |
182 const Json::Value& value, | |
183 const std::string& field) | |
184 { | |
185 std::vector<std::string> tmp; | |
186 ReadArrayOfStrings(tmp, value, field); | |
187 | |
188 target.clear(); | |
189 for (size_t i = 0; i < tmp.size(); i++) | |
190 { | |
191 target.insert(tmp[i]); | |
192 } | |
193 } | |
194 | |
195 | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
196 void ReadSetOfTags(std::set<DicomTag>& target, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
197 const Json::Value& value, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
198 const std::string& field) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
199 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
200 if (value.type() != Json::objectValue || |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
201 !value.isMember(field.c_str()) || |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
202 value[field.c_str()].type() != Json::arrayValue) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
203 { |
2966 | 204 throw OrthancException(ErrorCode_BadFileFormat, |
205 "Set of DICOM tags expected in field: " + field); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
206 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
207 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
208 const Json::Value& arr = value[field.c_str()]; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
209 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
210 target.clear(); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
211 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
212 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
213 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
214 DicomTag tag(0, 0); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
215 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
216 if (arr[i].type() != Json::stringValue || |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
217 !ParseTagInternal(tag, arr[i].asCString())) |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
218 { |
2966 | 219 throw OrthancException(ErrorCode_BadFileFormat, |
220 "Set of DICOM tags expected in field: " + field); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
221 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
222 else |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
223 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
224 target.insert(tag); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
225 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
226 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
227 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
228 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
229 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
230 void ReadMapOfStrings(std::map<std::string, std::string>& target, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
231 const Json::Value& value, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
232 const std::string& field) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
233 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
234 if (value.type() != Json::objectValue || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
235 !value.isMember(field.c_str()) || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
236 value[field.c_str()].type() != Json::objectValue) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
237 { |
2966 | 238 throw OrthancException(ErrorCode_BadFileFormat, |
239 "Associative array of strings to strings expected in field: " + field); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
240 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
241 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
242 const Json::Value& source = value[field.c_str()]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
243 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
244 target.clear(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
245 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
246 Json::Value::Members members = source.getMemberNames(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
247 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
248 for (size_t i = 0; i < members.size(); i++) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
249 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
250 const Json::Value& tmp = source[members[i]]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
251 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
252 if (tmp.type() != Json::stringValue) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
253 { |
2966 | 254 throw OrthancException(ErrorCode_BadFileFormat, |
255 "Associative array of string to strings expected in field: " + field); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
256 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
257 else |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
258 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
259 target[members[i]] = tmp.asString(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
260 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
261 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
262 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
263 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
264 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
265 void ReadMapOfTags(std::map<DicomTag, std::string>& target, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
266 const Json::Value& value, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
267 const std::string& field) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
268 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
269 if (value.type() != Json::objectValue || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
270 !value.isMember(field.c_str()) || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
271 value[field.c_str()].type() != Json::objectValue) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
272 { |
2966 | 273 throw OrthancException(ErrorCode_BadFileFormat, |
274 "Associative array of DICOM tags to strings expected in field: " + field); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
275 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
276 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
277 const Json::Value& source = value[field.c_str()]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
278 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
279 target.clear(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
280 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
281 Json::Value::Members members = source.getMemberNames(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
282 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
283 for (size_t i = 0; i < members.size(); i++) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
284 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
285 const Json::Value& tmp = source[members[i]]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
286 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
287 DicomTag tag(0, 0); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
288 |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
289 if (!ParseTagInternal(tag, members[i].c_str()) || |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
290 tmp.type() != Json::stringValue) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
291 { |
2966 | 292 throw OrthancException(ErrorCode_BadFileFormat, |
293 "Associative array of DICOM tags to strings expected in field: " + field); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
294 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
295 else |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
296 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
297 target[tag] = tmp.asString(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
298 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
299 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
300 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
301 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
302 |
2656 | 303 void WriteArrayOfStrings(Json::Value& target, |
304 const std::vector<std::string>& values, | |
305 const std::string& field) | |
306 { | |
307 if (target.type() != Json::objectValue || | |
308 target.isMember(field.c_str())) | |
309 { | |
310 throw OrthancException(ErrorCode_BadFileFormat); | |
311 } | |
312 | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
313 Json::Value& value = target[field]; |
2656 | 314 |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
315 value = Json::arrayValue; |
2656 | 316 for (size_t i = 0; i < values.size(); i++) |
317 { | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
318 value.append(values[i]); |
2656 | 319 } |
320 } | |
321 | |
322 | |
323 void WriteSetOfStrings(Json::Value& target, | |
324 const std::set<std::string>& values, | |
325 const std::string& field) | |
326 { | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
327 if (target.type() != Json::objectValue || |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
328 target.isMember(field.c_str())) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
329 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
330 throw OrthancException(ErrorCode_BadFileFormat); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
331 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
332 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
333 Json::Value& value = target[field]; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
334 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
335 value = Json::arrayValue; |
2656 | 336 |
337 for (std::set<std::string>::const_iterator it = values.begin(); | |
338 it != values.end(); ++it) | |
339 { | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
340 value.append(*it); |
2656 | 341 } |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
342 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
343 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
344 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
345 void WriteSetOfTags(Json::Value& target, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
346 const std::set<DicomTag>& tags, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
347 const std::string& field) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
348 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
349 if (target.type() != Json::objectValue || |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
350 target.isMember(field.c_str())) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
351 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
352 throw OrthancException(ErrorCode_BadFileFormat); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
353 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
354 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
355 Json::Value& value = target[field]; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
356 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
357 value = Json::arrayValue; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
358 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
359 for (std::set<DicomTag>::const_iterator it = tags.begin(); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
360 it != tags.end(); ++it) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
361 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
362 value.append(it->Format()); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
363 } |
2656 | 364 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
365 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
366 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
367 void WriteMapOfStrings(Json::Value& target, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
368 const std::map<std::string, std::string>& values, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
369 const std::string& field) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
370 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
371 if (target.type() != Json::objectValue || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
372 target.isMember(field.c_str())) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
373 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
374 throw OrthancException(ErrorCode_BadFileFormat); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
375 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
376 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
377 Json::Value& value = target[field]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
378 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
379 value = Json::objectValue; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
380 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
381 for (std::map<std::string, std::string>::const_iterator |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
382 it = values.begin(); it != values.end(); ++it) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
383 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
384 value[it->first] = it->second; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
385 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
386 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
387 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
388 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
389 void WriteMapOfTags(Json::Value& target, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
390 const std::map<DicomTag, std::string>& values, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
391 const std::string& field) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
392 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
393 if (target.type() != Json::objectValue || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
394 target.isMember(field.c_str())) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
395 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
396 throw OrthancException(ErrorCode_BadFileFormat); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
397 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
398 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
399 Json::Value& value = target[field]; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
400 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
401 value = Json::objectValue; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
402 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
403 for (std::map<DicomTag, std::string>::const_iterator |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
404 it = values.begin(); it != values.end(); ++it) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
405 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
406 value[it->first.Format()] = it->second; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
407 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
408 } |
2656 | 409 } |
410 } |