Mercurial > hg > orthanc
diff Core/DicomFormat/DicomMap.cpp @ 3005:8265a6b56100
DicomMap::FromDicomAsJson
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Dec 2018 15:42:33 +0100 |
parents | da12ba232119 |
children | 0e1755e5efd0 |
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp Wed Dec 12 09:08:34 2018 +0100 +++ b/Core/DicomFormat/DicomMap.cpp Wed Dec 12 15:42:33 2018 +0100 @@ -982,6 +982,45 @@ } + void DicomMap::FromDicomAsJson(const Json::Value& dicomAsJson) + { + Clear(); + + Json::Value::Members tags = dicomAsJson.getMemberNames(); + for (Json::Value::Members::const_iterator + it = tags.begin(); it != tags.end(); ++it) + { + DicomTag tag(0, 0); + if (!DicomTag::ParseHexadecimal(tag, it->c_str())) + { + throw OrthancException(ErrorCode_CorruptedFile); + } + + const Json::Value& value = dicomAsJson[*it]; + + if (value.type() != Json::objectValue || + !value.isMember("Type") || + !value.isMember("Value") || + value["Type"].type() != Json::stringValue) + { + throw OrthancException(ErrorCode_CorruptedFile); + } + + if (value["Type"] == "String") + { + if (value["Value"].type() != Json::stringValue) + { + throw OrthancException(ErrorCode_CorruptedFile); + } + else + { + SetValue(tag, value["Value"].asString(), false /* not binary */); + } + } + } + } + + void DicomMap::Serialize(Json::Value& target) const { target = Json::objectValue;