# HG changeset patch # User Alain Mazy # Date 1734368951 -3600 # Node ID 892ee42584bb4f588f00d831c177dbe9898b8e39 # Parent 25d265a1a029149e321910d8bfa28fa8129f3194# Parent 8a500c0defbfce190fe55e388ae67cbd8b554026 merge diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp --- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Dec 16 18:09:11 2024 +0100 @@ -266,6 +266,24 @@ default: throw OrthancException(ErrorCode_ParameterOutOfRange); } + + switch (source.GetCast()) + { + case FindRequest::OrderingCast_Int: + target.set_cast(DatabasePluginMessages::ORDERING_CAST_INT); + break; + + case FindRequest::OrderingCast_Float: + target.set_cast(DatabasePluginMessages::ORDERING_CAST_FLOAT); + break; + + case FindRequest::OrderingCast_String: + target.set_cast(DatabasePluginMessages::ORDERING_CAST_STRING); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } } static DatabasePluginMessages::LabelsConstraintType Convert(LabelsConstraint constraint) diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto --- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Dec 16 18:09:11 2024 +0100 @@ -88,6 +88,12 @@ ORDERING_DIRECTION_DESC = 1; } +enum OrderingCast { + ORDERING_CAST_STRING = 0; + ORDERING_CAST_INT = 1; + ORDERING_CAST_FLOAT = 2; +} + message ServerIndexChange { int64 seq = 1; int32 change_type = 2; // opaque "ChangeType" in Orthanc @@ -882,11 +888,12 @@ message Ordering { OrderingKeyType key_type = 1; OrderingDirection direction = 2; - uint32 tag_group = 3; - uint32 tag_element = 4; - bool is_identifier_tag = 5; - ResourceType tag_level = 6; - int32 metadata = 7; + OrderingCast cast = 3; + uint32 tag_group = 4; + uint32 tag_element = 5; + bool is_identifier_tag = 6; + ResourceType tag_level = 7; + int32 metadata = 8; } // Part 1 of the request: Constraints diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Sources/Database/FindRequest.cpp --- a/OrthancServer/Sources/Database/FindRequest.cpp Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Sources/Database/FindRequest.cpp Mon Dec 16 18:09:11 2024 +0100 @@ -226,16 +226,18 @@ void FindRequest::AddOrdering(const DicomTag& tag, + OrderingCast cast, OrderingDirection direction) { - ordering_.push_back(new Ordering(Key(tag), direction)); + ordering_.push_back(new Ordering(Key(tag), cast, direction)); } void FindRequest::AddOrdering(MetadataType metadataType, + OrderingCast cast, OrderingDirection direction) { - ordering_.push_back(new Ordering(Key(metadataType), direction)); + ordering_.push_back(new Ordering(Key(metadataType), cast, direction)); } diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Sources/Database/FindRequest.h --- a/OrthancServer/Sources/Database/FindRequest.h Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Sources/Database/FindRequest.h Mon Dec 16 18:09:11 2024 +0100 @@ -57,6 +57,12 @@ OrderingDirection_Descending }; + enum OrderingCast + { + OrderingCast_String, + OrderingCast_Int, + OrderingCast_Float + }; class Key { @@ -107,12 +113,15 @@ { private: OrderingDirection direction_; + OrderingCast cast_; Key key_; public: Ordering(const Key& key, + OrderingCast cast, OrderingDirection direction) : direction_(direction), + cast_(cast), key_(key) { } @@ -127,6 +136,11 @@ return direction_; } + OrderingCast GetCast() const + { + return cast_; + } + MetadataType GetMetadataType() const { return key_.GetMetadataType(); @@ -330,9 +344,11 @@ uint64_t GetLimitsCount() const; void AddOrdering(const DicomTag& tag, + OrderingCast cast, OrderingDirection direction); void AddOrdering(MetadataType metadataType, + OrderingCast cast, OrderingDirection direction); const std::deque& GetOrdering() const diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Mon Dec 16 18:09:11 2024 +0100 @@ -3499,19 +3499,43 @@ } Toolbox::ToLowerCase(typeString, order[KEY_ORDER_BY_TYPE].asString()); - if (typeString == "dicomtag") + if (Toolbox::StartsWith(typeString, "dicomtag")) { DicomTag tag = FromDcmtkBridge::ParseTag(order[KEY_ORDER_BY_KEY].asString()); - finder.AddOrdering(tag, direction); + + if (typeString == "dicomtagasint") + { + finder.AddOrdering(tag, FindRequest::OrderingCast_Int, direction); + } + else if (typeString == "dicomtagasfloat") + { + finder.AddOrdering(tag, FindRequest::OrderingCast_Float, direction); + } + else + { + finder.AddOrdering(tag, FindRequest::OrderingCast_String, direction); + } } - else if (typeString == "metadata") + else if (Toolbox::StartsWith(typeString, "metadata")) { MetadataType metadata = StringToMetadata(order[KEY_ORDER_BY_KEY].asString()); - finder.AddOrdering(metadata, direction); + + if (typeString == "metadataasint") + { + finder.AddOrdering(metadata, FindRequest::OrderingCast_Int, direction); + } + else if (typeString == "dicomtagasfloat") + { + finder.AddOrdering(metadata, FindRequest::OrderingCast_Float, direction); + } + else + { + finder.AddOrdering(metadata, FindRequest::OrderingCast_String, direction); + } } else { - throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\" or \"Metadata\""); + throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\", \"DicomTagAsInt\", \"DicomTagAsFloat\" or \"Metadata\", \"MetadataAsInt\", \"MetadataAsFloat\""); } } } diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Sources/ResourceFinder.h --- a/OrthancServer/Sources/ResourceFinder.h Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Sources/ResourceFinder.h Mon Dec 16 18:09:11 2024 +0100 @@ -127,15 +127,17 @@ void AddRequestedTags(const std::set& tags); void AddOrdering(const DicomTag& tag, + FindRequest::OrderingCast cast, FindRequest::OrderingDirection direction) { - request_.AddOrdering(tag, direction); + request_.AddOrdering(tag, cast, direction); } void AddOrdering(MetadataType metadataType, + FindRequest::OrderingCast cast, FindRequest::OrderingDirection direction) { - request_.AddOrdering(metadataType, direction); + request_.AddOrdering(metadataType, cast, direction); } void AddMetadataConstraint(DatabaseMetadataConstraint* constraint) diff -r 8a500c0defbf -r 892ee42584bb OrthancServer/Sources/Search/ISqlLookupFormatter.cpp --- a/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp Mon Dec 16 17:53:44 2024 +0100 +++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp Mon Dec 16 18:09:11 2024 +0100 @@ -766,7 +766,17 @@ // first filter by 0/1 and then by the column value itself orderByField += "order" + boost::lexical_cast(counter) + ".value IS NULL, "; #endif - orderByField += "order" + boost::lexical_cast(counter) + ".value"; + switch ((*it)->GetCast()) + { + case FindRequest::OrderingCast_Int: + orderByField += "CAST(order" + boost::lexical_cast(counter) + ".value AS INTEGER)"; + break; + case FindRequest::OrderingCast_Float: + orderByField += "CAST(order" + boost::lexical_cast(counter) + ".value AS REAL)"; + break; + default: + orderByField += "order" + boost::lexical_cast(counter) + ".value"; + } if ((*it)->GetDirection() == FindRequest::OrderingDirection_Ascending) {