changeset 5896:9b039f4b1421 find-refactoring

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Dec 2024 13:52:04 +0100
parents cdb8b2a3aad5
children 2fc5667633e6
files OrthancServer/Sources/Database/FindRequest.cpp OrthancServer/Sources/Database/FindRequest.h OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp
diffstat 3 files changed, 54 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/FindRequest.cpp	Sat Nov 30 21:57:48 2024 +0100
+++ b/OrthancServer/Sources/Database/FindRequest.cpp	Tue Dec 03 13:52:04 2024 +0100
@@ -290,4 +290,53 @@
             !GetLabels().empty() ||
             !GetOrdering().empty());
   }
+
+
+  bool FindRequest::IsTrivialFind(std::string& publicId /* out */) const
+  {
+    if (HasConstraints())
+    {
+      return false;
+    }
+    else if (GetLevel() == ResourceType_Patient &&
+             GetOrthancIdentifiers().HasPatientId() &&
+             !GetOrthancIdentifiers().HasStudyId() &&
+             !GetOrthancIdentifiers().HasSeriesId() &&
+             !GetOrthancIdentifiers().HasInstanceId())
+    {
+      publicId = GetOrthancIdentifiers().GetPatientId();
+      return true;
+    }
+    else if (GetLevel() == ResourceType_Study &&
+             !GetOrthancIdentifiers().HasPatientId() &&
+             GetOrthancIdentifiers().HasStudyId() &&
+             !GetOrthancIdentifiers().HasSeriesId() &&
+             !GetOrthancIdentifiers().HasInstanceId())
+    {
+      publicId = GetOrthancIdentifiers().GetStudyId();
+      return true;
+    }
+    else if (GetLevel() == ResourceType_Series &&
+             !GetOrthancIdentifiers().HasPatientId() &&
+             !GetOrthancIdentifiers().HasStudyId() &&
+             GetOrthancIdentifiers().HasSeriesId() &&
+             !GetOrthancIdentifiers().HasInstanceId())
+    {
+      publicId = GetOrthancIdentifiers().GetSeriesId();
+      return true;
+    }
+    else if (GetLevel() == ResourceType_Instance &&
+             !GetOrthancIdentifiers().HasPatientId() &&
+             !GetOrthancIdentifiers().HasStudyId() &&
+             !GetOrthancIdentifiers().HasSeriesId() &&
+             GetOrthancIdentifiers().HasInstanceId())
+    {
+      publicId = GetOrthancIdentifiers().GetInstanceId();
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
 }
--- a/OrthancServer/Sources/Database/FindRequest.h	Sat Nov 30 21:57:48 2024 +0100
+++ b/OrthancServer/Sources/Database/FindRequest.h	Tue Dec 03 13:52:04 2024 +0100
@@ -448,5 +448,7 @@
     bool IsRetrieveOneInstanceMetadataAndAttachments() const;
 
     bool HasConstraints() const;
+
+    bool IsTrivialFind(std::string& publicId /* out */) const;
   };
 }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Sat Nov 30 21:57:48 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Dec 03 13:52:04 2024 +0100
@@ -3281,45 +3281,11 @@
        **/
       std::list<std::string> identifiers;
 
-      if (!request.HasConstraints() &&
-          request.GetLevel() == ResourceType_Patient &&
-          request.GetOrthancIdentifiers().HasPatientId() &&
-          !request.GetOrthancIdentifiers().HasStudyId() &&
-          !request.GetOrthancIdentifiers().HasSeriesId() &&
-          !request.GetOrthancIdentifiers().HasInstanceId())
-      {
-        // This is a trivial case for which no transaction is needed
-        identifiers.push_back(request.GetOrthancIdentifiers().GetPatientId());
-      }
-      else if (!request.HasConstraints() &&
-               request.GetLevel() == ResourceType_Study &&
-               !request.GetOrthancIdentifiers().HasPatientId() &&
-               request.GetOrthancIdentifiers().HasStudyId() &&
-               !request.GetOrthancIdentifiers().HasSeriesId() &&
-               !request.GetOrthancIdentifiers().HasInstanceId())
+      std::string publicId;
+      if (request.IsTrivialFind(publicId))
       {
         // This is a trivial case for which no transaction is needed
-        identifiers.push_back(request.GetOrthancIdentifiers().GetStudyId());
-      }
-      else if (!request.HasConstraints() &&
-               request.GetLevel() == ResourceType_Series &&
-               !request.GetOrthancIdentifiers().HasPatientId() &&
-               !request.GetOrthancIdentifiers().HasStudyId() &&
-               request.GetOrthancIdentifiers().HasSeriesId() &&
-               !request.GetOrthancIdentifiers().HasInstanceId())
-      {
-        // This is a trivial case for which no transaction is needed
-        identifiers.push_back(request.GetOrthancIdentifiers().GetSeriesId());
-      }
-      else if (!request.HasConstraints() &&
-               request.GetLevel() == ResourceType_Instance &&
-               !request.GetOrthancIdentifiers().HasPatientId() &&
-               !request.GetOrthancIdentifiers().HasStudyId() &&
-               !request.GetOrthancIdentifiers().HasSeriesId() &&
-               request.GetOrthancIdentifiers().HasInstanceId())
-      {
-        // This is a trivial case for which no transaction is needed
-        identifiers.push_back(request.GetOrthancIdentifiers().GetInstanceId());
+        identifiers.push_back(publicId);
       }
       else
       {