comparison OrthancServer/Resources/Toolbox.lua @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Resources/Toolbox.lua@6406f5493d92
children
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 --[[ PrintRecursive(struct, [limit], [indent]) Recursively print arbitrary data.
2 Set limit (default 100) to stanch infinite loops.
3 Indents tables as [KEY] VALUE, nested tables as [KEY] [KEY]...[KEY] VALUE
4 Set indent ("") to prefix each line: Mytable [KEY] [KEY]...[KEY] VALUE
5 Source: https://gist.github.com/stuby/5445834#file-rprint-lua
6 --]]
7
8 function PrintRecursive(s, l, i) -- recursive Print (structure, limit, indent)
9 l = (l) or 100; -- default item limit
10 i = i or ""; -- indent string
11 if (l<1) then print "ERROR: Item limit reached."; return l-1 end;
12 local ts = type(s);
13 if (ts ~= "table") then print (i,ts,s); return l-1 end
14 print (i,ts); -- print "table"
15 for k,v in pairs(s) do -- print "[KEY] VALUE"
16 l = PrintRecursive(v, l, i.."\t["..tostring(k).."]");
17 if (l < 0) then break end
18 end
19 return l
20 end
21
22
23
24
25 function _InitializeJob()
26 _job = {}
27 end
28
29
30 function _AccessJob()
31 return _job
32 end
33
34
35 function SendToModality(resourceId, modality, localAet)
36 if resourceId == nil then
37 error('Cannot send a nonexistent resource')
38 end
39
40 table.insert(_job, {
41 Operation = 'store-scu',
42 Resource = resourceId,
43 Modality = modality,
44 LocalAet = localAet
45 })
46 return resourceId
47 end
48
49
50 function SendToPeer(resourceId, peer)
51 if resourceId == nil then
52 error('Cannot send a nonexistent resource')
53 end
54
55 table.insert(_job, {
56 Operation = 'store-peer',
57 Resource = resourceId,
58 Peer = peer
59 })
60 return resourceId
61 end
62
63
64 function Delete(resourceId)
65 if resourceId == nil then
66 error('Cannot delete a nonexistent resource')
67 end
68
69 table.insert(_job, {
70 Operation = 'delete',
71 Resource = resourceId
72 })
73 return nil -- Forbid chaining
74 end
75
76
77 function ModifyResource(resourceId, replacements, removals, removePrivateTags)
78 if resourceId == nil then
79 error('Cannot modify a nonexistent resource')
80 end
81
82 if resourceId == '' then
83 error('Cannot modify twice an resource');
84 end
85
86 table.insert(_job, {
87 Operation = 'modify',
88 Resource = resourceId,
89 Replace = replacements,
90 Remove = removals,
91 RemovePrivateTags = removePrivateTags
92 })
93
94 return '' -- Chain with another operation
95 end
96
97
98 function ModifyInstance(resourceId, replacements, removals, removePrivateTags)
99 return ModifyResource(resourceId, replacements, removals, removePrivateTags)
100 end
101
102
103 -- This function is only applicable to individual instances
104 function CallSystem(resourceId, command, args)
105 if resourceId == nil then
106 error('Cannot execute a system call on a nonexistent resource')
107 end
108
109 if command == nil then
110 error('No command was specified for system call')
111 end
112
113 table.insert(_job, {
114 Operation = 'call-system',
115 Resource = resourceId,
116 Command = command,
117 Arguments = args
118 })
119
120 return resourceId
121 end
122
123
124 print('Lua toolbox installed')