diff OrthancServer/OrthancFindRequestHandler.cpp @ 1331:77e129ba64e4

Prevent freeze on C-FIND if no DICOM tag is to be returned
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Mar 2015 10:47:32 +0100
parents 6e7e5ed91c2d
children f2033e228864
line wrap: on
line diff
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Wed Mar 11 16:57:01 2015 +0100
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Thu Mar 12 10:47:32 2015 +0100
@@ -197,7 +197,8 @@
 
   static void AddAnswer(DicomFindAnswers& answers,
                         const Json::Value& resource,
-                        const DicomArray& query)
+                        const DicomArray& query,
+                        bool isFirst)
   {
     DicomMap result;
 
@@ -220,7 +221,17 @@
       }
     }
 
-    answers.Add(result);
+    if (result.GetSize() == 0)
+    {
+      if (isFirst)
+      {
+        LOG(WARNING) << "The C-FIND request does not return any DICOM tag";
+      }
+    }
+    else
+    {
+      answers.Add(result);
+    }
   }
 
 
@@ -563,7 +574,6 @@
     std::list<std::string>  resources;
     candidates.Flatten(resources);
 
-    LOG(INFO) << "Number of candidate resources after exact filtering: " << resources.size();
 
     /**
      * Apply filtering on modalities for studies, if asked (this is an
@@ -581,11 +591,14 @@
       }
     }
 
-
     /**
      * Loop over all the resources for this query level.
      **/
 
+    LOG(INFO) << "Number of candidate resources after exact filtering on the identifiers only: " << resources.size();
+
+    bool isFirst = true;
+    
     for (std::list<std::string>::const_iterator 
            resource = resources.begin(); resource != resources.end(); ++resource)
     {
@@ -596,7 +609,7 @@
         {
           Json::Value info;
           context_.ReadJson(info, instance);
-        
+
           if (Matches(info, query))
           {
             if (HasReachedLimit(answers, level))
@@ -605,7 +618,8 @@
               return false;
             }
 
-            AddAnswer(answers, info, query);
+            AddAnswer(answers, info, query, isFirst);
+            isFirst = false;
           }
         }
       }
@@ -615,6 +629,8 @@
       }
     }
 
+    LOG(INFO) << "Number of candidate resources after filtering on all tags: " << answers.GetSize();
+
     return true;  // All the matching resources have been returned
   }
 }