Mercurial > hg > orthanc
diff OrthancFramework/Sources/Toolbox.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 | d25f4c0fa160 |
children | bf7b9edf6b81 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Toolbox.cpp Thu Jun 11 12:24:38 2020 +0200 +++ b/OrthancFramework/Sources/Toolbox.cpp Thu Jun 11 12:52:09 2020 +0200 @@ -2215,6 +2215,70 @@ return "2.25." + LargeHexadecimalToDecimal(hex); } + + + void Toolbox::SimplifyDicomAsJson(Json::Value& target, + const Json::Value& source, + DicomToJsonFormat format) + { + if (!source.isObject()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } + + target = Json::objectValue; + Json::Value::Members members = source.getMemberNames(); + + for (size_t i = 0; i < members.size(); i++) + { + const Json::Value& v = source[members[i]]; + const std::string& type = v["Type"].asString(); + + std::string name; + switch (format) + { + case DicomToJsonFormat_Human: + name = v["Name"].asString(); + break; + + case DicomToJsonFormat_Short: + name = members[i]; + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + if (type == "String") + { + target[name] = v["Value"].asString(); + } + else if (type == "TooLong" || + type == "Null") + { + target[name] = Json::nullValue; + } + else if (type == "Sequence") + { + const Json::Value& array = v["Value"]; + assert(array.isArray()); + + Json::Value children = Json::arrayValue; + for (Json::Value::ArrayIndex i = 0; i < array.size(); i++) + { + Json::Value c; + SimplifyDicomAsJson(c, array[i], format); + children.append(c); + } + + target[name] = children; + } + else + { + assert(0); + } + } + } }