# HG changeset patch # User Sebastien Jodogne # Date 1546433058 -3600 # Node ID 0e9d1731b1b097c1c1ea80f77acb4fbf41db9142 # Parent 1b05fd072c57aac5813adda31b133cbb75d2a5c3 refactoring to reuse DatabaseConstraint in separate projects diff -r 1b05fd072c57 -r 0e9d1731b1b0 OrthancServer/Search/DatabaseConstraint.cpp --- 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& 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::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()) diff -r 1b05fd072c57 -r 0e9d1731b1b0 OrthancServer/Search/DatabaseConstraint.h --- a/OrthancServer/Search/DatabaseConstraint.h Wed Jan 02 11:47:58 2019 +0100 +++ b/OrthancServer/Search/DatabaseConstraint.h Wed Jan 02 13:44:18 2019 +0100 @@ -33,10 +33,12 @@ #pragma once -#include "DicomTagConstraint.h" +#include "../../Core/DicomFormat/DicomMap.h" +#include "../ServerEnumerations.h" namespace Orthanc { + // This class is also used by the "orthanc-databases" project class DatabaseConstraint { private: @@ -49,10 +51,14 @@ bool mandatory_; public: - DatabaseConstraint(const DicomTagConstraint& constraint, - ResourceType level, - DicomTagType tagType); - + DatabaseConstraint(ResourceType level, + const DicomTag& tag, + bool isIdentifier, + ConstraintType type, + const std::vector& values, + bool caseSensitive, + bool mandatory); + ResourceType GetLevel() const { return level_; diff -r 1b05fd072c57 -r 0e9d1731b1b0 OrthancServer/Search/DicomTagConstraint.cpp --- a/OrthancServer/Search/DicomTagConstraint.cpp Wed Jan 02 11:47:58 2019 +0100 +++ b/OrthancServer/Search/DicomTagConstraint.cpp Wed Jan 02 13:44:18 2019 +0100 @@ -339,4 +339,46 @@ throw OrthancException(ErrorCode_InternalError); } } + + + DatabaseConstraint DicomTagConstraint::ConvertToDatabaseConstraint(ResourceType level, + DicomTagType tagType) const + { + bool isIdentifier, caseSensitive; + + switch (tagType) + { + case DicomTagType_Identifier: + isIdentifier = true; + caseSensitive = true; + break; + + case DicomTagType_Main: + isIdentifier = false; + caseSensitive = IsCaseSensitive(); + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + std::vector values; + values.reserve(values_.size()); + + for (std::set::const_iterator + it = values_.begin(); it != values_.end(); ++it) + { + if (isIdentifier) + { + values.push_back(ServerToolbox::NormalizeIdentifier(*it)); + } + else + { + values.push_back(*it); + } + } + + return DatabaseConstraint(level, tag_, isIdentifier, constraintType_, + values, caseSensitive, mandatory_); + } } diff -r 1b05fd072c57 -r 0e9d1731b1b0 OrthancServer/Search/DicomTagConstraint.h --- a/OrthancServer/Search/DicomTagConstraint.h Wed Jan 02 11:47:58 2019 +0100 +++ b/OrthancServer/Search/DicomTagConstraint.h Wed Jan 02 13:44:18 2019 +0100 @@ -35,13 +35,12 @@ #include "../ServerEnumerations.h" #include "../../Core/DicomFormat/DicomMap.h" +#include "DatabaseConstraint.h" #include namespace Orthanc { - class DatabaseConstraint; - class DicomTagConstraint : public boost::noncopyable { private: @@ -112,5 +111,8 @@ bool IsMatch(const DicomMap& value); std::string Format() const; + + DatabaseConstraint ConvertToDatabaseConstraint(ResourceType level, + DicomTagType tagType) const; }; } diff -r 1b05fd072c57 -r 0e9d1731b1b0 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Wed Jan 02 11:47:58 2019 +0100 +++ b/OrthancServer/ServerIndex.cpp Wed Jan 02 13:44:18 2019 +0100 @@ -2139,7 +2139,7 @@ DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true); std::vector query; - query.push_back(DatabaseConstraint(c, level, DicomTagType_Identifier)); + query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); { boost::mutex::scoped_lock lock(mutex_); @@ -2555,8 +2555,7 @@ level = ResourceType_Study; } - DatabaseConstraint c(source.GetConstraint(i), level, type); - target.push_back(c); + target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type)); } } } diff -r 1b05fd072c57 -r 0e9d1731b1b0 UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Wed Jan 02 11:47:58 2019 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Jan 02 13:44:18 2019 +0100 @@ -260,7 +260,7 @@ DicomTagConstraint c(tag, type, value, true, true); std::vector lookup; - lookup.push_back(DatabaseConstraint(c, level, DicomTagType_Identifier)); + lookup.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); index_->ApplyLookupResources(result, NULL, lookup, level, 0 /* no limit */); } @@ -280,8 +280,8 @@ DicomTagConstraint c2(tag, type2, value2, true, true); std::vector lookup; - lookup.push_back(DatabaseConstraint(c1, level, DicomTagType_Identifier)); - lookup.push_back(DatabaseConstraint(c2, level, DicomTagType_Identifier)); + lookup.push_back(c1.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); + lookup.push_back(c2.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); index_->ApplyLookupResources(result, NULL, lookup, level, 0 /* no limit */); }