changeset 1749:99f4a05f39fa db-changes

various types of constraints
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Oct 2015 10:54:51 +0100
parents 92203f713205
children 55d52567bebb
files CMakeLists.txt Core/DicomFormat/DicomMap.cpp Core/DicomFormat/DicomMap.h OrthancServer/Search/IFindConstraint.h OrthancServer/Search/ListConstraint.cpp OrthancServer/Search/ListConstraint.h OrthancServer/Search/LookupIdentifierQuery.cpp OrthancServer/Search/LookupIdentifierQuery.h OrthancServer/Search/LookupResource.cpp OrthancServer/Search/LookupResource.h OrthancServer/Search/RangeConstraint.cpp OrthancServer/Search/RangeConstraint.h OrthancServer/Search/ValueConstraint.cpp OrthancServer/Search/ValueConstraint.h OrthancServer/Search/WildcardConstraint.cpp OrthancServer/Search/WildcardConstraint.h
diffstat 16 files changed, 910 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Mon Oct 26 17:33:55 2015 +0100
+++ b/CMakeLists.txt	Tue Oct 27 10:54:51 2015 +0100
@@ -181,7 +181,12 @@
   OrthancServer/QueryRetrieveHandler.cpp
   OrthancServer/ResourceFinder.cpp
   OrthancServer/Search/LookupIdentifierQuery.cpp
+  OrthancServer/Search/LookupResource.cpp
   OrthancServer/Search/SetOfResources.cpp
+  OrthancServer/Search/ListConstraint.cpp
+  OrthancServer/Search/RangeConstraint.cpp
+  OrthancServer/Search/ValueConstraint.cpp
+  OrthancServer/Search/WildcardConstraint.cpp
   OrthancServer/ServerContext.cpp
   OrthancServer/ServerEnumerations.cpp
   OrthancServer/ServerIndex.cpp
--- a/Core/DicomFormat/DicomMap.cpp	Mon Oct 26 17:33:55 2015 +0100
+++ b/Core/DicomFormat/DicomMap.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -100,6 +100,36 @@
   };
 
 
