comparison OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp @ 4655:9f7eef20bc7d

Fix issue #195 (No need for BulkDataURI when Data Element is empty)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 May 2021 16:54:46 +0200
parents d9473bd5ed43
children 4e81412ead0a
comparison
equal deleted inserted replaced
4654:ef84a6feae68 4655:9f7eef20bc7d
33 33
34 34
35 static const char* const KEY_ALPHABETIC = "Alphabetic"; 35 static const char* const KEY_ALPHABETIC = "Alphabetic";
36 static const char* const KEY_IDEOGRAPHIC = "Ideographic"; 36 static const char* const KEY_IDEOGRAPHIC = "Ideographic";
37 static const char* const KEY_PHONETIC = "Phonetic"; 37 static const char* const KEY_PHONETIC = "Phonetic";
38 static const char* const KEY_BULK_DATA = "BulkData";
38 static const char* const KEY_BULK_DATA_URI = "BulkDataURI"; 39 static const char* const KEY_BULK_DATA_URI = "BulkDataURI";
39 static const char* const KEY_INLINE_BINARY = "InlineBinary"; 40 static const char* const KEY_INLINE_BINARY = "InlineBinary";
40 static const char* const KEY_SQ = "SQ"; 41 static const char* const KEY_SQ = "SQ";
41 static const char* const KEY_TAG = "tag"; 42 static const char* const KEY_TAG = "tag";
42 static const char* const KEY_VALUE = "Value"; 43 static const char* const KEY_VALUE = "Value";
43 static const char* const KEY_VR = "vr"; 44 static const char* const KEY_VR = "vr";
45 static const char* const KEY_NUMBER = "number";
44 46
45 47
46 namespace Orthanc 48 namespace Orthanc
47 { 49 {
48 #if ORTHANC_ENABLE_PUGIXML == 1 50 #if ORTHANC_ENABLE_PUGIXML == 1
117 if (vr == "SQ") 119 if (vr == "SQ")
118 { 120 {
119 if (content[KEY_VALUE][j].type() == Json::objectValue) 121 if (content[KEY_VALUE][j].type() == Json::objectValue)
120 { 122 {
121 pugi::xml_node child = node.append_child("Item"); 123 pugi::xml_node child = node.append_child("Item");
122 child.append_attribute("number").set_value(number.c_str()); 124 child.append_attribute(KEY_NUMBER).set_value(number.c_str());
123 ExploreXmlDataset(child, content[KEY_VALUE][j]); 125 ExploreXmlDataset(child, content[KEY_VALUE][j]);
124 } 126 }
125 } 127 }
126 if (vr == "PN") 128 if (vr == "PN")
127 { 129 {
137 if (hasAlphabetic || 139 if (hasAlphabetic ||
138 hasIdeographic || 140 hasIdeographic ||
139 hasPhonetic) 141 hasPhonetic)
140 { 142 {
141 pugi::xml_node child = node.append_child("PersonName"); 143 pugi::xml_node child = node.append_child("PersonName");
142 child.append_attribute("number").set_value(number.c_str()); 144 child.append_attribute(KEY_NUMBER).set_value(number.c_str());
143 145
144 if (hasAlphabetic) 146 if (hasAlphabetic)
145 { 147 {
146 pugi::xml_node name = child.append_child(KEY_ALPHABETIC); 148 pugi::xml_node name = child.append_child(KEY_ALPHABETIC);
147 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_ALPHABETIC].asString()); 149 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_ALPHABETIC].asString());
160 } 162 }
161 } 163 }
162 } 164 }
163 else 165 else
164 { 166 {
165 pugi::xml_node child = node.append_child("Value"); 167 pugi::xml_node child = node.append_child(KEY_VALUE);
166 child.append_attribute("number").set_value(number.c_str()); 168 child.append_attribute(KEY_NUMBER).set_value(number.c_str());
167 169
168 switch (content[KEY_VALUE][j].type()) 170 switch (content[KEY_VALUE][j].type())
169 { 171 {
170 case Json::stringValue: 172 case Json::stringValue:
171 child.text() = content[KEY_VALUE][j].asCString(); 173 child.text() = content[KEY_VALUE][j].asCString();
190 } 192 }
191 } 193 }
192 else if (content.isMember(KEY_BULK_DATA_URI) && 194 else if (content.isMember(KEY_BULK_DATA_URI) &&
193 content[KEY_BULK_DATA_URI].type() == Json::stringValue) 195 content[KEY_BULK_DATA_URI].type() == Json::stringValue)
194 { 196 {
195 pugi::xml_node child = node.append_child("BulkData"); 197 pugi::xml_node child = node.append_child(KEY_BULK_DATA);
196 child.append_attribute("URI").set_value(content[KEY_BULK_DATA_URI].asCString()); 198 child.append_attribute("URI").set_value(content[KEY_BULK_DATA_URI].asCString());
197 } 199 }
198 else if (content.isMember(KEY_INLINE_BINARY) && 200 else if (content.isMember(KEY_INLINE_BINARY) &&
199 content[KEY_INLINE_BINARY].type() == Json::stringValue) 201 content[KEY_INLINE_BINARY].type() == Json::stringValue)
200 { 202 {
201 pugi::xml_node child = node.append_child("InlineBinary"); 203 pugi::xml_node child = node.append_child(KEY_INLINE_BINARY);
202 child.text() = content[KEY_INLINE_BINARY].asCString(); 204 child.text() = content[KEY_INLINE_BINARY].asCString();
203 } 205 }
204 } 206 }
205 } 207 }
206 #endif 208 #endif
420 if (mode != BinaryMode_Ignore) 422 if (mode != BinaryMode_Ignore)
421 { 423 {
422 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); 424 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
423 node[KEY_VR] = EnumerationToString(vr); 425 node[KEY_VR] = EnumerationToString(vr);
424 426
425 switch (mode) 427 /**
426 { 428 * The test on "size > 0" is new in Orthanc 1.9.3, and fixes
427 case BinaryMode_BulkDataUri: 429 * issue #195 (No need for BulkDataURI when Data Element is
428 node[KEY_BULK_DATA_URI] = bulkDataUri; 430 * empty): https://bugs.orthanc-server.com/show_bug.cgi?id=195
429 break; 431 **/
430 432 if (size > 0)
431 case BinaryMode_InlineBinary: 433 {
434 switch (mode)
432 { 435 {
433 std::string tmp(static_cast<const char*>(data), size); 436 case BinaryMode_BulkDataUri:
437 node[KEY_BULK_DATA_URI] = bulkDataUri;
438 break;
439
440 case BinaryMode_InlineBinary:
441 {
442 std::string tmp(static_cast<const char*>(data), size);
434 443
435 std::string base64; 444 std::string base64;
436 Toolbox::EncodeBase64(base64, tmp); 445 Toolbox::EncodeBase64(base64, tmp);
437 446
438 node[KEY_INLINE_BINARY] = base64; 447 node[KEY_INLINE_BINARY] = base64;
439 break; 448 break;
449 }
450
451 default:
452 throw OrthancException(ErrorCode_ParameterOutOfRange);
440 } 453 }
441
442 default:
443 throw OrthancException(ErrorCode_ParameterOutOfRange);
444 } 454 }
445 } 455 }
446 } 456 }
447 } 457 }
448 458