changeset 1758:318c2e83c2bd db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2015 12:53:45 +0100
parents 98abb8d7f905
children e268412adcf1
files OrthancServer/DatabaseWrapperBase.cpp OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Search/LookupIdentifierQuery.cpp OrthancServer/Search/LookupIdentifierQuery.h OrthancServer/Search/LookupResource.cpp OrthancServer/Search/LookupResource.h OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 9 files changed, 79 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapperBase.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/DatabaseWrapperBase.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -743,7 +743,7 @@
         break;
 
       case IdentifierConstraintType_Wildcard:
-        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value LIKE ?"));
+        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value GLOB ?"));
         break;
 
       default:
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -307,7 +307,16 @@
       }
 
 #if USE_LOOKUP_RESOURCE == 1
-      finder.AddDicomConstraint(tag, value, caseSensitivePN);
+
+      ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
+
+      bool sensitive = true;
+      if (vr == ValueRepresentation_PatientName)
+      {
+      sensitive = caseSensitivePN;
+    }
+
+      finder.AddDicomConstraint(tag, value, sensitive);
 #else
 
       if (tag == DICOM_TAG_MODALITIES_IN_STUDY)
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -944,7 +944,8 @@
         request.isMember("Query") &&
         request["Level"].type() == Json::stringValue &&
         request["Query"].type() == Json::objectValue &&
-        (!request.isMember("CaseSensitive") || request["CaseSensitive"].type() == Json::booleanValue))
+        (!request.isMember("CaseSensitive") || request["CaseSensitive"].type() == Json::booleanValue) &&
+        (!request.isMember("Limit") || request["Limit"].type() == Json::intValue))
     {
       bool expand = false;
       if (request.isMember("Expand"))
@@ -958,10 +959,19 @@
         caseSensitive = request["CaseSensitive"].asBool();
       }
 
+      size_t limit = 0;
+      if (request.isMember("Limit"))
+      {
+        limit = request["CaseSensitive"].asInt();
+        if (limit < 0)
+        {
+          throw OrthancException(ErrorCode_ParameterOutOfRange);
+        }
+      }
+
       std::string level = request["Level"].asString();
 
-      DicomFindQuery query;
-      query.SetLevel(StringToResourceType(level.c_str()));
+      LookupResource query(StringToResourceType(level.c_str()));
 
       Json::Value::Members members = request["Query"].getMemberNames();
       for (size_t i = 0; i < members.size(); i++)
@@ -971,14 +981,13 @@
           throw OrthancException(ErrorCode_BadRequest);
         }
 
-        query.SetConstraint(FromDcmtkBridge::ParseTag(members[i]), 
-                            request["Query"][members[i]].asString(),
-                            caseSensitive);
+        query.AddDicomConstraint(FromDcmtkBridge::ParseTag(members[i]), 
+                                 request["Query"][members[i]].asString(),
+                                 caseSensitive);
       }
       
       std::list<std::string> resources;
-      ResourceFinder finder(context);
-      finder.Apply(resources, query);
+      context.Apply(resources, query, limit);
       AnswerListOfResources(call.GetOutput(), context.GetIndex(), resources, query.GetLevel(), expand);
     }
     else
--- a/OrthancServer/Search/LookupIdentifierQuery.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -35,6 +35,7 @@
 
 #include "../../Core/OrthancException.h"
 #include "SetOfResources.h"
+#include "../FromDcmtkBridge.h"
 
 #include <cassert>
 
@@ -230,4 +231,35 @@
     }
   }
 
+
+  void LookupIdentifierQuery::Print(std::ostream& s) const
+  {
+    s << "Constraint: " << std::endl;
+    for (Constraints::const_iterator
+           it = constraints_.begin(); it != constraints_.end(); ++it)
+    {
+      if (it == constraints_.begin())
+        s << "   ";
+      else
+        s << "OR ";
+
+      for (size_t j = 0; j < (*it)->GetSize(); j++)
+      {
+        const Constraint& c = (*it)->GetConstraint(j);
+        s << FromDcmtkBridge::GetName(c.GetTag());
+
+        switch (c.GetType())
+        {
+          case IdentifierConstraintType_Equal: s << " == "; break;
+          case IdentifierConstraintType_SmallerOrEqual: s << " <= "; break;
+          case IdentifierConstraintType_GreaterOrEqual: s << " >= "; break;
+          case IdentifierConstraintType_Wildcard: s << " ~= "; break;
+          default:
+            s << " ? ";
+        }
+
+        s << c.GetValue() << std::endl;
+      }
+    }
+  }
 }
