comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5568:b0b5546f1b9f find-refactoring

find refactor: re-use existing code. /studies?expand is almost fully implemented with new code
author Alain Mazy <am@orthanc.team>
date Thu, 25 Apr 2024 09:22:07 +0200
parents 12d8a1a266e9
children 738f80622e91
comparison
equal deleted inserted replaced
5567:f3562c1a150d 5568:b0b5546f1b9f
497 } 497 }
498 498
499 target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type)); 499 target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type));
500 } 500 }
501 } 501 }
502 }
503
504 void StatelessDatabaseOperations::NormalizeLookup(std::vector<DatabaseConstraint>& target,
505 const FindRequest& findRequest) const
506 {
507 assert(mainDicomTagsRegistry_.get() != NULL);
508
509 target.clear();
510 target.reserve(findRequest.GetDicomTagConstraintsCount());
511
512 for (size_t i = 0; i < findRequest.GetDicomTagConstraintsCount(); i++)
513 {
514 ResourceType level;
515 DicomTagType type;
516
517 mainDicomTagsRegistry_->LookupTag(level, type, findRequest.GetDicomTagConstraint(i).GetTag());
518
519 if (type == DicomTagType_Identifier ||
520 type == DicomTagType_Main)
521 {
522 // Use the fact that patient-level tags are copied at the study level
523 if (level == ResourceType_Patient &&
524 findRequest.GetLevel() != ResourceType_Patient)
525 {
526 level = ResourceType_Study;
527 }
528
529 target.push_back(findRequest.GetDicomTagConstraint(i).ConvertToDatabaseConstraint(level, type));
530 }
531 }
532
533 // TODO-FIND: add metadata constraints
502 } 534 }
503 535
504 536
505 class StatelessDatabaseOperations::Transaction : public boost::noncopyable 537 class StatelessDatabaseOperations::Transaction : public boost::noncopyable
506 { 538 {
3778 3810
3779 3811
3780 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response, 3812 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response,
3781 const FindRequest& request) 3813 const FindRequest& request)
3782 { 3814 {
3783 class Operations : public ReadOnlyOperationsT2<FindResponse&, const FindRequest&> 3815 class Operations : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&, const std::vector<DatabaseConstraint>&>
3784 { 3816 {
3785 public: 3817 public:
3786 virtual void ApplyTuple(ReadOnlyTransaction& transaction, 3818 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
3787 const Tuple& tuple) ORTHANC_OVERRIDE 3819 const Tuple& tuple) ORTHANC_OVERRIDE
3788 { 3820 {
3789 transaction.ExecuteFind(tuple.get<0>(), tuple.get<1>()); 3821 transaction.ExecuteFind(tuple.get<0>(), tuple.get<1>(), tuple.get<2>());
3790 } 3822 }
3791 }; 3823 };
3824
3825 std::vector<DatabaseConstraint> normalized;
3826 NormalizeLookup(normalized, request);
3792 3827
3793 Operations operations; 3828 Operations operations;
3794 operations.Apply(*this, response, request); 3829 operations.Apply(*this, response, request, normalized);
3830 }
3831
3832 // TODO-FIND: we reuse the ExpandedResource class to reuse Serialization code from ExpandedResource
3833 // But, finally, we might just get rid of ExpandedResource and replace it by FindResponse
3834 ExpandedResource::ExpandedResource(const FindResponse::Item& item) :
3835 id_(item.GetResourceId()),
3836 level_(item.GetLevel()),
3837 isStable_(false),
3838 expectedNumberOfInstances_(0),
3839 fileSize_(0),
3840 indexInSeries_(0)
3841 {
3842 if (item.HasResponseContent(FindRequest::ResponseContent_MainDicomTags))
3843 {
3844 tags_.Assign(item.GetDicomMap());
3845 }
3846
3847 if (item.HasResponseContent(FindRequest::ResponseContent_Children))
3848 {
3849 childrenIds_ = item.GetChildren();
3850 }
3851
3852 if (item.HasResponseContent(FindRequest::ResponseContent_Parent))
3853 {
3854 parentId_ = item.GetParent();
3855 }
3856
3857 if (item.HasResponseContent(FindRequest::ResponseContent_Metadata))
3858 {
3859 metadata_ = item.GetMetadata();
3860 std::string value;
3861 if (item.LookupMetadata(value, MetadataType_MainDicomTagsSignature))
3862 {
3863 mainDicomTagsSignature_ = value;
3864 }
3865 if (item.LookupMetadata(value, MetadataType_AnonymizedFrom))
3866 {
3867 anonymizedFrom_ = value;
3868 }
3869 if (item.LookupMetadata(value, MetadataType_ModifiedFrom))
3870 {
3871 modifiedFrom_ = value;
3872 }
3873 if (item.LookupMetadata(value, MetadataType_LastUpdate))
3874 {
3875 lastUpdate_ = value;
3876 }
3877 if (item.GetLevel() == ResourceType_Series)
3878 {
3879 if (item.LookupMetadata(value, MetadataType_Series_ExpectedNumberOfInstances))
3880 {
3881 expectedNumberOfInstances_ = boost::lexical_cast<int>(value);
3882 }
3883 }
3884 if (item.GetLevel() == ResourceType_Instance)
3885 {
3886 if (item.LookupMetadata(value, MetadataType_Instance_IndexInSeries))
3887 {
3888 indexInSeries_ = boost::lexical_cast<int>(value);
3889 }
3890 }
3891 }
3892
3893 if (item.HasResponseContent(FindRequest::ResponseContent_Labels))
3894 {
3895 labels_ = item.GetLabels();
3896 }
3897 // TODO-FIND: continue: isStable_, satus_, fileSize_, fileUuid_
3795 } 3898 }
3796 } 3899 }