1 """GNUmed data pack related 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
24 from Gnumed.business import gmSurgery
25 from Gnumed.business import gmPerson
26
27 from Gnumed.wxpython import gmEditArea
28 from Gnumed.wxpython import gmPhraseWheel
29 from Gnumed.wxpython import gmRegetMixin
30 from Gnumed.wxpython import gmPatSearchWidgets
31 from Gnumed.wxpython import gmGuiHelpers
32
33
34 _log = logging.getLogger('gm.ui')
35
36
37
39
48
49
51 self.matcher.set_items([ {'data': i, 'list_label': i, 'field_label': i, 'weight': 1} for i in items ])
52
53
54 from Gnumed.wxGladeWidgets import wxgWaitingListEntryEditAreaPnl
55
56 -class cWaitingListEntryEditAreaPnl(wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl, gmEditArea.cGenericEditAreaMixin):
57
58 - def __init__ (self, *args, **kwargs):
59
60 try:
61 self.patient = kwargs['patient']
62 del kwargs['patient']
63 except KeyError:
64 self.patient = None
65
66 try:
67 data = kwargs['entry']
68 del kwargs['entry']
69 except KeyError:
70 data = None
71
72 wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl.__init__(self, *args, **kwargs)
73 gmEditArea.cGenericEditAreaMixin.__init__(self)
74
75 if data is None:
76 self.mode = 'new'
77 else:
78 self.data = data
79 self.mode = 'edit'
80
81 praxis = gmSurgery.gmCurrentPractice()
82 pats = praxis.waiting_list_patients
83 zones = {}
84 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
85 self._PRW_zone.update_matcher(items = zones.keys())
86
87
88
90 if self.patient is None:
91 self._PRW_patient.person = None
92 self._PRW_patient.Enable(True)
93 self._PRW_patient.SetFocus()
94 else:
95 self._PRW_patient.person = self.patient
96 self._PRW_patient.Enable(False)
97 self._TCTRL_comment.SetFocus()
98 self._PRW_patient._display_name()
99
100 self._TCTRL_comment.SetValue(u'')
101 self._PRW_zone.SetValue(u'')
102 self._SPCTRL_urgency.SetValue(0)
103
105 self._PRW_patient.person = gmPerson.cIdentity(aPK_obj = self.data['pk_identity'])
106 self._PRW_patient.Enable(False)
107 self._PRW_patient._display_name()
108
109 self._TCTRL_comment.SetValue(gmTools.coalesce(self.data['comment'], u''))
110 self._PRW_zone.SetValue(gmTools.coalesce(self.data['waiting_zone'], u''))
111 self._SPCTRL_urgency.SetValue(self.data['urgency'])
112
113 self._TCTRL_comment.SetFocus()
114
115 - def _valid_for_save(self):
116 validity = True
117
118 self.display_tctrl_as_valid(tctrl = self._PRW_patient, valid = (self._PRW_patient.person is not None))
119 validity = (self._PRW_patient.person is not None)
120
121 if validity is False:
122 gmDispatcher.send(signal = 'statustext', msg = _('Cannot add to waiting list. Missing essential input.'))
123
124 return validity
125
126 - def _save_as_new(self):
127
128 self._PRW_patient.person.put_on_waiting_list (
129 urgency = self._SPCTRL_urgency.GetValue(),
130 comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), u''),
131 zone = gmTools.none_if(self._PRW_zone.GetValue().strip(), u'')
132 )
133
134 self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0}
135 return True
136
137 - def _save_as_update(self):
138 gmSurgery.gmCurrentPractice().update_in_waiting_list (
139 pk = self.data['pk_waiting_list'],
140 urgency = self._SPCTRL_urgency.GetValue(),
141 comment = self._TCTRL_comment.GetValue().strip(),
142 zone = self._PRW_zone.GetValue().strip()
143 )
144 return True
145
146 from Gnumed.wxGladeWidgets import wxgWaitingListPnl
147
148 -class cWaitingListPnl(wxgWaitingListPnl.wxgWaitingListPnl, gmRegetMixin.cRegetOnPaintMixin):
149
159
160
161
163 self._LCTRL_patients.set_columns ([
164 _('Zone'),
165 _('Urgency'),
166
167 _('Waiting time'),
168 _('Patient'),
169 _('Born'),
170 _('Comment')
171 ])
172 self._LCTRL_patients.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE_USEHEADER, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE])
173 self._LCTRL_patients.item_tooltip_callback = self._on_get_list_tooltip
174 self._PRW_zone.add_callback_on_selection(callback = self._on_zone_selected)
175 self._PRW_zone.add_callback_on_lose_focus(callback = self._on_zone_selected)
176
215
217 gmDispatcher.connect(signal = u'waiting_list_generic_mod_db', receiver = self._on_waiting_list_modified)
218
220
221 praxis = gmSurgery.gmCurrentPractice()
222 pats = praxis.waiting_list_patients
223
224
225 zones = {}
226 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
227 self._PRW_zone.update_matcher(items = zones.keys())
228
229
230 self.__current_zone = self._PRW_zone.GetValue().strip()
231 if self.__current_zone == u'':
232 pats = [ p for p in pats ]
233 else:
234 pats = [ p for p in pats if p['waiting_zone'] == self.__current_zone ]
235
236 old_pks = [ d['pk_waiting_list'] for d in self._LCTRL_patients.get_selected_item_data() ]
237 self._LCTRL_patients.set_string_items (
238 [ [
239 gmTools.coalesce(p['waiting_zone'], u''),
240 p['urgency'],
241 p['waiting_time_formatted'].replace(u'00 ', u'', 1).replace('00:', u'').lstrip('0'),
242 u'%s, %s (%s)' % (p['lastnames'], p['firstnames'], p['l10n_gender']),
243 gmTools.coalesce (
244 gmTools.coalesce (
245 p['dob'],
246 u'',
247 function_initial = ('strftime', '%d %b %Y')
248 ),
249 u'',
250 function_initial = ('decode', gmI18N.get_encoding())
251 ),
252 gmTools.coalesce(p['comment'], u'').split('\n')[0]
253 ] for p in pats ]
254 )
255 self._LCTRL_patients.set_column_widths()
256 self._LCTRL_patients.set_data(pats)
257 new_selections = []
258 new_pks = [ p['pk_waiting_list'] for p in pats ]
259 for old_pk in old_pks:
260 if old_pk in new_pks:
261 new_selections.append(new_pks.index(old_pk))
262 self._LCTRL_patients.selections = new_selections
263 self._LCTRL_patients.Refresh()
264
265 self._LBL_no_of_patients.SetLabel(_('(%s patients)') % len(pats))
266
267 if len(pats) == 0:
268 self._BTN_activate.Enable(False)
269 self._BTN_activateplus.Enable(False)
270 self._BTN_remove.Enable(False)
271 self._BTN_edit.Enable(False)
272 self._BTN_up.Enable(False)
273 self._BTN_down.Enable(False)
274 else:
275 self._BTN_activate.Enable(True)
276 self._BTN_activateplus.Enable(True)
277 self._BTN_remove.Enable(True)
278 self._BTN_edit.Enable(True)
279 if len(pats) > 1:
280 self._BTN_up.Enable(True)
281 self._BTN_down.Enable(True)
282
283
284
286 if self.__current_zone == self._PRW_zone.GetValue().strip():
287 return True
288 wx.CallAfter(self.__refresh_waiting_list)
289 return True
290
292 wx.CallAfter(self._schedule_data_reget)
293
300
307
315
327
336
374
380
386
387
388
389
390
392 self.__refresh_waiting_list()
393 return True
394
395
396
397 if __name__ == '__main__':
398
399 if len(sys.argv) < 2:
400 sys.exit()
401
402 if sys.argv[1] != 'test':
403 sys.exit()
404
405 gmI18N.activate_locale()
406 gmI18N.install_domain()
407
408
409
410
411
412
413
414
415
416
417
418
419 app = wx.PyWidgetTester(size = (200, 40))
420 app.SetWidget(cWaitingListPnl, -1)
421 app.MainLoop()
422
423
424