comparison OrthancServer/Sources/ServerToolbox.cpp @ 4055:9214e3a7b0a2 framework

moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 12:52:09 +0200
parents 05b8fd21089c
children a4f28efdfccf
comparison
equal deleted inserted replaced
4054:9c37896a4457 4055:9214e3a7b0a2
161 } 161 }
162 162
163 163
164 namespace ServerToolbox 164 namespace ServerToolbox
165 { 165 {
166 void SimplifyTags(Json::Value& target,
167 const Json::Value& source,
168 DicomToJsonFormat format)
169 {
170 if (!source.isObject())
171 {
172 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
173 }
174
175 target = Json::objectValue;
176 Json::Value::Members members = source.getMemberNames();
177
178 for (size_t i = 0; i < members.size(); i++)
179 {
180 const Json::Value& v = source[members[i]];
181 const std::string& type = v["Type"].asString();
182
183 std::string name;
184 switch (format)
185 {
186 case DicomToJsonFormat_Human:
187 name = v["Name"].asString();
188 break;
189
190 case DicomToJsonFormat_Short:
191 name = members[i];
192 break;
193
194 default:
195 throw OrthancException(ErrorCode_ParameterOutOfRange);
196 }
197
198 if (type == "String")
199 {
200 target[name] = v["Value"].asString();
201 }
202 else if (type == "TooLong" ||
203 type == "Null")
204 {
205 target[name] = Json::nullValue;
206 }
207 else if (type == "Sequence")
208 {
209 const Json::Value& array = v["Value"];
210 assert(array.isArray());
211
212 Json::Value children = Json::arrayValue;
213 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++)
214 {
215 Json::Value c;
216 SimplifyTags(c, array[i], format);
217 children.append(c);
218 }
219
220 target[name] = children;
221 }
222 else
223 {
224 assert(0);
225 }
226 }
227 }
228
229
230 bool FindOneChildInstance(int64_t& result, 166 bool FindOneChildInstance(int64_t& result,
231 IDatabaseWrapper& database, 167 IDatabaseWrapper& database,
232 int64_t resource, 168 int64_t resource,
233 ResourceType type) 169 ResourceType type)
234 { 170 {