changeset 5944:cc6027cbd8f1

prepared work for OE2 issue #73
author Alain Mazy <am@orthanc.team>
date Thu, 26 Dec 2024 13:18:12 +0100
parents 3ef2ead6bb6c
children 089b8e5158d1
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/Search/DatabaseLookup.cpp OrthancServer/Sources/Search/DatabaseLookup.h
diffstat 3 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu Dec 19 10:43:35 2024 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu Dec 26 13:18:12 2024 +0100
@@ -3072,6 +3072,26 @@
     FindType_Count
   };
 
+  static bool CanBePerformedInDb(const DatabaseLookup& lookup)
+  {
+    std::set<DicomTag> nonMainDicomTags;
+    if (!lookup.HasOnlyMainDicomTags(nonMainDicomTags))
+    {
+      // TODO: prepared work for https://github.com/orthanc-server/orthanc-explorer-2/issues/73
+      
+      // // filtering on ModalitiesInStudy is actually performed in DB too although the tag is not stored in the MainDicomTags
+      // if (nonMainDicomTags.size() == 1 && nonMainDicomTags.find(DICOM_TAG_MODALITIES_IN_STUDY) != nonMainDicomTags.end())
+      // {
+      //   return true;
+      // }
+
+      return false;
+    }
+
+    return true;
+  }
+
+
   template <enum FindType requestType>
   static void Find(RestApiPostCall& call)
   {
@@ -3319,7 +3339,7 @@
             }
           }
 
-          if (requestType == FindType_Count && !dicomTagLookup.HasOnlyMainDicomTags())
+          if (requestType == FindType_Count && !CanBePerformedInDb(dicomTagLookup))
           {
               throw OrthancException(ErrorCode_BadRequest,
                                     "Unable to count resources when querying tags that are not stored as MainDicomTags in the Database");
@@ -3426,7 +3446,7 @@
 
         if (((request.isMember(KEY_LIMIT) && request[KEY_LIMIT].asInt64() != 0) || 
              (request.isMember(KEY_SINCE) && request[KEY_SINCE].asInt64() != 0)) &&
-            !dicomTagLookup.HasOnlyMainDicomTags())
+            !CanBePerformedInDb(dicomTagLookup))
         {
             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");
--- a/OrthancServer/Sources/Search/DatabaseLookup.cpp	Thu Dec 19 10:43:35 2024 +0100
+++ b/OrthancServer/Sources/Search/DatabaseLookup.cpp	Thu Dec 26 13:18:12 2024 +0100
@@ -282,6 +282,14 @@
 
   bool DatabaseLookup::HasOnlyMainDicomTags() const
   {
+    std::set<DicomTag> notUsed;
+    
+    return HasOnlyMainDicomTags(notUsed);
+  }
+
+
+  bool DatabaseLookup::HasOnlyMainDicomTags(std::set<DicomTag>& /* out*/ nonMainDicomTags) const
+  {
     std::set<DicomTag> allMainTags;
     DicomMap::GetAllMainDicomTags(allMainTags);
 
@@ -292,11 +300,11 @@
       if (allMainTags.find(constraints_[i]->GetTag()) == allMainTags.end())
       {
         // This is not a main DICOM tag
-        return false;
+        nonMainDicomTags.insert(constraints_[i]->GetTag());
       }
     }
 
-    return true;
+    return nonMainDicomTags.size() == 0;
   }
 
 
--- a/OrthancServer/Sources/Search/DatabaseLookup.h	Thu Dec 19 10:43:35 2024 +0100
+++ b/OrthancServer/Sources/Search/DatabaseLookup.h	Thu Dec 26 13:18:12 2024 +0100
@@ -84,6 +84,8 @@
 
     bool HasOnlyMainDicomTags() const;
 
+    bool HasOnlyMainDicomTags(std::set<DicomTag>& /* out*/ nonMainDicomTags) const;
+
     std::string Format() const;
 
     bool HasTag(const DicomTag& tag) const;