1 """GNUmed Surgery related middleware."""
2
3
4
5 __license__ = "GPL"
6 __version__ = "$Revision: 1.14 $"
7 __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
8
9
10 import sys, os
11
12
13 if __name__ == '__main__':
14 sys.path.insert(0, '../../')
15 from Gnumed.pycommon import gmPG2, gmTools, gmBorg, gmCfg2
16
17 _cfg = gmCfg2.gmCfgData()
18
20
21 args = {'wp': workplace}
22
23
24 queries = [
25 {'cmd': u"""
26 delete from cfg.cfg_item
27 where
28 fk_template = (
29 select pk
30 from cfg.cfg_template
31 where name = 'horstspace.notebook.plugin_load_order'
32 )
33 and
34 workplace = %(wp)s""",
35 'args': args
36 }
37 ]
38
39
40 if delete_config:
41 queries.append ({
42 'cmd': u"""
43 delete from cfg.cfg_item
44 where
45 workplace = %(wp)s""",
46 'args': args
47 })
48
49 gmPG2.run_rw_queries(link_obj = conn, queries = queries, end_tx = True)
50
52
54 try:
55 self.already_inited
56 return
57 except AttributeError:
58 pass
59
60 self.__helpdesk = None
61 self.__active_workplace = None
62
63 self.already_inited = True
64
65
66
68 cmd = u'delete from clin.waiting_list where pk = %(pk)s'
69 args = {'pk': pk}
70 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
71
73 cmd = u"""
74 update clin.waiting_list
75 set
76 urgency = %(urg)s,
77 comment = %(cmt)s,
78 area = %(zone)s
79 where
80 pk = %(pk)s"""
81 args = {
82 'pk': pk,
83 'urg': urgency,
84 'cmt': gmTools.none_if(comment, u''),
85 'zone': gmTools.none_if(zone, u'')
86 }
87
88 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
89
91 if current_position == 1:
92 return
93
94 cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s - 1))'
95 args = {'pos': current_position}
96
97 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
98
100 cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s+1))'
101 args = {'pos': current_position}
102
103 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
104
105
106
108 cmd = u'select * from clin.v_waiting_list order by list_position'
109 rows, idx = gmPG2.run_ro_queries (
110 queries = [{'cmd': cmd}],
111 get_col_idx = False
112 )
113 return rows
114
115 waiting_list_patients = property (_get_waiting_list_patients, lambda x:x)
116
119
121
122 if self.__helpdesk is not None:
123 return self.__helpdesk
124
125 self.__helpdesk = gmTools.coalesce (
126 _cfg.get (
127 group = u'workplace',
128 option = u'help desk',
129 source_order = [
130 ('explicit', 'return'),
131 ('workbase', 'return'),
132 ('local', 'return'),
133 ('user', 'return'),
134 ('system', 'return')
135 ]
136 ),
137 u'http://wiki.gnumed.de'
138 )
139
140 return self.__helpdesk
141
142 helpdesk = property(_get_helpdesk, _set_helpdesk)
143
145 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select _(message) from cfg.db_logon_banner'}])
146 if len(rows) == 0:
147 return u''
148 return gmTools.coalesce(rows[0][0], u'').strip()
149
151 queries = [
152 {'cmd': u'delete from cfg.db_logon_banner'}
153 ]
154 if banner.strip() != u'':
155 queries.append ({
156 'cmd': u'insert into cfg.db_logon_banner (message) values (%(msg)s)',
157 'args': {'msg': banner.strip()}
158 })
159 rows, idx = gmPG2.run_rw_queries(queries = queries, end_tx = True)
160
161 db_logon_banner = property(_get_db_logon_banner, _set_db_logon_banner)
162
166
168 """Return the current workplace (client profile) definition.
169
170 The first occurrence counts.
171 """
172 if self.__active_workplace is not None:
173 return self.__active_workplace
174
175 self.__active_workplace = gmTools.coalesce (
176 _cfg.get (
177 group = u'workplace',
178 option = u'name',
179 source_order = [
180 ('explicit', 'return'),
181 ('workbase', 'return'),
182 ('local', 'return'),
183 ('user', 'return'),
184 ('system', 'return'),
185 ]
186 ),
187 u'Local Default'
188 )
189
190 return self.__active_workplace
191
192 active_workplace = property(_get_workplace, _set_workplace)
193
196
198 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select distinct workplace from cfg.cfg_item'}])
199 return [ r[0] for r in rows ]
200
201 workplaces = property(_get_workplaces, _set_workplaces)
202
204
205 return _cfg.get (
206 group = u'preferences',
207 option = u'user email',
208 source_order = [
209 ('explicit', 'return'),
210 ('user', 'return'),
211 ('local', 'return'),
212 ('workbase', 'return'),
213 ('system', 'return')
214 ]
215 )
216
226
227 user_email = property(_get_user_email, _set_user_email)
228
229 if __name__ == '__main__':
230
249
250 if len(sys.argv) > 1 and sys.argv[1] == 'test':
251 if not run_tests():
252 print "regression tests failed"
253 print "regression tests succeeded"
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301