changeset 5887:1625fa53a6a3 find-refactoring

refactoring StatelessDatabaseOperations::LookupIdentifierExact()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 Nov 2024 17:18:44 +0100
parents 9b73ec6a07be
children 1b6836f9ad28
files OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h
diffstat 4 files changed, 28 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Fri Nov 29 16:29:46 2024 +0100
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Fri Nov 29 17:18:44 2024 +0100
@@ -241,9 +241,9 @@
                !request.GetOrthancIdentifiers().HasSeriesId() &&
                !request.GetOrthancIdentifiers().HasInstanceId())
       {
-        transaction_.ApplyLookupResources(identifiers, NULL /* TODO-FIND: Could the "instancesId" information be exploited? */,
-                                          request.GetDicomTagConstraints(), request.GetLevel(), request.GetLabels(),
-                                          request.GetLabelsConstraint(), request.HasLimits() ? request.GetLimitsCount() : 0);
+        compatibilityTransaction_.ApplyLookupResources(identifiers, NULL /* TODO-FIND: Could the "instancesId" information be exploited? */,
+                                                       request.GetDicomTagConstraints(), request.GetLevel(), request.GetLabels(),
+                                                       request.GetLabelsConstraint(), request.HasLimits() ? request.GetLimitsCount() : 0);
       }
       else
       {
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h	Fri Nov 29 16:29:46 2024 +0100
+++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h	Fri Nov 29 17:18:44 2024 +0100
@@ -310,13 +310,6 @@
     
       virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
     
-      virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
-                                        std::list<std::string>* instancesId, // Can be NULL if not needed
-                                        const DatabaseDicomTagConstraints& lookup,
-                                        ResourceType queryLevel,
-                                        const std::set<std::string>& labels,
-                                        LabelsConstraint labelsConstraint,
-                                        uint32_t limit) = 0;
 
       // Returns "true" iff. the instance is new and has been inserted
       // into the database. If "false" is returned, the content of
@@ -432,6 +425,18 @@
                                        int64_t id) = 0;
 
       /**
+       * Primitives introduced in Orthanc 1.5.2
+       **/
+
+      virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                        std::list<std::string>* instancesId, // Can be NULL if not needed
+                                        const DatabaseDicomTagConstraints& lookup,
+                                        ResourceType queryLevel,
+                                        const std::set<std::string>& labels,
+                                        LabelsConstraint labelsConstraint,
+                                        uint32_t limit) = 0;
+
+      /**
        * Primitives introduced in Orthanc 1.5.4
        **/
 
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Fri Nov 29 16:29:46 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Fri Nov 29 17:18:44 2024 +0100
@@ -288,22 +288,6 @@
   }
 
 
-  static void CopyListToVector(std::vector<std::string>& target,
-                               const std::list<std::string>& source)
-  {
-    target.resize(source.size());
-
-    size_t pos = 0;
-    
-    for (std::list<std::string>::const_iterator
-           it = source.begin(); it != source.end(); ++it)
-    {
-      target[pos] = *it;
-      pos ++;
-    }      
-  }
-
-
   void StatelessDatabaseOperations::ReadWriteTransaction::LogChange(int64_t internalId,
                                                                     ChangeType changeType,
                                                                     ResourceType resourceType,
@@ -1245,45 +1229,24 @@
            (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
            (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
            (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
-    
-    result.clear();
+
+    FindRequest request(level);
 
     DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true);
 
-    DatabaseDicomTagConstraints query;
     bool isIdentical;  // unused
-    query.AddConstraint(c.ConvertToDatabaseConstraint(isIdentical, level, DicomTagType_Identifier));
-
-
-    class Operations : public IReadOnlyOperations
+    request.GetDicomTagConstraints().AddConstraint(c.ConvertToDatabaseConstraint(isIdentical, level, DicomTagType_Identifier));
+
+    FindResponse response;
+    ExecuteFind(response, request);
+
+    result.clear();
+    result.reserve(response.GetSize());
+
+    for (size_t i = 0; i < response.GetSize(); i++)
     {
-    private:
-      std::vector<std::string>&   result_;
-      const DatabaseDicomTagConstraints&  query_;
-      ResourceType                level_;
-      
-    public:
-      Operations(std::vector<std::string>& result,
-                 const DatabaseDicomTagConstraints& query,
-                 ResourceType level) :
-        result_(result),
-        query_(query),
-        level_(level)
-      {
-      }
-
-      virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
-      {
-        // TODO - CANDIDATE FOR "TransactionType_Implicit"
-        std::list<std::string> tmp;
-        std::set<std::string> labels;
-        transaction.ApplyLookupResources(tmp, NULL, query_, level_, labels, LabelsConstraint_Any, 0);
-        CopyListToVector(result_, tmp);
-      }
-    };
-
-    Operations operations(result, query, level);
-    Apply(operations);
+      result.push_back(response.GetResourceByIndex(i).GetIdentifier());
+    }
   }
 
 
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Fri Nov 29 16:29:46 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Fri Nov 29 17:18:44 2024 +0100
@@ -123,18 +123,6 @@
        * Read-only methods from "IDatabaseWrapper"
        **/
 
-      void ApplyLookupResources(std::list<std::string>& resourcesId,
-                                std::list<std::string>* instancesId, // Can be NULL if not needed
-                                const DatabaseDicomTagConstraints& lookup,
-                                ResourceType queryLevel,
-                                const std::set<std::string>& labels,  // New in Orthanc 1.12.0
-                                LabelsConstraint labelsConstraint,    // New in Orthanc 1.12.0
-                                uint32_t limit)
-      {
-        return transaction_.ApplyLookupResources(resourcesId, instancesId, lookup, queryLevel,
-                                                 labels, labelsConstraint, limit);
-      }
-
       void GetAllMetadata(std::map<MetadataType, std::string>& target,
                           int64_t id)
       {