Mercurial > hg > orthanc
comparison Resources/Samples/Lua/Autorouting.lua @ 1010:160dfe770618 lua-scripting
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 17:05:00 +0200 |
parents | 187ed107a59f |
children | 23590917e83e |
comparison
equal
deleted
inserted
replaced
1009:26642cecd36d | 1010:160dfe770618 |
---|---|
1 function _InitializeJob() | |
2 _job = {} | |
3 end | |
4 | |
5 function _AccessJob() | |
6 return _job | |
7 end | |
8 | |
9 function SendToModality(instanceId, modality) | |
10 if instanceId == nil then | |
11 error('Cannot send an nonexistent instance') | |
12 end | |
13 | |
14 table.insert(_job, { | |
15 operation = 'store-scu', | |
16 instance = instanceId, | |
17 modality = modality | |
18 }) | |
19 return instanceId | |
20 end | |
21 | |
22 function SendToPeer(instanceId, peer) | |
23 if instanceId == nil then | |
24 error('Cannot send an nonexistent instance') | |
25 end | |
26 | |
27 table.insert(_job, { | |
28 operation = 'store-peer', | |
29 instance = instanceId, | |
30 peer = peer | |
31 }) | |
32 return instanceId | |
33 end | |
34 | |
35 function Delete(instanceId) | |
36 if instanceId == nil then | |
37 error('Cannot delete an nonexistent instance') | |
38 end | |
39 | |
40 table.insert(_job, { | |
41 operation = 'delete', | |
42 instance = instanceId | |
43 }) | |
44 return nil -- Forbid chaining | |
45 end | |
46 | |
47 function Modify(instanceId, replacements, removals, removePrivateTags) | |
48 if instanceId == nil then | |
49 error('Cannot modify an nonexistent instance') | |
50 end | |
51 | |
52 if instanceId == '' then | |
53 error('Cannot modify twice an instance'); | |
54 end | |
55 | |
56 table.insert(_job, { | |
57 operation = 'modify', | |
58 instance = instanceId, | |
59 replacements = replacements, | |
60 removals = removals, | |
61 removePrivateTags = removePrivateTags | |
62 }) | |
63 return '' -- Chain with another operation | |
64 end | |
65 | |
66 | |
67 function OnStoredInstance(instanceId, tags, metadata) | 1 function OnStoredInstance(instanceId, tags, metadata) |
68 --PrintRecursive(tags) | 2 --PrintRecursive(tags) |
69 --PrintRecursive(metadata) | 3 --PrintRecursive(metadata) |
70 --print(metadata['RemoteAET']) | 4 --print(metadata['RemoteAET']) |
71 | 5 |
73 metadata['AnonymizedFrom'] == nil) then | 7 metadata['AnonymizedFrom'] == nil) then |
74 local patientName = string.lower(tags['PatientName']) | 8 local patientName = string.lower(tags['PatientName']) |
75 if string.find(patientName, 'david') ~= nil then | 9 if string.find(patientName, 'david') ~= nil then |
76 --Delete(SendToModality(instanceId, 'sample')) | 10 --Delete(SendToModality(instanceId, 'sample')) |
77 --Delete(SendToPeer(instanceId, 'peer')) | 11 --Delete(SendToPeer(instanceId, 'peer')) |
78 SendToModality(Modify(instanceId, { PatientName = 'Hello^World' }), 'sample') | 12 local replace = {} |
13 replace['StationName'] = 'My Medical Device' | |
14 | |
15 local remove = { 'MilitaryRank' } | |
16 | |
17 Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'sample')) | |
79 Delete(instanceId) | 18 Delete(instanceId) |
80 else | 19 else |
81 Delete(instanceId) | 20 Delete(instanceId) |
82 end | 21 end |
83 end | 22 end |