changeset 567:22bbce1f88ff find-refactoring

changes extended: support multiple filters
author Alain Mazy <am@orthanc.team>
date Mon, 23 Sep 2024 16:03:24 +0200
parents 3a83c434b284
children 77c8544bbd7d
files Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h
diffstat 4 files changed, 27 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Fri Sep 20 18:36:52 2024 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Mon Sep 23 16:03:24 2024 +0200
@@ -783,7 +783,13 @@
         Output output(*response.mutable_get_changes_extended());
 
         bool done;
-        backend.GetChangesExtended(output, done, manager, request.get_changes_extended().since(), request.get_changes_extended().to(), static_cast<OrthancPluginChangeType>(request.get_changes_extended().change_type()), request.get_changes_extended().limit());
+        std::set<uint32_t> changeTypes;
+        for (int i = 0; i < request.get_changes_extended().change_type_size(); ++i)
+        {
+          changeTypes.insert(request.get_changes_extended().change_type(i));
+        }
+
+        backend.GetChangesExtended(output, done, manager, request.get_changes_extended().since(), request.get_changes_extended().to(), changeTypes, request.get_changes_extended().limit());
 
         response.mutable_get_changes_extended()->set_done(done);
         break;
--- a/Framework/Plugins/IDatabaseBackend.h	Fri Sep 20 18:36:52 2024 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Mon Sep 23 16:03:24 2024 +0200
@@ -115,7 +115,7 @@
                                     DatabaseManager& manager,
                                     int64_t since,
                                     int64_t to,
-                                    int32_t changeType,
+                                    const std::set<uint32_t>& changeTypes,
                                     uint32_t limit) = 0;
 
     virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/,
--- a/Framework/Plugins/IndexBackend.cpp	Fri Sep 20 18:36:52 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Mon Sep 23 16:03:24 2024 +0200
@@ -60,6 +60,19 @@
     return s;
   }
 
+  static std::string JoinChanges(const std::set<uint32_t>& changeTypes)
+  {
+    std::set<std::string> changeTypesString;
+    for (std::set<uint32_t>::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it)
+    {
+      changeTypesString.insert(boost::lexical_cast<std::string>(*it));
+    }
+
+    std::string joinedChangesTypes;
+    Orthanc::Toolbox::JoinStrings(joinedChangesTypes, changeTypesString, ", ");
+
+    return joinedChangesTypes;
+  }
   
   template <typename T>
   static void ReadListOfIntegers(std::list<T>& target,
@@ -597,11 +610,8 @@
                                 int64_t since,
                                 uint32_t limit)
   {
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)    
-    GetChangesExtended(output, done, manager, since, -1, _OrthancPluginChangeType_All, limit);
-#else
-    GetChangesExtended(output, done, manager, since, -1, 65535, limit);
-#endif
+    std::set<uint32_t> changeTypes;
+    GetChangesExtended(output, done, manager, since, -1, changeTypes, limit);
   }
 
   /* Use GetOutput().AnswerChange() */
@@ -610,7 +620,7 @@
                                         DatabaseManager& manager,
                                         int64_t since,
                                         int64_t to,
-                                        int32_t changeType,
+                                        const std::set<uint32_t>& changeTypes,
                                         uint32_t limit)
   {
     std::string limitSuffix;
@@ -626,7 +636,6 @@
     std::vector<std::string> filters;
     bool hasSince = false;
     bool hasTo = false;
-    bool hasFilterType = false;    
 
     if (since > 0)
     {
@@ -638,10 +647,9 @@
       hasTo = true;
       filters.push_back("seq<=${to}");
     }
-    if (changeType != _OrthancPluginChangeType_All)
+    if (changeTypes.size() > 0)
     {
-      hasFilterType = true;
-      filters.push_back("changeType=${changeType}");
+      filters.push_back("changeType IN (" + JoinChanges(changeTypes) + ") ");
     }
 
     std::string filtersString;
@@ -691,12 +699,6 @@
       args.SetIntegerValue("to", to);
     }
 
-    if (hasFilterType)
-    {
-      statement.SetParameterType("changeType", ValueType_Integer64);
-      args.SetIntegerValue("changeType", changeType);
-    }
-
     ReadChangesInternal(output, done, manager, statement, args, limit, returnFirstResults);
   }
 
--- a/Framework/Plugins/IndexBackend.h	Fri Sep 20 18:36:52 2024 +0200
+++ b/Framework/Plugins/IndexBackend.h	Mon Sep 23 16:03:24 2024 +0200
@@ -137,7 +137,7 @@
                                     DatabaseManager& manager,
                                     int64_t since,
                                     int64_t to,
-                                    int32_t changeType,
+                                    const std::set<uint32_t>& changeTypes,
                                     uint32_t limit) ORTHANC_OVERRIDE;
 
     virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/,