Mercurial > hg > orthanc
diff OrthancFramework/Sources/Lua/LuaFunctionCall.cpp @ 4105:c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jul 2020 13:48:10 +0200 |
parents | d25f4c0fa160 |
children | bf7b9edf6b81 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Lua/LuaFunctionCall.cpp Mon Jul 06 11:45:39 2020 +0200 +++ b/OrthancFramework/Sources/Lua/LuaFunctionCall.cpp Mon Jul 06 13:48:10 2020 +0200 @@ -37,6 +37,10 @@ #include "../OrthancException.h" #include "../Logging.h" +#if ORTHANC_ENABLE_DCMTK == 1 +# include "../DicomParsing/FromDcmtkBridge.h" +#endif + #include <cassert> #include <stdio.h> #include <boost/lexical_cast.hpp> @@ -188,4 +192,43 @@ PushJson(value); } + + +#if ORTHANC_ENABLE_DCMTK == 1 + void LuaFunctionCall::ExecuteToDicom(DicomMap& target) + { + Json::Value output; + ExecuteToJson(output, true /* keep strings */); + + target.Clear(); + + if (output.type() == Json::arrayValue && + output.size() == 0) + { + // This case happens for empty tables + return; + } + + if (output.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_LuaBadOutput, + "Lua: The script must return a table"); + } + + Json::Value::Members members = output.getMemberNames(); + + for (size_t i = 0; i < members.size(); i++) + { + if (output[members[i]].type() != Json::stringValue) + { + throw OrthancException(ErrorCode_LuaBadOutput, + "Lua: The script must return a table " + "mapping names of DICOM tags to strings"); + } + + DicomTag tag(FromDcmtkBridge::ParseTag(members[i])); + target.SetValue(tag, output[members[i]].asString(), false); + } + } +#endif }