Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 5750:f39406a9eda4 find-refactoring
ExtendedFind in SQLite continued (6 tests still failing)
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 03 Sep 2024 09:34:41 +0200 |
parents | 4bc650d88463 |
children | 5d78e5cafabc |
comparison
equal
deleted
inserted
replaced
5749:3cee66f96e2e | 5750:f39406a9eda4 |
---|---|
427 static_cast<uint16_t>(s.ColumnInt(2)), | 427 static_cast<uint16_t>(s.ColumnInt(2)), |
428 s.ColumnString(3)); | 428 s.ColumnString(3)); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 // need MainDicomTags from parent | |
433 if (request.GetLevel() > ResourceType_Patient && request.GetParentSpecification(static_cast<ResourceType>(request.GetLevel() - 1)).IsRetrieveMainDicomTags()) | |
434 { | |
435 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value " | |
436 "FROM MainDicomTags " | |
437 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId " | |
438 "INNER JOIN Lookup ON MainDicomTags.id = currentLevel.parentId"; | |
439 | |
440 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
441 while (s.Step()) | |
442 { | |
443 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
444 res.AddStringDicomTag(static_cast<ResourceType>(request.GetLevel() - 1), | |
445 static_cast<uint16_t>(s.ColumnInt(1)), | |
446 static_cast<uint16_t>(s.ColumnInt(2)), | |
447 s.ColumnString(3)); | |
448 } | |
449 } | |
450 | |
451 // need MainDicomTags from grandparent | |
452 if (request.GetLevel() > ResourceType_Study && request.GetParentSpecification(static_cast<ResourceType>(request.GetLevel() - 2)).IsRetrieveMainDicomTags()) | |
453 { | |
454 sql = "SELECT currentLevel.internalId, tagGroup, tagElement, value " | |
455 "FROM MainDicomTags " | |
456 "INNER JOIN Resources currentLevel ON Lookup.internalId = currentLevel.internalId " | |
457 "INNER JOIN Resources parentLevel ON currentLevel.parentId = parentLevel.internalId " | |
458 "INNER JOIN Lookup ON MainDicomTags.id = parentLevel.parentId"; | |
459 | |
460 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
461 while (s.Step()) | |
462 { | |
463 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
464 res.AddStringDicomTag(static_cast<ResourceType>(request.GetLevel() - 2), | |
465 static_cast<uint16_t>(s.ColumnInt(1)), | |
466 static_cast<uint16_t>(s.ColumnInt(2)), | |
467 s.ColumnString(3)); | |
468 } | |
469 } | |
470 | |
471 // need MainDicomTags from children | |
472 if (request.GetLevel() <= ResourceType_Series && request.GetChildrenSpecification(static_cast<ResourceType>(request.GetLevel() + 1)).GetMainDicomTags().size() > 0) | |
473 { | |
474 sql = "SELECT Lookup.internalId, tagGroup, tagElement, value " | |
475 "FROM MainDicomTags " | |
476 "INNER JOIN Resources childLevel ON childLevel.parentId = Lookup.internalId " | |
477 "INNER JOIN Lookup ON MainDicomTags.id = childLevel.internalId "; | |
478 | |
479 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
480 while (s.Step()) | |
481 { | |
482 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
483 res.AddChildrenMainDicomTagValue(static_cast<ResourceType>(request.GetLevel() + 1), | |
484 DicomTag(static_cast<uint16_t>(s.ColumnInt(1)), | |
485 static_cast<uint16_t>(s.ColumnInt(2))), | |
486 s.ColumnString(3)); | |
487 } | |
488 } | |
489 | |
490 // need MainDicomTags from grandchildren | |
491 if (request.GetLevel() <= ResourceType_Study && request.GetChildrenSpecification(static_cast<ResourceType>(request.GetLevel() + 2)).GetMainDicomTags().size() > 0) | |
492 { | |
493 sql = "SELECT Lookup.internalId, tagGroup, tagElement, value " | |
494 "FROM MainDicomTags " | |
495 "INNER JOIN Resources childLevel ON childLevel.parentId = Lookup.internalId " | |
496 "INNER JOIN Resources grandChildLevel ON childLevel.parentId = Lookup.internalId " | |
497 "INNER JOIN Lookup ON MainDicomTags.id = grandChildLevel.internalId "; | |
498 | |
499 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
500 while (s.Step()) | |
501 { | |
502 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
503 res.AddChildrenMainDicomTagValue(static_cast<ResourceType>(request.GetLevel() + 2), | |
504 DicomTag(static_cast<uint16_t>(s.ColumnInt(1)), | |
505 static_cast<uint16_t>(s.ColumnInt(2))), | |
506 s.ColumnString(3)); | |
507 } | |
508 } | |
509 | |
432 if (request.IsRetrieveParentIdentifier()) | 510 if (request.IsRetrieveParentIdentifier()) |
433 { | 511 { |
434 sql = "SELECT currentLevel.internalId, parentLevel.publicId " | 512 sql = "SELECT currentLevel.internalId, parentLevel.publicId " |
435 "FROM Resources AS currentLevel " | 513 "FROM Resources AS currentLevel " |
436 "INNER JOIN Lookup ON currentLevel.internalId = Lookup.internalId " | 514 "INNER JOIN Lookup ON currentLevel.internalId = Lookup.internalId " |
469 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | 547 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); |
470 while (s.Step()) | 548 while (s.Step()) |
471 { | 549 { |
472 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | 550 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); |
473 res.AddLabel(s.ColumnString(1)); | 551 res.AddLabel(s.ColumnString(1)); |
552 } | |
553 } | |
554 | |
555 if (request.IsRetrieveOneInstanceIdentifier()) | |
556 { | |
557 if (request.GetLevel() == ResourceType_Series) | |
558 { | |
559 sql = "SELECT Lookup.internalId, childLevel.publicId " | |
560 "FROM Resources AS childLevel " | |
561 "INNER JOIN Lookup ON childLevel.parentId = Lookup.internalId "; | |
562 | |
563 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
564 while (s.Step()) | |
565 { | |
566 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
567 res.AddChildIdentifier(ResourceType_Instance, s.ColumnString(1)); | |
568 } | |
569 } | |
570 else if (request.GetLevel() == ResourceType_Study) | |
571 { | |
572 sql = "SELECT Lookup.internalId, grandChildLevel.publicId " | |
573 "FROM Resources AS grandChildLevel " | |
574 "INNER JOIN Resources childLevel ON grandChildLevel.parentId = childLevel.internalId " | |
575 "INNER JOIN Lookup ON childLevel.parentId = Lookup.internalId "; | |
576 | |
577 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
578 while (s.Step()) | |
579 { | |
580 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
581 res.AddChildIdentifier(ResourceType_Instance, s.ColumnString(1)); | |
582 } | |
583 } | |
584 else if (request.GetLevel() == ResourceType_Patient) | |
585 { | |
586 sql = "SELECT Lookup.internalId, grandGrandChildLevel.publicId " | |
587 "FROM Resources AS grandGrandChildLevel " | |
588 "INNER JOIN Resources grandChildLevel ON grandGrandChildLevel.parentId = grandChildLevel.internalId " | |
589 "INNER JOIN Resources childLevel ON grandChildLevel.parentId = childLevel.internalId " | |
590 "INNER JOIN Lookup ON childLevel.parentId = Lookup.internalId "; | |
591 | |
592 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
593 while (s.Step()) | |
594 { | |
595 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
596 res.AddChildIdentifier(ResourceType_Instance, s.ColumnString(1)); | |
597 } | |
598 } | |
599 else | |
600 { | |
601 throw OrthancException(ErrorCode_InternalError); | |
474 } | 602 } |
475 } | 603 } |
476 | 604 |
477 if (request.GetLevel() <= ResourceType_Series && request.GetChildrenSpecification(static_cast<ResourceType>(request.GetLevel() + 1)).IsRetrieveIdentifiers()) | 605 if (request.GetLevel() <= ResourceType_Series && request.GetChildrenSpecification(static_cast<ResourceType>(request.GetLevel() + 1)).IsRetrieveIdentifiers()) |
478 { | 606 { |
501 while (s.Step()) | 629 while (s.Step()) |
502 { | 630 { |
503 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | 631 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); |
504 res.AddChildIdentifier(static_cast<ResourceType>(request.GetLevel() + 2), s.ColumnString(1)); | 632 res.AddChildIdentifier(static_cast<ResourceType>(request.GetLevel() + 2), s.ColumnString(1)); |
505 } | 633 } |
634 } | |
635 | |
636 if (request.IsRetrieveAttachments()) | |
637 { | |
638 sql = "SELECT id, fileType, uuid, uncompressedSize, compressedSize, compressionType, uncompressedMD5, compressedMD5 " | |
639 "FROM AttachedFiles " | |
640 "INNER JOIN Lookup ON AttachedFiles.id = Lookup.internalId"; | |
641 | |
642 SQLite::Statement s(db_, SQLITE_FROM_HERE, sql); | |
643 while (s.Step()) | |
644 { | |
645 FindResponse::Resource& res = response.GetResourceByInternalId(s.ColumnInt64(0)); | |
646 FileInfo file(s.ColumnString(2), static_cast<FileContentType>(s.ColumnInt(1)), | |
647 s.ColumnInt64(3), s.ColumnString(6), | |
648 static_cast<CompressionType>(s.ColumnInt(5)), | |
649 s.ColumnInt64(4), s.ColumnString(7)); | |
650 res.AddAttachment(file); | |
651 } | |
652 | |
506 } | 653 } |
507 } | 654 } |
508 | 655 |
509 | 656 |
510 | 657 |