comparison OrthancServer/Sources/ResourceFinder.cpp @ 5789:40ad08b75d84 find-refactoring

cleanup + W005
author Alain Mazy <am@orthanc.team>
date Tue, 17 Sep 2024 17:16:42 +0200
parents 61c9e5df64d7
children a3d283f61304
comparison
equal deleted inserted replaced
5788:61c9e5df64d7 5789:40ad08b75d84
482 hasLimitsCount_(false), 482 hasLimitsCount_(false),
483 limitsSince_(0), 483 limitsSince_(0),
484 limitsCount_(0), 484 limitsCount_(0),
485 expand_(expand), 485 expand_(expand),
486 allowStorageAccess_(true), 486 allowStorageAccess_(true),
487 hasRequestedTags_(false) 487 isWarning002Enabled_(false),
488 { 488 isWarning004Enabled_(false),
489 isWarning005Enabled_(false)
490 {
491 {
492 OrthancConfiguration::ReaderLock lock;
493 isWarning002Enabled_ = lock.GetConfiguration().IsWarningEnabled(Warnings_002_InconsistentDicomTagsInDb);
494 isWarning004Enabled_ = lock.GetConfiguration().IsWarningEnabled(Warnings_004_NoMainDicomTagsSignature);
495 isWarning005Enabled_ = lock.GetConfiguration().IsWarningEnabled(Warnings_005_RequestingTagFromLowerResourceLevel);
496 }
497
498
489 UpdateRequestLimits(); 499 UpdateRequestLimits();
490 500
491 if (expand) 501 if (expand)
492 { 502 {
493 request_.SetRetrieveMainDicomTags(true); 503 request_.SetRetrieveMainDicomTags(true);
619 629
620 630
621 void ResourceFinder::AddRequestedTag(const DicomTag& tag) 631 void ResourceFinder::AddRequestedTag(const DicomTag& tag)
622 { 632 {
623 requestedTags_.insert(tag); 633 requestedTags_.insert(tag);
624 hasRequestedTags_ = true;
625 634
626 if (DicomMap::IsMainDicomTag(tag, ResourceType_Patient)) 635 if (DicomMap::IsMainDicomTag(tag, ResourceType_Patient))
627 { 636 {
628 if (request_.GetLevel() == ResourceType_Patient) 637 if (request_.GetLevel() == ResourceType_Patient)
629 { 638 {
630 request_.SetRetrieveMainDicomTags(true); 639 request_.SetRetrieveMainDicomTags(true);
631 requestedPatientTags_.insert(tag);
632 } 640 }
633 else 641 else
634 { 642 {
635 /** 643 /**
636 * This comes from the fact that patient-level tags are copied 644 * This comes from the fact that patient-level tags are copied
637 * at the study level, as implemented by "ResourcesContent::AddResource()". 645 * at the study level, as implemented by "ResourcesContent::AddResource()".
638 **/ 646 **/
639 requestedStudyTags_.insert(tag);
640
641 if (request_.GetLevel() == ResourceType_Study) 647 if (request_.GetLevel() == ResourceType_Study)
642 { 648 {
643 request_.SetRetrieveMainDicomTags(true); 649 request_.SetRetrieveMainDicomTags(true);
644 } 650 }
645 else 651 else
650 } 656 }
651 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Study)) 657 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Study))
652 { 658 {
653 if (request_.GetLevel() == ResourceType_Patient) 659 if (request_.GetLevel() == ResourceType_Patient)
654 { 660 {
655 LOG(WARNING) << "Requested tag " << tag.Format() 661 if (isWarning005Enabled_)
656 << " should only be read at the study, series, or instance level"; 662 {
663 LOG(WARNING) << "W005: Requested tag " << tag.Format()
664 << " should only be read at the study, series, or instance level";
665 }
657 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance 666 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance
658 } 667 }
659 else 668 else
660 { 669 {
661 if (request_.GetLevel() == ResourceType_Study) 670 if (request_.GetLevel() == ResourceType_Study)
664 } 673 }
665 else 674 else
666 { 675 {
667 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true); 676 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true);
668 } 677 }
669
670 requestedStudyTags_.insert(tag);
671 } 678 }
672 } 679 }
673 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Series)) 680 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Series))
674 { 681 {
675 if (request_.GetLevel() == ResourceType_Patient || 682 if (request_.GetLevel() == ResourceType_Patient ||
676 request_.GetLevel() == ResourceType_Study) 683 request_.GetLevel() == ResourceType_Study)
677 { 684 {
678 LOG(WARNING) << "Requested tag " << tag.Format() 685 if (isWarning005Enabled_)
679 << " should only be read at the series or instance level"; 686 {
687 LOG(WARNING) << "W005: Requested tag " << tag.Format()
688 << " should only be read at the series or instance level";
689 }
680 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance 690 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance
681 } 691 }
682 else 692 else
683 { 693 {
684 if (request_.GetLevel() == ResourceType_Series) 694 if (request_.GetLevel() == ResourceType_Series)
687 } 697 }
688 else 698 else
689 { 699 {
690 request_.GetParentSpecification(ResourceType_Series).SetRetrieveMainDicomTags(true); 700 request_.GetParentSpecification(ResourceType_Series).SetRetrieveMainDicomTags(true);
691 } 701 }
692
693 requestedSeriesTags_.insert(tag);
694 } 702 }
695 } 703 }
696 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Instance)) 704 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Instance))
697 { 705 {
698 if (request_.GetLevel() == ResourceType_Patient || 706 if (request_.GetLevel() == ResourceType_Patient ||
699 request_.GetLevel() == ResourceType_Study || 707 request_.GetLevel() == ResourceType_Study ||
700 request_.GetLevel() == ResourceType_Series) 708 request_.GetLevel() == ResourceType_Series)
701 { 709 {
702 LOG(WARNING) << "Requested tag " << tag.Format() 710 if (isWarning005Enabled_)
703 << " should only be read at the instance level"; 711 {
712 LOG(WARNING) << "W005: Requested tag " << tag.Format()
713 << " should only be read at the instance level";
714 }
704 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance 715 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); // we might need to get it from one instance
705 } 716 }
706 else 717 else
707 { 718 {
708 request_.SetRetrieveMainDicomTags(true); 719 request_.SetRetrieveMainDicomTags(true);
709 requestedInstanceTags_.insert(tag);
710 } 720 }
711 } 721 }
712 else if (tag == DICOM_TAG_NUMBER_OF_PATIENT_RELATED_STUDIES) 722 else if (tag == DICOM_TAG_NUMBER_OF_PATIENT_RELATED_STUDIES)
713 { 723 {
714 ConfigureChildrenCountComputedTag(tag, ResourceType_Patient, ResourceType_Study); 724 ConfigureChildrenCountComputedTag(tag, ResourceType_Patient, ResourceType_Study);
755 requestedComputedTags_.insert(tag); 765 requestedComputedTags_.insert(tag);
756 } 766 }
757 else 767 else
758 { 768 {
759 // This is neither a main DICOM tag, nor a computed DICOM tag: 769 // This is neither a main DICOM tag, nor a computed DICOM tag:
760 // We might need to access the DICOM file 770 // We might need to access a DICOM file or the MainDicomSequences metadata
771
772 request_.SetRetrieveMetadata(true);
773
761 if (request_.GetLevel() != ResourceType_Instance) 774 if (request_.GetLevel() != ResourceType_Instance)
762 { 775 {
763 request_.SetRetrieveOneInstanceMetadataAndAttachments(true); 776 request_.SetRetrieveOneInstanceMetadataAndAttachments(true);
764 } 777 }
765 } 778 }
972 } 985 }
973 #endif 986 #endif
974 987
975 DicomMap outRequestedTags; 988 DicomMap outRequestedTags;
976 989
977 if (hasRequestedTags_) 990 if (HasRequestedTags())
978 { 991 {
979 std::set<DicomTag> remainingRequestedTags = requestedTags_; // at this point, all requested tags are "missing" 992 std::set<DicomTag> remainingRequestedTags = requestedTags_; // at this point, all requested tags are "missing"
980 993
981 InjectComputedTags(outRequestedTags, resource); 994 InjectComputedTags(outRequestedTags, resource);
982 Toolbox::RemoveSets(remainingRequestedTags, requestedComputedTags_); 995 Toolbox::RemoveSets(remainingRequestedTags, requestedComputedTags_);
983 996
984 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Patient /*, requestedPatientTags_*/); 997 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Patient);
985 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Study /*, requestedStudyTags_*/); 998 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Study);
986 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Series /*, requestedSeriesTags_*/); 999 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Series);
987 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Instance /*, requestedInstanceTags_*/); 1000 InjectRequestedTags(outRequestedTags, remainingRequestedTags, resource, ResourceType_Instance);
988 1001
989 if (!remainingRequestedTags.empty()) 1002 if (!remainingRequestedTags.empty())
990 { 1003 {
991 if (!allowStorageAccess_) 1004 if (!allowStorageAccess_)
992 { 1005 {
1003 if (isWarning002Enabled && 1016 if (isWarning002Enabled &&
1004 resource.LookupMetadata(mainDicomTagsSignature, resource.GetLevel(), MetadataType_MainDicomTagsSignature) && 1017 resource.LookupMetadata(mainDicomTagsSignature, resource.GetLevel(), MetadataType_MainDicomTagsSignature) &&
1005 mainDicomTagsSignature != DicomMap::GetMainDicomTagsSignature(resource.GetLevel())) 1018 mainDicomTagsSignature != DicomMap::GetMainDicomTagsSignature(resource.GetLevel()))
1006 { 1019 {
1007 LOG(WARNING) << "W002: " << Orthanc::GetResourceTypeText(resource.GetLevel(), false , false) 1020 LOG(WARNING) << "W002: " << Orthanc::GetResourceTypeText(resource.GetLevel(), false , false)
1008 << " has been stored with another version of Main Dicom Tags list, you should POST to /" 1021 << " has been stored with another version of Main Dicom Tags list, you should POST to /"
1009 << Orthanc::GetResourceTypeText(resource.GetLevel(), true, false) 1022 << Orthanc::GetResourceTypeText(resource.GetLevel(), true, false)
1010 << "/" << resource.GetIdentifier() 1023 << "/" << resource.GetIdentifier()
1011 << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin. Some MainDicomTags might be missing from this answer."; 1024 << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin. Some MainDicomTags might be missing from this answer.";
1012 } 1025 }
1013 else if (isWarning004Enabled && 1026 else if (isWarning004Enabled &&
1027 request_.IsRetrieveMetadata() &&
1014 !resource.LookupMetadata(mainDicomTagsSignature, resource.GetLevel(), MetadataType_MainDicomTagsSignature)) 1028 !resource.LookupMetadata(mainDicomTagsSignature, resource.GetLevel(), MetadataType_MainDicomTagsSignature))
1015 { 1029 {
1016 // LOG(WARNING) << "W004: " << Orthanc::GetResourceTypeText(resource.GetLevel(), false , false) 1030 LOG(WARNING) << "W004: " << Orthanc::GetResourceTypeText(resource.GetLevel(), false , false)
1017 // << " has been stored a while ago and does not have a MainDicomTagsSignature, you should POST to /" 1031 << " has been stored with an old Orthanc version and does not have a MainDicomTagsSignature, you should POST to /"
1018 // << Orthanc::GetResourceTypeText(resource.GetLevel(), true, false) 1032 << Orthanc::GetResourceTypeText(resource.GetLevel(), true, false)
1019 // << "/" << resource.GetIdentifier() 1033 << "/" << resource.GetIdentifier()
1020 // << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin. Some MainDicomTags might be missing from this answer."; 1034 << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin. Some MainDicomTags might be missing from this answer.";
1021 // TODO: sometimes, we do not read the metadata at all !
1022 } 1035 }
1023 1036
1024 } 1037 }
1025 1038
1026 bool match = true; 1039 bool match = true;
1128 } 1141 }
1129 }; 1142 };
1130 1143
1131 target = Json::arrayValue; 1144 target = Json::arrayValue;
1132 1145
1133 Visitor visitor(*this, context.GetIndex(), target, format, hasRequestedTags_, includeAllMetadata); 1146 Visitor visitor(*this, context.GetIndex(), target, format, HasRequestedTags(), includeAllMetadata);
1134 Execute(visitor, context); 1147 Execute(visitor, context);
1135 } 1148 }
1136 1149
1137 1150
1138 bool ResourceFinder::ExecuteOneResource(Json::Value& target, 1151 bool ResourceFinder::ExecuteOneResource(Json::Value& target,