| Home | Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed Praxis related middleware."""
2 #============================================================
3 __license__ = "GPL"
4 __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
5
6
7 import sys
8 import logging
9
10
11 if __name__ == '__main__':
12 sys.path.insert(0, '../../')
13 from Gnumed.pycommon import gmPG2
14 from Gnumed.pycommon import gmTools
15 from Gnumed.pycommon import gmBorg
16 from Gnumed.pycommon import gmCfg2
17 from Gnumed.pycommon import gmBusinessDBObject
18
19 from Gnumed.business import gmOrganization
20
21
22 _log = logging.getLogger('gm.praxis')
23 _cfg = gmCfg2.gmCfgData()
24 #============================================================
26
27 args = {'wp': workplace}
28
29 # delete workplace itself (plugin load list, that is)
30 queries = [
31 {'cmd': u"""
32 delete from cfg.cfg_item
33 where
34 fk_template = (
35 select pk
36 from cfg.cfg_template
37 where name = 'horstspace.notebook.plugin_load_order'
38 )
39 and
40 workplace = %(wp)s""",
41 'args': args
42 }
43 ]
44
45 # delete other config items associated with this workplace
46 if delete_config:
47 queries.append ({
48 'cmd': u"""
49 delete from cfg.cfg_item
50 where
51 workplace = %(wp)s""",
52 'args': args
53 })
54
55 gmPG2.run_rw_queries(link_obj = conn, queries = queries, end_tx = True)
56
57 #============================================================
58 # short description
59 #------------------------------------------------------------
60 _SQL_get_praxis_branches = u"SELECT * FROM dem.v_praxis_branches WHERE %s"
61
63 """Represents a praxis branch"""
64
65 _cmd_fetch_payload = _SQL_get_praxis_branches % u"pk_praxis_branch = %s"
66 _cmds_store_payload = [
67 u"""UPDATE dem.praxis_branch SET
68 fk_org_unit = %(pk_org_unit)s
69 WHERE
70 pk = %(pk_praxis_branch)s
71 AND
72 xmin = %(xmin_praxis_branch)s
73 RETURNING
74 xmin as xmin_praxis_branch
75 """
76 ]
77 _updatable_fields = [
78 u'pk_org_unit'
79 ]
80 #--------------------------------------------------------
82 txt = _('Praxis branch #%s\n') % self._payload[self._idx['pk_praxis_branch']]
83 txt += u' '
84 txt += u'\n '.join(self.org_unit.format(with_address = True, with_org = True, with_comms = True))
85 return txt
86 #--------------------------------------------------------
87 # properties
88 #--------------------------------------------------------
91
92 org_unit = property(_get_org_unit, lambda x:x)
93 #--------------------------------------------------------
96
97 organization = property(_get_org, lambda x:x)
98
99 #------------------------------------------------------------
101 if order_by is None:
102 order_by = u'true'
103 else:
104 order_by = u'true ORDER BY %s' % order_by
105
106 cmd = _SQL_get_praxis_branches % order_by
107 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd}], get_col_idx = True)
108 return [ cPraxisBranch(row = {'data': r, 'idx': idx, 'pk_field': 'pk_praxis_branch'}) for r in rows ]
109 #------------------------------------------------------------
111
112 args = {u'fk_unit': pk_org_unit}
113 cmd = u"""
114 INSERT INTO dem.praxis_branch (fk_org_unit)
115 VALUES (%(fk_unit)s)
116 RETURNING pk
117 """
118 rows, idx = gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}], return_data = True, get_col_idx = False)
119
120 return cPraxisBranch(aPK_obj = rows[0]['pk'])
121 #------------------------------------------------------------
123 args = {'pk': pk_praxis_branch}
124 cmd = u"DELETE FROM dem.praxis_branch WHERE pk = %(pk)s"
125 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
126 return True
127
128 #============================================================
130
132 try:
133 self.branch
134 except AttributeError:
135 self.branch = None
136 self.__helpdesk = None
137 self.__active_workplace = None
138
139 # user wants copy of current branch
140 if branch is None:
141 return None
142
143 # must be cPraxisBranch instance, then
144 if not isinstance(branch, cPraxisBranch):
145 _log.error('cannot set current praxis branch to [%s], must be a cPraxisBranch instance' % str(branch))
146 raise TypeError, 'gmPraxis.gmCurrentPraxisBranch.__init__(): <branch> must be a cPraxisBranch instance but is: %s' % str(branch)
147
148 self.branch = branch
149 _log.debug('current praxis branch now: %s', self.branch)
150
151 return None
152 #--------------------------------------------------------
153 # waiting list handling
154 #--------------------------------------------------------
156 cmd = u'delete from clin.waiting_list where pk = %(pk)s'
157 args = {'pk': pk}
158 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
159 #--------------------------------------------------------
161 cmd = u"""
162 update clin.waiting_list
163 set
164 urgency = %(urg)s,
165 comment = %(cmt)s,
166 area = %(zone)s
167 where
168 pk = %(pk)s"""
169 args = {
170 'pk': pk,
171 'urg': urgency,
172 'cmt': gmTools.none_if(comment, u''),
173 'zone': gmTools.none_if(zone, u'')
174 }
175
176 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
177 #--------------------------------------------------------
179 if current_position == 1:
180 return
181
182 cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s - 1))'
183 args = {'pos': current_position}
184
185 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
186 #--------------------------------------------------------
188 cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s+1))'
189 args = {'pos': current_position}
190
191 gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
192 #--------------------------------------------------------
193 # properties
194 #--------------------------------------------------------
196 cmd = u"""
197 SELECT * FROM clin.v_waiting_list
198 ORDER BY
199 list_position
200 """
201 rows, idx = gmPG2.run_ro_queries (
202 queries = [{'cmd': cmd}],
203 get_col_idx = False
204 )
205 return rows
206
207 waiting_list_patients = property (_get_waiting_list_patients, lambda x:x)
208 #--------------------------------------------------------
211
213
214 if self.__helpdesk is not None:
215 return self.__helpdesk
216
217 self.__helpdesk = gmTools.coalesce (
218 _cfg.get (
219 group = u'workplace',
220 option = u'help desk',
221 source_order = [
222 ('explicit', 'return'),
223 ('workbase', 'return'),
224 ('local', 'return'),
225 ('user', 'return'),
226 ('system', 'return')
227 ]
228 ),
229 u'http://wiki.gnumed.de'
230 )
231
232 return self.__helpdesk
233
234 helpdesk = property(_get_helpdesk, _set_helpdesk)
235 #--------------------------------------------------------
241
252
253 db_logon_banner = property(_get_db_logon_banner, _set_db_logon_banner)
254 #--------------------------------------------------------
258
260 """Return the current workplace (client profile) definition.
261
262 The first occurrence counts.
263 """
264 if self.__active_workplace is not None:
265 return self.__active_workplace
266
267 self.__active_workplace = gmTools.coalesce (
268 _cfg.get (
269 group = u'workplace',
270 option = u'name',
271 source_order = [
272 ('explicit', 'return'),
273 ('workbase', 'return'),
274 ('local', 'return'),
275 ('user', 'return'),
276 ('system', 'return'),
277 ]
278 ),
279 u'Local Default'
280 )
281
282 return self.__active_workplace
283
284 active_workplace = property(_get_workplace, _set_workplace)
285 #--------------------------------------------------------
288
290 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'SELECT DISTINCT workplace FROM cfg.cfg_item ORDER BY workplace'}])
291 return [ r[0] for r in rows ]
292
293 workplaces = property(_get_workplaces, _set_workplaces)
294 #--------------------------------------------------------
296 # FIXME: get this from the current users staff record in the database
297 return _cfg.get (
298 group = u'preferences',
299 option = u'user email',
300 source_order = [
301 ('explicit', 'return'),
302 ('user', 'return'),
303 ('local', 'return'),
304 ('workbase', 'return'),
305 ('system', 'return')
306 ]
307 )
308
310 prefs_file = _cfg.get(option = 'user_preferences_file')
311 gmCfg2.set_option_in_INI_file (
312 filename = prefs_file,
313 group = u'preferences',
314 option = u'user email',
315 value = val
316 )
317 _cfg.reload_file_source(file = prefs_file)
318
319 user_email = property(_get_user_email, _set_user_email)
320 #============================================================
321 if __name__ == '__main__':
322
323 if len(sys.argv) < 2:
324 sys.exit()
325
326 if sys.argv[1] != 'test':
327 sys.exit()
328
329 from Gnumed.pycommon import gmI18N
330 gmI18N.install_domain()
331
333 prac = gmCurrentPraxisBranch()
334 # print "help desk:", prac.helpdesk
335 # print "active workplace:", prac.active_workplace
336
337 old_banner = prac.db_logon_banner
338 test_banner = u'a test banner'
339 prac.db_logon_banner = test_banner
340 if prac.db_logon_banner != test_banner:
341 print 'Cannot set logon banner to', test_banner
342 return False
343 prac.db_logon_banner = u''
344 if prac.db_logon_banner != u'':
345 print 'Cannot set logon banner to ""'
346 return False
347 prac.db_logon_banner = old_banner
348
349 return True
350
351 # if not run_tests():
352 # print "regression tests failed"
353 # print "regression tests succeeded"
354
355 for b in get_praxis_branches():
356 print b.format()
357
358 #============================================================
359
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Jun 10 03:56:50 2013 | http://epydoc.sourceforge.net |