Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
4054:9c37896a4457 | 4055:9214e3a7b0a2 |
---|---|
2213 uuid.substr(24, 12)); | 2213 uuid.substr(24, 12)); |
2214 assert(hex.size() == 32); | 2214 assert(hex.size() == 32); |
2215 | 2215 |
2216 return "2.25." + LargeHexadecimalToDecimal(hex); | 2216 return "2.25." + LargeHexadecimalToDecimal(hex); |
2217 } | 2217 } |
2218 | |
2219 | |
2220 void Toolbox::SimplifyDicomAsJson(Json::Value& target, | |
2221 const Json::Value& source, | |
2222 DicomToJsonFormat format) | |
2223 { | |
2224 if (!source.isObject()) | |
2225 { | |
2226 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
2227 } | |
2228 | |
2229 target = Json::objectValue; | |
2230 Json::Value::Members members = source.getMemberNames(); | |
2231 | |
2232 for (size_t i = 0; i < members.size(); i++) | |
2233 { | |
2234 const Json::Value& v = source[members[i]]; | |
2235 const std::string& type = v["Type"].asString(); | |
2236 | |
2237 std::string name; | |
2238 switch (format) | |
2239 { | |
2240 case DicomToJsonFormat_Human: | |
2241 name = v["Name"].asString(); | |
2242 break; | |
2243 | |
2244 case DicomToJsonFormat_Short: | |
2245 name = members[i]; | |
2246 break; | |
2247 | |
2248 default: | |
2249 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
2250 } | |
2251 | |
2252 if (type == "String") | |
2253 { | |
2254 target[name] = v["Value"].asString(); | |
2255 } | |
2256 else if (type == "TooLong" || | |
2257 type == "Null") | |
2258 { | |
2259 target[name] = Json::nullValue; | |
2260 } | |
2261 else if (type == "Sequence") | |
2262 { | |
2263 const Json::Value& array = v["Value"]; | |
2264 assert(array.isArray()); | |
2265 | |
2266 Json::Value children = Json::arrayValue; | |
2267 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++) | |
2268 { | |
2269 Json::Value c; | |
2270 SimplifyDicomAsJson(c, array[i], format); | |
2271 children.append(c); | |
2272 } | |
2273 | |
2274 target[name] = children; | |
2275 } | |
2276 else | |
2277 { | |
2278 assert(0); | |
2279 } | |
2280 } | |
2281 } | |
2218 } | 2282 } |
2219 | 2283 |
2220 | 2284 |
2221 | 2285 |
2222 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) | 2286 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) |