| Home | Trees | Indices | Help |
|
|---|
|
|
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 # stdlib
7 import logging
8 import sys
9
10
11 # 3rd party
12 import wx
13
14
15 # GNUmed
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 # waiting list widgets
36 #============================================================
38
40
41 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs)
42
43 mp = gmMatchProvider.cMatchProvider_FixedList(aSeq = [])
44 mp.setThresholds(1, 2, 2)
45 self.matcher = mp
46 self.selection_only = False
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
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 # edit area mixin API
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 #--------------------------------------------------------
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 #----------------------------------------------------------------
126 # FIXME: filter out dupes
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 # dummy:
133 self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0}
134 return True
135 #----------------------------------------------------------------
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
148
150
151 wxgWaitingListPnl.wxgWaitingListPnl.__init__(self, *args, **kwargs)
152 gmRegetMixin.cRegetOnPaintMixin.__init__(self)
153
154 self.__current_zone = None
155
156 self.__init_ui()
157 self.__register_events()
158 #--------------------------------------------------------
159 # interal helpers
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 #--------------------------------------------------------
177
178 dob = gmTools.coalesce (
179 gmTools.coalesce (
180 entry['dob'],
181 u'',
182 function_initial = ('strftime', '%d %b %Y')
183 ),
184 u'',
185 u' (%s)',
186 function_initial = ('decode', gmI18N.get_encoding())
187 )
188
189 tt = _(
190 '%s patients are waiting.\n'
191 '\n'
192 'Doubleclick to activate (entry will stay in list).'
193 ) % self._LCTRL_patients.GetItemCount()
194
195 tt += _(
196 '\n'
197 '%s\n'
198 'Patient: %s%s\n'
199 '%s'
200 'Urgency: %s\n'
201 'Time: %s\n'
202 '%s'
203 ) % (
204 gmTools.u_box_horiz_single * 50,
205 u'%s, %s (%s)' % (entry['lastnames'], entry['firstnames'], entry['l10n_gender']),
206 dob,
207 gmTools.coalesce(entry['waiting_zone'], u'', _('Zone: %s\n')),
208 entry['urgency'],
209 entry['waiting_time_formatted'].replace(u'00 ', u'', 1).replace('00:', u'').lstrip('0'),
210 gmTools.coalesce(entry['comment'], u'', u'\n%s')
211 )
212
213 return tt
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 # set matcher to all zones currently in use
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 # filter patient list by zone and set waiting list
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 # event handlers
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 #--------------------------------------------------------
292 #--------------------------------------------------------
294 item = self._LCTRL_patients.get_selected_item_data(only_one=True)
295 if item is None:
296 return
297 pat = gmPerson.cIdentity(aPK_obj = item['pk_identity'])
298 wx.CallAfter(gmPatSearchWidgets.set_active_patient, patient = pat)
299 #--------------------------------------------------------
306 #--------------------------------------------------------
314 #--------------------------------------------------------
326 #--------------------------------------------------------
335 #--------------------------------------------------------
341 #--------------------------------------------------------
347 #--------------------------------------------------------
353 #--------------------------------------------------------
354 # edit
355 #--------------------------------------------------------
356 # reget-on-paint API
357 #--------------------------------------------------------
361 #================================================================
362 # main
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 # def test_generic_codes_prw():
377 # gmPG2.get_connection()
378 # app = wx.PyWidgetTester(size = (500, 40))
379 # pw = cGenericCodesPhraseWheel(app.frame, -1)
380 # #pw.set_context(context = u'zip', val = u'04318')
381 # app.frame.Show(True)
382 # app.MainLoop()
383 # #--------------------------------------------------------
384 # test_generic_codes_prw()
385
386 app = wx.PyWidgetTester(size = (200, 40))
387 app.SetWidget(cWaitingListPnl, -1)
388 app.MainLoop()
389
390 #================================================================
391
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Oct 18 04:00:18 2011 | http://epydoc.sourceforge.net |