+  void DicomMap::LoadMainDicomTags(const DicomTag*& tags,
+                                   size_t& size,
+                                   ResourceType level)
+  {
+    switch (level)
+    {
+      case ResourceType_Patient:
+        tags = patientTags;
+        size = sizeof(patientTags) / sizeof(DicomTag);
+        break;
+
+      case ResourceType_Study:
+        tags = studyTags;
+        size = sizeof(studyTags) / sizeof(DicomTag);
+        break;
+
+      case ResourceType_Series:
+        tags = seriesTags;
+        size = sizeof(seriesTags) / sizeof(DicomTag);
+        break;
+
+      case ResourceType_Instance:
+        tags = instanceTags;
+        size = sizeof(instanceTags) / sizeof(DicomTag);
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
 
 
   void DicomMap::SetValue(uint16_t group, 
--- a/Core/DicomFormat/DicomMap.h	Mon Oct 26 17:33:55 2015 +0100
+++ b/Core/DicomFormat/DicomMap.h	Tue Oct 27 10:54:51 2015 +0100
@@ -172,5 +172,9 @@
     void Print(FILE* fp) const;
 
     void GetTags(std::set<DicomTag>& tags) const;
+
+    static void LoadMainDicomTags(const DicomTag*& tags,
+                                  size_t& size,
+                                  ResourceType level);
   };
 }
--- a/OrthancServer/Search/IFindConstraint.h	Mon Oct 26 17:33:55 2015 +0100
+++ b/OrthancServer/Search/IFindConstraint.h	Tue Oct 27 10:54:51 2015 +0100
@@ -38,11 +38,23 @@
 {
   class IFindConstraint : public boost::noncopyable
   {
+  private:
+    DicomTag   tag_;
+
   public:
+    IFindConstraint(const DicomTag& tag) : tag_(tag)
+    {
+    }
+    
     virtual ~IFindConstraint()
     {
     }
 
+    const DicomTag& GetTag() const
+    {
+      return tag_;
+    }
+
     virtual void Setup(LookupIdentifierQuery& lookup) const = 0;
 
     virtual bool Match(const std::string& value) const = 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/ListConstraint.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,77 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeadersServer.h"
+#include "ListConstraint.h"
+
+
+namespace Orthanc
+{
+  void ListConstraint::AddAllowedValue(const std::string& value)
+  {
+    if (isCaseSensitive_)
+    {
+      std::string s = value;
+      Toolbox::ToUpperCase(s);
+      allowedValues_.insert(s);      
+    }
+    else
+    {
+      allowedValues_.insert(value);
+    }
+  }
+
+
+  void ListConstraint::Setup(LookupIdentifierQuery& lookup) const
+  {
+    LookupIdentifierQuery::Disjunction& target = lookup.AddDisjunction();
+
+    for (std::set<std::string>::const_iterator
+           it = allowedValues_.begin(); it != allowedValues_.end(); ++it)
+    {
+      target.Add(GetTag(), IdentifierConstraintType_Equal, *it);
+    }
+  }
+
+
+  bool ListConstraint::Match(const std::string& value) const
+  {
+    std::string v = value;
+
+    if (isCaseSensitive_)
+    {
+      Toolbox::ToUpperCase(v);
+    }
+
+    return allowedValues_.find(v) != allowedValues_.end();
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/ListConstraint.h	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,61 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IFindConstraint.h"
+
+#include <set>
+
+namespace Orthanc
+{
+  class ListConstraint : public IFindConstraint
+  {
+  private:
+    std::set<std::string>  allowedValues_;
+    bool                   isCaseSensitive_;
+
+  public:
+    ListConstraint(const DicomTag& tag, 
+                   bool isCaseSensitive) : 
+      IFindConstraint(tag),
+      isCaseSensitive_(isCaseSensitive)
+    {
+    }
+
+    void AddAllowedValue(const std::string& value);
+
+    virtual void Setup(LookupIdentifierQuery& lookup) const;
+
+    virtual bool Match(const std::string& value) const;
+  };
+}
--- a/OrthancServer/Search/LookupIdentifierQuery.cpp	Mon Oct 26 17:33:55 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -70,9 +70,10 @@
     DICOM_TAG_SOP_INSTANCE_UID
   };
 
-  static void LoadIdentifiers(const DicomTag*& tags,
-                              size_t& size,
-                              ResourceType level)
+
+  void LookupIdentifierQuery::LoadIdentifiers(const DicomTag*& tags,
+                                              size_t& size,
+                                              ResourceType level)
   {
     switch (level)
     {
@@ -102,18 +103,20 @@
   }
 
 
-  LookupIdentifierQuery::Union::~Union()
+  LookupIdentifierQuery::Disjunction::~Disjunction()
   {
-    for (size_t i = 0; i < union_.size(); i++)
+    for (size_t i = 0; i < disjunction_.size(); i++)
     {
-      delete union_[i];
+      delete disjunction_[i];
     }
   }
 
 
-  void LookupIdentifierQuery::Union::Add(const Constraint& constraint)
+  void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag,
+                                               IdentifierConstraintType type,
+                                               const std::string& value)
   {
-    union_.push_back(new Constraint(constraint));
+    disjunction_.push_back(new Constraint(tag, type, value));
   }
 
 
@@ -153,23 +156,14 @@
                                             const std::string& value)
   {
     assert(IsIdentifier(tag));
-
-    Constraint constraint(tag, type, NormalizeIdentifier(value));
-    constraints_.push_back(new Union);
-    constraints_.back()->Add(constraint);
+    constraints_.back()->Add(tag, type, value);
   }
 
 
-  void LookupIdentifierQuery::AddDisjunction(const std::list<Constraint>& constraints)
+  LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction()
   {
-    constraints_.push_back(new Union);
-
-    for (std::list<Constraint>::const_iterator
-           it = constraints.begin(); it != constraints.end(); ++it)
-    {
-      assert(IsIdentifier(it->GetTag()));
-      constraints_.back()->Add(*it);
-    }
+    constraints_.push_back(new Disjunction);
+    return *constraints_.back();
   }
 
 
--- a/OrthancServer/Search/LookupIdentifierQuery.h	Mon Oct 26 17:33:55 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.h	Tue Oct 27 10:54:51 2015 +0100
@@ -76,7 +76,7 @@
                  const std::string& value) : 
         tag_(tag),
         type_(type),
-        value_(value)
+        value_(NormalizeIdentifier(value))
       {
       }
 
@@ -97,30 +97,32 @@
     };
 
 
-  private:
-    class Union
+    class Disjunction : public boost::noncopyable
     {
     private:
-      std::vector<Constraint*>  union_;
+      std::vector<Constraint*>  disjunction_;
 
     public:
-      ~Union();
+      ~Disjunction();
 
-      void Add(const Constraint& constraint);
+      void Add(const DicomTag& tag,
+               IdentifierConstraintType type,
+               const std::string& value);
 
       size_t GetSize() const
       {
-        return union_.size();
+        return disjunction_.size();
       }
 
       const Constraint&  GetConstraint(size_t i) const
       {
-        return *union_[i];
+        return *disjunction_[i];
       }
     };
 
 
-    typedef std::vector<Union*>  Constraints;
+  private:
+    typedef std::vector<Disjunction*>  Constraints;
 
     ResourceType  level_;
     Constraints   constraints_;
@@ -143,7 +145,7 @@
                        IdentifierConstraintType type,
                        const std::string& value);
 
