Mercurial > hg > orthanc
changeset 3420:0a0e7eca95ae
fix encoding in DICOMweb
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jun 2019 12:11:58 +0200 |
parents | af271172cc36 |
children | decbede6e3ad |
files | Core/DicomParsing/DicomWebJsonVisitor.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h UnitTestsSources/FromDcmtkTests.cpp |
diffstat | 5 files changed, 54 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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<std::string> 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++) {
--- 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; }
--- 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 */
--- 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
--- 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());