1 """GNUmed waiting list widgets."""
2
3 __author__ = 'karsten.hilbert@gmx.net'
4 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
5
6
7 import logging
8 import sys
9
10
11
12 import wx
13
14
15
16 if __name__ == '__main__':
17 sys.path.insert(0, '../../')
18
19 from Gnumed.pycommon import gmDispatcher
20 from Gnumed.pycommon import gmTools
21 from Gnumed.pycommon import gmMatchProvider
22 from Gnumed.pycommon import gmI18N
23 from Gnumed.pycommon import gmExceptions
24
25 from Gnumed.business import gmSurgery
26 from Gnumed.business import gmPerson
27
28 from Gnumed.wxpython import gmEditArea
29 from Gnumed.wxpython import gmPhraseWheel
30 from Gnumed.wxpython import gmRegetMixin
31 from Gnumed.wxpython import gmPatSearchWidgets
32 from Gnumed.wxpython import gmGuiHelpers
33
34
35 _log = logging.getLogger('gm.ui')
36
37
38
40
49
50
52 self.matcher.set_items([ {'data': i, 'list_label': i, 'field_label': i, 'weight': 1} for i in items ])
53
54
55 from Gnumed.wxGladeWidgets import wxgWaitingListEntryEditAreaPnl
56
57 -class cWaitingListEntryEditAreaPnl(wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl, gmEditArea.cGenericEditAreaMixin):
58
59 - def __init__ (self, *args, **kwargs):
60
61 try:
62 self.patient = kwargs['patient']
63 del kwargs['patient']
64 except KeyError:
65 self.patient = None
66
67 try:
68 data = kwargs['entry']
69 del kwargs['entry']
70 except KeyError:
71 data = None
72
73 wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl.__init__(self, *args, **kwargs)
74 gmEditArea.cGenericEditAreaMixin.__init__(self)
75
76 if data is None:
77 self.mode = 'new'
78 else:
79 self.data = data
80 self.mode = 'edit'
81
82 praxis = gmSurgery.gmCurrentPractice()
83 pats = praxis.waiting_list_patients
84 zones = {}
85 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
86 self._PRW_zone.update_matcher(items = zones.keys())
87
88
89
91 if self.patient is None:
92 self._PRW_patient.person = None
93 self._PRW_patient.Enable(True)
94 self._PRW_patient.SetFocus()
95 else:
96 self._PRW_patient.person = self.patient
97 self._PRW_patient.Enable(False)
98 self._TCTRL_comment.SetFocus()
99 self._PRW_patient._display_name()
100
101 self._TCTRL_comment.SetValue(u'')
102 self._PRW_zone.SetValue(u'')
103 self._SPCTRL_urgency.SetValue(0)
104
106 self._PRW_patient.person = gmPerson.cIdentity(aPK_obj = self.data['pk_identity'])
107 self._PRW_patient.Enable(False)
108 self._PRW_patient._display_name()
109
110 self._TCTRL_comment.SetValue(gmTools.coalesce(self.data['comment'], u''))
111 self._PRW_zone.SetValue(gmTools.coalesce(self.data['waiting_zone'], u''))
112 self._SPCTRL_urgency.SetValue(self.data['urgency'])
113
114 self._TCTRL_comment.SetFocus()
115
116 - def _valid_for_save(self):
117 validity = True
118
119 self.display_tctrl_as_valid(tctrl = self._PRW_patient, valid = (self._PRW_patient.person is not None))
120 validity = (self._PRW_patient.person is not None)
121
122 if validity is False:
123 gmDispatcher.send(signal = 'statustext', msg = _('Cannot add to waiting list. Missing essential input.'))
124
125 return validity
126
127 - def _save_as_new(self):
128
129 self._PRW_patient.person.put_on_waiting_list (
130 urgency = self._SPCTRL_urgency.GetValue(),
131 comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), u''),
132 zone = gmTools.none_if(self._PRW_zone.GetValue().strip(), u'')
133 )
134
135 self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0}
136 return True
137
138 - def _save_as_update(self):
139 gmSurgery.gmCurrentPractice().update_in_waiting_list (
140 pk = self.data['pk_waiting_list'],
141 urgency = self._SPCTRL_urgency.GetValue(),
142 comment = self._TCTRL_comment.GetValue().strip(),
143 zone = self._PRW_zone.GetValue().strip()
144 )
145 return True
146
147 from Gnumed.wxGladeWidgets import wxgWaitingListPnl
148
149 -class cWaitingListPnl(wxgWaitingListPnl.wxgWaitingListPnl, gmRegetMixin.cRegetOnPaintMixin):
150
162
163
164
166 self._LCTRL_patients.set_columns ([
167 _('Zone'),
168 _('Urgency'),
169
170 _('Waiting time'),
171 _('Patient'),
172 _('Born'),
173 _('Comment')
174 ])
175 self._LCTRL_patients.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE_USEHEADER, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE])
176 self._LCTRL_patients.item_tooltip_callback = self._on_get_list_tooltip
177 self._PRW_zone.add_callback_on_selection(callback = self._on_zone_selected)
178 self._PRW_zone.add_callback_on_lose_focus(callback = self._on_zone_selected)
179
181 """
182 This gets called when a patient has been activated, but
183 only when the waiting list is actually in use (that is,
184 the plugin is loaded
185 """
186 pat = gmPerson.gmCurrentPatient()
187 enc = pat.emr.active_encounter
188 if gmTools.coalesce(enc['reason_for_encounter'], u'').strip() != u'':
189 return
190 entries = pat.waiting_list_entries
191 if len(entries) == 0:
192 if self.__last_patient is None:
193 return
194 if self.__last_patient != pat.ID:
195 return
196 rfe = self.__last_comment
197 else:
198 entry = entries[0]
199 if gmTools.coalesce(entry['comment'], u'').strip() == u'':
200 return
201 rfe = entry['comment'].strip()
202 enc['reason_for_encounter'] = rfe
203 enc.save()
204 self.__last_patient = None
205
244
246 gmDispatcher.connect(signal = u'waiting_list_generic_mod_db', receiver = self._on_waiting_list_modified)
247 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._on_post_patient_selection)
248
250 self.__last_patient = None
251
252 praxis = gmSurgery.gmCurrentPractice()
253 pats = praxis.waiting_list_patients
254
255
256 zones = {}
257 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
258 self._PRW_zone.update_matcher(items = zones.keys())
259
260
261 self.__current_zone = self._PRW_zone.GetValue().strip()
262 if self.__current_zone == u'':
263 pats = [ p for p in pats ]
264 else:
265 pats = [ p for p in pats if p['waiting_zone'] == self.__current_zone ]
266
267 old_pks = [ d['pk_waiting_list'] for d in self._LCTRL_patients.get_selected_item_data() ]
268 self._LCTRL_patients.set_string_items (
269 [ [
270 gmTools.coalesce(p['waiting_zone'], u''),
271 p['urgency'],
272 p['waiting_time_formatted'].replace(u'00 ', u'', 1).replace('00:', u'').lstrip('0'),
273 u'%s, %s (%s)' % (p['lastnames'], p['firstnames'], p['l10n_gender']),
274 gmTools.coalesce (
275 gmTools.coalesce (
276 p['dob'],
277 u'',
278 function_initial = ('strftime', '%d %b %Y')
279 ),
280 u'',
281 function_initial = ('decode', gmI18N.get_encoding())
282 ),
283 gmTools.coalesce(p['comment'], u'').split('\n')[0]
284 ] for p in pats ]
285 )
286 self._LCTRL_patients.set_column_widths()
287 self._LCTRL_patients.set_data(pats)
288 new_selections = []
289 new_pks = [ p['pk_waiting_list'] for p in pats ]
290 for old_pk in old_pks:
291 if old_pk in new_pks:
292 new_selections.append(new_pks.index(old_pk))
293 self._LCTRL_patients.selections = new_selections
294 self._LCTRL_patients.Refresh()
295
296 self._LBL_no_of_patients.SetLabel(_('(%s patients)') % len(pats))
297
298 if len(pats) == 0:
299 self._BTN_activate.Enable(False)
300 self._BTN_activateplus.Enable(False)
301 self._BTN_remove.Enable(False)
302 self._BTN_edit.Enable(False)
303 self._BTN_up.Enable(False)
304 self._BTN_down.Enable(False)
305 else:
306 self._BTN_activate.Enable(True)
307 self._BTN_activateplus.Enable(True)
308 self._BTN_remove.Enable(True)
309 self._BTN_edit.Enable(True)
310 if len(pats) > 1:
311 self._BTN_up.Enable(True)
312 self._BTN_down.Enable(True)
313
314
315
317 self.__last_patient = None
318 if self.__current_zone == self._PRW_zone.GetValue().strip():
319 return True
320 wx.CallAfter(self.__refresh_waiting_list)
321 return True
322
324 self.__last_patient = None
325 wx.CallAfter(self._schedule_data_reget)
326
327 - def _on_post_patient_selection(self, *args, **kwargs):
328 wx.CallAfter(self._check_RFE)
329
344
359
376
387
397
436
443
450
451
452
453
454
456 self.__refresh_waiting_list()
457 return True
458
459
460
461 if __name__ == '__main__':
462
463 if len(sys.argv) < 2:
464 sys.exit()
465
466 if sys.argv[1] != 'test':
467 sys.exit()
468
469 gmI18N.activate_locale()
470 gmI18N.install_domain()
471
472
473
474
475
476
477
478
479
480
481
482
483 app = wx.PyWidgetTester(size = (200, 40))
484 app.SetWidget(cWaitingListPnl, -1)
485 app.MainLoop()
486
487
488