diff OrthancServer/DatabaseWrapper.cpp @ 268:4bc02e2254ec

preparing ServerIndex for recycling
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Dec 2012 13:43:35 +0100
parents 2354560daf2f
children d384af918264
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Fri Dec 07 13:19:42 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Fri Dec 07 13:43:35 2012 +0100
@@ -795,6 +795,26 @@
     }    
   }
 
+  bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId,
+                                               int64_t patientIdToAvoid)
+  {
+    SQLite::Statement s(db_, SQLITE_FROM_HERE,
+                        "SELECT patientId FROM PatientRecyclingOrder "
+                        "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
+    s.BindInt(0, patientIdToAvoid);
+
+    if (!s.Step())
+    {
+      // No patient remaining or all the patients are protected
+      return false;
+    }
+    else
+    {
+      internalId = s.ColumnInt(0);
+      return true;
+    }   
+  }
+
   bool DatabaseWrapper::IsProtectedPatient(int64_t internalId)
   {
     SQLite::Statement s(db_, SQLITE_FROM_HERE,