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
32
33 _log = logging.getLogger('gm.ui')
34
35
36
38
47
48
50 self.matcher.set_items([ {'data': i, 'list_label': i, 'field_label': i, 'weight': 1} for i in items ])
51
52
53 from Gnumed.wxGladeWidgets import wxgWaitingListEntryEditAreaPnl
54
55 -class cWaitingListEntryEditAreaPnl(wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl, gmEditArea.cGenericEditAreaMixin):
56
57 - def __init__ (self, *args, **kwargs):
58
59 try:
60 self.patient = kwargs['patient']
61 del kwargs['patient']
62 except KeyError:
63 self.patient = None
64
65 try:
66 data = kwargs['entry']
67 del kwargs['entry']
68 except KeyError:
69 data = None
70
71 wxgWaitingListEntryEditAreaPnl.wxgWaitingListEntryEditAreaPnl.__init__(self, *args, **kwargs)
72 gmEditArea.cGenericEditAreaMixin.__init__(self)
73
74 if data is None:
75 self.mode = 'new'
76 else:
77 self.data = data
78 self.mode = 'edit'
79
80 praxis = gmSurgery.gmCurrentPractice()
81 pats = praxis.waiting_list_patients
82 zones = {}
83 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
84 self._PRW_zone.update_matcher(items = zones.keys())
85
86
87
89 if self.patient is None:
90 self._PRW_patient.person = None
91 self._PRW_patient.Enable(True)
92 self._PRW_patient.SetFocus()
93 else:
94 self._PRW_patient.person = self.patient
95 self._PRW_patient.Enable(False)
96 self._TCTRL_comment.SetFocus()
97 self._PRW_patient._display_name()
98
99 self._TCTRL_comment.SetValue(u'')
100 self._PRW_zone.SetValue(u'')
101 self._SPCTRL_urgency.SetValue(0)
102
104 self._PRW_patient.person = gmPerson.cIdentity(aPK_obj = self.data['pk_identity'])
105 self._PRW_patient.Enable(False)
106 self._PRW_patient._display_name()
107
108 self._TCTRL_comment.SetValue(gmTools.coalesce(self.data['comment'], u''))
109 self._PRW_zone.SetValue(gmTools.coalesce(self.data['waiting_zone'], u''))
110 self._SPCTRL_urgency.SetValue(self.data['urgency'])
111
112 self._TCTRL_comment.SetFocus()
113
114 - def _valid_for_save(self):
115 validity = True
116
117 self.display_tctrl_as_valid(tctrl = self._PRW_patient, valid = (self._PRW_patient.person is not None))
118 validity = (self._PRW_patient.person is not None)
119
120 if validity is False:
121 gmDispatcher.send(signal = 'statustext', msg = _('Cannot add to waiting list. Missing essential input.'))
122
123 return validity
124
125 - def _save_as_new(self):
126
127 self._PRW_patient.person.put_on_waiting_list (
128 urgency = self._SPCTRL_urgency.GetValue(),
129 comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), u''),
130 zone = gmTools.none_if(self._PRW_zone.GetValue().strip(), u'')
131 )
132
133 self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0}
134 return True
135
136 - def _save_as_update(self):
137 gmSurgery.gmCurrentPractice().update_in_waiting_list (
138 pk = self.data['pk_waiting_list'],
139 urgency = self._SPCTRL_urgency.GetValue(),
140 comment = self._TCTRL_comment.GetValue().strip(),
141 zone = self._PRW_zone.GetValue().strip()
142 )
143 return True
144
145 from Gnumed.wxGladeWidgets import wxgWaitingListPnl
146
147 -class cWaitingListPnl(wxgWaitingListPnl.wxgWaitingListPnl, gmRegetMixin.cRegetOnPaintMixin):
148
158
159
160
162 self._LCTRL_patients.set_columns ([
163 _('Zone'),
164 _('Urgency'),
165
166 _('Waiting time'),
167 _('Patient'),
168 _('Born'),
169 _('Comment')
170 ])
171 self._LCTRL_patients.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE_USEHEADER, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE])
172 self._LCTRL_patients.item_tooltip_callback = self._on_get_list_tooltip
173 self._PRW_zone.add_callback_on_selection(callback = self._on_zone_selected)
174 self._PRW_zone.add_callback_on_lose_focus(callback = self._on_zone_selected)
175
214
216 gmDispatcher.connect(signal = u'waiting_list_generic_mod_db', receiver = self._on_waiting_list_modified)
217
219
220 praxis = gmSurgery.gmCurrentPractice()
221 pats = praxis.waiting_list_patients
222
223
224 zones = {}
225 zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
226 self._PRW_zone.update_matcher(items = zones.keys())
227
228
229 self.__current_zone = self._PRW_zone.GetValue().strip()
230 if self.__current_zone == u'':
231 pats = [ p for p in pats ]
232 else:
233 pats = [ p for p in pats if p['waiting_zone'] == self.__current_zone ]
234
235 old_pks = [ d['pk_waiting_list'] for d in self._LCTRL_patients.get_selected_item_data() ]
236 self._LCTRL_patients.set_string_items (
237 [ [
238 gmTools.coalesce(p['waiting_zone'], u''),
239 p['urgency'],
240 p['waiting_time_formatted'].replace(u'00 ', u'', 1).replace('00:', u'').lstrip('0'),
241 u'%s, %s (%s)' % (p['lastnames'], p['firstnames'], p['l10n_gender']),
242 gmTools.coalesce (
243 gmTools.coalesce (
244 p['dob'],
245 u'',
246 function_initial = ('strftime', '%d %b %Y')
247 ),
248 u'',
249 function_initial = ('decode', gmI18N.get_encoding())
250 ),
251 gmTools.coalesce(p['comment'], u'').split('\n')[0]
252 ] for p in pats ]
253 )
254 self._LCTRL_patients.set_column_widths()
255 self._LCTRL_patients.set_data(pats)
256 new_selections = []
257 new_pks = [ p['pk_waiting_list'] for p in pats ]
258 for old_pk in old_pks:
259 if old_pk in new_pks:
260 new_selections.append(new_pks.index(old_pk))
261 self._LCTRL_patients.selections = new_selections
262 self._LCTRL_patients.Refresh()
263
264 self._LBL_no_of_patients.SetLabel(_('(%s patients)') % len(pats))
265
266 if len(pats) == 0:
267 self._BTN_activate.Enable(False)
268 self._BTN_activateplus.Enable(False)
269 self._BTN_remove.Enable(False)
270 self._BTN_edit.Enable(False)
271 self._BTN_up.Enable(False)
272 self._BTN_down.Enable(False)
273 else:
274 self._BTN_activate.Enable(True)
275 self._BTN_activateplus.Enable(True)
276 self._BTN_remove.Enable(True)
277 self._BTN_edit.Enable(True)
278 if len(pats) > 1:
279 self._BTN_up.Enable(True)
280 self._BTN_down.Enable(True)
281
282
283
285 if self.__current_zone == self._PRW_zone.GetValue().strip():
286 return True
287 wx.CallAfter(self.__refresh_waiting_list)
288 return True
289
291 wx.CallAfter(self._schedule_data_reget)
292
299
306
314
326
335
341
347
353
354
355
356
357
359 self.__refresh_waiting_list()
360 return True
361
362
363
364 if __name__ == '__main__':
365
366 if len(sys.argv) < 2:
367 sys.exit()
368
369 if sys.argv[1] != 'test':
370 sys.exit()
371
372 gmI18N.activate_locale()
373 gmI18N.install_domain()
374
375
376
377
378
379
380
381
382
383
384
385
386 app = wx.PyWidgetTester(size = (200, 40))
387 app.SetWidget(cWaitingListPnl, -1)
388 app.MainLoop()
389
390
391