# HG changeset patch # User Sebastien Jodogne # Date 1466500234 -7200 # Node ID bfdf24883ff33c3b05d3c7a963e2d06997e2d579 # Parent 65b1ce7cb84fee971d59a6cc4cff93dbdb15b18b more generic AutoroutingModification.lua sample diff -r 65b1ce7cb84f -r bfdf24883ff3 Resources/Samples/Lua/AutoroutingModification.lua --- 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