diff OrthancServer/Search/LookupIdentifierQuery.cpp @ 1748:92203f713205 db-changes

IFindConstraint
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 26 Oct 2015 17:33:55 +0100
parents ca69082ab200
children 99f4a05f39fa
line wrap: on
line diff
--- a/OrthancServer/Search/LookupIdentifierQuery.cpp	Mon Oct 26 16:58:11 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.cpp	Mon Oct 26 17:33:55 2015 +0100
@@ -102,6 +102,20 @@
   }
 
 
+  LookupIdentifierQuery::Union::~Union()
+  {
+    for (size_t i = 0; i < union_.size(); i++)
+    {
+      delete union_[i];
+    }
+  }
+
+
+  void LookupIdentifierQuery::Union::Add(const Constraint& constraint)
+  {
+    union_.push_back(new Constraint(constraint));
+  }
+
 
   LookupIdentifierQuery::~LookupIdentifierQuery()
   {
@@ -114,21 +128,13 @@
 
 
 
-  void  LookupIdentifierQuery::CheckIndex(size_t index) const
-  {
-    if (index >= constraints_.size())
-    {
-      throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
-  }
-
-
-  bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag) const
+  bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag,
+                                           ResourceType level)
   {
     const DicomTag* tags;
     size_t size;
 
-    LoadIdentifiers(tags, size, level_);
+    LoadIdentifiers(tags, size, level);
 
     for (size_t i = 0; i < size; i++)
     {
@@ -147,28 +153,23 @@
                                             const std::string& value)
   {
     assert(IsIdentifier(tag));
-    constraints_.push_back(new Constraint(tag, type, NormalizeIdentifier(value)));
-  }
 
-
-  const DicomTag& LookupIdentifierQuery::GetTag(size_t index) const
-  {
-    CheckIndex(index);
-    return constraints_[index]->tag_;
+    Constraint constraint(tag, type, NormalizeIdentifier(value));
+    constraints_.push_back(new Union);
+    constraints_.back()->Add(constraint);
   }
 
 
-  IdentifierConstraintType  LookupIdentifierQuery::GetType(size_t index) const
+  void LookupIdentifierQuery::AddDisjunction(const std::list<Constraint>& constraints)
   {
-    CheckIndex(index);
-    return constraints_[index]->type_;
-  }
+    constraints_.push_back(new Union);
 
-
-  const std::string& LookupIdentifierQuery::GetValue(size_t index) const
-  {
-    CheckIndex(index);
-    return constraints_[index]->value_;
+    for (std::list<Constraint>::const_iterator
+           it = constraints.begin(); it != constraints.end(); ++it)
+    {
+      assert(IsIdentifier(it->GetTag()));
+      constraints_.back()->Add(*it);
+    }
   }
 
 
@@ -211,9 +212,18 @@
     
     for (size_t i = 0; i < GetSize(); i++)
     {
-      std::list<int64_t> tmp;
-      database.LookupIdentifier(tmp, level_, GetTag(i), GetType(i), GetValue(i));
-      resources.Intersect(tmp);
+      std::list<int64_t> a;
+
+      for (size_t j = 0; j < constraints_[i]->GetSize(); j++)
+      {
+        const Constraint& constraint = constraints_[i]->GetConstraint(j);
+        std::list<int64_t> b;
+        database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue());
+
+        a.splice(a.end(), b);
+      }
+
+      resources.Intersect(a);
     }
 
     resources.Flatten(result);