1
2
3
4
5
6 __license__ = 'GPL'
7 __version__ = "$Revision: 1.135 $"
8 __author__ = "R.Terry, K.Hilbert"
9
10
11 import logging
12
13
14 import wx
15
16
17 from Gnumed.pycommon import gmDispatcher, gmExceptions
18 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg, wxgGenericEditAreaDlg2
19
20
21 _log = logging.getLogger('gm.ui')
22 _log.info(__version__)
23
24 edit_area_modes = ['new', 'edit', 'new_from_existing']
25
27 """Mixin for edit area panels providing generic functionality.
28
29 #====================================================================
30 # Class definition:
31
32 from Gnumed.wxGladeWidgets import wxgXxxEAPnl
33
34 class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin):
35
36 def __init__(self, *args, **kwargs):
37
38 try:
39 data = kwargs['xxx']
40 del kwargs['xxx']
41 except KeyError:
42 data = None
43
44 wxgXxxEAPnl.wxgXxxPatientEAPnl.__init__(self, *args, **kwargs)
45 gmEditArea.cGenericEditAreaMixin.__init__(self)
46
47 # Code using this mixin should set mode and data
48 # after instantiating the class:
49 self.mode = 'new'
50 self.data = data
51 if data is not None:
52 self.mode = 'edit'
53
54 #self.__init_ui()
55 #----------------------------------------------------------------
56 # def __init_ui(self):
57 # # adjust phrasewheels etc
58 #----------------------------------------------------------------
59 # generic Edit Area mixin API
60 #----------------------------------------------------------------
61 def _valid_for_save(self):
62 return False
63 return True
64 #----------------------------------------------------------------
65 def _save_as_new(self):
66 # save the data as a new instance
67 data =
68
69 data[''] =
70 data[''] =
71
72 data.save()
73
74 # must be done very late or else the property access
75 # will refresh the display such that later field
76 # access will return empty values
77 self.data = data
78 return False
79 return True
80 #----------------------------------------------------------------
81 def _save_as_update(self):
82 # update self.data and save the changes
83 self.data[''] =
84 self.data[''] =
85 self.data[''] =
86 self.data.save()
87 return True
88 #----------------------------------------------------------------
89 def _refresh_as_new(self):
90 pass
91 #----------------------------------------------------------------
92 def _refresh_from_existing(self):
93 pass
94 #----------------------------------------------------------------
95 def _refresh_as_new_from_existing(self):
96 pass
97 #----------------------------------------------------------------
98
99 """
101 self.__mode = 'new'
102 self.__data = None
103 self.successful_save_msg = None
104 self._refresh_as_new()
105 self.__tctrl_validity_colors = {
106 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW),
107 False: 'pink'
108 }
109
112
114 if mode not in edit_area_modes:
115 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
116 if mode == 'edit':
117 if self.__data is None:
118 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
119 self.__mode = mode
120
121 mode = property(_get_mode, _set_mode)
122
125
127 if data is None:
128 if self.__mode == 'edit':
129 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
130 self.__data = data
131 self.refresh()
132
133 data = property(_get_data, _set_data)
134
136 """Invoked from the generic edit area dialog.
137
138 Invokes
139 _valid_for_save,
140 _save_as_new,
141 _save_as_update
142 on the implementing edit area as needed.
143
144 _save_as_* must set self.__data and return True/False
145 """
146 if not self._valid_for_save():
147 return False
148
149 if self.__mode in ['new', 'new_from_existing']:
150 if self._save_as_new():
151 self.mode = 'edit'
152 return True
153 return False
154
155 elif self.__mode == 'edit':
156 return self._save_as_update()
157
158 else:
159 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
160
162 """Invoked from the generic edit area dialog.
163
164 Invokes
165 _refresh_as_new
166 _refresh_from_existing
167 _refresh_as_new_from_existing
168 on the implementing edit area as needed.
169 """
170 if self.__mode == 'new':
171 return self._refresh_as_new()
172 elif self.__mode == 'edit':
173 return self._refresh_from_existing()
174 elif self.__mode == 'new_from_existing':
175 return self._refresh_as_new_from_existing()
176 else:
177 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
178
180 tctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
181 tctrl.Refresh()
182
184 """Dialog for parenting edit area panels with save/clear/next/cancel"""
185
187
188 new_ea = kwargs['edit_area']
189 del kwargs['edit_area']
190
191 if not isinstance(new_ea, cGenericEditAreaMixin):
192 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin')
193
194 try:
195 single_entry = kwargs['single_entry']
196 del kwargs['single_entry']
197 except KeyError:
198 single_entry = False
199
200 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs)
201
202
203 old_ea = self._PNL_ea
204 ea_pnl_szr = old_ea.GetContainingSizer()
205 ea_pnl_parent = old_ea.GetParent()
206 ea_pnl_szr.Remove(old_ea)
207 del old_ea
208
209 new_ea.Reparent(ea_pnl_parent)
210 self._PNL_ea = new_ea
211 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0)
212
213
214 if single_entry:
215 self._BTN_forward.Enable(False)
216 self._BTN_forward.Hide()
217
218 self._adjust_clear_revert_buttons()
219
220
221 self.Layout()
222 main_szr = self.GetSizer()
223 main_szr.Fit(self)
224 self.Refresh()
225
226 self._PNL_ea.refresh()
227
239
246
249
252
267
268
270 """Dialog for parenting edit area with save/clear/cancel"""
271
273
274 ea = kwargs['edit_area']
275 del kwargs['edit_area']
276
277 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs)
278
279 szr = self._PNL_ea.GetContainingSizer()
280 szr.Remove(self._PNL_ea)
281 ea.Reparent(self)
282 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4)
283 self._PNL_ea = ea
284
285 self.Layout()
286 szr = self.GetSizer()
287 szr.Fit(self)
288 self.Refresh()
289
290 self._PNL_ea.refresh()
291
299
302
303
304
305 import time
306
307 from Gnumed.business import gmPerson, gmDemographicRecord
308 from Gnumed.pycommon import gmGuiBroker
309 from Gnumed.wxpython import gmDateTimeInput, gmPhraseWheel, gmGuiHelpers
310
311 _gb = gmGuiBroker.GuiBroker()
312
313 gmSECTION_SUMMARY = 1
314 gmSECTION_DEMOGRAPHICS = 2
315 gmSECTION_CLINICALNOTES = 3
316 gmSECTION_FAMILYHISTORY = 4
317 gmSECTION_PASTHISTORY = 5
318 gmSECTION_SCRIPT = 8
319 gmSECTION_REQUESTS = 9
320 gmSECTION_REFERRALS = 11
321 gmSECTION_RECALLS = 12
322
323 richards_blue = wx.Colour(0,0,131)
324 richards_aqua = wx.Colour(0,194,197)
325 richards_dark_gray = wx.Color(131,129,131)
326 richards_light_gray = wx.Color(255,255,255)
327 richards_coloured_gray = wx.Color(131,129,131)
328
329
330 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox']
331
333 widget.SetForegroundColour(wx.Color(255, 0, 0))
334 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
335
348 if not isinstance(edit_area, cEditArea2):
349 raise gmExceptions.ConstructorError, '<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area)
350 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name)
351 self.__wxID_BTN_SAVE = wx.NewId()
352 self.__wxID_BTN_RESET = wx.NewId()
353 self.__editarea = edit_area
354 self.__do_layout()
355 self.__register_events()
356
357
358
361
363 self.__editarea.Reparent(self)
364
365 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save"))
366 self.__btn_SAVE.SetToolTipString(_('save entry into medical record'))
367 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset"))
368 self.__btn_RESET.SetToolTipString(_('reset entry'))
369 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
370 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel'))
371
372 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
373 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1)
374 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1)
375 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1)
376
377 szr_main = wx.BoxSizer(wx.VERTICAL)
378 szr_main.Add(self.__editarea, 1, wx.EXPAND)
379 szr_main.Add(szr_buttons, 0, wx.EXPAND)
380
381 self.SetSizerAndFit(szr_main)
382
383
384
386
387 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed)
388 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed)
389 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed)
390
391 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed)
392
393
394
395
396
397
398 return 1
399
401 if self.__editarea.save_data():
402 self.__editarea.Close()
403 self.EndModal(wx.ID_OK)
404 return
405 short_err = self.__editarea.get_short_error()
406 long_err = self.__editarea.get_long_error()
407 if (short_err is None) and (long_err is None):
408 long_err = _(
409 'Unspecified error saving data in edit area.\n\n'
410 'Programmer forgot to specify proper error\n'
411 'message in [%s].'
412 ) % self.__editarea.__class__.__name__
413 if short_err is not None:
414 gmDispatcher.send(signal = 'statustext', msg = short_err)
415 if long_err is not None:
416 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
417
419 self.__editarea.Close()
420 self.EndModal(wx.ID_CANCEL)
421
424
426 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
427
428 wx.Panel.__init__ (
429 self,
430 parent,
431 id,
432 pos = pos,
433 size = size,
434 style = style | wx.TAB_TRAVERSAL
435 )
436 self.SetBackgroundColour(wx.Color(222,222,222))
437
438 self.data = None
439 self.fields = {}
440 self.prompts = {}
441 self._short_error = None
442 self._long_error = None
443 self._summary = None
444 self._patient = gmPerson.gmCurrentPatient()
445 self.__wxID_BTN_OK = wx.NewId()
446 self.__wxID_BTN_CLEAR = wx.NewId()
447 self.__do_layout()
448 self.__register_events()
449 self.Show()
450
451
452
454 """This needs to be overridden by child classes."""
455 self._long_error = _(
456 'Cannot save data from edit area.\n\n'
457 'Programmer forgot to override method:\n'
458 ' <%s.save_data>'
459 ) % self.__class__.__name__
460 return False
461
463 msg = _(
464 'Cannot reset fields in edit area.\n\n'
465 'Programmer forgot to override method:\n'
466 ' <%s.reset_ui>'
467 ) % self.__class__.__name__
468 gmGuiHelpers.gm_show_error(msg)
469
471 tmp = self._short_error
472 self._short_error = None
473 return tmp
474
476 tmp = self._long_error
477 self._long_error = None
478 return tmp
479
481 return _('<No embed string for [%s]>') % self.__class__.__name__
482
483
484
496
501
502
503
505 self.__deregister_events()
506 event.Skip()
507
509 """Only active if _make_standard_buttons was called in child class."""
510
511 try:
512 event.Skip()
513 if self.data is None:
514 self._save_new_entry()
515 self.reset_ui()
516 else:
517 self._save_modified_entry()
518 self.reset_ui()
519 except gmExceptions.InvalidInputError, err:
520
521
522 gmGuiHelpers.gm_show_error (err, _("Invalid Input"))
523 except:
524 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
525
527 """Only active if _make_standard_buttons was called in child class."""
528
529 self.reset_ui()
530 event.Skip()
531
533 self.__deregister_events()
534
535 if not self._patient.connected:
536 return True
537
538
539
540
541 return True
542 _log.error('[%s] lossage' % self.__class__.__name__)
543 return False
544
546 """Just before new patient becomes active."""
547
548 if not self._patient.connected:
549 return True
550
551
552
553
554 return True
555 _log.error('[%s] lossage' % self.__class__.__name__)
556 return False
557
559 """Just after new patient became active."""
560
561 self.reset_ui()
562
563
564
566
567
568 self._define_prompts()
569 self._define_fields(parent = self)
570 if len(self.fields) != len(self.prompts):
571 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
572 return None
573
574
575 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2)
576 color = richards_aqua
577 lines = self.prompts.keys()
578 lines.sort()
579 for line in lines:
580
581 label, color, weight = self.prompts[line]
582
583 prompt = wx.StaticText (
584 parent = self,
585 id = -1,
586 label = label,
587 style = wx.ALIGN_CENTRE
588 )
589
590 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
591 prompt.SetForegroundColour(color)
592 prompt.SetBackgroundColour(richards_light_gray)
593 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT)
594
595
596 szr_line = wx.BoxSizer(wx.HORIZONTAL)
597 positions = self.fields[line].keys()
598 positions.sort()
599 for pos in positions:
600 field, weight = self.fields[line][pos]
601
602 szr_line.Add(field, weight, wx.EXPAND)
603 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT)
604
605
606 szr_main_fgrid.AddGrowableCol(1)
607
608
609
610
611
612
613
614 self.SetSizerAndFit(szr_main_fgrid)
615
616
617
618
620 """Child classes override this to define their prompts using _add_prompt()"""
621 _log.error('missing override in [%s]' % self.__class__.__name__)
622
624 """Add a new prompt line.
625
626 To be used from _define_fields in child classes.
627
628 - label, the label text
629 - color
630 - weight, the weight given in sizing the various rows. 0 means the row
631 always has minimum size
632 """
633 self.prompts[line] = (label, color, weight)
634
636 """Defines the fields.
637
638 - override in child classes
639 - mostly uses _add_field()
640 """
641 _log.error('missing override in [%s]' % self.__class__.__name__)
642
643 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
644 if None in (line, pos, widget):
645 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
646 if not self.fields.has_key(line):
647 self.fields[line] = {}
648 self.fields[line][pos] = (widget, weight)
649
667
668
669
670
672 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
673 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER)
674 _decorate_editarea_field(self)
675
677 - def __init__(self, parent, id, pos, size, style):
678
679 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
680
681
682 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
683 self.SetBackgroundColour(wx.Color(222,222,222))
684
685 self.data = None
686 self.fields = {}
687 self.prompts = {}
688
689 ID_BTN_OK = wx.NewId()
690 ID_BTN_CLEAR = wx.NewId()
691
692 self.__do_layout()
693
694
695
696
697
698
699 self._patient = gmPerson.gmCurrentPatient()
700 self.__register_events()
701 self.Show(True)
702
703
704
706
707 self._define_prompts()
708 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
709 self._define_fields(parent = self.fields_pnl)
710
711 szr_prompts = self.__generate_prompts()
712 szr_fields = self.__generate_fields()
713
714
715 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
716 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND)
717 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
718 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND)
719
720
721
722 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
723 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
724
725
726 self.SetAutoLayout(True)
727 self.SetSizer(self.szr_central_container)
728 self.szr_central_container.Fit(self)
729
731 if len(self.fields) != len(self.prompts):
732 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
733 return None
734
735 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
736 prompt_pnl.SetBackgroundColour(richards_light_gray)
737
738 color = richards_aqua
739 lines = self.prompts.keys()
740 lines.sort()
741 self.prompt_widget = {}
742 for line in lines:
743 label, color, weight = self.prompts[line]
744 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color)
745
746 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
747 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
748 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
749 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
750 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
751
752
753 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
754 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
755 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
756
757
758 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
759 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
760 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
761 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
762 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND)
763
764
765 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
766 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
767 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
768
769 return hszr_prompts
770
772 self.fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
773
774 vszr = wx.BoxSizer(wx.VERTICAL)
775 lines = self.fields.keys()
776 lines.sort()
777 self.field_line_szr = {}
778 for line in lines:
779 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL)
780 positions = self.fields[line].keys()
781 positions.sort()
782 for pos in positions:
783 field, weight = self.fields[line][pos]
784 self.field_line_szr[line].Add(field, weight, wx.EXPAND)
785 try:
786 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND)
787 except KeyError:
788 _log.error("Error with line=%s, self.field_line_szr has key:%s; self.prompts has key: %s" % (line, self.field_line_szr.has_key(line), self.prompts.has_key(line) ) )
789
790 self.fields_pnl.SetSizer(vszr)
791 vszr.Fit(self.fields_pnl)
792
793
794 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
795 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
796 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
797 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
798 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
799
800
801 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
802 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND)
803 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
804
805
806 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
807 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
808 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
809 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
810 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
811
812
813 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
814 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
815 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
816
817 return hszr_edit_fields
818
820
821 prompt = wx.StaticText(
822 parent,
823 -1,
824 aLabel,
825 style = wx.ALIGN_RIGHT
826 )
827 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
828 prompt.SetForegroundColour(aColor)
829 return prompt
830
831
832
834 """Add a new prompt line.
835
836 To be used from _define_fields in child classes.
837
838 - label, the label text
839 - color
840 - weight, the weight given in sizing the various rows. 0 means the rwo
841 always has minimum size
842 """
843 self.prompts[line] = (label, color, weight)
844
845 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
846 if None in (line, pos, widget):
847 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
848 if not self.fields.has_key(line):
849 self.fields[line] = {}
850 self.fields[line][pos] = (widget, weight)
851
853 """Defines the fields.
854
855 - override in child classes
856 - mostly uses _add_field()
857 """
858 _log.error('missing override in [%s]' % self.__class__.__name__)
859
861 _log.error('missing override in [%s]' % self.__class__.__name__)
862
876
879
881 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__)
882 _log.info('child classes of cEditArea *must* override this function')
883 return False
884
885
886
888
889 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed)
890 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed)
891
892 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields)
893
894
895 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection)
896 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing)
897 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection)
898
899 return 1
900
901
902
919
921
922 self.set_data()
923 event.Skip()
924
928
930
931 if not self._patient.connected:
932 return True
933 if self._save_data():
934 return True
935 _log.error('[%s] lossage' % self.__class__.__name__)
936 return False
937
939
940 if not self._patient.connected:
941 return True
942 if self._save_data():
943 return True
944 _log.error('[%s] lossage' % self.__class__.__name__)
945 return False
946
948 self.fields_pnl.Layout()
949
950 for i in self.field_line_szr.keys():
951
952 pos = self.field_line_szr[i].GetPosition()
953
954 self.prompt_widget[i].SetPosition((0, pos.y))
955
957 - def __init__(self, parent, id, aType = None):
958
959 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
960
961
962 if aType not in _known_edit_area_types:
963 _log.error('unknown edit area type: [%s]' % aType)
964 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType
965 self._type = aType
966
967
968 cEditArea.__init__(self, parent, id)
969
970 self.input_fields = {}
971
972 self._postInit()
973 self.old_data = {}
974
975 self._patient = gmPerson.gmCurrentPatient()
976 self.Show(True)
977
978
979
980
981
982
984
985 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
986 prompt_pnl.SetBackgroundColour(richards_light_gray)
987
988 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2)
989 color = richards_aqua
990 for prompt in prompt_labels:
991 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color)
992 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
993 color = richards_blue
994 gszr.RemoveGrowableRow (line-1)
995
996 prompt_pnl.SetSizer(gszr)
997 gszr.Fit(prompt_pnl)
998 prompt_pnl.SetAutoLayout(True)
999
1000
1001 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1002 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1003 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1004 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
1005 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1006
1007
1008 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
1009 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
1010 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1011
1012
1013 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1014 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1015 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1016 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1017 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1018
1019
1020 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
1021 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
1022 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1023
1024 return hszr_prompts
1025
1027 _log.error('programmer forgot to define edit area lines for [%s]' % self._type)
1028 _log.info('child classes of gmEditArea *must* override this function')
1029 return []
1030
1032
1033 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1034 fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
1035
1036 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2)
1037
1038
1039 lines = self._make_edit_lines(parent = fields_pnl)
1040
1041 self.lines = lines
1042 if len(lines) != len(_prompt_defs[self._type]):
1043 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type)
1044 for line in lines:
1045 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT)
1046
1047 fields_pnl.SetSizer(gszr)
1048 gszr.Fit(fields_pnl)
1049 fields_pnl.SetAutoLayout(True)
1050
1051
1052 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1053 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
1054 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1055 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
1056 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
1057
1058
1059 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
1060 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND)
1061 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
1062
1063
1064 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1065 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
1066 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
1067 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
1068 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
1069
1070
1071 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1072 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
1073 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
1074
1075 return hszr_edit_fields
1076
1079
1084
1086 map = {}
1087 for k in self.input_fields.keys():
1088 map[k] = ''
1089 return map
1090
1091
1093 self._default_init_fields()
1094
1095
1096
1097
1098
1100 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1101
1102
1103 - def _postInit(self):
1104 """override for further control setup"""
1105 pass
1106
1107
1109 szr = wx.BoxSizer(wx.HORIZONTAL)
1110 szr.Add( widget, weight, wx.EXPAND)
1111 szr.Add( 0,0, spacerWeight, wx.EXPAND)
1112 return szr
1113
1115
1116 cb = wx.CheckBox( parent, -1, _(title))
1117 cb.SetForegroundColour( richards_blue)
1118 return cb
1119
1120
1121
1123 """this is a utlity method to add extra columns"""
1124
1125 if self.__class__.__dict__.has_key("extraColumns"):
1126 for x in self.__class__.extraColumns:
1127 lines = self._addColumn(parent, lines, x, weightMap)
1128 return lines
1129
1130
1131
1132 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1133 """
1134 # add ia extra column in the edit area.
1135 # preconditions:
1136 # parent is fields_pnl (weak);
1137 # self.input_fields exists (required);
1138 # ; extra is a list of tuples of format -
1139 # ( key for input_fields, widget label , widget class to instantiate )
1140 """
1141
1142 newlines = []
1143 i = 0
1144 for x in lines:
1145
1146 if weightMap.has_key( x):
1147 (existingWeight, extraWeight) = weightMap[x]
1148
1149 szr = wx.BoxSizer(wx.HORIZONTAL)
1150 szr.Add( x, existingWeight, wx.EXPAND)
1151 if i < len(extra) and extra[i] <> None:
1152
1153 (inputKey, widgetLabel, aclass) = extra[i]
1154 if aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1155 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) )
1156 widgetLabel = ""
1157
1158
1159 w = aclass( parent, -1, widgetLabel)
1160 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1161 w.SetForegroundColour(richards_blue)
1162
1163 szr.Add(w, extraWeight , wx.EXPAND)
1164
1165
1166 self.input_fields[inputKey] = w
1167
1168 newlines.append(szr)
1169 i += 1
1170 return newlines
1171
1191
1194
1197
1203
1214
1222
1224 _log.debug("making family Hx lines")
1225 lines = []
1226 self.input_fields = {}
1227
1228
1229
1230 self.input_fields['name'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1231 self.input_fields['DOB'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1232 lbl_dob = self._make_prompt(parent, _(" Date of Birth "), richards_blue)
1233 szr = wx.BoxSizer(wx.HORIZONTAL)
1234 szr.Add(self.input_fields['name'], 4, wx.EXPAND)
1235 szr.Add(lbl_dob, 2, wx.EXPAND)
1236 szr.Add(self.input_fields['DOB'], 4, wx.EXPAND)
1237 lines.append(szr)
1238
1239
1240
1241 self.input_fields['relationship'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1242 szr = wx.BoxSizer(wx.HORIZONTAL)
1243 szr.Add(self.input_fields['relationship'], 4, wx.EXPAND)
1244 lines.append(szr)
1245
1246 self.input_fields['condition'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1247 self.cb_condition_confidential = wx.CheckBox(parent, -1, _("confidental"), wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER)
1248 szr = wx.BoxSizer(wx.HORIZONTAL)
1249 szr.Add(self.input_fields['condition'], 6, wx.EXPAND)
1250 szr.Add(self.cb_condition_confidential, 0, wx.EXPAND)
1251 lines.append(szr)
1252
1253 self.input_fields['comment'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1254 lines.append(self.input_fields['comment'])
1255
1256 lbl_onset = self._make_prompt(parent, _(" age onset "), richards_blue)
1257 self.input_fields['age onset'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1258
1259 lbl_caused_death = self._make_prompt(parent, _(" caused death "), richards_blue)
1260 self.input_fields['caused death'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1261 lbl_aod = self._make_prompt(parent, _(" age died "), richards_blue)
1262 self.input_fields['AOD'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1263 szr = wx.BoxSizer(wx.HORIZONTAL)
1264 szr.Add(lbl_onset, 0, wx.EXPAND)
1265 szr.Add(self.input_fields['age onset'], 1,wx.EXPAND)
1266 szr.Add(lbl_caused_death, 0, wx.EXPAND)
1267 szr.Add(self.input_fields['caused death'], 2,wx.EXPAND)
1268 szr.Add(lbl_aod, 0, wx.EXPAND)
1269 szr.Add(self.input_fields['AOD'], 1, wx.EXPAND)
1270 szr.Add(2, 2, 8)
1271 lines.append(szr)
1272
1273 self.input_fields['progress notes'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1274 lines.append(self.input_fields['progress notes'])
1275
1276 self.Btn_next_condition = wx.Button(parent, -1, _("Next Condition"))
1277 szr = wx.BoxSizer(wx.HORIZONTAL)
1278 szr.AddSpacer(10, 0, 0)
1279 szr.Add(self.Btn_next_condition, 0, wx.EXPAND | wx.ALL, 1)
1280 szr.Add(2, 1, 5)
1281 szr.Add(self._make_standard_buttons(parent), 0, wx.EXPAND)
1282 lines.append(szr)
1283
1284 return lines
1285
1288
1289
1290 -class gmPastHistoryEditArea(gmEditArea):
1291
1292 - def __init__(self, parent, id):
1293 gmEditArea.__init__(self, parent, id, aType = 'past history')
1294
1295 - def _define_prompts(self):
1296 self._add_prompt(line = 1, label = _("When Noted"))
1297 self._add_prompt(line = 2, label = _("Laterality"))
1298 self._add_prompt(line = 3, label = _("Condition"))
1299 self._add_prompt(line = 4, label = _("Notes"))
1300 self._add_prompt(line = 6, label = _("Status"))
1301 self._add_prompt(line = 7, label = _("Progress Note"))
1302 self._add_prompt(line = 8, label = '')
1303
1304 - def _define_fields(self, parent):
1305
1306 self.fld_date_noted = gmDateTimeInput.gmDateInput(
1307 parent = parent,
1308 id = -1,
1309 style = wx.SIMPLE_BORDER
1310 )
1311 self._add_field(
1312 line = 1,
1313 pos = 1,
1314 widget = self.fld_date_noted,
1315 weight = 2
1316 )
1317 self._add_field(
1318 line = 1,
1319 pos = 2,
1320 widget = cPrompt_edit_area(parent,-1, _("Age")),
1321 weight = 0)
1322
1323 self.fld_age_noted = cEditAreaField(parent)
1324 self._add_field(
1325 line = 1,
1326 pos = 3,
1327 widget = self.fld_age_noted,
1328 weight = 2
1329 )
1330
1331
1332 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A"))
1333 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L"))
1334 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R"))
1335 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both"))
1336 self._add_field(
1337 line = 2,
1338 pos = 1,
1339 widget = self.fld_laterality_none,
1340 weight = 0
1341 )
1342 self._add_field(
1343 line = 2,
1344 pos = 2,
1345 widget = self.fld_laterality_left,
1346 weight = 0
1347 )
1348 self._add_field(
1349 line = 2,
1350 pos = 3,
1351 widget = self.fld_laterality_right,
1352 weight = 1
1353 )
1354 self._add_field(
1355 line = 2,
1356 pos = 4,
1357 widget = self.fld_laterality_both,
1358 weight = 1
1359 )
1360
1361 self.fld_condition= cEditAreaField(parent)
1362 self._add_field(
1363 line = 3,
1364 pos = 1,
1365 widget = self.fld_condition,
1366 weight = 6
1367 )
1368
1369 self.fld_notes= cEditAreaField(parent)
1370 self._add_field(
1371 line = 4,
1372 pos = 1,
1373 widget = self.fld_notes,
1374 weight = 6
1375 )
1376
1377 self.fld_significant= wx.CheckBox(
1378 parent,
1379 -1,
1380 _("significant"),
1381 style = wx.NO_BORDER
1382 )
1383 self.fld_active= wx.CheckBox(
1384 parent,
1385 -1,
1386 _("active"),
1387 style = wx.NO_BORDER
1388 )
1389
1390 self._add_field(
1391 line = 5,
1392 pos = 1,
1393 widget = self.fld_significant,
1394 weight = 0
1395 )
1396 self._add_field(
1397 line = 5,
1398 pos = 2,
1399 widget = self.fld_active,
1400 weight = 0
1401 )
1402
1403 self.fld_progress= cEditAreaField(parent)
1404 self._add_field(
1405 line = 6,
1406 pos = 1,
1407 widget = self.fld_progress,
1408 weight = 6
1409 )
1410
1411
1412 self._add_field(
1413 line = 7,
1414 pos = 4,
1415 widget = self._make_standard_buttons(parent),
1416 weight = 2
1417 )
1418
1419 - def _postInit(self):
1420 return
1421
1422 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus)
1423 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1424
1425 - def _ageKillFocus( self, event):
1426
1427 event.Skip()
1428 try :
1429 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() )
1430 self.fld_date_noted.SetValue( str (year) )
1431 except:
1432 pass
1433
1434 - def _getBirthYear(self):
1435 try:
1436 birthyear = int(str(self._patient['dob']).split('-')[0])
1437 except:
1438 birthyear = time.localtime()[0]
1439
1440 return birthyear
1441
1442 - def _yearKillFocus( self, event):
1443 event.Skip()
1444 try:
1445 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear()
1446 self.fld_age_noted.SetValue( str (age) )
1447 except:
1448 pass
1449
1450 __init_values = {
1451 "condition": "",
1452 "notes1": "",
1453 "notes2": "",
1454 "age": "",
1455 "year": str(time.localtime()[0]),
1456 "progress": "",
1457 "active": 1,
1458 "operation": 0,
1459 "confidential": 0,
1460 "significant": 1,
1461 "both": 0,
1462 "left": 0,
1463 "right": 0,
1464 "none" : 1
1465 }
1466
1467 - def _getDefaultAge(self):
1468 try:
1469 return time.localtime()[0] - self._patient.getBirthYear()
1470 except:
1471 return 0
1472
1473 - def _get_init_values(self):
1474 values = gmPastHistoryEditArea.__init_values
1475 values["age"] = str( self._getDefaultAge())
1476 return values
1477
1478
1479 - def _save_data(self):
1480 clinical = self._patient.get_emr().get_past_history()
1481 if self.getDataId() is None:
1482 id = clinical.create_history( self.get_fields_formatting_values() )
1483 self.setDataId(id)
1484 return
1485
1486 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1487
1488
1498
1500 self._add_prompt (line = 1, label = _ ("Specialty"))
1501 self._add_prompt (line = 2, label = _ ("Name"))
1502 self._add_prompt (line = 3, label = _ ("Address"))
1503 self._add_prompt (line = 4, label = _ ("Options"))
1504 self._add_prompt (line = 5, label = _("Text"), weight =6)
1505 self._add_prompt (line = 6, label = "")
1506
1508 self.fld_specialty = gmPhraseWheel.cPhraseWheel (
1509 parent = parent,
1510 id = -1,
1511 style = wx.SIMPLE_BORDER
1512 )
1513
1514 self._add_field (
1515 line = 1,
1516 pos = 1,
1517 widget = self.fld_specialty,
1518 weight = 1
1519 )
1520 self.fld_name = gmPhraseWheel.cPhraseWheel (
1521 parent = parent,
1522 id = -1,
1523 style = wx.SIMPLE_BORDER
1524 )
1525
1526 self._add_field (
1527 line = 2,
1528 pos = 1,
1529 widget = self.fld_name,
1530 weight = 1
1531 )
1532 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY)
1533
1534 self._add_field (
1535 line = 3,
1536 pos = 1,
1537 widget = self.fld_address,
1538 weight = 1
1539 )
1540
1541
1542 self.fld_name.add_callback_on_selection(self.setAddresses)
1543
1544 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER)
1545 self._add_field (
1546 line = 4,
1547 pos = 1,
1548 widget = self.fld_med,
1549 weight = 1
1550 )
1551 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER)
1552 self._add_field (
1553 line = 4,
1554 pos = 4,
1555 widget = self.fld_past,
1556 weight = 1
1557 )
1558 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE)
1559 self._add_field (
1560 line = 5,
1561 pos = 1,
1562 widget = self.fld_text,
1563 weight = 1)
1564
1565 self._add_field(
1566 line = 6,
1567 pos = 1,
1568 widget = self._make_standard_buttons(parent),
1569 weight = 1
1570 )
1571 return 1
1572
1574 """
1575 Doesn't accept any value as this doesn't make sense for this edit area
1576 """
1577 self.fld_specialty.SetValue ('')
1578 self.fld_name.SetValue ('')
1579 self.fld_address.Clear ()
1580 self.fld_address.SetValue ('')
1581 self.fld_med.SetValue (0)
1582 self.fld_past.SetValue (0)
1583 self.fld_text.SetValue ('')
1584 self.recipient = None
1585
1587 """
1588 Set the available addresses for the selected identity
1589 """
1590 if id is None:
1591 self.recipient = None
1592 self.fld_address.Clear ()
1593 self.fld_address.SetValue ('')
1594 else:
1595 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id)
1596 self.fld_address.Clear ()
1597 self.addr = self.recipient.getAddresses ('work')
1598 for i in self.addr:
1599 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i))
1600 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX)
1601 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL)
1602 if fax:
1603 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax))
1604 if email:
1605 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1606
1607 - def _save_new_entry(self):
1608 """
1609 We are always saving a "new entry" here because data_ID is always None
1610 """
1611 if not self.recipient:
1612 raise gmExceptions.InvalidInputError(_('must have a recipient'))
1613 if self.fld_address.GetSelection() == -1:
1614 raise gmExceptions.InvalidInputError(_('must select address'))
1615 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection())
1616 text = self.fld_text.GetValue()
1617 flags = {}
1618 flags['meds'] = self.fld_med.GetValue()
1619 flags['pasthx'] = self.fld_past.GetValue()
1620 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags):
1621 raise gmExceptions.InvalidInputError('error sending form')
1622
1623
1624
1625
1626
1634
1635
1636
1638 _log.debug("making prescription lines")
1639 lines = []
1640 self.txt_problem = cEditAreaField(parent)
1641 self.txt_class = cEditAreaField(parent)
1642 self.txt_generic = cEditAreaField(parent)
1643 self.txt_brand = cEditAreaField(parent)
1644 self.txt_strength= cEditAreaField(parent)
1645 self.txt_directions= cEditAreaField(parent)
1646 self.txt_for = cEditAreaField(parent)
1647 self.txt_progress = cEditAreaField(parent)
1648
1649 lines.append(self.txt_problem)
1650 lines.append(self.txt_class)
1651 lines.append(self.txt_generic)
1652 lines.append(self.txt_brand)
1653 lines.append(self.txt_strength)
1654 lines.append(self.txt_directions)
1655 lines.append(self.txt_for)
1656 lines.append(self.txt_progress)
1657 lines.append(self._make_standard_buttons(parent))
1658 self.input_fields = {
1659 "problem": self.txt_problem,
1660 "class" : self.txt_class,
1661 "generic" : self.txt_generic,
1662 "brand" : self.txt_brand,
1663 "strength": self.txt_strength,
1664 "directions": self.txt_directions,
1665 "for" : self.txt_for,
1666 "progress": self.txt_progress
1667
1668 }
1669
1670 return self._makeExtraColumns( parent, lines)
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1689
1690
1691
1692
1693
1694
1697 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT)
1698 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
1699 self.SetForegroundColour(aColor)
1700
1701
1702
1703
1704
1706 - def __init__(self, parent, id, prompt_labels):
1707 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1708 self.SetBackgroundColour(richards_light_gray)
1709 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2)
1710 color = richards_aqua
1711 for prompt_key in prompt_labels.keys():
1712 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color)
1713 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1714 color = richards_blue
1715 self.SetSizer(gszr)
1716 gszr.Fit(self)
1717 self.SetAutoLayout(True)
1718
1719
1720
1721
1722
1723
1724
1725 -class EditTextBoxes(wx.Panel):
1726 - def __init__(self, parent, id, editareaprompts, section):
1727 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1728 self.SetBackgroundColour(wx.Color(222,222,222))
1729 self.parent = parent
1730
1731 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2)
1732
1733 if section == gmSECTION_SUMMARY:
1734 pass
1735 elif section == gmSECTION_DEMOGRAPHICS:
1736 pass
1737 elif section == gmSECTION_CLINICALNOTES:
1738 pass
1739 elif section == gmSECTION_FAMILYHISTORY:
1740 pass
1741 elif section == gmSECTION_PASTHISTORY:
1742 pass
1743
1744
1745 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize)
1746 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize)
1747 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER)
1748 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize)
1749 rbsizer = wx.BoxSizer(wx.HORIZONTAL)
1750 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND)
1751 rbsizer.Add(self.rb_sideright,1,wx.EXPAND)
1752 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND)
1753 szr1 = wx.BoxSizer(wx.HORIZONTAL)
1754 szr1.Add(self.txt_condition, 4, wx.EXPAND)
1755 szr1.Add(rbsizer, 3, wx.EXPAND)
1756
1757
1758
1759
1760 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize)
1761
1762 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize)
1763
1764 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize)
1765 szr4 = wx.BoxSizer(wx.HORIZONTAL)
1766 szr4.Add(self.txt_agenoted, 1, wx.EXPAND)
1767 szr4.Add(5, 0, 5)
1768
1769 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize)
1770 szr5 = wx.BoxSizer(wx.HORIZONTAL)
1771 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND)
1772 szr5.Add(5, 0, 5)
1773
1774 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1775 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1776 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1777 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1778 szr6 = wx.BoxSizer(wx.HORIZONTAL)
1779 szr6.Add(self.parent.cb_active, 1, wx.EXPAND)
1780 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND)
1781 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND)
1782 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND)
1783
1784 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize)
1785
1786 szr8 = wx.BoxSizer(wx.HORIZONTAL)
1787 szr8.Add(5, 0, 6)
1788 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND)
1789
1790 self.gszr.Add(szr1,0,wx.EXPAND)
1791 self.gszr.Add(self.txt_notes1,0,wx.EXPAND)
1792 self.gszr.Add(self.txt_notes2,0,wx.EXPAND)
1793 self.gszr.Add(szr4,0,wx.EXPAND)
1794 self.gszr.Add(szr5,0,wx.EXPAND)
1795 self.gszr.Add(szr6,0,wx.EXPAND)
1796 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND)
1797 self.gszr.Add(szr8,0,wx.EXPAND)
1798
1799
1800 elif section == gmSECTION_SCRIPT:
1801 pass
1802 elif section == gmSECTION_REQUESTS:
1803 pass
1804 elif section == gmSECTION_RECALLS:
1805 pass
1806 else:
1807 pass
1808
1809 self.SetSizer(self.gszr)
1810 self.gszr.Fit(self)
1811
1812 self.SetAutoLayout(True)
1813 self.Show(True)
1814
1816 self.btn_OK = wx.Button(self, -1, _("Ok"))
1817 self.btn_Clear = wx.Button(self, -1, _("Clear"))
1818 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
1819 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1)
1820 szr_buttons.Add(5, 0, 0)
1821 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1)
1822 return szr_buttons
1823
1825 - def __init__(self, parent, id, line_labels, section):
1826 _log.warning('***** old style EditArea instantiated, please convert *****')
1827
1828 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER)
1829 self.SetBackgroundColour(wx.Color(222,222,222))
1830
1831
1832 prompts = gmPnlEditAreaPrompts(self, -1, line_labels)
1833
1834 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1835
1836 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1837 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1838 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND)
1839 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1840
1841 szr_prompts = wx.BoxSizer(wx.VERTICAL)
1842 szr_prompts.Add(prompts, 97, wx.EXPAND)
1843 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1844
1845
1846 edit_fields = EditTextBoxes(self, -1, line_labels, section)
1847
1848 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1849
1850 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray)
1851 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL)
1852 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND)
1853 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND)
1854
1855 szr_editarea = wx.BoxSizer(wx.VERTICAL)
1856 szr_editarea.Add(edit_fields, 92, wx.EXPAND)
1857 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND)
1858
1859
1860
1861 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1862 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1863 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1864 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1865 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1866
1867 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1868 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray)
1869 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL)
1870 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND)
1871 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND)
1872
1873
1874 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
1875 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND)
1876 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1877 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
1878 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND)
1879 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND)
1880
1881
1882
1883 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
1884 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
1885 self.SetSizer(self.szr_central_container)
1886 self.szr_central_container.Fit(self)
1887 self.SetAutoLayout(True)
1888 self.Show(True)
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165 if __name__ == "__main__":
2166
2167
2172 self._add_prompt(line=1, label='line 1')
2173 self._add_prompt(line=2, label='buttons')
2175
2176 self.fld_substance = cEditAreaField(parent)
2177 self._add_field(
2178 line = 1,
2179 pos = 1,
2180 widget = self.fld_substance,
2181 weight = 1
2182 )
2183
2184 self._add_field(
2185 line = 2,
2186 pos = 1,
2187 widget = self._make_standard_buttons(parent),
2188 weight = 1
2189 )
2190
2191 app = wxPyWidgetTester(size = (400, 200))
2192 app.SetWidget(cTestEditArea)
2193 app.MainLoop()
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642