comparison OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5667:93dff1fccf36 find-refactoring

recursive descent to the children
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jul 2024 21:31:48 +0200
parents aa231c18b9d2
children bd1352bd9d82
comparison
equal deleted inserted replaced
5666:aa231c18b9d2 5667:93dff1fccf36
238 { 238 {
239 case ResourceType_Patient: 239 case ResourceType_Patient:
240 return ResourceType_Patient; 240 return ResourceType_Patient;
241 241
242 case ResourceType_Study: 242 case ResourceType_Study:
243 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMainDicomTags() || 243 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsOfInterest())
244 request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMetadata())
245 { 244 {
246 return ResourceType_Patient; 245 return ResourceType_Patient;
247 } 246 }
248 else 247 else
249 { 248 {
250 return ResourceType_Study; 249 return ResourceType_Study;
251 } 250 }
252 251
253 case ResourceType_Series: 252 case ResourceType_Series:
254 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMainDicomTags() || 253 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsOfInterest())
255 request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMetadata())
256 { 254 {
257 return ResourceType_Patient; 255 return ResourceType_Patient;
258 } 256 }
259 else if (request.GetParentRetrieveSpecification(ResourceType_Study).IsRetrieveMainDicomTags() || 257 else if (request.GetParentRetrieveSpecification(ResourceType_Study).IsOfInterest())
260 request.GetParentRetrieveSpecification(ResourceType_Study).IsRetrieveMetadata())
261 { 258 {
262 return ResourceType_Study; 259 return ResourceType_Study;
263 } 260 }
264 else 261 else
265 { 262 {
266 return ResourceType_Series; 263 return ResourceType_Series;
267 } 264 }
268 265
269 case ResourceType_Instance: 266 case ResourceType_Instance:
270 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMainDicomTags() || 267 if (request.GetParentRetrieveSpecification(ResourceType_Patient).IsOfInterest())
271 request.GetParentRetrieveSpecification(ResourceType_Patient).IsRetrieveMetadata())
272 { 268 {
273 return ResourceType_Patient; 269 return ResourceType_Patient;
274 } 270 }
275 else if (request.GetParentRetrieveSpecification(ResourceType_Study).IsRetrieveMainDicomTags() || 271 else if (request.GetParentRetrieveSpecification(ResourceType_Study).IsOfInterest())
276 request.GetParentRetrieveSpecification(ResourceType_Study).IsRetrieveMetadata())
277 { 272 {
278 return ResourceType_Study; 273 return ResourceType_Study;
279 } 274 }
280 else if (request.GetParentRetrieveSpecification(ResourceType_Series).IsRetrieveMainDicomTags() || 275 else if (request.GetParentRetrieveSpecification(ResourceType_Series).IsOfInterest())
281 request.GetParentRetrieveSpecification(ResourceType_Series).IsRetrieveMetadata())
282 { 276 {
283 return ResourceType_Series; 277 return ResourceType_Series;
284 } 278 }
285 else 279 else
286 { 280 {
287 return ResourceType_Instance; 281 return ResourceType_Instance;
288 } 282 }
283
284 default:
285 throw OrthancException(ErrorCode_ParameterOutOfRange);
286 }
287 }
288
289
290 static ResourceType GetBottomLevelOfInterest(const FindRequest& request)
291 {
292 switch (request.GetLevel())
293 {
294 case ResourceType_Patient:
295 if (request.GetChildrenRetrieveSpecification(ResourceType_Instance).IsOfInterest())
296 {
297 return ResourceType_Instance;
298 }
299 else if (request.GetChildrenRetrieveSpecification(ResourceType_Series).IsOfInterest())
300 {
301 return ResourceType_Series;
302 }
303 else if (request.GetChildrenRetrieveSpecification(ResourceType_Study).IsOfInterest())
304 {
305 return ResourceType_Study;
306 }
307 else
308 {
309 return ResourceType_Patient;
310 }
311
312 case ResourceType_Study:
313 if (request.GetChildrenRetrieveSpecification(ResourceType_Instance).IsOfInterest())
314 {
315 return ResourceType_Instance;
316 }
317 else if (request.GetChildrenRetrieveSpecification(ResourceType_Series).IsOfInterest())
318 {
319 return ResourceType_Series;
320 }
321 else
322 {
323 return ResourceType_Study;
324 }
325
326 case ResourceType_Series:
327 if (request.GetChildrenRetrieveSpecification(ResourceType_Instance).IsOfInterest())
328 {
329 return ResourceType_Instance;
330 }
331 else
332 {
333 return ResourceType_Series;
334 }
335
336 case ResourceType_Instance:
337 return ResourceType_Instance;
289 338
290 default: 339 default:
291 throw OrthancException(ErrorCode_ParameterOutOfRange); 340 throw OrthancException(ErrorCode_ParameterOutOfRange);
292 } 341 }
293 } 342 }
409 throw OrthancException(ErrorCode_DatabasePlugin); 458 throw OrthancException(ErrorCode_DatabasePlugin);
410 } 459 }
411 } 460 }
412 } 461 }
413 462
414 if (request.GetLevel() != ResourceType_Instance) 463 {
415 { 464 const ResourceType bottomLevel = GetBottomLevelOfInterest(request);
416 // TODO-FIND: Retrieve other levels than immediate children 465
417 const ResourceType childLevel = GetChildResourceType(request.GetLevel()); 466 std::list<int64_t> currentIds;
418 467 currentIds.push_back(internalId);
419 if (request.GetChildrenRetrieveSpecification(childLevel).IsRetrieveIdentifiers()) 468
420 { 469 ResourceType currentLevel = level;
421 std::list<std::string> children; 470
422 transaction_.GetChildrenPublicId(children, internalId); 471 while (currentLevel != bottomLevel)
423 472 {
424 for (std::list<std::string>::const_iterator it = children.begin(); it != children.end(); ++it) 473 ResourceType childrenLevel = GetChildResourceType(currentLevel);
425 { 474
426 resource->AddChildIdentifier(childLevel, *it); 475 if (request.GetChildrenRetrieveSpecification(childrenLevel).IsRetrieveIdentifiers())
427 } 476 {
477 for (std::list<int64_t>::const_iterator it = currentIds.begin();
478 it != currentIds.end(); ++it)
479 {
480 std::list<std::string> ids;
481 transaction_.GetChildrenPublicId(ids, *it);
482
483 for (std::list<std::string>::const_iterator it2 = ids.begin(); it2 != ids.end(); ++it2)
484 {
485 resource->AddChildIdentifier(childrenLevel, *it2);
486 }
487 }
488 }
489
490 if (childrenLevel != bottomLevel)
491 {
492 std::list<int64_t> childrenIds;
493
494 for (std::list<int64_t>::const_iterator it = currentIds.begin(); it != currentIds.end(); ++it)
495 {
496 std::list<int64_t> tmp;
497 transaction_.GetChildrenInternalId(tmp, *it);
498
499 childrenIds.splice(childrenIds.end(), tmp);
500 }
501
502 currentIds = childrenIds;
503 }
504 else
505 {
506 currentIds.clear();
507 }
508
509 currentLevel = childrenLevel;
428 } 510 }
429 } 511 }
430 512
431 for (std::set<MetadataType>::const_iterator it = request.GetRetrieveChildrenMetadata().begin(); 513 for (std::set<MetadataType>::const_iterator it = request.GetRetrieveChildrenMetadata().begin();
432 it != request.GetRetrieveChildrenMetadata().end(); ++it) 514 it != request.GetRetrieveChildrenMetadata().end(); ++it)