changeset 378:9db9e0275ec0 db-protobuf

refactoring IndexBackend::LogExportedResource()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 Mar 2023 08:19:40 +0200
parents 02fe4606f5e4
children 33b2aaffdd6c
files Framework/Plugins/DatabaseBackendAdapterV2.cpp Framework/Plugins/DatabaseBackendAdapterV3.cpp Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h Framework/Plugins/IndexUnitTests.h
diffstat 7 files changed, 91 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Mar 29 08:19:40 2023 +0200
@@ -946,7 +946,9 @@
     try
     {
       DatabaseBackendAdapterV2::Adapter::DatabaseAccessor accessor(*adapter);      
-      adapter->GetBackend().LogExportedResource(accessor.GetManager(), *exported);
+      adapter->GetBackend().LogExportedResource(accessor.GetManager(), exported->resourceType, exported->publicId,
+                                                exported->modality, exported->date, exported->patientId,
+                                                exported->studyInstanceUid, exported->seriesInstanceUid, exported->sopInstanceUid);
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH;
--- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Mar 29 08:19:40 2023 +0200
@@ -1501,19 +1501,9 @@
 
     try
     {
-      OrthancPluginExportedResource exported;
-      exported.seq = 0;
-      exported.resourceType = resourceType;
-      exported.publicId = publicId;
-      exported.modality = modality;
-      exported.date = date;
-      exported.patientId = patientId;
-      exported.studyInstanceUid = studyInstanceUid;
-      exported.seriesInstanceUid = seriesInstanceUid;
-      exported.sopInstanceUid = sopInstanceUid;
-        
       t->GetOutput().Clear();
-      t->GetBackend().LogExportedResource(t->GetManager(), exported);
+      t->GetBackend().LogExportedResource(t->GetManager(), resourceType, publicId, modality, date,
+                                          patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext());
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Mar 29 08:19:40 2023 +0200
@@ -636,6 +636,49 @@
         break;
       }
       
+      case Orthanc::DatabasePluginMessages::OPERATION_IS_PROTECTED_PATIENT:
+      {
+        bool isProtected = backend.IsProtectedPatient(manager, request.is_protected_patient().patient_id());
+        response.mutable_is_protected_patient()->set_protected_patient(isProtected);
+        break;
+      }
+      
+      case Orthanc::DatabasePluginMessages::OPERATION_LIST_AVAILABLE_ATTACHMENTS:
+      {
+        std::list<int32_t>  values;
+        backend.ListAvailableAttachments(values, manager, request.list_available_attachments().id());
+
+        for (std::list<int32_t>::const_iterator it = values.begin(); it != values.end(); ++it)
+        {
+          response.mutable_list_available_attachments()->add_attachments(*it);
+        }
+        
+        break;
+      }
+      
+      case Orthanc::DatabasePluginMessages::OPERATION_LOG_CHANGE:
+      {
+        backend.LogChange(manager, request.log_change().change_type(),
+                          request.log_change().resource_id(),
+                          Convert(request.log_change().resource_type()),
+                          request.log_change().date().c_str());
+        break;
+      }
+      
+      case Orthanc::DatabasePluginMessages::OPERATION_LOG_EXPORTED_RESOURCE:
+      {
+        backend.LogExportedResource(manager,
+                                    Convert(request.log_exported_resource().resource_type()),
+                                    request.log_exported_resource().public_id().c_str(),
+                                    request.log_exported_resource().modality().c_str(),
+                                    request.log_exported_resource().date().c_str(),
+                                    request.log_exported_resource().patient_id().c_str(),
+                                    request.log_exported_resource().study_instance_uid().c_str(),
+                                    request.log_exported_resource().series_instance_uid().c_str(),
+                                    request.log_exported_resource().sop_instance_uid().c_str());
+        break;
+      }
+      
       default:
         LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation();
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
--- a/Framework/Plugins/IDatabaseBackend.h	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Wed Mar 29 08:19:40 2023 +0200
@@ -164,7 +164,14 @@
                            const char* date) = 0;
     
     virtual void LogExportedResource(DatabaseManager& manager,
-                                     const OrthancPluginExportedResource& resource) = 0;
+                                     OrthancPluginResourceType resourceType,
+                                     const char* publicId,
+                                     const char* modality,
+                                     const char* date,
+                                     const char* patientId,
+                                     const char* studyInstanceUid,
+                                     const char* seriesInstanceUid,
+                                     const char* sopInstanceUid) = 0;
     
     /* Use GetOutput().AnswerAttachment() */
     virtual bool LookupAttachment(IDatabaseBackendOutput& output,
--- a/Framework/Plugins/IndexBackend.cpp	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Wed Mar 29 08:19:40 2023 +0200
@@ -1010,7 +1010,14 @@
 
     
   void IndexBackend::LogExportedResource(DatabaseManager& manager,
-                                         const OrthancPluginExportedResource& resource)
+                                         OrthancPluginResourceType resourceType,
+                                         const char* publicId,
+                                         const char* modality,
+                                         const char* date,
+                                         const char* patientId,
+                                         const char* studyInstanceUid,
+                                         const char* seriesInstanceUid,
+                                         const char* sopInstanceUid)
   {
     DatabaseManager::CachedStatement statement(
       STATEMENT_FROM_HERE, manager,
@@ -1027,14 +1034,14 @@
     statement.SetParameterType("date", ValueType_Utf8String);
 
     Dictionary args;
-    args.SetIntegerValue("type", resource.resourceType);
-    args.SetUtf8Value("publicId", resource.publicId);
-    args.SetUtf8Value("modality", resource.modality);
-    args.SetUtf8Value("patient", resource.patientId);
-    args.SetUtf8Value("study", resource.studyInstanceUid);
-    args.SetUtf8Value("series", resource.seriesInstanceUid);
-    args.SetUtf8Value("instance", resource.sopInstanceUid);
-    args.SetUtf8Value("date", resource.date);
+    args.SetIntegerValue("type", resourceType);
+    args.SetUtf8Value("publicId", publicId);
+    args.SetUtf8Value("modality", modality);
+    args.SetUtf8Value("patient", patientId);
+    args.SetUtf8Value("study", studyInstanceUid);
+    args.SetUtf8Value("series", seriesInstanceUid);
+    args.SetUtf8Value("instance", sopInstanceUid);
+    args.SetUtf8Value("date", date);
 
     statement.Execute(args);
   }
--- a/Framework/Plugins/IndexBackend.h	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/IndexBackend.h	Wed Mar 29 08:19:40 2023 +0200
@@ -186,7 +186,14 @@
                            const char* date) ORTHANC_OVERRIDE;
     
     virtual void LogExportedResource(DatabaseManager& manager,
-                                     const OrthancPluginExportedResource& resource) ORTHANC_OVERRIDE;
+                                     OrthancPluginResourceType resourceType,
+                                     const char* publicId,
+                                     const char* modality,
+                                     const char* date,
+                                     const char* patientId,
+                                     const char* studyInstanceUid,
+                                     const char* seriesInstanceUid,
+                                     const char* sopInstanceUid) ORTHANC_OVERRIDE;
     
     virtual bool LookupAttachment(IDatabaseBackendOutput& output,
                                   int64_t& revision /*out*/,
--- a/Framework/Plugins/IndexUnitTests.h	Wed Mar 29 07:57:49 2023 +0200
+++ b/Framework/Plugins/IndexUnitTests.h	Wed Mar 29 08:19:40 2023 +0200
@@ -510,20 +510,19 @@
   ASSERT_EQ(0u, ci.size());
 
 
-  OrthancPluginExportedResource exp;
-  exp.seq = -1;
-  exp.resourceType = OrthancPluginResourceType_Study;
-  exp.publicId = "id";
-  exp.modality = "remote";
-  exp.date = "date";
-  exp.patientId = "patient";
-  exp.studyInstanceUid = "study";
-  exp.seriesInstanceUid = "series";
-  exp.sopInstanceUid = "instance";
-  db.LogExportedResource(*manager, exp);
+  db.LogExportedResource(*manager, OrthancPluginResourceType_Study, "id", "remote", "date",
+                         "patient", "study", "series", "instance");
 
   expectedExported.reset(new OrthancPluginExportedResource());
-  *expectedExported = exp;
+  expectedExported->seq = -1;
+  expectedExported->resourceType = OrthancPluginResourceType_Study;
+  expectedExported->publicId = "id";
+  expectedExported->modality = "remote";
+  expectedExported->date = "date";
+  expectedExported->patientId = "patient";
+  expectedExported->studyInstanceUid = "study";
+  expectedExported->seriesInstanceUid = "series";
+  expectedExported->sopInstanceUid = "instance";
 
   bool done;
   db.GetExportedResources(*output, done, *manager, 0, 10);