--- a/OrthancServer/Search/LookupIdentifierQuery.h	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.h	Wed Oct 28 12:53:45 2015 +0100
@@ -177,5 +177,7 @@
                                  int64_t resource,
                                  ResourceType level,
                                  const DicomMap& map);
+
+    void Print(std::ostream& s) const;
   };
 }
--- a/OrthancServer/Search/LookupResource.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/Search/LookupResource.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -230,6 +230,13 @@
 
     query.Apply(candidates, database);
 
+    /*{
+      query.Print(std::cout);
+      std::list<int64_t>  source;
+      candidates.Flatten(source);
+      printf("=> %d\n", source.size());
+      }*/
+
     // Secondly, filter using the main DICOM tags
     if (!identifiersConstraints_.empty() ||
         !mainTagsConstraints_.empty())
@@ -417,19 +424,12 @@
 
   void LookupResource::AddDicomConstraint(const DicomTag& tag,
                                           const std::string& dicomQuery,
-                                          bool caseSensitivePN)
+                                          bool caseSensitive)
   {
     ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
 
-    bool sensitive = true;
-    if (vr == ValueRepresentation_PatientName)
-    {
-      sensitive = caseSensitivePN;
-    }
-
     // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
     // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html  
-
     if (tag == DICOM_TAG_MODALITIES_IN_STUDY)
     {
       SetModalitiesInStudy(dicomQuery);
@@ -450,11 +450,11 @@
       size_t separator = dicomQuery.find('-');
       std::string lower = dicomQuery.substr(0, separator);
       std::string upper = dicomQuery.substr(separator + 1);
-      Add(tag, new RangeConstraint(lower, upper, sensitive));
+      Add(tag, new RangeConstraint(lower, upper, caseSensitive));
     }
     else if (dicomQuery.find('\\') != std::string::npos)
     {
-      std::auto_ptr<ListConstraint> constraint(new ListConstraint(sensitive));
+      std::auto_ptr<ListConstraint> constraint(new ListConstraint(caseSensitive));
 
       std::vector<std::string> items;
       Toolbox::TokenizeString(items, dicomQuery, '\\');
@@ -469,7 +469,7 @@
     else if (dicomQuery.find('*') != std::string::npos ||
              dicomQuery.find('?') != std::string::npos)
     {
-      Add(tag, new WildcardConstraint(dicomQuery, sensitive));
+      Add(tag, new WildcardConstraint(dicomQuery, caseSensitive));
     }
     else
     {
@@ -504,7 +504,7 @@
        * (0020,000E) UI SeriesInstanceUID  => Case-sensitive
       **/
 
-      Add(tag, new ValueConstraint(dicomQuery, sensitive));
+      Add(tag, new ValueConstraint(dicomQuery, caseSensitive));
     }
   }
 }
--- a/OrthancServer/Search/LookupResource.h	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/Search/LookupResource.h	Wed Oct 28 12:53:45 2015 +0100
@@ -97,7 +97,7 @@
 
     void AddDicomConstraint(const DicomTag& tag,
                             const std::string& dicomQuery,
-                            bool caseSensitivePN);
+                            bool caseSensitive);
 
     void FindCandidates(std::list<int64_t>& result,
                         IDatabaseWrapper& database) const;
--- a/OrthancServer/ServerContext.cpp	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/ServerContext.cpp	Wed Oct 28 12:53:45 2015 +0100
@@ -545,10 +545,12 @@
   }
 
 
-  bool ServerContext::Apply(std::vector<std::string>& result,
+  bool ServerContext::Apply(std::list<std::string>& result,
                             const ::Orthanc::LookupResource& lookup,
                             size_t maxResults)
   {
+    result.clear();
+
     std::vector<std::string> resources, instances;
     GetIndex().FindCandidates(resources, instances, lookup);
 
--- a/OrthancServer/ServerContext.h	Wed Oct 28 12:29:12 2015 +0100
+++ b/OrthancServer/ServerContext.h	Wed Oct 28 12:53:45 2015 +0100
@@ -246,7 +246,7 @@
 
     void Stop();
 
-    bool Apply(std::vector<std::string>& result,
+    bool Apply(std::list<std::string>& result,
                const ::Orthanc::LookupResource& lookup,
                size_t maxResults);