changeset 3124:c0d7aee8c3f8 db-changes

Fix issue #58 (Patient recycling order should be defined by their received last instance)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 Jan 2019 21:09:33 +0100
parents f86ebf971a72
children 8296f0f75716
files NEWS OrthancServer/Database/Compatibility/ICreateInstance.cpp OrthancServer/Database/Compatibility/ICreateInstance.h OrthancServer/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Database/SQLiteDatabaseWrapper.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h Plugins/Include/orthanc/OrthancCDatabasePlugin.h
diffstat 8 files changed, 48 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jan 14 16:23:08 2019 +0100
+++ b/NEWS	Tue Jan 15 21:09:33 2019 +0100
@@ -17,6 +17,7 @@
 * Don't consider tags whose group is below 0x0008 in C-FIND SCP
 * Compatibility with DCMTK 3.6.4
 * Fix issue #21 (DICOM files missing after uploading with Firefox)
+* Fix issue #58 (Patient recycling order should be defined by their received last instance)
 * Fix issue #118 (Wording in Configuration.json regarding SynchronousCMove)
 * Fix issue #124 (GET /studies/ID/media fails for certain dicom file)
 * Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
--- a/OrthancServer/Database/Compatibility/ICreateInstance.cpp	Mon Jan 14 16:23:08 2019 +0100
+++ b/OrthancServer/Database/Compatibility/ICreateInstance.cpp	Tue Jan 15 21:09:33 2019 +0100
@@ -143,7 +143,7 @@
         database.AttachChild(result.patientId_, result.studyId_);
       }
 
-      database.TagAsMostRecentPatient(result.patientId_);
+      database.TagMostRecentPatient(result.patientId_);
       
       // Sanity checks
       assert(result.patientId_ != -1);
--- a/OrthancServer/Database/Compatibility/ICreateInstance.h	Mon Jan 14 16:23:08 2019 +0100
+++ b/OrthancServer/Database/Compatibility/ICreateInstance.h	Tue Jan 15 21:09:33 2019 +0100
@@ -52,7 +52,7 @@
       virtual void AttachChild(int64_t parent,
                                int64_t child) = 0;
 
-      virtual void TagAsMostRecentPatient(int64_t patientId) = 0;
+      virtual void TagMostRecentPatient(int64_t patientId) = 0;
       
       static bool Apply(ICreateInstance& database,
                         IDatabaseWrapper::CreateInstanceResult& result,
--- a/OrthancServer/Database/SQLiteDatabaseWrapper.cpp	Mon Jan 14 16:23:08 2019 +0100
+++ b/OrthancServer/Database/SQLiteDatabaseWrapper.cpp	Tue Jan 15 21:09:33 2019 +0100
@@ -1323,8 +1323,29 @@
   }
 
 
-  void SQLiteDatabaseWrapper::TagAsMostRecentPatient(int64_t patient)
+  void SQLiteDatabaseWrapper::TagMostRecentPatient(int64_t patient)
   {
-    // TODO
+    {
+      SQLite::Statement s(db_, SQLITE_FROM_HERE,
+                          "DELETE FROM PatientRecyclingOrder WHERE patientId=?");
+      s.BindInt64(0, patient);
+      s.Run();
+
+      assert(db_.GetLastChangeCount() == 0 ||
+             db_.GetLastChangeCount() == 1);
+      
+      if (db_.GetLastChangeCount() == 0)
+      {
+        // The patient was protected, there was nothing to delete from the recycling order
+        return;
+      }
+    }
+
+    {
+      SQLite::Statement s(db_, SQLITE_FROM_HERE,
+                          "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)");
+      s.BindInt64(0, patient);
+      s.Run();
+    }
   }
 }
--- a/OrthancServer/Database/SQLiteDatabaseWrapper.h	Mon Jan 14 16:23:08 2019 +0100
+++ b/OrthancServer/Database/SQLiteDatabaseWrapper.h	Tue Jan 15 21:09:33 2019 +0100
@@ -360,6 +360,6 @@
 
     virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE;
 
-    virtual void TagAsMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE;
+    virtual void TagMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE;
   };
 }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Jan 14 16:23:08 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Jan 15 21:09:33 2019 +0100
@@ -272,17 +272,25 @@
 
     if (isOptimal)
     {
-      LOG(INFO) << "The performance of the database index plugin is optimal for this version of Orthanc";
+      LOG(INFO) << "The performance of the database index plugin "
+                << "is optimal for this version of Orthanc";
     }
     else
     {
-      LOG(WARNING) << "Performance warning in the database index: Some extensions are missing in the plugin";
+      LOG(WARNING) << "Performance warning in the database index: "
+                   << "Some extensions are missing in the plugin";
     }
 
     if (extensions_.getLastChangeIndex == NULL)
     {
       LOG(WARNING) << "The database extension GetLastChangeIndex() is missing";
     }
+
+    if (extensions_.tagMostRecentPatient == NULL)
+    {
+      LOG(WARNING) << "The database extension TagMostRecentPatient() is missing "
+                   << "(affected by issue 58)";
+    }
   }
 
 
@@ -1416,8 +1424,11 @@
   }
 
   
-  void OrthancPluginDatabase::TagAsMostRecentPatient(int64_t patient)
+  void OrthancPluginDatabase::TagMostRecentPatient(int64_t patient)
   {
-    // TODO
+    if (extensions_.tagMostRecentPatient != NULL)
+    {
+      CheckSuccess(extensions_.tagMostRecentPatient(payload_, patient));
+    }
   }
 }
--- a/Plugins/Engine/OrthancPluginDatabase.h	Mon Jan 14 16:23:08 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Tue Jan 15 21:09:33 2019 +0100
@@ -363,7 +363,7 @@
 
     virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE;
   
-    virtual void TagAsMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE;
+    virtual void TagMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE;
   };
 }
 
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Mon Jan 14 16:23:08 2019 +0100
+++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Tue Jan 15 21:09:33 2019 +0100
@@ -820,6 +820,11 @@
       /* inputs */
       void* payload);
                    
+    OrthancPluginErrorCode  (*tagMostRecentPatient) (
+      /* inputs */
+      void* payload,
+      int64_t patientId);
+                   
   } OrthancPluginDatabaseExtensions;
 
 /*<! @endcond */