# HG changeset patch # User Sebastien Jodogne # Date 1446030846 -3600 # Node ID 03b030680e3df77c99882f63fdb7ccee8bb8b136 # Parent 39c37a994b2fb39a241df3dfdab990ced9a3d336 refactoring diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/IFindConstraint.h --- a/OrthancServer/Search/IFindConstraint.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/IFindConstraint.h Wed Oct 28 12:14:06 2015 +0100 @@ -38,26 +38,15 @@ { class IFindConstraint : public boost::noncopyable { - private: - DicomTag tag_; - public: - IFindConstraint(const DicomTag& tag) : tag_(tag) - { - } - virtual ~IFindConstraint() { } - const DicomTag& GetTag() const - { - return tag_; - } - virtual IFindConstraint* Clone() const = 0; - virtual void Setup(LookupIdentifierQuery& lookup) const = 0; + virtual void Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const = 0; virtual bool Match(const std::string& value) const = 0; }; diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/ListConstraint.cpp --- a/OrthancServer/Search/ListConstraint.cpp Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/ListConstraint.cpp Wed Oct 28 12:14:06 2015 +0100 @@ -51,14 +51,15 @@ } - void ListConstraint::Setup(LookupIdentifierQuery& lookup) const + void ListConstraint::Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const { LookupIdentifierQuery::Disjunction& target = lookup.AddDisjunction(); for (std::set::const_iterator it = allowedValues_.begin(); it != allowedValues_.end(); ++it) { - target.Add(GetTag(), IdentifierConstraintType_Equal, *it); + target.Add(tag, IdentifierConstraintType_Equal, *it); } } diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/ListConstraint.h --- a/OrthancServer/Search/ListConstraint.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/ListConstraint.h Wed Oct 28 12:14:06 2015 +0100 @@ -45,16 +45,13 @@ bool isCaseSensitive_; ListConstraint(const ListConstraint& other) : - IFindConstraint(other.GetTag()), allowedValues_(other.allowedValues_), isCaseSensitive_(other.isCaseSensitive_) { } public: - ListConstraint(const DicomTag& tag, - bool isCaseSensitive) : - IFindConstraint(tag), + ListConstraint(bool isCaseSensitive) : isCaseSensitive_(isCaseSensitive) { } @@ -66,7 +63,8 @@ return new ListConstraint(*this); } - virtual void Setup(LookupIdentifierQuery& lookup) const; + virtual void Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const; virtual bool Match(const std::string& value) const; }; diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/LookupResource.cpp --- a/OrthancServer/Search/LookupResource.cpp Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/LookupResource.cpp Wed Oct 28 12:14:06 2015 +0100 @@ -74,42 +74,43 @@ for (Constraints::iterator it = mainTagsConstraints_.begin(); it != mainTagsConstraints_.end(); ++it) { - delete *it; + delete it->second; } for (Constraints::iterator it = identifiersConstraints_.begin(); it != identifiersConstraints_.end(); ++it) { - delete *it; + delete it->second; } } - bool LookupResource::Level::Add(std::auto_ptr& constraint) + bool LookupResource::Level::Add(const DicomTag& tag, + std::auto_ptr& constraint) { - if (identifiers_.find(constraint->GetTag()) != identifiers_.end()) + if (identifiers_.find(tag) != identifiers_.end()) { if (level_ == ResourceType_Patient) { // The filters on the patient level must be cloned to the study level - identifiersConstraints_.push_back(constraint->Clone()); + identifiersConstraints_[tag] = constraint->Clone(); } else { - identifiersConstraints_.push_back(constraint.release()); + identifiersConstraints_[tag] = constraint.release(); } return true; } - else if (mainTags_.find(constraint->GetTag()) != mainTags_.end()) + else if (mainTags_.find(tag) != mainTags_.end()) { if (level_ == ResourceType_Patient) { // The filters on the patient level must be cloned to the study level - mainTagsConstraints_.push_back(constraint->Clone()); + mainTagsConstraints_[tag] = constraint->Clone(); } else { - mainTagsConstraints_.push_back(constraint.release()); + mainTagsConstraints_[tag] = constraint.release(); } return true; @@ -158,19 +159,20 @@ for (Constraints::iterator it = unoptimizedConstraints_.begin(); it != unoptimizedConstraints_.end(); ++it) { - delete *it; + delete it->second; } } bool LookupResource::AddInternal(ResourceType level, + const DicomTag& tag, std::auto_ptr& constraint) { Levels::iterator it = levels_.find(level); if (it != levels_.end()) { - if (it->second->Add(constraint)) + if (it->second->Add(tag, constraint)) { return true; } @@ -180,24 +182,26 @@ } - void LookupResource::Add(IFindConstraint* constraint) + void LookupResource::Add(const DicomTag& tag, + IFindConstraint* constraint) { std::auto_ptr c(constraint); - if (!AddInternal(ResourceType_Patient, c) && - !AddInternal(ResourceType_Study, c) && - !AddInternal(ResourceType_Series, c) && - !AddInternal(ResourceType_Instance, c)) + if (!AddInternal(ResourceType_Patient, tag, c) && + !AddInternal(ResourceType_Study, tag, c) && + !AddInternal(ResourceType_Series, tag, c) && + !AddInternal(ResourceType_Instance, tag, c)) { - unoptimizedConstraints_.push_back(c.release()); + unoptimizedConstraints_[tag] = c.release(); } } static bool Match(const DicomMap& tags, + const DicomTag& tag, const IFindConstraint& constraint) { - const DicomValue* value = tags.TestAndGetValue(constraint.GetTag()); + const DicomValue* value = tags.TestAndGetValue(tag); if (value == NULL || value->IsNull() || @@ -221,7 +225,7 @@ for (Constraints::const_iterator it = identifiersConstraints_.begin(); it != identifiersConstraints_.end(); ++it) { - (*it)->Setup(query); + it->second->Setup(query, it->first); } query.Apply(candidates, database); @@ -248,7 +252,7 @@ for (Constraints::const_iterator it = identifiersConstraints_.begin(); match && it != identifiersConstraints_.end(); ++it) { - if (!Match(tags, **it)) + if (!Match(tags, it->first, *it->second)) { match = false; } @@ -257,7 +261,7 @@ for (Constraints::const_iterator it = mainTagsConstraints_.begin(); match && it != mainTagsConstraints_.end(); ++it) { - if (!Match(tags, **it)) + if (!Match(tags, it->first, *it->second)) { match = false; } @@ -280,12 +284,12 @@ for (Constraints::const_iterator it = unoptimizedConstraints_.begin(); it != unoptimizedConstraints_.end(); ++it) { - std::string tag = (*it)->GetTag().Format(); + std::string tag = it->first.Format(); if (dicomAsJson.isMember(tag) && dicomAsJson[tag]["Type"] == "String") { std::string value = dicomAsJson[tag]["Value"].asString(); - if (!(*it)->Match(value)) + if (!it->second->Match(value)) { return false; } @@ -399,8 +403,7 @@ void LookupResource::SetModalitiesInStudy(const std::string& modalities) { - modalitiesInStudy_.reset(new ListConstraint(DICOM_TAG_MODALITIES_IN_STUDY, - true /* case sensitive */)); + modalitiesInStudy_.reset(new ListConstraint(true /* case sensitive */)); std::vector items; Toolbox::TokenizeString(items, modalities, '\\'); @@ -447,11 +450,11 @@ size_t separator = dicomQuery.find('-'); std::string lower = dicomQuery.substr(0, separator); std::string upper = dicomQuery.substr(separator + 1); - Add(new RangeConstraint(tag, lower, upper, sensitive)); + Add(tag, new RangeConstraint(lower, upper, sensitive)); } else if (dicomQuery.find('\\') != std::string::npos) { - std::auto_ptr constraint(new ListConstraint(tag, sensitive)); + std::auto_ptr constraint(new ListConstraint(sensitive)); std::vector items; Toolbox::TokenizeString(items, dicomQuery, '\\'); @@ -461,12 +464,12 @@ constraint->AddAllowedValue(items[i]); } - Add(constraint.release()); + Add(tag, constraint.release()); } else if (dicomQuery.find('*') != std::string::npos || dicomQuery.find('?') != std::string::npos) { - Add(new WildcardConstraint(tag, dicomQuery, sensitive)); + Add(tag, new WildcardConstraint(dicomQuery, sensitive)); } else { @@ -501,7 +504,7 @@ * (0020,000E) UI SeriesInstanceUID => Case-sensitive **/ - Add(new ValueConstraint(tag, dicomQuery, sensitive)); + Add(tag, new ValueConstraint(dicomQuery, sensitive)); } } } diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/LookupResource.h --- a/OrthancServer/Search/LookupResource.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/LookupResource.h Wed Oct 28 12:14:06 2015 +0100 @@ -42,7 +42,7 @@ class LookupResource : public boost::noncopyable { private: - typedef std::list Constraints; + typedef std::map Constraints; class Level { @@ -58,7 +58,8 @@ ~Level(); - bool Add(std::auto_ptr& constraint); + bool Add(const DicomTag& tag, + std::auto_ptr& constraint); void Apply(SetOfResources& candidates, IDatabaseWrapper& database) const; @@ -72,6 +73,7 @@ std::auto_ptr modalitiesInStudy_; bool AddInternal(ResourceType level, + const DicomTag& tag, std::auto_ptr& constraint); void ApplyLevel(SetOfResources& candidates, @@ -90,7 +92,8 @@ void SetModalitiesInStudy(const std::string& modalities); - void Add(IFindConstraint* constraint); // Takes ownership + void Add(const DicomTag& tag, + IFindConstraint* constraint); // Takes ownership void AddDicomConstraint(const DicomTag& tag, const std::string& dicomQuery, diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/RangeConstraint.cpp --- a/OrthancServer/Search/RangeConstraint.cpp Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/RangeConstraint.cpp Wed Oct 28 12:14:06 2015 +0100 @@ -37,11 +37,9 @@ namespace Orthanc { - RangeConstraint::RangeConstraint(const DicomTag& tag, - const std::string& lower, + RangeConstraint::RangeConstraint(const std::string& lower, const std::string& upper, bool isCaseSensitive) : - IFindConstraint(tag), lower_(lower), upper_(upper), isCaseSensitive_(isCaseSensitive) @@ -54,10 +52,11 @@ } - void RangeConstraint::Setup(LookupIdentifierQuery& lookup) const + void RangeConstraint::Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const { - lookup.AddConstraint(GetTag(), IdentifierConstraintType_GreaterOrEqual, lower_); - lookup.AddConstraint(GetTag(), IdentifierConstraintType_SmallerOrEqual, upper_); + lookup.AddConstraint(tag, IdentifierConstraintType_GreaterOrEqual, lower_); + lookup.AddConstraint(tag, IdentifierConstraintType_SmallerOrEqual, upper_); } diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/RangeConstraint.h --- a/OrthancServer/Search/RangeConstraint.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/RangeConstraint.h Wed Oct 28 12:14:06 2015 +0100 @@ -44,7 +44,6 @@ bool isCaseSensitive_; RangeConstraint(const RangeConstraint& other) : - IFindConstraint(other.GetTag()), lower_(other.lower_), upper_(other.upper_), isCaseSensitive_(other.isCaseSensitive_) @@ -52,8 +51,7 @@ } public: - RangeConstraint(const DicomTag& tag, - const std::string& lower, + RangeConstraint(const std::string& lower, const std::string& upper, bool isCaseSensitive); @@ -62,7 +60,8 @@ return new RangeConstraint(*this); } - virtual void Setup(LookupIdentifierQuery& lookup) const; + virtual void Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const; virtual bool Match(const std::string& value) const; }; diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/ValueConstraint.cpp --- a/OrthancServer/Search/ValueConstraint.cpp Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/ValueConstraint.cpp Wed Oct 28 12:14:06 2015 +0100 @@ -39,10 +39,8 @@ namespace Orthanc { - ValueConstraint::ValueConstraint(const DicomTag& tag, - const std::string& value, + ValueConstraint::ValueConstraint(const std::string& value, bool isCaseSensitive) : - IFindConstraint(tag), value_(value), isCaseSensitive_(isCaseSensitive) { @@ -53,9 +51,10 @@ } - void ValueConstraint::Setup(LookupIdentifierQuery& lookup) const + void ValueConstraint::Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const { - lookup.AddConstraint(GetTag(), IdentifierConstraintType_Equal, value_); + lookup.AddConstraint(tag, IdentifierConstraintType_Equal, value_); } bool ValueConstraint::Match(const std::string& value) const diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/ValueConstraint.h --- a/OrthancServer/Search/ValueConstraint.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/ValueConstraint.h Wed Oct 28 12:14:06 2015 +0100 @@ -43,15 +43,13 @@ bool isCaseSensitive_; ValueConstraint(const ValueConstraint& other) : - IFindConstraint(other.GetTag()), value_(other.value_), isCaseSensitive_(other.isCaseSensitive_) { } public: - ValueConstraint(const DicomTag& tag, - const std::string& value, + ValueConstraint(const std::string& value, bool isCaseSensitive); virtual IFindConstraint* Clone() const @@ -59,7 +57,8 @@ return new ValueConstraint(*this); } - virtual void Setup(LookupIdentifierQuery& lookup) const; + virtual void Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const; virtual bool Match(const std::string& value) const; }; diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/WildcardConstraint.cpp --- a/OrthancServer/Search/WildcardConstraint.cpp Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/WildcardConstraint.cpp Wed Oct 28 12:14:06 2015 +0100 @@ -45,16 +45,13 @@ WildcardConstraint::WildcardConstraint(const WildcardConstraint& other) : - IFindConstraint(other.GetTag()), pimpl_(new PImpl(*other.pimpl_)) { } - WildcardConstraint::WildcardConstraint(const DicomTag& tag, - const std::string& wildcard, + WildcardConstraint::WildcardConstraint(const std::string& wildcard, bool isCaseSensitive) : - IFindConstraint(tag), pimpl_(new PImpl) { pimpl_->wildcard_ = wildcard; @@ -76,8 +73,9 @@ return boost::regex_match(value, pimpl_->pattern_); } - void WildcardConstraint::Setup(LookupIdentifierQuery& lookup) const + void WildcardConstraint::Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const { - lookup.AddConstraint(GetTag(), IdentifierConstraintType_Wildcard, pimpl_->wildcard_); + lookup.AddConstraint(tag, IdentifierConstraintType_Wildcard, pimpl_->wildcard_); } } diff -r 39c37a994b2f -r 03b030680e3d OrthancServer/Search/WildcardConstraint.h --- a/OrthancServer/Search/WildcardConstraint.h Wed Oct 28 12:02:15 2015 +0100 +++ b/OrthancServer/Search/WildcardConstraint.h Wed Oct 28 12:14:06 2015 +0100 @@ -47,8 +47,7 @@ WildcardConstraint(const WildcardConstraint& other); public: - WildcardConstraint(const DicomTag& tag, - const std::string& wildcard, + WildcardConstraint(const std::string& wildcard, bool isCaseSensitive); virtual IFindConstraint* Clone() const @@ -56,7 +55,8 @@ return new WildcardConstraint(*this); } - virtual void Setup(LookupIdentifierQuery& lookup) const; + virtual void Setup(LookupIdentifierQuery& lookup, + const DicomTag& tag) const; virtual bool Match(const std::string& value) const; };