Mercurial > hg > orthanc
comparison PalantirServer/FromDcmtkBridge.cpp @ 35:f6d12037f886
full json vs. simplified json
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 Aug 2012 12:24:31 +0200 |
parents | 67a6978503b7 |
children | c1097a676eca |
comparison
equal
deleted
inserted
replaced
34:96e57b863dd9 | 35:f6d12037f886 |
---|---|
296 DcmElement& element, | 296 DcmElement& element, |
297 unsigned int maxStringLength) | 297 unsigned int maxStringLength) |
298 { | 298 { |
299 assert(target.type() == Json::objectValue); | 299 assert(target.type() == Json::objectValue); |
300 | 300 |
301 const std::string tagName = FromDcmtkBridge::GetName(FromDcmtkBridge::GetTag(element)); | 301 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
302 const std::string tagName = FromDcmtkBridge::GetName(tag); | |
303 const std::string formattedTag = tag.Format(); | |
302 | 304 |
303 if (element.isLeaf()) | 305 if (element.isLeaf()) |
304 { | 306 { |
307 Json::Value value(Json::objectValue); | |
308 value["Name"] = tagName; | |
309 | |
305 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element)); | 310 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element)); |
306 if (v->IsNull()) | 311 if (v->IsNull()) |
307 { | 312 { |
308 target[tagName] = Json::nullValue; | 313 value["Type"] = "Null"; |
314 value["Value"] = Json::nullValue; | |
309 } | 315 } |
310 else | 316 else |
311 { | 317 { |
312 std::string s = v->AsString(); | 318 std::string s = v->AsString(); |
313 if (maxStringLength == 0 || | 319 if (maxStringLength == 0 || |
314 s.size() <= maxStringLength) | 320 s.size() <= maxStringLength) |
315 { | 321 { |
316 target[tagName] = s; | 322 value["Type"] = "String"; |
317 } | 323 value["Value"] = s; |
318 else | 324 } |
319 { | 325 else |
320 // An integer value of 0 in JSON indicates too long field | 326 { |
321 target[tagName] = 0; | 327 value["Type"] = "TooLong"; |
322 } | 328 value["Value"] = Json::nullValue; |
323 } | 329 } |
330 } | |
331 | |
332 target[formattedTag] = value; | |
324 } | 333 } |
325 else | 334 else |
326 { | 335 { |
327 target[tagName] = Json::Value(Json::arrayValue); | 336 Json::Value children(Json::arrayValue); |
328 | 337 |
329 // "All subclasses of DcmElement except for DcmSequenceOfItems | 338 // "All subclasses of DcmElement except for DcmSequenceOfItems |
330 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | 339 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset |
331 // etc. are not." The following cast is thus OK. | 340 // etc. are not." The following cast is thus OK. |
332 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); | 341 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); |
333 | 342 |
334 for (unsigned long i = 0; i < sequence.card(); i++) | 343 for (unsigned long i = 0; i < sequence.card(); i++) |
335 { | 344 { |
336 DcmItem* child = sequence.getItem(i); | 345 DcmItem* child = sequence.getItem(i); |
337 Json::Value& v = target[tagName].append(Json::objectValue); | 346 Json::Value& v = children.append(Json::objectValue); |
338 StoreItem(v, *child, maxStringLength); | 347 StoreItem(v, *child, maxStringLength); |
339 } | 348 } |
349 | |
350 target[formattedTag]["Name"] = tagName; | |
351 target[formattedTag]["Type"] = "Sequence"; | |
352 target[formattedTag]["Value"] = children; | |
340 } | 353 } |
341 } | 354 } |
342 | 355 |
343 | 356 |
344 void FromDcmtkBridge::ToJson(Json::Value& root, | 357 void FromDcmtkBridge::ToJson(Json::Value& root, |