changeset 5841:57ab63fe9108 find-refactoring tip

tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
author Alain Mazy <am@orthanc.team>
date Thu, 24 Oct 2024 15:08:43 +0200
parents b24b61331566
children
files NEWS OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Oct 21 18:24:09 2024 +0200
+++ b/NEWS	Thu Oct 24 15:08:43 2024 +0200
@@ -43,6 +43,8 @@
     resource (e.g: Metadata, Children, ...)
 * With DB backend with "HasExtendedFind" support, a new /tools/count-resources API route
   is similar to tools/find but only returns the number of resources matching the criteria.
+* With DB backend with "HasExtendedFind" support, usage of 'Limit' and 'Since in /tools/find
+  is not allowed if your query includes filtering on DICOM tags that are not stored in DB.
 
 
 Maintenance
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Oct 21 18:24:09 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu Oct 24 15:08:43 2024 +0200
@@ -3465,6 +3465,8 @@
 
       ResourceFinder finder(level, responseContent);
 
+      DatabaseLookup dicomTagLookup;
+
       { // common query code
         bool caseSensitive = false;
         if (request.isMember(KEY_CASE_SENSITIVE))
@@ -3473,7 +3475,6 @@
         }
 
         { // DICOM Tag query
-          DatabaseLookup dicomTagLookup;
 
           Json::Value::Members members = request[KEY_QUERY].getMemberNames();
           for (size_t i = 0; i < members.size(); i++)
@@ -3601,6 +3602,13 @@
 
         finder.SetDatabaseLimits(context.GetDatabaseLimits(level));
 
+        if ((request.isMember(KEY_LIMIT) || request.isMember(KEY_SINCE)) &&
+          !dicomTagLookup.HasOnlyMainDicomTags())
+        {
+            throw OrthancException(ErrorCode_BadRequest,
+                                  "Unable to use " + std::string(KEY_LIMIT) + " or " + std::string(KEY_SINCE) + " in tools/find when querying tags that are not stored as MainDicomTags in the Database");
+        }
+
         if (request.isMember(KEY_LIMIT))
         {
           int64_t tmp = request[KEY_LIMIT].asInt64();