Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
4104:d5c09b5f882f | 4105:c02a2d9efbc2 |
---|---|
35 #include "LuaFunctionCall.h" | 35 #include "LuaFunctionCall.h" |
36 | 36 |
37 #include "../OrthancException.h" | 37 #include "../OrthancException.h" |
38 #include "../Logging.h" | 38 #include "../Logging.h" |
39 | 39 |
40 #if ORTHANC_ENABLE_DCMTK == 1 | |
41 # include "../DicomParsing/FromDcmtkBridge.h" | |
42 #endif | |
43 | |
40 #include <cassert> | 44 #include <cassert> |
41 #include <stdio.h> | 45 #include <stdio.h> |
42 #include <boost/lexical_cast.hpp> | 46 #include <boost/lexical_cast.hpp> |
43 | 47 |
44 namespace Orthanc | 48 namespace Orthanc |
186 value[dicom.GetElement(i).GetTag().Format()] = s; | 190 value[dicom.GetElement(i).GetTag().Format()] = s; |
187 } | 191 } |
188 | 192 |
189 PushJson(value); | 193 PushJson(value); |
190 } | 194 } |
195 | |
196 | |
197 #if ORTHANC_ENABLE_DCMTK == 1 | |
198 void LuaFunctionCall::ExecuteToDicom(DicomMap& target) | |
199 { | |
200 Json::Value output; | |
201 ExecuteToJson(output, true /* keep strings */); | |
202 | |
203 target.Clear(); | |
204 | |
205 if (output.type() == Json::arrayValue && | |
206 output.size() == 0) | |
207 { | |
208 // This case happens for empty tables | |
209 return; | |
210 } | |
211 | |
212 if (output.type() != Json::objectValue) | |
213 { | |
214 throw OrthancException(ErrorCode_LuaBadOutput, | |
215 "Lua: The script must return a table"); | |
216 } | |
217 | |
218 Json::Value::Members members = output.getMemberNames(); | |
219 | |
220 for (size_t i = 0; i < members.size(); i++) | |
221 { | |
222 if (output[members[i]].type() != Json::stringValue) | |
223 { | |
224 throw OrthancException(ErrorCode_LuaBadOutput, | |
225 "Lua: The script must return a table " | |
226 "mapping names of DICOM tags to strings"); | |
227 } | |
228 | |
229 DicomTag tag(FromDcmtkBridge::ParseTag(members[i])); | |
230 target.SetValue(tag, output[members[i]].asString(), false); | |
231 } | |
232 } | |
233 #endif | |
191 } | 234 } |