changeset 2033:bfdf24883ff3

more generic AutoroutingModification.lua sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 Jun 2016 11:10:34 +0200
parents 65b1ce7cb84f
children 07f2ba3677df
files Resources/Samples/Lua/AutoroutingModification.lua
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/Lua/AutoroutingModification.lua	Tue Jun 21 09:26:56 2016 +0200
+++ b/Resources/Samples/Lua/AutoroutingModification.lua	Tue Jun 21 11:10:34 2016 +0200
@@ -1,8 +1,7 @@
-function OnStoredInstance(instanceId, tags, metadata)
-   -- Ignore the instances that result from a modification to avoid
-   -- infinite loops
-   if (metadata['ModifiedFrom'] == nil and
-       metadata['AnonymizedFrom'] == nil) then
+function OnStoredInstance(instanceId, tags, metadata, origin)
+   -- Ignore the instances that result from the present Lua script to
+   -- avoid infinite loops
+   if origin['RequestOrigin'] ~= 'Lua' then
 
       -- The tags to be replaced
       local replace = {}
@@ -12,10 +11,21 @@
       -- The tags to be removed
       local remove = { 'MilitaryRank' }
 
-      -- Modify the instance, send it, then delete the modified instance
-      Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'sample'))
+      -- Modify the instance
+      local command = {}
+      command['Replace'] = replace
+      command['Remove'] = remove
+      local modifiedFile = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true))
 
-      -- Delete the original instance
-      Delete(instanceId)
+      -- Upload the modified instance to the Orthanc database so that
+      -- it can be sent by Orthanc to other modalities
+      local modifiedId = ParseJson(RestApiPost('/instances/', modifiedFile)) ['ID']
+
+      -- Send the modified instance to another modality
+      RestApiPost('/modalities/sample/store', modifiedId)
+
+      -- Delete the original and the modified instances
+      RestApiDelete('/instances/' .. instanceId)
+      RestApiDelete('/instances/' .. modifiedId)
    end
 end