# HG changeset patch # User Sebastien Jodogne # Date 1547582973 -3600 # Node ID c0d7aee8c3f864d6150177bad6524fff99ef4806 # Parent f86ebf971a72d4e155f82d7274c42b71ded0b45b Fix issue #58 (Patient recycling order should be defined by their received last instance) diff -r f86ebf971a72 -r c0d7aee8c3f8 NEWS --- 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) diff -r f86ebf971a72 -r c0d7aee8c3f8 OrthancServer/Database/Compatibility/ICreateInstance.cpp --- 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); diff -r f86ebf971a72 -r c0d7aee8c3f8 OrthancServer/Database/Compatibility/ICreateInstance.h --- 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, diff -r f86ebf971a72 -r c0d7aee8c3f8 OrthancServer/Database/SQLiteDatabaseWrapper.cpp --- 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(); + } } } diff -r f86ebf971a72 -r c0d7aee8c3f8 OrthancServer/Database/SQLiteDatabaseWrapper.h --- 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; }; } diff -r f86ebf971a72 -r c0d7aee8c3f8 Plugins/Engine/OrthancPluginDatabase.cpp --- 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)); + } } } diff -r f86ebf971a72 -r c0d7aee8c3f8 Plugins/Engine/OrthancPluginDatabase.h --- 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; }; } diff -r f86ebf971a72 -r c0d7aee8c3f8 Plugins/Include/orthanc/OrthancCDatabasePlugin.h --- 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; /*