comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 5790:a3d283f61304 find-refactoring

improved handling of DicomSequences in parent
author Alain Mazy <am@orthanc.team>
date Wed, 18 Sep 2024 09:34:52 +0200
parents f1ccb67fce31
children 16ce3c920f71
comparison
equal deleted inserted replaced
5789:40ad08b75d84 5790:a3d283f61304
467 static_cast<uint16_t>(s.ColumnInt(2)), 467 static_cast<uint16_t>(s.ColumnInt(2)),
468 s.ColumnString(3)); 468 s.ColumnString(3));
469 } 469 }
470 } 470 }
471 471
472 // need MainDicomTags from parent ? 472
473 if (requestLevel > ResourceType_Patient && request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 1)).IsRetrieveMainDicomTags()) 473 if (requestLevel > ResourceType_Patient)
474 { 474 {
475 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value " 475 // need MainDicomTags from parent ?
476 "FROM MainDicomTags " 476 if (request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 1)).IsRetrieveMainDicomTags())
477 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId " 477 {
478 "INNER JOIN Lookup ON MainDicomTags.id = currentLevel.parentId"; 478 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value "
479 479 "FROM MainDicomTags "
480 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); 480 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId "
481 while (s.Step()) 481 "INNER JOIN Lookup ON MainDicomTags.id = currentLevel.parentId";
482 { 482
483 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); 483 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql);
484 res.AddStringDicomTag(static_cast<ResourceType>(requestLevel - 1), 484 while (s.Step())
485 static_cast<uint16_t>(s.ColumnInt(1)), 485 {
486 static_cast<uint16_t>(s.ColumnInt(2)), 486 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0));
487 s.ColumnString(3)); 487 res.AddStringDicomTag(static_cast<ResourceType>(requestLevel - 1),
488 } 488 static_cast<uint16_t>(s.ColumnInt(1)),
489 } 489 static_cast<uint16_t>(s.ColumnInt(2)),
490 490 s.ColumnString(3));
491 // need MainDicomTags from grandparent ? 491 }
492 if (requestLevel > ResourceType_Study && request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 2)).IsRetrieveMainDicomTags()) 492 }
493 { 493
494 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value " 494 // need metadata from parent ?
495 "FROM MainDicomTags " 495 if (request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 1)).IsRetrieveMetadata())
496 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId " 496 {
497 "INNER JOIN Resources parentLevel ON currentLevel.parentId = parentLevel.internalId " 497 sql = "SELECT currentLevel.internalId, type, value "
498 "INNER JOIN Lookup ON MainDicomTags.id = parentLevel.parentId"; 498 "FROM Metadata "
499 499 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId "
500 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); 500 "INNER JOIN Lookup ON Metadata.id = currentLevel.parentId";
501 while (s.Step()) 501
502 { 502 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql);
503 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); 503 while (s.Step())
504 res.AddStringDicomTag(static_cast<ResourceType>(requestLevel - 2), 504 {
505 static_cast<uint16_t>(s.ColumnInt(1)), 505 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0));
506 static_cast<uint16_t>(s.ColumnInt(2)), 506 res.AddMetadata(static_cast<ResourceType>(requestLevel - 1),
507 s.ColumnString(3)); 507 static_cast<MetadataType>(s.ColumnInt(1)),
508 s.ColumnString(2));
509 }
510 }
511 }
512
513 if (requestLevel > ResourceType_Study)
514 {
515 // need MainDicomTags from grandparent ?
516 if (request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 2)).IsRetrieveMainDicomTags())
517 {
518 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value "
519 "FROM MainDicomTags "
520 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId "
521 "INNER JOIN Resources parentLevel ON currentLevel.parentId = parentLevel.internalId "
522 "INNER JOIN Lookup ON MainDicomTags.id = parentLevel.parentId";
523
524 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql);
525 while (s.Step())
526 {
527 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0));
528 res.AddStringDicomTag(static_cast<ResourceType>(requestLevel - 2),
529 static_cast<uint16_t>(s.ColumnInt(1)),
530 static_cast<uint16_t>(s.ColumnInt(2)),
531 s.ColumnString(3));
532 }
533 }
534
535 // need metadata from grandparent ?
536 if (request.GetParentSpecification(static_cast<ResourceType>(requestLevel - 2)).IsRetrieveMetadata())
537 {
538 sql = "SELECT currentLevel.internalId, type, value "
539 "FROM Metadata "
540 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId "
541 "INNER JOIN Resources parentLevel ON currentLevel.parentId = parentLevel.internalId "
542 "INNER JOIN Lookup ON Metadata.id = parentLevel.parentId";
543
544 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql);
545 while (s.Step())
546 {
547 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0));
548 res.AddMetadata(static_cast<ResourceType>(requestLevel - 2),
549 static_cast<MetadataType>(s.ColumnInt(1)),
550 s.ColumnString(2));
551 }
508 } 552 }
509 } 553 }
510 554
511 // need MainDicomTags from children ? 555 // need MainDicomTags from children ?
512 if (requestLevel <= ResourceType_Series && request.GetChildrenSpecification(static_cast<ResourceType>(requestLevel + 1)).GetMainDicomTags().size() > 0) 556 if (requestLevel <= ResourceType_Series && request.GetChildrenSpecification(static_cast<ResourceType>(requestLevel + 1)).GetMainDicomTags().size() > 0)