changeset 628:a9316631f2da default tip

tools/find: fix query by ModalitiesInStudy with pagination
author Alain Mazy <am@orthanc.team>
date Wed, 08 Jan 2025 15:18:33 +0100
parents 78ed0f5389cc
children
files Framework/Plugins/ISqlLookupFormatter.cpp PostgreSQL/NEWS
diffstat 2 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/ISqlLookupFormatter.cpp	Fri Jan 03 10:46:22 2025 +0100
+++ b/Framework/Plugins/ISqlLookupFormatter.cpp	Wed Jan 08 15:18:33 2025 +0100
@@ -1023,7 +1023,25 @@
       {
         std::string join;
         FormatJoin(join, constraint, count);
-        joins += join;
+
+
+        if (constraint.GetLevel() <= queryLevel)
+        {
+          joins += join;
+        }
+        else if (constraint.GetLevel() == queryLevel + 1 && !comparison.empty())
+        {
+          // new in v 1.12.6, the constraints on child tags are actually looking for one child with this value
+          comparison = " EXISTS (SELECT 1 FROM Resources AS " + FormatLevel(static_cast<Orthanc::ResourceType>(queryLevel + 1)) + 
+                       join + 
+                       " WHERE " + comparison + " AND " + 
+                       FormatLevel(static_cast<Orthanc::ResourceType>(queryLevel + 1)) + ".parentId = " + FormatLevel(static_cast<Orthanc::ResourceType>(queryLevel)) + ".internalId) ";
+        }
+
+        if (!comparison.empty())
+        {
+          comparisons += " AND " + comparison;
+        }
 
         if (!comparison.empty())
         {
@@ -1062,13 +1080,14 @@
               FormatLevel(static_cast<Orthanc::ResourceType>(level + 1)) + ".parentId");
     }
 
-    for (int level = queryLevel + 1; level <= lowerLevel; level++)
-    {
-      sql += (" INNER JOIN Resources " +
-              FormatLevel(static_cast<Orthanc::ResourceType>(level)) + " ON " +
-              FormatLevel(static_cast<Orthanc::ResourceType>(level - 1)) + ".internalId=" +
-              FormatLevel(static_cast<Orthanc::ResourceType>(level)) + ".parentId");
-    }
+    // disabled in v 1.12.6 now that the child levels are considered as "is there at least one child that meets this constraint"
+    // for (int level = queryLevel + 1; level <= lowerLevel; level++)
+    // {
+    //   sql += (" INNER JOIN Resources " +
+    //           FormatLevel(static_cast<Orthanc::ResourceType>(level)) + " ON " +
+    //           FormatLevel(static_cast<Orthanc::ResourceType>(level - 1)) + ".internalId=" +
+    //           FormatLevel(static_cast<Orthanc::ResourceType>(level)) + ".parentId");
+    // }
 
     std::list<std::string> where;
     where.push_back(strQueryLevel + ".resourceType = " +
--- a/PostgreSQL/NEWS	Fri Jan 03 10:46:22 2025 +0100
+++ b/PostgreSQL/NEWS	Wed Jan 08 15:18:33 2025 +0100
@@ -12,6 +12,9 @@
 
 
 * Disable DB Housekeeping thread on ReadOnly systems.
+* Find: Implemented support for searching for child resources fulfilling 
+  a dicom tag constraint.  This solves the search against ModalitiesInStudy
+  that was broken when used with pagination.
 
 
 Release 7.0 (2024-12-18)