1
2 """GNUmed provider inbox middleware.
3
4 This should eventually end up in a class cPractice.
5 """
6
7
8
9 __license__ = "GPL"
10 __version__ = "$Revision: 1.14 $"
11 __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
12
13
14 import sys
15
16
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19 from Gnumed.pycommon import gmPG2, gmBusinessDBObject
20
21
23
24 _cmd_fetch_payload = u"select * from dem.v_message_inbox where pk_message_inbox = %s"
25
26 _cmds_store_payload = [
27 ]
28
29 u"""update clin.test_result set
30 clin_when = %(clin_when)s,
31 narrative = nullif(trim(%(comment)s), ''),
32 val_num = %(val_num)s,
33 val_alpha = nullif(trim(%(val_alpha)s), ''),
34 val_unit = nullif(trim(%(val_unit)s), ''),
35 val_normal_min = %(val_normal_min)s,
36 val_normal_max = %(val_normal_max)s,
37 val_normal_range = nullif(trim(%(val_normal_range)s), ''),
38 val_target_min = %(val_target_min)s,
39 val_target_max = %(val_target_max)s,
40 val_target_range = nullif(trim(%(val_target_range)s), ''),
41 abnormality_indicator = nullif(trim(%(abnormality_indicator)s), ''),
42 norm_ref_group = nullif(trim(%(norm_ref_group)s), ''),
43 note_test_org = nullif(trim(%(note_test_org)s), ''),
44 material = nullif(trim(%(material)s), ''),
45 material_detail = nullif(trim(%(material_detail)s), ''),
46 fk_intended_reviewer = %(pk_intended_reviewer)s,
47 fk_encounter = %(pk_encounter)s,
48 fk_episode = %(pk_episode)s,
49 fk_type = %(pk_test_type)s
50 where
51 pk = %(pk_test_result)s and
52 xmin = %(xmin_test_result)s""",
53 u"""select xmin_test_result from clin.v_test_results where pk_test_result = %(pk_test_result)s"""
54
55 _updatable_fields = [
56 u'pk_staff',
57 u'pk_patient',
58 u'pk_type',
59 u'comment',
60 u'pk_context',
61 u'data',
62 u'importance'
63 ]
64
66
67 args = {}
68 where_parts = []
69
70 if pk_staff is not None:
71 if include_without_provider:
72 where_parts.append(u'pk_staff in (%(staff)s, NULL)')
73 else:
74 where_parts.append(u'pk_staff = %(staff)s')
75 args['staff'] = pk_staff
76
77 if pk_patient is not None:
78 where_parts.append(u'pk_patient = %(pat)s')
79 args['pat'] = pk_patient
80
81 cmd = u"""
82 SELECT *
83 FROM dem.v_message_inbox
84 WHERE %s
85 ORDER BY importance desc, received_when desc""" % u' AND '.join(where_parts)
86
87 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': args}], get_col_idx = True)
88 return [ cInboxMessage(row = {'pk_field': 'pk_message_inbox', 'idx': idx, 'data': r}) for r in rows ]
89
91 gmPG2.run_rw_queries(queries = [{'cmd': u"delete from dem.message_inbox where pk = %s", 'args': [pk]}])
92 return True
93
101
103 cmd = u"""
104 select
105 importance,
106 l10n_category,
107 l10n_type,
108 comment,
109 category,
110 type,
111 pk_context,
112 data,
113 pk_message_inbox,
114 received_when,
115 pk_patient
116 from dem.v_message_inbox
117 where pk_staff = %s
118 order by importance desc, received_when desc"""
119 try:
120 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': [self.__provider_id]}])
121 except:
122 return [[
123 1,
124 _('error'),
125 _('error'),
126 _('unable to get provider inbox messages from database'),
127 'error',
128 'error',
129 None,
130 _('An error occurred while retrieving provider inbox messages from the database.'),
131 None,
132 None,
133 None
134 ]]
135 return rows
136
139
142
143 messages = property(_get_messages, _set_messages)
144
147
148 if __name__ == '__main__':
149
150 from Gnumed.pycommon import gmI18N
151 from Gnumed.business import gmPerson
152
153 gmI18N.activate_locale()
154 gmI18N.install_domain()
155
156
162
166
167 if (len(sys.argv) > 1) and (sys.argv[1] == 'test'):
168 test_inbox()
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220