diff 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
line wrap: on
line diff
--- a/OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp	Fri Aug 14 08:26:07 2020 +0200
+++ b/OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp	Mon Aug 17 14:48:11 2020 +0200
@@ -31,6 +31,7 @@
 
 static std::string folder_;
 static bool filterIssuerAet_ = false;
+static unsigned int limitAnswers_ = 0;
 
 /**
  * This is the main function for matching a DICOM worklist against a query.
@@ -150,8 +151,8 @@
 
     fs::path source(folder_);
     fs::directory_iterator end;
-    int parsedFilesCount = 0;
-    int matchedWorklistCount = 0;
+    unsigned int parsedFilesCount = 0;
+    unsigned int matchedWorklistCount = 0;
 
     try
     {
@@ -171,6 +172,16 @@
             // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query
             if (MatchWorklist(answers, query, *matcher, it->path().string()))
             {
+              if (limitAnswers_ != 0 &&
+                  matchedWorklistCount >= limitAnswers_)
+              {
+                // Too many answers are to be returned wrt. the
+                // "LimitAnswers" configuration parameter. Mark the
+                // C-FIND result as incomplete.
+                OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), answers);
+                return OrthancPluginErrorCode_Success;
+              }
+              
               OrthancPlugins::LogInfo("Worklist matched: " + it->path().string());
               matchedWorklistCount++;
             }
@@ -179,9 +190,9 @@
       }
 
       std::ostringstream message;
-      message << "Worklist C-Find: parsed " << parsedFilesCount << " files, found " << matchedWorklistCount << " match(es)";
+      message << "Worklist C-Find: parsed " << parsedFilesCount
+              << " files, found " << matchedWorklistCount << " match(es)";
       OrthancPlugins::LogInfo(message.str());
-
     }
     catch (fs::filesystem_error&)
     {
@@ -189,9 +200,6 @@
       return OrthancPluginErrorCode_DirectoryExpected;
     }
 
-    // Uncomment the following line if too many answers are to be returned
-    // OrthancPluginMarkWorklistAnswersIncomplete(OrthancPlugins::GetGlobalContext(), answers);
-
     return OrthancPluginErrorCode_Success;
   }
   catch (OrthancPlugins::PluginException& e)
@@ -239,6 +247,7 @@
       }
 
       filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false);
+      limitAnswers_ = worklists.GetUnsignedIntegerValue("LimitAnswers", 0);
     }
     else
     {