comparison OrthancServer/Sources/Database/FindResponse.cpp @ 5772:093a8693ba16 find-refactoring

replaced SetRetrieveOneInstanceIdentifier() by SetRetrieveOneInstanceMetadataAndAttachments()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Sep 2024 20:49:34 +0200
parents f39406a9eda4
children f96abfe08946
comparison
equal deleted inserted replaced
5771:4db9f897df58 5772:093a8693ba16
481 return false; 481 return false;
482 } 482 }
483 } 483 }
484 484
485 485
486 const std::string& FindResponse::Resource::GetOneInstanceIdentifier() const 486 void FindResponse::Resource::SetOneInstanceMetadataAndAttachments(const std::string& instancePublicId,
487 { 487 const std::map<MetadataType, std::string>& metadata,
488 const std::set<std::string>& instances = GetChildrenInformation(ResourceType_Instance).GetIdentifiers(); 488 const std::map<FileContentType, FileInfo>& attachments)
489 489 {
490 if (instances.size() == 0) 490 if (hasOneInstanceMetadataAndAttachments_)
491 { 491 {
492 throw OrthancException(ErrorCode_BadSequenceOfCalls); // HasOneInstanceIdentifier() should have been called 492 throw OrthancException(ErrorCode_BadSequenceOfCalls);
493 } 493 }
494 else 494 else if (instancePublicId.empty())
495 { 495 {
496 return *instances.begin(); 496 throw OrthancException(ErrorCode_ParameterOutOfRange);
497 }
498 else
499 {
500 hasOneInstanceMetadataAndAttachments_ = true;
501 oneInstancePublicId_ = instancePublicId;
502 oneInstanceMetadata_ = metadata;
503 oneInstanceAttachments_ = attachments;
504 }
505 }
506
507
508 const std::string& FindResponse::Resource::GetOneInstancePublicId() const
509 {
510 if (hasOneInstanceMetadataAndAttachments_)
511 {
512 return oneInstancePublicId_;
513 }
514 else
515 {
516 throw OrthancException(ErrorCode_BadSequenceOfCalls);
517 }
518 }
519
520
521 const std::map<MetadataType, std::string>& FindResponse::Resource::GetOneInstanceMetadata() const
522 {
523 if (hasOneInstanceMetadataAndAttachments_)
524 {
525 return oneInstanceMetadata_;
526 }
527 else
528 {
529 throw OrthancException(ErrorCode_BadSequenceOfCalls);
530 }
531 }
532
533
534 const std::map<FileContentType, FileInfo>& FindResponse::Resource::GetOneInstanceAttachments() const
535 {
536 if (hasOneInstanceMetadataAndAttachments_)
537 {
538 return oneInstanceAttachments_;
539 }
540 else
541 {
542 throw OrthancException(ErrorCode_BadSequenceOfCalls);
497 } 543 }
498 } 544 }
499 545
500 546
501 static void DebugDicomMap(Json::Value& target, 547 static void DebugDicomMap(Json::Value& target,
540 u.append(static_cast<Json::UInt64>(info.GetUncompressedSize())); 586 u.append(static_cast<Json::UInt64>(info.GetUncompressedSize()));
541 target[EnumerationToString(info.GetContentType())] = u; 587 target[EnumerationToString(info.GetContentType())] = u;
542 } 588 }
543 589
544 590
591 static void DebugAttachments(Json::Value& target,
592 const std::map<FileContentType, FileInfo>& attachments)
593 {
594 Json::Value v = Json::objectValue;
595 for (std::map<FileContentType, FileInfo>::const_iterator it = attachments.begin();
596 it != attachments.end(); ++it)
597 {
598 if (it->first != it->second.GetContentType())
599 {
600 throw OrthancException(ErrorCode_DatabasePlugin);
601 }
602 else
603 {
604 DebugAddAttachment(v, it->second);
605 }
606 }
607 }
608
609
545 static void DebugSetOfStrings(Json::Value& target, 610 static void DebugSetOfStrings(Json::Value& target,
546 const std::set<std::string>& values) 611 const std::set<std::string>& values)
547 { 612 {
548 target = Json::arrayValue; 613 target = Json::arrayValue;
549 for (std::set<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) 614 for (std::set<std::string>::const_iterator it = values.begin(); it != values.end(); ++it)
631 DebugSetOfStrings(target["Labels"], labels_); 696 DebugSetOfStrings(target["Labels"], labels_);
632 } 697 }
633 698
634 if (request.IsRetrieveAttachments()) 699 if (request.IsRetrieveAttachments())
635 { 700 {
636 Json::Value v = Json::objectValue; 701 DebugAttachments(target["Attachments"], attachments_);
637 for (std::map<FileContentType, FileInfo>::const_iterator it = attachments_.begin(); 702 }
638 it != attachments_.end(); ++it) 703
639 { 704 if (request.IsRetrieveOneInstanceMetadataAndAttachments())
640 if (it->first != it->second.GetContentType()) 705 {
641 { 706 DebugMetadata(target["OneInstance"]["Metadata"], GetOneInstanceMetadata());
642 throw OrthancException(ErrorCode_DatabasePlugin); 707 DebugAttachments(target["OneInstance"]["Attachments"], GetOneInstanceAttachments());
643 }
644 else
645 {
646 DebugAddAttachment(v, it->second);
647 }
648 }
649 target["Attachments"] = v;
650 }
651
652 if (request.IsRetrieveOneInstanceIdentifier())
653 {
654 target["OneInstance"] = GetOneInstanceIdentifier();
655 } 708 }
656 } 709 }
657 710
658 711
659 FindResponse::~FindResponse() 712 FindResponse::~FindResponse()