diff OrthancServer/Sources/LuaScripting.cpp @ 4554:efd90f778cd2 db-changes

simplification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Mar 2021 16:31:57 +0100
parents 350a22c094f2
children 456ed3fcff81
line wrap: on
line diff
--- a/OrthancServer/Sources/LuaScripting.cpp	Wed Mar 03 13:44:01 2021 +0100
+++ b/OrthancServer/Sources/LuaScripting.cpp	Wed Mar 03 16:31:57 2021 +0100
@@ -38,6 +38,7 @@
 #include "OrthancRestApi/OrthancRestApi.h"
 #include "ServerContext.h"
 
+#include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../OrthancFramework/Sources/HttpServer/StringHttpOutput.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h"
@@ -131,7 +132,7 @@
     private:
       const ServerIndexChange&            change_;
       bool                                ok_;
-      Json::Value                         tags_;
+      DicomMap                            tags_;
       std::map<MetadataType, std::string> metadata_;      
 
     public:
@@ -143,11 +144,15 @@
       
       virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
       {
-        if (transaction.LookupResource(tags_, change_.GetPublicId(), change_.GetResourceType()))
+        int64_t internalId;
+        ResourceType level;
+        if (transaction.LookupResource(internalId, level, change_.GetPublicId()) &&
+            level == change_.GetResourceType())
         {
-          transaction.GetAllMetadata(metadata_, change_.GetPublicId(), change_.GetResourceType());
+          transaction.GetMainDicomTags(tags_, internalId);
+          transaction.GetAllMetadata(metadata_, internalId);
           ok_ = true;
-        }               
+        }
       }
 
       void CallLua(LuaScripting& that,
@@ -171,9 +176,22 @@
             {
               that.InitializeJob();
 
+              Json::Value json = Json::objectValue;
+
+              if (change_.GetResourceType() == ResourceType_Study)
+              {
+                DicomMap t;
+                tags_.ExtractStudyInformation(t);  // Discard patient-related tags
+                FromDcmtkBridge::ToJson(json, t, true);
+              }
+              else
+              {
+                FromDcmtkBridge::ToJson(json, tags_, true);
+              }
+
               LuaFunctionCall call(lock.GetLua(), name);
               call.PushString(change_.GetPublicId());
-              call.PushJson(tags_["MainDicomTags"]);
+              call.PushJson(json);
               call.PushJson(formattedMetadata);
               call.Execute();