Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1747:ca69082ab200 | 1748:92203f713205 |
---|---|
100 throw OrthancException(ErrorCode_ParameterOutOfRange); | 100 throw OrthancException(ErrorCode_ParameterOutOfRange); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 LookupIdentifierQuery::Union::~Union() | |
106 { | |
107 for (size_t i = 0; i < union_.size(); i++) | |
108 { | |
109 delete union_[i]; | |
110 } | |
111 } | |
112 | |
113 | |
114 void LookupIdentifierQuery::Union::Add(const Constraint& constraint) | |
115 { | |
116 union_.push_back(new Constraint(constraint)); | |
117 } | |
118 | |
105 | 119 |
106 LookupIdentifierQuery::~LookupIdentifierQuery() | 120 LookupIdentifierQuery::~LookupIdentifierQuery() |
107 { | 121 { |
108 for (Constraints::iterator it = constraints_.begin(); | 122 for (Constraints::iterator it = constraints_.begin(); |
109 it != constraints_.end(); ++it) | 123 it != constraints_.end(); ++it) |
112 } | 126 } |
113 } | 127 } |
114 | 128 |
115 | 129 |
116 | 130 |
117 void LookupIdentifierQuery::CheckIndex(size_t index) const | 131 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag, |
118 { | 132 ResourceType level) |
119 if (index >= constraints_.size()) | |
120 { | |
121 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
122 } | |
123 } | |
124 | |
125 | |
126 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag) const | |
127 { | 133 { |
128 const DicomTag* tags; | 134 const DicomTag* tags; |
129 size_t size; | 135 size_t size; |
130 | 136 |
131 LoadIdentifiers(tags, size, level_); | 137 LoadIdentifiers(tags, size, level); |
132 | 138 |
133 for (size_t i = 0; i < size; i++) | 139 for (size_t i = 0; i < size; i++) |
134 { | 140 { |
135 if (tag == tags[i]) | 141 if (tag == tags[i]) |
136 { | 142 { |
145 void LookupIdentifierQuery::AddConstraint(DicomTag tag, | 151 void LookupIdentifierQuery::AddConstraint(DicomTag tag, |
146 IdentifierConstraintType type, | 152 IdentifierConstraintType type, |
147 const std::string& value) | 153 const std::string& value) |
148 { | 154 { |
149 assert(IsIdentifier(tag)); | 155 assert(IsIdentifier(tag)); |
150 constraints_.push_back(new Constraint(tag, type, NormalizeIdentifier(value))); | 156 |
151 } | 157 Constraint constraint(tag, type, NormalizeIdentifier(value)); |
152 | 158 constraints_.push_back(new Union); |
153 | 159 constraints_.back()->Add(constraint); |
154 const DicomTag& LookupIdentifierQuery::GetTag(size_t index) const | 160 } |
155 { | 161 |
156 CheckIndex(index); | 162 |
157 return constraints_[index]->tag_; | 163 void LookupIdentifierQuery::AddDisjunction(const std::list<Constraint>& constraints) |
158 } | 164 { |
159 | 165 constraints_.push_back(new Union); |
160 | 166 |
161 IdentifierConstraintType LookupIdentifierQuery::GetType(size_t index) const | 167 for (std::list<Constraint>::const_iterator |
162 { | 168 it = constraints.begin(); it != constraints.end(); ++it) |
163 CheckIndex(index); | 169 { |
164 return constraints_[index]->type_; | 170 assert(IsIdentifier(it->GetTag())); |
165 } | 171 constraints_.back()->Add(*it); |
166 | 172 } |
167 | |
168 const std::string& LookupIdentifierQuery::GetValue(size_t index) const | |
169 { | |
170 CheckIndex(index); | |
171 return constraints_[index]->value_; | |
172 } | 173 } |
173 | 174 |
174 | 175 |
175 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value) | 176 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value) |
176 { | 177 { |
209 { | 210 { |
210 SetOfResources resources(database, level_); | 211 SetOfResources resources(database, level_); |
211 | 212 |
212 for (size_t i = 0; i < GetSize(); i++) | 213 for (size_t i = 0; i < GetSize(); i++) |
213 { | 214 { |
214 std::list<int64_t> tmp; | 215 std::list<int64_t> a; |
215 database.LookupIdentifier(tmp, level_, GetTag(i), GetType(i), GetValue(i)); | 216 |
216 resources.Intersect(tmp); | 217 for (size_t j = 0; j < constraints_[i]->GetSize(); j++) |
218 { | |
219 const Constraint& constraint = constraints_[i]->GetConstraint(j); | |
220 std::list<int64_t> b; | |
221 database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue()); | |
222 | |
223 a.splice(a.end(), b); | |
224 } | |
225 | |
226 resources.Intersect(a); | |
217 } | 227 } |
218 | 228 |
219 resources.Flatten(result); | 229 resources.Flatten(result); |
220 } | 230 } |
221 } | 231 } |