Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Lua/LuaFunctionCall.cpp @ 5113:a3c3f13368ea
clarification that "image/jpg" is not a correct MIME type
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Nov 2022 14:28:50 +0100 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
rev | line source |
---|---|
386 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
386 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
11 * the License, or (at your option) any later version. |
386 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
16 * Lesser General Public License for more details. |
386 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
386 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
386 | 25 #include "LuaFunctionCall.h" |
26 | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
27 #include "../OrthancException.h" |
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
28 #include "../Logging.h" |
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
29 |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
30 #if ORTHANC_ENABLE_DCMTK == 1 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
31 # include "../DicomParsing/FromDcmtkBridge.h" |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
32 #endif |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
33 |
996
cf52f3bcb2b3
clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include <cassert> |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
35 #include <stdio.h> |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
36 #include <boost/lexical_cast.hpp> |
386 | 37 |
38 namespace Orthanc | |
39 { | |
40 void LuaFunctionCall::CheckAlreadyExecuted() | |
41 { | |
42 if (isExecuted_) | |
43 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
44 throw OrthancException(ErrorCode_LuaAlreadyExecuted); |
386 | 45 } |
46 } | |
47 | |
48 LuaFunctionCall::LuaFunctionCall(LuaContext& context, | |
49 const char* functionName) : | |
50 context_(context), | |
51 isExecuted_(false) | |
52 { | |
53 // Clear the stack to fulfill the invariant | |
54 lua_settop(context_.lua_, 0); | |
55 lua_getglobal(context_.lua_, functionName); | |
56 } | |
57 | |
58 void LuaFunctionCall::PushString(const std::string& value) | |
59 { | |
60 CheckAlreadyExecuted(); | |
1465
905842836ad4
sample Lua script to write DICOM series to disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1448
diff
changeset
|
61 lua_pushlstring(context_.lua_, value.c_str(), value.size()); |
386 | 62 } |
63 | |
64 void LuaFunctionCall::PushBoolean(bool value) | |
65 { | |
66 CheckAlreadyExecuted(); | |
67 lua_pushboolean(context_.lua_, value); | |
68 } | |
69 | |
70 void LuaFunctionCall::PushInteger(int value) | |
71 { | |
72 CheckAlreadyExecuted(); | |
73 lua_pushinteger(context_.lua_, value); | |
74 } | |
75 | |
76 void LuaFunctionCall::PushDouble(double value) | |
77 { | |
78 CheckAlreadyExecuted(); | |
79 lua_pushnumber(context_.lua_, value); | |
80 } | |
81 | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
82 void LuaFunctionCall::PushJson(const Json::Value& value) |
386 | 83 { |
84 CheckAlreadyExecuted(); | |
1051 | 85 context_.PushJson(value); |
386 | 86 } |
87 | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
88 void LuaFunctionCall::ExecuteInternal(int numOutputs) |
386 | 89 { |
90 CheckAlreadyExecuted(); | |
91 | |
92 assert(lua_gettop(context_.lua_) >= 1); | |
93 int nargs = lua_gettop(context_.lua_) - 1; | |
94 int error = lua_pcall(context_.lua_, nargs, numOutputs, 0); | |
95 | |
96 if (error) | |
97 { | |
98 assert(lua_gettop(context_.lua_) >= 1); | |
99 | |
100 std::string description(lua_tostring(context_.lua_, -1)); | |
101 lua_pop(context_.lua_, 1); /* pop error message from the stack */ | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
102 |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
103 throw OrthancException(ErrorCode_CannotExecuteLua, description); |
386 | 104 } |
105 | |
106 if (lua_gettop(context_.lua_) < numOutputs) | |
107 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
108 throw OrthancException(ErrorCode_LuaBadOutput); |
386 | 109 } |
110 | |
111 isExecuted_ = true; | |
112 } | |
113 | |
114 bool LuaFunctionCall::ExecutePredicate() | |
115 { | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
116 ExecuteInternal(1); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
117 |
386 | 118 if (!lua_isboolean(context_.lua_, 1)) |
119 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
120 throw OrthancException(ErrorCode_NotLuaPredicate); |
386 | 121 } |
122 | |
123 return lua_toboolean(context_.lua_, 1) != 0; | |
124 } | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
125 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
126 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1583
diff
changeset
|
127 void LuaFunctionCall::ExecuteToJson(Json::Value& result, |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1583
diff
changeset
|
128 bool keepStrings) |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
129 { |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
130 ExecuteInternal(1); |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
131 context_.GetJson(result, context_.lua_, lua_gettop(context_.lua_), keepStrings); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
132 } |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
133 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
134 |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
135 void LuaFunctionCall::ExecuteToString(std::string& result) |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
136 { |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
137 ExecuteInternal(1); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
138 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
139 int top = lua_gettop(context_.lua_); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
140 if (lua_isstring(context_.lua_, top)) |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
141 { |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
142 result = lua_tostring(context_.lua_, top); |
1010 | 143 } |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
144 else |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
145 { |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
146 throw OrthancException(ErrorCode_LuaReturnsNoString); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
147 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
148 } |
1959
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
149 |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
150 void LuaFunctionCall::ExecuteToInt(int& result) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
151 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
152 ExecuteInternal(1); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
153 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
154 int top = lua_gettop(context_.lua_); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
155 if (lua_isnumber(context_.lua_, top)) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
156 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
157 result = static_cast<int>(lua_tointeger(context_.lua_, top)); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
158 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
159 else |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
160 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
161 throw OrthancException(ErrorCode_LuaReturnsNoString); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
162 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
163 } |
1959
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
164 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
165 void LuaFunctionCall::PushStringMap(const std::map<std::string, std::string>& value) |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
166 { |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
167 Json::Value json = Json::objectValue; |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
168 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
169 for (std::map<std::string, std::string>::const_iterator |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
170 it = value.begin(); it != value.end(); ++it) |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
171 { |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
172 json[it->first] = it->second; |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
173 } |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
174 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
175 PushJson(json); |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
176 } |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
177 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
178 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
179 void LuaFunctionCall::PushDicom(const DicomMap& dicom) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
180 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
181 DicomArray a(dicom); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
182 PushDicom(a); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
183 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
184 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
185 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
186 void LuaFunctionCall::PushDicom(const DicomArray& dicom) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
187 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
188 Json::Value value = Json::objectValue; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
189 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
190 for (size_t i = 0; i < dicom.GetSize(); i++) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
191 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
192 const DicomValue& v = dicom.GetElement(i).GetValue(); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
193 std::string s = (v.IsNull() || v.IsBinary()) ? "" : v.GetContent(); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
194 value[dicom.GetElement(i).GetTag().Format()] = s; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
195 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
196 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
197 PushJson(value); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
198 } |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
199 |
4300 | 200 void LuaFunctionCall::Execute() |
201 { | |
202 ExecuteInternal(0); | |
203 } | |
204 | |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
205 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
206 #if ORTHANC_ENABLE_DCMTK == 1 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
207 void LuaFunctionCall::ExecuteToDicom(DicomMap& target) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
208 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
209 Json::Value output; |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
210 ExecuteToJson(output, true /* keep strings */); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
211 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
212 target.Clear(); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
213 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
214 if (output.type() == Json::arrayValue && |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
215 output.size() == 0) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
216 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
217 // This case happens for empty tables |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
218 return; |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
219 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
220 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
221 if (output.type() != Json::objectValue) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
222 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
223 throw OrthancException(ErrorCode_LuaBadOutput, |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
224 "Lua: The script must return a table"); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
225 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
226 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
227 Json::Value::Members members = output.getMemberNames(); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
228 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
229 for (size_t i = 0; i < members.size(); i++) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
230 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
231 if (output[members[i]].type() != Json::stringValue) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
232 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
233 throw OrthancException(ErrorCode_LuaBadOutput, |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
234 "Lua: The script must return a table " |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
235 "mapping names of DICOM tags to strings"); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
236 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
237 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
238 DicomTag tag(FromDcmtkBridge::ParseTag(members[i])); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
239 target.SetValue(tag, output[members[i]].asString(), false); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
240 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
241 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
242 #endif |
386 | 243 } |