comparison OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp @ 5561:0b18690c1935

SDK: added OrthancPluginLogMessage to display plugin name + file and line from plugin
author Alain Mazy <am@orthanc.team>
date Tue, 23 Apr 2024 09:34:02 +0200
parents 6ce05f8b5b13
children e02cdf358905
comparison
equal deleted inserted replaced
5560:c80dbbae3f60 5561:0b18690c1935
21 21
22 22
23 #define MODALITY_WORKLISTS_NAME "worklists" 23 #define MODALITY_WORKLISTS_NAME "worklists"
24 24
25 #include "../../../../OrthancFramework/Sources/Compatibility.h" 25 #include "../../../../OrthancFramework/Sources/Compatibility.h"
26 #include "../../../../OrthancFramework/Sources/Logging.h"
26 #include "../Common/OrthancPluginCppWrapper.h" 27 #include "../Common/OrthancPluginCppWrapper.h"
27 28
28 #include <boost/filesystem.hpp> 29 #include <boost/filesystem.hpp>
29 #include <json/value.h> 30 #include <json/value.h>
30 #include <string.h> 31 #include <string.h>
52 OrthancPluginErrorCode code = OrthancPluginWorklistAddAnswer 53 OrthancPluginErrorCode code = OrthancPluginWorklistAddAnswer
53 (OrthancPlugins::GetGlobalContext(), answers, query, dicom.GetData(), dicom.GetSize()); 54 (OrthancPlugins::GetGlobalContext(), answers, query, dicom.GetData(), dicom.GetSize());
54 55
55 if (code != OrthancPluginErrorCode_Success) 56 if (code != OrthancPluginErrorCode_Success)
56 { 57 {
57 OrthancPlugins::LogError("Error while adding an answer to a worklist request"); 58 LOG(ERROR) << "Error while adding an answer to a worklist request";
58 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); 59 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
59 } 60 }
60 61
61 return true; 62 return true;
62 } 63 }
75 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode 76 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode
76 Json::Value json; 77 Json::Value json;
77 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, 78 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short,
78 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); 79 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
79 80
80 OrthancPlugins::LogInfo("Received worklist query from remote modality " + 81 LOG(INFO) << "Received worklist query from remote modality " << issuerAet << ":\n" + json.toStyledString();
81 std::string(issuerAet) + ":\n" + json.toStyledString());
82 82
83 if (!filterIssuerAet_) 83 if (!filterIssuerAet_)
84 { 84 {
85 return new OrthancPlugins::FindMatcher(query); 85 return new OrthancPlugins::FindMatcher(query);
86 } 86 }
183 // C-FIND result as incomplete. 183 // C-FIND result as incomplete.
184 OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), answers); 184 OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), answers);
185 return OrthancPluginErrorCode_Success; 185 return OrthancPluginErrorCode_Success;
186 } 186 }
187 187
188 OrthancPlugins::LogInfo("Worklist matched: " + it->path().string()); 188 LOG(INFO) << "Worklist matched: " << it->path().string();
189 matchedWorklistCount++; 189 matchedWorklistCount++;
190 } 190 }
191 } 191 }
192 } 192 }
193 } 193 }
194 194
195 std::ostringstream message; 195 LOG(INFO) << "Worklist C-Find: parsed " << parsedFilesCount
196 message << "Worklist C-Find: parsed " << parsedFilesCount 196 << " files, found " << matchedWorklistCount << " match(es)";
197 << " files, found " << matchedWorklistCount << " match(es)";
198 OrthancPlugins::LogInfo(message.str());
199 } 197 }
200 catch (fs::filesystem_error&) 198 catch (fs::filesystem_error&)
201 { 199 {
202 OrthancPlugins::LogError("Inexistent folder while scanning for worklists: " + source.string()); 200 LOG(ERROR) << "Inexistent folder while scanning for worklists: " << source.string();
203 return OrthancPluginErrorCode_DirectoryExpected; 201 return OrthancPluginErrorCode_DirectoryExpected;
204 } 202 }
205 203
206 return OrthancPluginErrorCode_Success; 204 return OrthancPluginErrorCode_Success;
207 } 205 }
225 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 223 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
226 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 224 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
227 return -1; 225 return -1;
228 } 226 }
229 227
230 OrthancPlugins::LogWarning("Sample worklist plugin is initializing"); 228 LOG(WARNING) << "Sample worklist plugin is initializing";
231 OrthancPluginSetDescription2(c, MODALITY_WORKLISTS_NAME, "Serve DICOM modality worklists from a folder with Orthanc."); 229 OrthancPluginSetDescription2(c, MODALITY_WORKLISTS_NAME, "Serve DICOM modality worklists from a folder with Orthanc.");
232 230
233 OrthancPlugins::OrthancConfiguration configuration; 231 OrthancPlugins::OrthancConfiguration configuration;
234 232
235 OrthancPlugins::OrthancConfiguration worklists; 233 OrthancPlugins::OrthancConfiguration worklists;
238 bool enabled = worklists.GetBooleanValue("Enable", false); 236 bool enabled = worklists.GetBooleanValue("Enable", false);
239 if (enabled) 237 if (enabled)
240 { 238 {
241 if (worklists.LookupStringValue(folder_, "Database")) 239 if (worklists.LookupStringValue(folder_, "Database"))
242 { 240 {
243 OrthancPlugins::LogWarning("The database of worklists will be read from folder: " + folder_); 241 LOG(WARNING) << "The database of worklists will be read from folder: " << folder_;
244 OrthancPluginRegisterWorklistCallback(OrthancPlugins::GetGlobalContext(), Callback); 242 OrthancPluginRegisterWorklistCallback(OrthancPlugins::GetGlobalContext(), Callback);
245 } 243 }
246 else 244 else
247 { 245 {
248 OrthancPlugins::LogError("The configuration option \"Worklists.Database\" must contain a path"); 246 LOG(ERROR) << "The configuration option \"Worklists.Database\" must contain a path";
249 return -1; 247 return -1;
250 } 248 }
251 249
252 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); 250 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false);
253 limitAnswers_ = worklists.GetUnsignedIntegerValue("LimitAnswers", 0); 251 limitAnswers_ = worklists.GetUnsignedIntegerValue("LimitAnswers", 0);
254 } 252 }
255 else 253 else
256 { 254 {
257 OrthancPlugins::LogWarning("Worklist server is disabled by the configuration file"); 255 LOG(WARNING) << "Worklist server is disabled by the configuration file";
258 } 256 }
259 257
260 return 0; 258 return 0;
261 } 259 }
262 260
263 261
264 ORTHANC_PLUGINS_API void OrthancPluginFinalize() 262 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
265 { 263 {
266 OrthancPlugins::LogWarning("Sample worklist plugin is finalizing"); 264 LOG(WARNING) << "Sample worklist plugin is finalizing";
267 } 265 }
268 266
269 267
270 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 268 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
271 { 269 {