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