diff OrthancServer/DatabaseWrapperBase.cpp @ 1763:f7014cca73c7

integration db-changes->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Oct 2015 12:45:20 +0100
parents f4286d99ee0a
children b1291df2f780
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapperBase.cpp	Fri Oct 23 17:04:22 2015 +0200
+++ b/OrthancServer/DatabaseWrapperBase.cpp	Thu Oct 29 12:45:20 2015 +0100
@@ -34,6 +34,7 @@
 #include "DatabaseWrapperBase.h"
 
 #include <stdio.h>
+#include <memory>
 
 namespace Orthanc
 {
@@ -532,6 +533,20 @@
     return static_cast<uint64_t>(s.ColumnInt64(0));
   }
 
+  void DatabaseWrapperBase::GetAllInternalIds(std::list<int64_t>& target,
+                                              ResourceType resourceType)
+  {
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT internalId FROM Resources WHERE resourceType=?");
+    s.BindInt(0, resourceType);
+
+    target.clear();
+    while (s.Step())
+    {
+      target.push_back(s.ColumnInt64(0));
+    }
+  }
+
+
   void DatabaseWrapperBase::GetAllPublicIds(std::list<std::string>& target,
                                             ResourceType resourceType)
   {
@@ -665,28 +680,51 @@
   }
 
 
+
   void DatabaseWrapperBase::LookupIdentifier(std::list<int64_t>& target,
+                                             ResourceType level,
                                              const DicomTag& tag,
+                                             IdentifierConstraintType type,
                                              const std::string& value)
   {
-    assert(tag == DICOM_TAG_PATIENT_ID ||
-           tag == DICOM_TAG_STUDY_INSTANCE_UID ||
-           tag == DICOM_TAG_SERIES_INSTANCE_UID ||
-           tag == DICOM_TAG_SOP_INSTANCE_UID ||
-           tag == DICOM_TAG_ACCESSION_NUMBER);
-    
-    SQLite::Statement s(db_, SQLITE_FROM_HERE, 
-                        "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?");
+    static const char* COMMON = ("SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
+                                 "d.id = r.internalId AND r.resourceType=? AND "
+                                 "d.tagGroup=? AND d.tagElement=? AND ");
+
+    std::auto_ptr<SQLite::Statement> s;
+
+    switch (type)
+    {
+      case IdentifierConstraintType_GreaterOrEqual:
+        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value>=?"));
+        break;
+
+      case IdentifierConstraintType_SmallerOrEqual:
+        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value<=?"));
+        break;
 
-    s.BindInt(0, tag.GetGroup());
-    s.BindInt(1, tag.GetElement());
-    s.BindString(2, value);
+      case IdentifierConstraintType_Wildcard:
+        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value GLOB ?"));
+        break;
+
+      case IdentifierConstraintType_Equal:
+      default:
+        s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value=?"));
+        break;
+    }
+
+    assert(s.get() != NULL);
+
+    s->BindInt(0, level);
+    s->BindInt(1, tag.GetGroup());
+    s->BindInt(2, tag.GetElement());
+    s->BindString(3, value);
 
     target.clear();
 
-    while (s.Step())
+    while (s->Step())
     {
-      target.push_back(s.ColumnInt64(0));
-    }
+      target.push_back(s->ColumnInt64(0));
+    }    
   }
 }