comparison OrthancServer/Search/Compatibility/DatabaseLookup.cpp @ 3084:195ba4cbac3f db-changes

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jan 2019 16:42:55 +0100
parents ead8576a02ef
children c829758b9ca0
comparison
equal deleted inserted replaced
3083:683d572424b6 3084:195ba4cbac3f
90 }; 90 };
91 } 91 }
92 92
93 93
94 static void ApplyIdentifierConstraint(SetOfResources& candidates, 94 static void ApplyIdentifierConstraint(SetOfResources& candidates,
95 CompatibilityDatabaseWrapper& database, 95 CompatibilityDatabaseWrapper& compatibility,
96 const DatabaseConstraint& constraint, 96 const DatabaseConstraint& constraint,
97 ResourceType level) 97 ResourceType level)
98 { 98 {
99 std::list<int64_t> matches; 99 std::list<int64_t> matches;
100 100
101 switch (constraint.GetConstraintType()) 101 switch (constraint.GetConstraintType())
102 { 102 {
103 case ConstraintType_Equal: 103 case ConstraintType_Equal:
104 database.LookupIdentifier(matches, level, constraint.GetTag(), 104 compatibility.LookupIdentifier(matches, level, constraint.GetTag(),
105 IdentifierConstraintType_Equal, constraint.GetSingleValue()); 105 IdentifierConstraintType_Equal, constraint.GetSingleValue());
106 break; 106 break;
107 107
108 case ConstraintType_SmallerOrEqual: 108 case ConstraintType_SmallerOrEqual:
109 database.LookupIdentifier(matches, level, constraint.GetTag(), 109 compatibility.LookupIdentifier(matches, level, constraint.GetTag(),
110 IdentifierConstraintType_SmallerOrEqual, constraint.GetSingleValue()); 110 IdentifierConstraintType_SmallerOrEqual, constraint.GetSingleValue());
111 break; 111 break;
112 112
113 case ConstraintType_GreaterOrEqual: 113 case ConstraintType_GreaterOrEqual:
114 database.LookupIdentifier(matches, level, constraint.GetTag(), 114 compatibility.LookupIdentifier(matches, level, constraint.GetTag(),
115 IdentifierConstraintType_GreaterOrEqual, constraint.GetSingleValue()); 115 IdentifierConstraintType_GreaterOrEqual, constraint.GetSingleValue());
116 116
117 break; 117 break;
118 118
119 case ConstraintType_Wildcard: 119 case ConstraintType_Wildcard:
120 database.LookupIdentifier(matches, level, constraint.GetTag(), 120 compatibility.LookupIdentifier(matches, level, constraint.GetTag(),
121 IdentifierConstraintType_Wildcard, constraint.GetSingleValue()); 121 IdentifierConstraintType_Wildcard, constraint.GetSingleValue());
122 122
123 break; 123 break;
124 124
125 case ConstraintType_List: 125 case ConstraintType_List:
126 for (size_t i = 0; i < constraint.GetValuesCount(); i++) 126 for (size_t i = 0; i < constraint.GetValuesCount(); i++)
127 { 127 {
128 std::list<int64_t> tmp; 128 std::list<int64_t> tmp;
129 database.LookupIdentifier(tmp, level, constraint.GetTag(), 129 compatibility.LookupIdentifier(tmp, level, constraint.GetTag(),
130 IdentifierConstraintType_Wildcard, constraint.GetValue(i)); 130 IdentifierConstraintType_Wildcard, constraint.GetValue(i));
131 matches.splice(matches.end(), tmp); 131 matches.splice(matches.end(), tmp);
132 } 132 }
133 133
134 break; 134 break;
140 candidates.Intersect(matches); 140 candidates.Intersect(matches);
141 } 141 }
142 142
143 143
144 static void ApplyIdentifierRange(SetOfResources& candidates, 144 static void ApplyIdentifierRange(SetOfResources& candidates,
145 CompatibilityDatabaseWrapper& database, 145 CompatibilityDatabaseWrapper& compatibility,
146 const DatabaseConstraint& smaller, 146 const DatabaseConstraint& smaller,
147 const DatabaseConstraint& greater, 147 const DatabaseConstraint& greater,
148 ResourceType level) 148 ResourceType level)
149 { 149 {
150 assert(smaller.GetConstraintType() == ConstraintType_SmallerOrEqual && 150 assert(smaller.GetConstraintType() == ConstraintType_SmallerOrEqual &&
151 greater.GetConstraintType() == ConstraintType_GreaterOrEqual && 151 greater.GetConstraintType() == ConstraintType_GreaterOrEqual &&
152 smaller.GetTag() == greater.GetTag() && 152 smaller.GetTag() == greater.GetTag() &&
153 ServerToolbox::IsIdentifier(smaller.GetTag(), level)); 153 ServerToolbox::IsIdentifier(smaller.GetTag(), level));
154 154
155 std::list<int64_t> matches; 155 std::list<int64_t> matches;
156 database.LookupIdentifierRange(matches, level, smaller.GetTag(), 156 compatibility.LookupIdentifierRange(matches, level, smaller.GetTag(),
157 greater.GetSingleValue(), smaller.GetSingleValue()); 157 greater.GetSingleValue(), smaller.GetSingleValue());
158 candidates.Intersect(matches); 158 candidates.Intersect(matches);
159 } 159 }
160 160
161 161
162 static void ApplyLevel(SetOfResources& candidates, 162 static void ApplyLevel(SetOfResources& candidates,
163 CompatibilityDatabaseWrapper& database, 163 IDatabaseWrapper& database,
164 CompatibilityDatabaseWrapper& compatibility,
164 const std::vector<DatabaseConstraint>& lookup, 165 const std::vector<DatabaseConstraint>& lookup,
165 ResourceType level) 166 ResourceType level)
166 { 167 {
167 typedef std::set<const DatabaseConstraint*> SetOfConstraints; 168 typedef std::set<const DatabaseConstraint*> SetOfConstraints;
168 typedef std::map<DicomTag, SetOfConstraints> Identifiers; 169 typedef std::map<DicomTag, SetOfConstraints> Identifiers;
218 219
219 if (smaller != NULL && 220 if (smaller != NULL &&
220 greater != NULL) 221 greater != NULL)
221 { 222 {
222 // There is a range constraint: Apply it, as it is more efficient 223 // There is a range constraint: Apply it, as it is more efficient
223 ApplyIdentifierRange(candidates, database, *smaller, *greater, level); 224 ApplyIdentifierRange(candidates, compatibility, *smaller, *greater, level);
224 } 225 }
225 else 226 else
226 { 227 {
227 smaller = NULL; 228 smaller = NULL;
228 greater = NULL; 229 greater = NULL;
233 { 234 {
234 // Check to avoid applying twice the range constraint 235 // Check to avoid applying twice the range constraint
235 if (*it2 != smaller && 236 if (*it2 != smaller &&
236 *it2 != greater) 237 *it2 != greater)
237 { 238 {
238 ApplyIdentifierConstraint(candidates, database, **it2, level); 239 ApplyIdentifierConstraint(candidates, compatibility, **it2, level);
239 } 240 }
240 } 241 }
241 } 242 }
242 243
243 244
255 assert(*it != NULL); 256 assert(*it != NULL);
256 c.Add(**it); 257 c.Add(**it);
257 } 258 }
258 259
259 std::list<int64_t> source; 260 std::list<int64_t> source;
260 candidates.Flatten(source); 261 candidates.Flatten(compatibility, source);
261 candidates.Clear(); 262 candidates.Clear();
262 263
263 std::list<int64_t> filtered; 264 std::list<int64_t> filtered;
264 for (std::list<int64_t>::const_iterator candidate = source.begin(); 265 for (std::list<int64_t>::const_iterator candidate = source.begin();
265 candidate != source.end(); ++candidate) 266 candidate != source.end(); ++candidate)
287 candidates.Intersect(filtered); 288 candidates.Intersect(filtered);
288 } 289 }
289 } 290 }
290 291
291 292
292 static std::string GetOneInstance(IDatabaseWrapper& database, 293 static std::string GetOneInstance(IDatabaseWrapper& compatibility,
293 int64_t resource, 294 int64_t resource,
294 ResourceType level) 295 ResourceType level)
295 { 296 {
296 for (int i = level; i < ResourceType_Instance; i++) 297 for (int i = level; i < ResourceType_Instance; i++)
297 { 298 {
298 assert(database.GetResourceType(resource) == static_cast<ResourceType>(i)); 299 assert(compatibility.GetResourceType(resource) == static_cast<ResourceType>(i));
299 300
300 std::list<int64_t> children; 301 std::list<int64_t> children;
301 database.GetChildrenInternalId(children, resource); 302 compatibility.GetChildrenInternalId(children, resource);
302 303
303 if (children.empty()) 304 if (children.empty())
304 { 305 {
305 throw OrthancException(ErrorCode_Database); 306 throw OrthancException(ErrorCode_Database);
306 } 307 }
307 308
308 resource = children.front(); 309 resource = children.front();
309 } 310 }
310 311
311 return database.GetPublicId(resource); 312 return compatibility.GetPublicId(resource);
312 } 313 }
313 314
314 315
315 void DatabaseLookup::ApplyLookupResources(std::list<std::string>& resourcesId, 316 void DatabaseLookup::ApplyLookupResources(std::list<std::string>& resourcesId,
316 std::list<std::string>* instancesId, 317 std::list<std::string>* instancesId,
348 349
349 SetOfResources candidates(database_, upperLevel); 350 SetOfResources candidates(database_, upperLevel);
350 351
351 for (int level = upperLevel; level <= lowerLevel; level++) 352 for (int level = upperLevel; level <= lowerLevel; level++)
352 { 353 {
353 ApplyLevel(candidates, database_, lookup, static_cast<ResourceType>(level)); 354 ApplyLevel(candidates, database_, compatibility_, lookup, static_cast<ResourceType>(level));
354 355
355 if (level != lowerLevel) 356 if (level != lowerLevel)
356 { 357 {
357 candidates.GoDown(); 358 candidates.GoDown();
358 } 359 }
359 } 360 }
360 361
361 std::list<int64_t> resources; 362 std::list<int64_t> resources;
362 candidates.Flatten(resources); 363 candidates.Flatten(compatibility_, resources);
363 364
364 // Climb up, up to queryLevel 365 // Climb up, up to queryLevel
365 366
366 for (int level = lowerLevel; level > queryLevel; level--) 367 for (int level = lowerLevel; level > queryLevel; level--)
367 { 368 {