comparison OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp @ 4145:c5cdb6dc6865

New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Aug 2020 14:48:11 +0200
parents 05b8fd21089c
children 3c400d3c11ef
comparison
equal deleted inserted replaced
4144:be88fe7e4670 4145:c5cdb6dc6865
29 #include <iostream> 29 #include <iostream>
30 #include <algorithm> 30 #include <algorithm>
31 31
32 static std::string folder_; 32 static std::string folder_;
33 static bool filterIssuerAet_ = false; 33 static bool filterIssuerAet_ = false;
34 static unsigned int limitAnswers_ = 0;
34 35
35 /** 36 /**
36 * This is the main function for matching a DICOM worklist against a query. 37 * This is the main function for matching a DICOM worklist against a query.
37 **/ 38 **/
38 static bool MatchWorklist(OrthancPluginWorklistAnswers* answers, 39 static bool MatchWorklist(OrthancPluginWorklistAnswers* answers,
148 // Loop over the regular files in the database folder 149 // Loop over the regular files in the database folder
149 namespace fs = boost::filesystem; 150 namespace fs = boost::filesystem;
150 151
151 fs::path source(folder_); 152 fs::path source(folder_);
152 fs::directory_iterator end; 153 fs::directory_iterator end;
153 int parsedFilesCount = 0; 154 unsigned int parsedFilesCount = 0;
154 int matchedWorklistCount = 0; 155 unsigned int matchedWorklistCount = 0;
155 156
156 try 157 try
157 { 158 {
158 for (fs::directory_iterator it(source); it != end; ++it) 159 for (fs::directory_iterator it(source); it != end; ++it)
159 { 160 {
169 { 170 {
170 parsedFilesCount++; 171 parsedFilesCount++;
171 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query 172 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query
172 if (MatchWorklist(answers, query, *matcher, it->path().string())) 173 if (MatchWorklist(answers, query, *matcher, it->path().string()))
173 { 174 {
175 if (limitAnswers_ != 0 &&
176 matchedWorklistCount >= limitAnswers_)
177 {
178 // Too many answers are to be returned wrt. the
179 // "LimitAnswers" configuration parameter. Mark the
180 // C-FIND result as incomplete.
181 OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), answers);
182 return OrthancPluginErrorCode_Success;
183 }
184
174 OrthancPlugins::LogInfo("Worklist matched: " + it->path().string()); 185 OrthancPlugins::LogInfo("Worklist matched: " + it->path().string());
175 matchedWorklistCount++; 186 matchedWorklistCount++;
176 } 187 }
177 } 188 }
178 } 189 }
179 } 190 }
180 191
181 std::ostringstream message; 192 std::ostringstream message;
182 message << "Worklist C-Find: parsed " << parsedFilesCount << " files, found " << matchedWorklistCount << " match(es)"; 193 message << "Worklist C-Find: parsed " << parsedFilesCount
194 << " files, found " << matchedWorklistCount << " match(es)";
183 OrthancPlugins::LogInfo(message.str()); 195 OrthancPlugins::LogInfo(message.str());
184
185 } 196 }
186 catch (fs::filesystem_error&) 197 catch (fs::filesystem_error&)
187 { 198 {
188 OrthancPlugins::LogError("Inexistent folder while scanning for worklists: " + source.string()); 199 OrthancPlugins::LogError("Inexistent folder while scanning for worklists: " + source.string());
189 return OrthancPluginErrorCode_DirectoryExpected; 200 return OrthancPluginErrorCode_DirectoryExpected;
190 } 201 }
191
192 // Uncomment the following line if too many answers are to be returned
193 // OrthancPluginMarkWorklistAnswersIncomplete(OrthancPlugins::GetGlobalContext(), answers);
194 202
195 return OrthancPluginErrorCode_Success; 203 return OrthancPluginErrorCode_Success;
196 } 204 }
197 catch (OrthancPlugins::PluginException& e) 205 catch (OrthancPlugins::PluginException& e)
198 { 206 {
237 OrthancPlugins::LogError("The configuration option \"Worklists.Database\" must contain a path"); 245 OrthancPlugins::LogError("The configuration option \"Worklists.Database\" must contain a path");
238 return -1; 246 return -1;
239 } 247 }
240 248
241 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); 249 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false);
250 limitAnswers_ = worklists.GetUnsignedIntegerValue("LimitAnswers", 0);
242 } 251 }
243 else 252 else
244 { 253 {
245 OrthancPlugins::LogWarning("Worklist server is disabled by the configuration file"); 254 OrthancPlugins::LogWarning("Worklist server is disabled by the configuration file");
246 } 255 }