# HG changeset patch # User Sebastien Jodogne # Date 1560334318 -7200 # Node ID 0a0e7eca95ae478b609ff92b7fab94b2db66d864 # Parent af271172cc36f334c05377d454849ec99d56c998 fix encoding in DICOMweb diff -r af271172cc36 -r 0a0e7eca95ae Core/DicomParsing/DicomWebJsonVisitor.cpp --- a/Core/DicomParsing/DicomWebJsonVisitor.cpp Wed Jun 12 09:57:02 2019 +0200 +++ b/Core/DicomParsing/DicomWebJsonVisitor.cpp Wed Jun 12 12:11:58 2019 +0200 @@ -521,15 +521,21 @@ Json::Value& node = CreateNode(parentTags, parentIndexes, tag); node[KEY_VR] = EnumerationToString(vr); +#if 0 + /** + * TODO - The JSON file has an UTF-8 encoding, thus DCMTK + * replaces the specific character set with "ISO_IR 192" + * (UNICODE UTF-8). On Google Cloud Healthcare, however, the + * source encoding is reported, which seems more logical. We + * thus choose the Google convention. Enabling this block will + * mimic the DCMTK behavior. + **/ if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET) { - // TODO - The JSON file has an UTF-8 encoding, thus DCMTK - // replaces the specific character set with "ISO_IR 192" - // (UNICODE UTF-8). It is unclear whether the source - // character set should be kept: We thus mimic DCMTK. node[KEY_VALUE].append("ISO_IR 192"); } else +#endif { std::string truncated; @@ -542,12 +548,21 @@ { truncated = value; } - + if (!truncated.empty()) { std::vector tokens; Toolbox::TokenizeString(tokens, truncated, '\\'); + if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET && + tokens.size() > 1 && + tokens[0].empty()) + { + std::string s = tokens[1]; + tokens.clear(); + tokens.push_back(s); + } + node[KEY_VALUE] = Json::arrayValue; for (size_t i = 0; i < tokens.size(); i++) { diff -r af271172cc36 -r 0a0e7eca95ae Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Jun 12 09:57:02 2019 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Jun 12 12:11:58 2019 +0200 @@ -3672,7 +3672,7 @@ { visitor.FormatXml(s); } - + *p.target = CopyString(s); return true; } diff -r af271172cc36 -r 0a0e7eca95ae Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Jun 12 09:57:02 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Jun 12 12:11:58 2019 +0200 @@ -2314,17 +2314,27 @@ { private: std::string body_; + bool done_; public: MemoryRequestBody(const std::string& body) : - body_(body) + body_(body), + done_(false) { } virtual bool ReadNextChunk(std::string& chunk) { - chunk.swap(body_); - return true; + if (done_) + { + return false; + } + else + { + chunk.swap(body_); + done_ = true; + return true; + } } }; @@ -2603,6 +2613,21 @@ #endif } + + void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, + Json::Value& answerBody /* out */) + { + std::string body; + Execute(answerHeaders, body); + + Json::Reader reader; + if (!reader.parse(body, answerBody)) + { + LogError("Cannot convert HTTP answer body to JSON"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ diff -r af271172cc36 -r 0a0e7eca95ae Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Jun 12 09:57:02 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Jun 12 12:11:58 2019 +0200 @@ -915,6 +915,9 @@ void Execute(HttpHeaders& answerHeaders /* out */, std::string& answerBody /* out */); + + void Execute(HttpHeaders& answerHeaders /* out */, + Json::Value& answerBody /* out */); }; #endif diff -r af271172cc36 -r 0a0e7eca95ae UnitTestsSources/FromDcmtkTests.cpp --- a/UnitTestsSources/FromDcmtkTests.cpp Wed Jun 12 09:57:02 2019 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Wed Jun 12 12:11:58 2019 +0200 @@ -1582,7 +1582,7 @@ doc.load_buffer(xml.c_str(), xml.size()); pugi::xpath_node node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]/Value"); - ASSERT_STREQ("ISO_IR 192", node.node().text().as_string()); + ASSERT_STREQ("ISO 2022 IR 149", node.node().text().as_string()); node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]"); ASSERT_STREQ("CS", node.node().attribute("vr").value()); @@ -1662,7 +1662,7 @@ doc.load_buffer(xml.c_str(), xml.size()); pugi::xpath_node node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]/Value"); - ASSERT_STREQ("ISO_IR 192", node.node().text().as_string()); + ASSERT_STREQ("ISO 2022 IR 87", node.node().text().as_string()); node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]"); ASSERT_STREQ("CS", node.node().attribute("vr").value());