changeset 998:4136fab6a639 lua-scripting

callback on stored instance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jul 2014 18:30:23 +0200
parents 1b1d51e9f1a2
children db18c071fbd7
files OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h Resources/Samples/Lua/Autorouting.lua
diffstat 3 files changed, 43 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp	Thu Jul 03 18:12:50 2014 +0200
+++ b/OrthancServer/ServerContext.cpp	Thu Jul 03 18:30:23 2014 +0200
@@ -93,16 +93,13 @@
   }
 
 
-  bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& dicomJson,
+  bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& simplified,
                                                   const std::string& remoteAet)
   {
     LuaContextLocker locker(*this);
 
     if (locker.GetLua().IsExistingFunction(RECEIVED_INSTANCE_FILTER))
     {
-      Json::Value simplified;
-      SimplifyTags(simplified, dicomJson);
-
       LuaFunctionCall call(locker.GetLua(), RECEIVED_INSTANCE_FILTER);
       call.PushJson(simplified);
       call.PushString(remoteAet);
@@ -117,14 +114,37 @@
   }
 
 
+  void ServerContext::ApplyOnStoredInstance(const Json::Value& simplified,
+                                            const std::string& instanceId)
+  {
+    LuaContextLocker locker(*this);
+
+    if (locker.GetLua().IsExistingFunction(ON_STORED_INSTANCE))
+    {
+      LuaFunctionCall call(locker.GetLua(), ON_STORED_INSTANCE);
+      call.PushJson(simplified);
+      call.PushString(instanceId);
+
+      Json::Value result;
+      call.ExecuteToJson(result);
+
+      printf("TODO\n");
+      std::cout << result;
+    }
+  }
+
+
   StoreStatus ServerContext::Store(const char* dicomInstance,
                                    size_t dicomSize,
                                    const DicomMap& dicomSummary,
                                    const Json::Value& dicomJson,
                                    const std::string& remoteAet)
   {
+    Json::Value simplified;
+    SimplifyTags(simplified, dicomJson);
+
     // Test if the instance must be filtered out
-    if (!ApplyReceivedInstanceFilter(dicomJson, remoteAet))
+    if (!ApplyReceivedInstanceFilter(simplified, remoteAet))
     {
       LOG(INFO) << "An incoming instance has been discarded by the filter";
       return StoreStatus_FilteredOut;
@@ -173,6 +193,13 @@
         break;
     }
 
+    if (status == StoreStatus_Success ||
+        status == StoreStatus_AlreadyStored)
+    {
+      DicomInstanceHasher hasher(dicomSummary);
+      ApplyOnStoredInstance(simplified, hasher.HashInstance());
+    }
+
     return status;
   }
 
--- a/OrthancServer/ServerContext.h	Thu Jul 03 18:12:50 2014 +0200
+++ b/OrthancServer/ServerContext.h	Thu Jul 03 18:30:23 2014 +0200
@@ -65,9 +65,12 @@
       virtual IDynamicObject* Provide(const std::string& id);
     };
 
-    bool ApplyReceivedInstanceFilter(const Json::Value& dicomJson,
+    bool ApplyReceivedInstanceFilter(const Json::Value& simplified,
                                      const std::string& remoteAet);
 
+    void ApplyOnStoredInstance(const Json::Value& simplified,
+                               const std::string& instanceId);
+
     FileStorage storage_;
     ServerIndex index_;
     CompressedFileStorageAccessor accessor_;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/Autorouting.lua	Thu Jul 03 18:30:23 2014 +0200
@@ -0,0 +1,7 @@
+function OnStoredInstance(tags, instance)
+  PrintRecursive(tags)
+  return { 
+    { "store", instance, "pacs" }, 
+    { "delete", instance } 
+  }
+end