diff OrthancServer/Search/DatabaseConstraint.cpp @ 3073:0e9d1731b1b0 db-changes

refactoring to reuse DatabaseConstraint in separate projects
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Jan 2019 13:44:18 +0100
parents 5ebd2ef5e7ae
children 495c5edce708
line wrap: on
line diff
--- a/OrthancServer/Search/DatabaseConstraint.cpp	Wed Jan 02 11:47:58 2019 +0100
+++ b/OrthancServer/Search/DatabaseConstraint.cpp	Wed Jan 02 13:44:18 2019 +0100
@@ -35,52 +35,32 @@
 #include "DatabaseConstraint.h"
 
 #include "../../Core/OrthancException.h"
-#include "../ServerToolbox.h"
 
 namespace Orthanc
 {
-  DatabaseConstraint::DatabaseConstraint(const DicomTagConstraint& constraint,
-                                         ResourceType level,
-                                         DicomTagType tagType) :
+  DatabaseConstraint::DatabaseConstraint(ResourceType level,
+                                         const DicomTag& tag,
+                                         bool isIdentifier,
+                                         ConstraintType type,
+                                         const std::vector<std::string>& values,
+                                         bool caseSensitive,
+                                         bool mandatory) :
     level_(level),
-    tag_(constraint.GetTag()),
-    constraintType_(constraint.GetConstraintType()),
-    mandatory_(constraint.IsMandatory())
+    tag_(tag),
+    isIdentifier_(isIdentifier),
+    constraintType_(type),
+    values_(values),
+    caseSensitive_(caseSensitive),
+    mandatory_(mandatory)
   {
-    switch (tagType)
+    if (type != ConstraintType_List &&
+        values_.size() != 1)
     {
-      case DicomTagType_Identifier:
-        isIdentifier_ = true;
-        caseSensitive_ = true;
-        break;
-
-      case DicomTagType_Main:
-        isIdentifier_ = false;
-        caseSensitive_ = constraint.IsCaseSensitive();
-        break;
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }      
 
-      default:
-        throw OrthancException(ErrorCode_InternalError);
-    }
-
-    values_.reserve(constraint.GetValues().size());
-      
-    for (std::set<std::string>::const_iterator
-           it = constraint.GetValues().begin();
-         it != constraint.GetValues().end(); ++it)
-    {
-      if (isIdentifier_)
-      {
-        values_.push_back(ServerToolbox::NormalizeIdentifier(*it));
-      }
-      else
-      {
-        values_.push_back(*it);
-      }
-    }
-  }
-
-  
+    
   const std::string& DatabaseConstraint::GetValue(size_t index) const
   {
     if (index >= values_.size())