changeset 5934:892ee42584bb

merge
author Alain Mazy <am@orthanc.team>
date Mon, 16 Dec 2024 18:09:11 +0100
parents 25d265a1a029 (diff) 8a500c0defbf (current diff)
children 433e89edb3a0
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 7 files changed, 94 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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
--- 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));
   }
 
 
--- 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<Ordering*>& GetOrdering() const
--- 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\"");
               }
             }
           }
--- 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<DicomTag>& 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)
--- 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<std::string>(counter) + ".value IS NULL, ";
 #endif
-        orderByField += "order" + boost::lexical_cast<std::string>(counter) + ".value";
+        switch ((*it)->GetCast())
+        {
+          case FindRequest::OrderingCast_Int:
+            orderByField += "CAST(order" + boost::lexical_cast<std::string>(counter) + ".value AS INTEGER)";
+            break;
+          case FindRequest::OrderingCast_Float:
+            orderByField += "CAST(order" + boost::lexical_cast<std::string>(counter) + ".value AS REAL)";
+            break;
+          default:
+            orderByField += "order" + boost::lexical_cast<std::string>(counter) + ".value";
+        }
 
         if ((*it)->GetDirection() == FindRequest::OrderingDirection_Ascending)
         {