comparison Resources/Samples/Lua/AutoroutingModification.lua @ 2033:bfdf24883ff3

more generic AutoroutingModification.lua sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 Jun 2016 11:10:34 +0200
parents f796207e3df1
children
comparison
equal deleted inserted replaced
2032:65b1ce7cb84f 2033:bfdf24883ff3
1 function OnStoredInstance(instanceId, tags, metadata) 1 function OnStoredInstance(instanceId, tags, metadata, origin)
2 -- Ignore the instances that result from a modification to avoid 2 -- Ignore the instances that result from the present Lua script to
3 -- infinite loops 3 -- avoid infinite loops
4 if (metadata['ModifiedFrom'] == nil and 4 if origin['RequestOrigin'] ~= 'Lua' then
5 metadata['AnonymizedFrom'] == nil) then
6 5
7 -- The tags to be replaced 6 -- The tags to be replaced
8 local replace = {} 7 local replace = {}
9 replace['StationName'] = 'My Medical Device' 8 replace['StationName'] = 'My Medical Device'
10 replace['0031-1020'] = 'Some private tag' 9 replace['0031-1020'] = 'Some private tag'
11 10
12 -- The tags to be removed 11 -- The tags to be removed
13 local remove = { 'MilitaryRank' } 12 local remove = { 'MilitaryRank' }
14 13
15 -- Modify the instance, send it, then delete the modified instance 14 -- Modify the instance
16 Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'sample')) 15 local command = {}
16 command['Replace'] = replace
17 command['Remove'] = remove
18 local modifiedFile = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true))
17 19
18 -- Delete the original instance 20 -- Upload the modified instance to the Orthanc database so that
19 Delete(instanceId) 21 -- it can be sent by Orthanc to other modalities
22 local modifiedId = ParseJson(RestApiPost('/instances/', modifiedFile)) ['ID']
23
24 -- Send the modified instance to another modality
25 RestApiPost('/modalities/sample/store', modifiedId)
26
27 -- Delete the original and the modified instances
28 RestApiDelete('/instances/' .. instanceId)
29 RestApiDelete('/instances/' .. modifiedId)
20 end 30 end
21 end 31 end