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"""
107 SELECT * FROM clin.v_waiting_list
108 ORDER BY
109 list_position
110 """
111 rows, idx = gmPG2.run_ro_queries (
112 queries = [{'cmd': cmd}],
113 get_col_idx = False
114 )
115 return rows
116
117 waiting_list_patients = property (_get_waiting_list_patients, lambda x:x)
118
121
123
124 if self.__helpdesk is not None:
125 return self.__helpdesk
126
127 self.__helpdesk = gmTools.coalesce (
128 _cfg.get (
129 group = u'workplace',
130 option = u'help desk',
131 source_order = [
132 ('explicit', 'return'),
133 ('workbase', 'return'),
134 ('local', 'return'),
135 ('user', 'return'),
136 ('system', 'return')
137 ]
138 ),
139 u'http://wiki.gnumed.de'
140 )
141
142 return self.__helpdesk
143
144 helpdesk = property(_get_helpdesk, _set_helpdesk)
145
147 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select _(message) from cfg.db_logon_banner'}])
148 if len(rows) == 0:
149 return u''
150 return gmTools.coalesce(rows[0][0], u'').strip()
151
153 queries = [
154 {'cmd': u'delete from cfg.db_logon_banner'}
155 ]
156 if banner.strip() != u'':
157 queries.append ({
158 'cmd': u'insert into cfg.db_logon_banner (message) values (%(msg)s)',
159 'args': {'msg': banner.strip()}
160 })
161 rows, idx = gmPG2.run_rw_queries(queries = queries, end_tx = True)
162
163 db_logon_banner = property(_get_db_logon_banner, _set_db_logon_banner)
164
168
170 """Return the current workplace (client profile) definition.
171
172 The first occurrence counts.
173 """
174 if self.__active_workplace is not None:
175 return self.__active_workplace
176
177 self.__active_workplace = gmTools.coalesce (
178 _cfg.get (
179 group = u'workplace',
180 option = u'name',
181 source_order = [
182 ('explicit', 'return'),
183 ('workbase', 'return'),
184 ('local', 'return'),
185 ('user', 'return'),
186 ('system', 'return'),
187 ]
188 ),
189 u'Local Default'
190 )
191
192 return self.__active_workplace
193
194 active_workplace = property(_get_workplace, _set_workplace)
195
198
200 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select distinct workplace from cfg.cfg_item'}])
201 return [ r[0] for r in rows ]
202
203 workplaces = property(_get_workplaces, _set_workplaces)
204
206
207 return _cfg.get (
208 group = u'preferences',
209 option = u'user email',
210 source_order = [
211 ('explicit', 'return'),
212 ('user', 'return'),
213 ('local', 'return'),
214 ('workbase', 'return'),
215 ('system', 'return')
216 ]
217 )
218
228
229 user_email = property(_get_user_email, _set_user_email)
230
231 if __name__ == '__main__':
232
251
252 if len(sys.argv) > 1 and sys.argv[1] == 'test':
253 if not run_tests():
254 print "regression tests failed"
255 print "regression tests succeeded"
256
257
258