# HG changeset patch # User Sebastien Jodogne # Date 1547583050 -3600 # Node ID eb08ec14fb04a5ffb45b4eee5af5359e4f469830 # Parent 48d445f756db7c10a5b4a4ff99f38ce7ca696476 new extension implemented: TagMostRecentPatient diff -r 48d445f756db -r eb08ec14fb04 Framework/Plugins/IndexBackend.cpp --- a/Framework/Plugins/IndexBackend.cpp Thu Jan 10 20:39:36 2019 +0100 +++ b/Framework/Plugins/IndexBackend.cpp Tue Jan 15 21:10:50 2019 +0100 @@ -1882,4 +1882,73 @@ ReadListOfStrings(target, statement, args); } + + + // New primitive since Orthanc 1.5.2 + void IndexBackend::TagMostRecentPatient(int64_t patient) + { + int64_t seq; + + { + DatabaseManager::CachedStatement statement( + STATEMENT_FROM_HERE, manager_, + "SELECT * FROM PatientRecyclingOrder WHERE seq >= " + "(SELECT seq FROM PatientRecyclingOrder WHERE patientid=${id}) ORDER BY seq LIMIT 2"); + + statement.SetReadOnly(true); + statement.SetParameterType("id", ValueType_Integer64); + + Dictionary args; + args.SetIntegerValue("id", patient); + + statement.Execute(args); + + if (statement.IsDone()) + { + // The patient is protected, don't add it to the recycling order + return; + } + + seq = ReadInteger64(statement, 0); + + statement.Next(); + + if (statement.IsDone()) + { + // The patient is already at the end of the recycling order + // (because of the "LIMIT 2" above), no need to modify the table + return; + } + } + + // Delete the old position of the patient in the recycling order + + { + DatabaseManager::CachedStatement statement( + STATEMENT_FROM_HERE, manager_, + "DELETE FROM PatientRecyclingOrder WHERE seq=${seq}"); + + statement.SetParameterType("seq", ValueType_Integer64); + + Dictionary args; + args.SetIntegerValue("seq", seq); + + statement.Execute(args); + } + + // Add the patient to the end of the recycling order + + { + DatabaseManager::CachedStatement statement( + STATEMENT_FROM_HERE, manager_, + "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); + + statement.SetParameterType("id", ValueType_Integer64); + + Dictionary args; + args.SetIntegerValue("id", patient); + + statement.Execute(args); + } + } } diff -r 48d445f756db -r eb08ec14fb04 Framework/Plugins/IndexBackend.h --- a/Framework/Plugins/IndexBackend.h Thu Jan 10 20:39:36 2019 +0100 +++ b/Framework/Plugins/IndexBackend.h Tue Jan 15 21:10:50 2019 +0100 @@ -281,5 +281,7 @@ virtual void GetChildrenMetadata(std::list& target, int64_t resourceId, int32_t metadata); + + virtual void TagMostRecentPatient(int64_t patient); }; } diff -r 48d445f756db -r eb08ec14fb04 Framework/Plugins/OrthancCppDatabasePlugin.h --- a/Framework/Plugins/OrthancCppDatabasePlugin.h Thu Jan 10 20:39:36 2019 +0100 +++ b/Framework/Plugins/OrthancCppDatabasePlugin.h Tue Jan 15 21:10:50 2019 +0100 @@ -532,6 +532,8 @@ int32_t metadata) = 0; virtual int64_t GetLastChangeIndex() = 0; + + virtual void TagMostRecentPatient(int64_t patientId) = 0; }; @@ -1630,6 +1632,22 @@ } ORTHANC_PLUGINS_DATABASE_CATCH } + + + // New primitive since Orthanc 1.5.2 + static OrthancPluginErrorCode TagMostRecentPatient(void* payload, + int64_t patientId) + { + IDatabaseBackend* backend = reinterpret_cast(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->TagMostRecentPatient(patientId); + return OrthancPluginErrorCode_Success; + } + ORTHANC_PLUGINS_DATABASE_CATCH + } public: @@ -1717,6 +1735,7 @@ extensions.setResourcesContent = SetResourcesContent; // Fast setting tags/metadata extensions.getChildrenMetadata = GetChildrenMetadata; extensions.getLastChangeIndex = GetLastChangeIndex; + extensions.tagMostRecentPatient = TagMostRecentPatient; if (backend.HasCreateInstance()) { diff -r 48d445f756db -r eb08ec14fb04 PostgreSQL/Plugins/PostgreSQLIndex.cpp --- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp Thu Jan 10 20:39:36 2019 +0100 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp Tue Jan 15 21:10:50 2019 +0100 @@ -381,6 +381,9 @@ result.patientId = ReadInteger64(statement, 4); result.studyId = ReadInteger64(statement, 5); result.seriesId = ReadInteger64(statement, 6); + + // TODO - Move this to the stored procedure + TagMostRecentPatient(result.patientId); } } #endif