-    void AddDisjunction(const std::list<Constraint>& constraints);
+    Disjunction& AddDisjunction();
 
     ResourceType GetLevel() const
     {
@@ -159,6 +161,10 @@
     void Apply(std::list<std::string>& result,
                IDatabaseWrapper& database);
 
+    static void LoadIdentifiers(const DicomTag*& tags,
+                                size_t& size,
+                                ResourceType level);
+
     static bool IsIdentifier(const DicomTag& tag,
                              ResourceType level);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/LookupResource.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,194 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeadersServer.h"
+#include "LookupResource.h"
+
+#include "../../Core/OrthancException.h"
+
+namespace Orthanc
+{
+  LookupResource::Level::Level(ResourceType level)
+  {
+    const DicomTag* tags = NULL;
+    size_t size;
+    
+    LookupIdentifierQuery::LoadIdentifiers(tags, size, level);
+    
+    for (size_t i = 0; i < size; i++)
+    {
+      identifiers_.insert(tags[i]);
+    }
+    
+    DicomMap::LoadMainDicomTags(tags, size, level);
+    
+    for (size_t i = 0; i < size; i++)
+    {
+      if (identifiers_.find(tags[i]) == identifiers_.end())
+      {
+        mainTags_.insert(tags[i]);
+      }
+    }    
+  }
+
+  LookupResource::Level::~Level()
+  {
+    for (Constraints::iterator it = mainTagsConstraints_.begin();
+         it != mainTagsConstraints_.end(); ++it)
+    {
+      delete *it;
+    }
+
+    for (Constraints::iterator it = identifiersConstraints_.begin();
+         it != identifiersConstraints_.end(); ++it)
+    {
+      delete *it;
+    }
+  }
+
+  bool LookupResource::Level::Add(std::auto_ptr<IFindConstraint>& constraint)
+  {
+    if (identifiers_.find(constraint->GetTag()) != identifiers_.end())
+    {
+      identifiersConstraints_.push_back(constraint.release());
+      return true;
+    }
+    else if (mainTags_.find(constraint->GetTag()) != mainTags_.end())
+    {
+      mainTagsConstraints_.push_back(constraint.release());
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+
+
+  LookupResource::LookupResource(ResourceType level) : level_(level)
+  {
+    switch (level)
+    {
+      case ResourceType_Patient:
+        levels_[ResourceType_Patient] = new Level(ResourceType_Patient);
+        break;
+
+      case ResourceType_Study:
+        levels_[ResourceType_Study] = new Level(ResourceType_Study);
+        // Do not add "break" here
+
+      case ResourceType_Series:
+        levels_[ResourceType_Series] = new Level(ResourceType_Series);
+        // Do not add "break" here
+
+      case ResourceType_Instance:
+        levels_[ResourceType_Instance] = new Level(ResourceType_Instance);
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_InternalError);
+    }
+  }
+
+
+  LookupResource::~LookupResource()
+  {
+    for (Levels::iterator it = levels_.begin();
+         it != levels_.end(); ++it)
+    {
+      delete it->second;
+    }
+
+    for (Constraints::iterator it = unoptimizedConstraints_.begin();
+         it != unoptimizedConstraints_.end(); ++it)
+    {
+      delete *it;
+    }    
+  }
+
+
+
+  bool LookupResource::AddInternal(ResourceType level,
+                                   std::auto_ptr<IFindConstraint>& constraint)
+  {
+    Levels::iterator it = levels_.find(level);
+    if (it != levels_.end())
+    {
+      if (it->second->Add(constraint))
+      {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+
+  void LookupResource::Add(IFindConstraint* constraint)
+  {
+    std::auto_ptr<IFindConstraint> c(constraint);
+
+    if (!AddInternal(ResourceType_Patient, c) &&
+        !AddInternal(ResourceType_Study, c) &&
+        !AddInternal(ResourceType_Series, c) &&
+        !AddInternal(ResourceType_Instance, c))
+    {
+      unoptimizedConstraints_.push_back(c.release());
+    }
+  }
+
+
+  static int64_t ChooseOneInstance(IDatabaseWrapper& database,
+                                   int64_t parent,
+                                   ResourceType type)
+  {
+    for (;;)
+    {
+      if (type == ResourceType_Instance)
+      {
+        return parent;
+      }
+
+      std::list<int64_t>  children;
+      database.GetChildrenInternalId(children, parent);
+
+      if (children.empty())
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+
+      parent = children.front();
+      type = GetChildResourceType(type);
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/LookupResource.h	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,92 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IFindConstraint.h"
+#include "SetOfResources.h"
+
+#include <memory>
+
+namespace Orthanc
+{
+  class LookupResource : public boost::noncopyable
+  {
+  private:
+    typedef std::list<IFindConstraint*>  Constraints;
+    
+    class Level
+    {
+    private:
+      std::set<DicomTag>  identifiers_;
+      std::set<DicomTag>  mainTags_;
+      Constraints         identifiersConstraints_;
+      Constraints         mainTagsConstraints_;
+
+    public:
+      Level(ResourceType level);
+
+      ~Level();
+
+      bool Add(std::auto_ptr<IFindConstraint>& constraint);
+    };
+
+    typedef std::map<ResourceType, Level*>  Levels;
+
+    ResourceType level_;
+    Levels       levels_;
+    Constraints  unoptimizedConstraints_;
+    size_t       maxResults_;
+
+    bool AddInternal(ResourceType level,
+                     std::auto_ptr<IFindConstraint>& constraint);
+
+    void ApplyUnoptimizedConstraints(SetOfResources& result);
+
+  public:
+    LookupResource(ResourceType level);
+
+    ~LookupResource();
+
+    void Add(IFindConstraint* constraint);   // Takes ownership
+
+    void SetMaxResults(size_t maxResults)
+    {
+      maxResults_ = maxResults;
+    }
+
+    size_t GetMaxResults() const
+    {
+      return maxResults_;
+    }
+  };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/RangeConstraint.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,91 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeadersServer.h"
+#include "RangeConstraint.h"
+
+#include "../../Core/Toolbox.h"
+
+namespace Orthanc
+{
+  RangeConstraint::RangeConstraint(const DicomTag& tag, 
+                                   const std::string& lower,
+                                   const std::string& upper,
+                                   bool isCaseSensitive) : 
+    IFindConstraint(tag),
+    lower_(lower),
+    upper_(upper),
+    isCaseSensitive_(isCaseSensitive)
+  {
+    if (isCaseSensitive_)
+    {
+      Toolbox::ToUpperCase(lower_);
+      Toolbox::ToUpperCase(upper_);
+    }
+  }
+
+
+  void RangeConstraint::Setup(LookupIdentifierQuery& lookup) const
+  {
+    lookup.AddConstraint(GetTag(), IdentifierConstraintType_GreaterOrEqual, lower_);
+    lookup.AddConstraint(GetTag(), IdentifierConstraintType_SmallerOrEqual, upper_);
+  }
+
+
+  bool RangeConstraint::Match(const std::string& value) const
+  {
+    std::string v = value;
+
+    if (isCaseSensitive_)
+    {
+      Toolbox::ToUpperCase(v);
+    }
+
+    if (lower_.size() == 0 && 
+        upper_.size() == 0)
+    {
+      return false;
+    }
+
+    if (lower_.size() == 0)
+    {
+      return v <= upper_;
+    }
+
+    if (upper_.size() == 0)
+    {
+      return v >= lower_;
+    }
+    
+    return (v >= lower_ && v <= upper_);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/RangeConstraint.h	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,56 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IFindConstraint.h"
+
+namespace Orthanc
+{
+  class RangeConstraint : public IFindConstraint
+  {
+  private:
+    std::string  lower_;
+    std::string  upper_;
+    bool         isCaseSensitive_;
+
+  public:
+    RangeConstraint(const DicomTag& tag, 
+                    const std::string& lower,
+                    const std::string& upper,
+                    bool isCaseSensitive);
+
+    virtual void Setup(LookupIdentifierQuery& lookup) const;
+
+    virtual bool Match(const std::string& value) const;
+  };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/ValueConstraint.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,72 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeadersServer.h"
+#include "ValueConstraint.h"
+
+#include "../../Core/Toolbox.h"
+
+namespace Orthanc
+{
+  ValueConstraint::ValueConstraint(const DicomTag& tag, 
+                                   const std::string& value,
+                                   bool isCaseSensitive) : 
+    IFindConstraint(tag),
+    value_(value),
+    isCaseSensitive_(isCaseSensitive)
+  {
+    if (isCaseSensitive)
+    {
+      Toolbox::ToUpperCase(value_);
+    }
+  }
+
+
+  void ValueConstraint::Setup(LookupIdentifierQuery& lookup) const
+  {
+    lookup.AddConstraint(GetTag(), IdentifierConstraintType_Equal, value_);
+  }
+
+  bool ValueConstraint::Match(const std::string& value) const
+  {
+    if (isCaseSensitive_)
+    {
+      return value_ == value;
+    }
+    else
+    {
+      std::string v;
+      Toolbox::ToLowerCase(v, value);
+      return value_ == v;
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/ValueConstraint.h	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,54 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IFindConstraint.h"
+
+namespace Orthanc
+{
+  class ValueConstraint : public IFindConstraint
+  {
+  private:
+    std::string  value_;
+    bool         isCaseSensitive_;
+
+  public:
+    ValueConstraint(const DicomTag& tag, 
+                    const std::string& value,
+                    bool isCaseSensitive);
+
+    virtual void Setup(LookupIdentifierQuery& lookup) const;
+
+    virtual bool Match(const std::string& value) const;
+  };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/WildcardConstraint.cpp	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,75 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeadersServer.h"
+#include "WildcardConstraint.h"
+
+#include <boost/regex.hpp>
+
+namespace Orthanc
+{
+  struct WildcardConstraint::PImpl
+  {
+    boost::regex  pattern_;
+    std::string   wildcard_;
+  };
+
+  WildcardConstraint::WildcardConstraint(const DicomTag& tag, 
+                                         const std::string& wildcard,
+                                         bool isCaseSensitive) :
+    IFindConstraint(tag),
+    pimpl_(new PImpl)
+  {
+    pimpl_->wildcard_ = wildcard;
+
+    std::string re = Toolbox::WildcardToRegularExpression(wildcard);
+
+    if (isCaseSensitive)
+    {
+      pimpl_->pattern_ = boost::regex(re);
+    }
+    else
+    {
+      pimpl_->pattern_ = boost::regex(re, boost::regex::icase /* case insensitive search */);
+    }
+  }
+
+  bool WildcardConstraint::Match(const std::string& value) const
+  {
+    return boost::regex_match(value, pimpl_->pattern_);
+  }
+
+  void WildcardConstraint::Setup(LookupIdentifierQuery& lookup) const
+  {
+    lookup.AddConstraint(GetTag(), IdentifierConstraintType_Wildcard, pimpl_->wildcard_);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Search/WildcardConstraint.h	Tue Oct 27 10:54:51 2015 +0100
@@ -0,0 +1,56 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IFindConstraint.h"
+
+#include <boost/shared_ptr.hpp>
+
+namespace Orthanc
+{
+  class WildcardConstraint : public IFindConstraint
+  {
+  private:
+    struct PImpl;
+    boost::shared_ptr<PImpl>  pimpl_;
+
+  public:
+    WildcardConstraint(const DicomTag& tag, 
+                       const std::string& wildcard,
+                       bool isCaseSensitive);
+
+    virtual void Setup(LookupIdentifierQuery& lookup) const;
+
+    virtual bool Match(const std::string& value) const;
+  };
+}