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
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
112
113 if __name__ == '__main__':
114
115 from Gnumed.pycommon import gmI18N
116 from Gnumed.business import gmPerson
117
118 gmI18N.activate_locale()
119 gmI18N.install_domain()
120
121
127
131
132 if (len(sys.argv) > 1) and (sys.argv[1] == 'test'):
133 test_inbox()
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185