1
2
3
4 __license__ = 'GPL'
5 __version__ = "$Revision: 1.135 $"
6 __author__ = "R.Terry, K.Hilbert"
7
8
9 import sys
10 import logging
11 import datetime as pydt
12
13
14 import wx
15
16
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19 from Gnumed.pycommon import gmDispatcher
20
21
22 _log = logging.getLogger('gm.ui')
23 _log.info(__version__)
24
25 edit_area_modes = ['new', 'edit', 'new_from_existing']
26
28 """Mixin for edit area panels providing generic functionality.
29
30 **************** start of template ****************
31
32 #====================================================================
33 # Class definition:
34
35 from Gnumed.wxGladeWidgets import wxgXxxEAPnl
36
37 class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin):
38
39 def __init__(self, *args, **kwargs):
40
41 try:
42 data = kwargs['xxx']
43 del kwargs['xxx']
44 except KeyError:
45 data = None
46
47 wxgXxxEAPnl.wxgXxxEAPnl.__init__(self, *args, **kwargs)
48 gmEditArea.cGenericEditAreaMixin.__init__(self)
49
50 # Code using this mixin should set mode and data
51 # after instantiating the class:
52 self.mode = 'new'
53 self.data = data
54 if data is not None:
55 self.mode = 'edit'
56
57 #self.__init_ui()
58 #----------------------------------------------------------------
59 # def __init_ui(self):
60 # # adjust phrasewheels etc
61 #----------------------------------------------------------------
62 # generic Edit Area mixin API
63 #----------------------------------------------------------------
64 def _valid_for_save(self):
65
66 # its best to validate bottom -> top such that the
67 # cursor ends up in the topmost failing field
68
69 # remove when implemented:
70 return False
71
72 validity = True
73
74 if self._TCTRL_xxx.GetValue().strip() == u'':
75 validity = False
76 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = False)
77 gmDispatcher.send(signal = 'statustext', msg = _('No entry in field xxx.'))
78 self._TCTRL_xxx.SetFocus()
79 else:
80 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = True)
81
82 if self._PRW_xxx.GetData() is None:
83 validity = False
84 self._PRW_xxx.display_as_valid(False)
85 gmDispatcher.send(signal = 'statustext', msg = _('No entry in field xxx.'))
86 self._PRW_xxx.SetFocus()
87 else:
88 self._PRW_xxx.display_as_valid(True)
89
90 return validity
91 #----------------------------------------------------------------
92 def _save_as_new(self):
93
94 # remove when implemented:
95 return False
96
97 # save the data as a new instance
98 data = gmXXXX.create_xxxx()
99
100 data[''] = self._
101 data[''] = self._
102
103 data.save()
104
105 # must be done very late or else the property access
106 # will refresh the display such that later field
107 # access will return empty values
108 self.data = data
109 return False
110 return True
111 #----------------------------------------------------------------
112 def _save_as_update(self):
113
114 # remove when implemented:
115 return False
116
117 # update self.data and save the changes
118 self.data[''] = self._TCTRL_xxx.GetValue().strip()
119 self.data[''] = self._PRW_xxx.GetData()
120 self.data[''] = self._CHBOX_xxx.GetValue()
121 self.data.save()
122 return True
123 #----------------------------------------------------------------
124 def _refresh_as_new(self):
125 pass
126 #----------------------------------------------------------------
127 def _refresh_as_new_from_existing(self):
128 self._refresh_as_new()
129 #----------------------------------------------------------------
130 def _refresh_from_existing(self):
131 pass
132 #----------------------------------------------------------------
133
134 **************** end of template ****************
135 """
137 self.__mode = 'new'
138 self.__data = None
139 self.successful_save_msg = None
140 self.__tctrl_validity_colors = {
141 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW),
142 False: 'pink'
143 }
144 self._refresh_as_new()
145
148
150 if mode not in edit_area_modes:
151 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
152 if mode == 'edit':
153 if self.__data is None:
154 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
155
156 prev_mode = self.__mode
157 self.__mode = mode
158 if mode != prev_mode:
159 self.refresh()
160
161 mode = property(_get_mode, _set_mode)
162
165
167 if data is None:
168 if self.__mode == 'edit':
169 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
170 self.__data = data
171 self.refresh()
172
173 data = property(_get_data, _set_data)
174
176 """Invoked from the generic edit area dialog.
177
178 Invokes
179 _valid_for_save,
180 _save_as_new,
181 _save_as_update
182 on the implementing edit area as needed.
183
184 _save_as_* must set self.__data and return True/False
185 """
186 if not self._valid_for_save():
187 return False
188
189
190 gmDispatcher.send(signal = 'statustext', msg = u'')
191
192 if self.__mode in ['new', 'new_from_existing']:
193 if self._save_as_new():
194 self.mode = 'edit'
195 return True
196 return False
197
198 elif self.__mode == 'edit':
199 return self._save_as_update()
200
201 else:
202 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
203
205 """Invoked from the generic edit area dialog.
206
207 Invokes
208 _refresh_as_new()
209 _refresh_from_existing()
210 _refresh_as_new_from_existing()
211 on the implementing edit area as needed.
212
213 Then calls _valid_for_save().
214 """
215 if self.__mode == 'new':
216 result = self._refresh_as_new()
217 self._valid_for_save()
218 return result
219 elif self.__mode == 'edit':
220 result = self._refresh_from_existing()
221 return result
222 elif self.__mode == 'new_from_existing':
223 result = self._refresh_as_new_from_existing()
224 self._valid_for_save()
225 return result
226 else:
227 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
228
231
233 ctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
234 ctrl.Refresh()
235
236 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg2
237
239 """Dialog for parenting edit area panels with save/clear/next/cancel"""
240
241 _lucky_day = 1
242 _lucky_month = 4
243 _today = pydt.date.today()
244
246
247 new_ea = kwargs['edit_area']
248 del kwargs['edit_area']
249
250 if not isinstance(new_ea, cGenericEditAreaMixin):
251 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin')
252
253 try:
254 single_entry = kwargs['single_entry']
255 del kwargs['single_entry']
256 except KeyError:
257 single_entry = False
258
259 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs)
260
261 self.left_extra_button = None
262
263 if cGenericEditAreaDlg2._today.day != cGenericEditAreaDlg2._lucky_day:
264 self._BTN_lucky.Enable(False)
265 self._BTN_lucky.Hide()
266 else:
267 if cGenericEditAreaDlg2._today.month != cGenericEditAreaDlg2._lucky_month:
268 self._BTN_lucky.Enable(False)
269 self._BTN_lucky.Hide()
270
271
272 dummy_ea_pnl = self._PNL_ea
273 ea_pnl_szr = dummy_ea_pnl.GetContainingSizer()
274 ea_pnl_parent = dummy_ea_pnl.GetParent()
275 ea_pnl_szr.Remove(dummy_ea_pnl)
276 dummy_ea_pnl.Destroy()
277 del dummy_ea_pnl
278 new_ea_min_size = new_ea.GetMinSize()
279 new_ea.Reparent(ea_pnl_parent)
280 self._PNL_ea = new_ea
281 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0)
282 ea_pnl_szr.SetMinSize(new_ea_min_size)
283 ea_pnl_szr.Fit(new_ea)
284
285
286 if single_entry:
287 self._BTN_forward.Enable(False)
288 self._BTN_forward.Hide()
289
290 self._adjust_clear_revert_buttons()
291
292
293 self._TCTRL_status.SetValue('')
294 gmDispatcher.connect(signal = u'statustext', receiver = self._on_set_statustext)
295
296
297
298 main_szr = self.GetSizer()
299 main_szr.Fit(self)
300 self.Layout()
301
302
303 self._PNL_ea.refresh()
304
305 - def _on_set_statustext(self, msg=None, loglevel=None, beep=True):
306 if msg is None:
307 self._TCTRL_status.SetValue('')
308 return
309 if msg.strip() == u'':
310 self._TCTRL_status.SetValue('')
311 return
312 self._TCTRL_status.SetValue(msg)
313 return
314
326
334
337
340
355
366
375
376
377
393
394 left_extra_button = property(lambda x:x, _set_left_extra_button)
395
396
397 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg
398
400 """Dialog for parenting edit area with save/clear/cancel"""
401
403
404 ea = kwargs['edit_area']
405 del kwargs['edit_area']
406
407 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs)
408
409 szr = self._PNL_ea.GetContainingSizer()
410 szr.Remove(self._PNL_ea)
411 ea.Reparent(self)
412 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4)
413 self._PNL_ea = ea
414
415 self.Layout()
416 szr = self.GetSizer()
417 szr.Fit(self)
418 self.Refresh()
419
420 self._PNL_ea.refresh()
421
429
432
433
434
435
436
437
438 from Gnumed.pycommon import gmGuiBroker
439
440
441 _gb = gmGuiBroker.GuiBroker()
442
443 gmSECTION_SUMMARY = 1
444 gmSECTION_DEMOGRAPHICS = 2
445 gmSECTION_CLINICALNOTES = 3
446 gmSECTION_FAMILYHISTORY = 4
447 gmSECTION_PASTHISTORY = 5
448 gmSECTION_SCRIPT = 8
449 gmSECTION_REQUESTS = 9
450 gmSECTION_REFERRALS = 11
451 gmSECTION_RECALLS = 12
452
453 richards_blue = wx.Colour(0,0,131)
454 richards_aqua = wx.Colour(0,194,197)
455 richards_dark_gray = wx.Colour(131,129,131)
456 richards_light_gray = wx.Colour(255,255,255)
457 richards_coloured_gray = wx.Colour(131,129,131)
458
459
460 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox']
461
463 widget.SetForegroundColour(wx.Colour(255, 0, 0))
464 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
465
478 if not isinstance(edit_area, cEditArea2):
479 raise TypeError('<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area))
480 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name)
481 self.__wxID_BTN_SAVE = wx.NewId()
482 self.__wxID_BTN_RESET = wx.NewId()
483 self.__editarea = edit_area
484 self.__do_layout()
485 self.__register_events()
486
487
488
491
493 self.__editarea.Reparent(self)
494
495 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save"))
496 self.__btn_SAVE.SetToolTipString(_('save entry into medical record'))
497 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset"))
498 self.__btn_RESET.SetToolTipString(_('reset entry'))
499 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
500 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel'))
501
502 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
503 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1)
504 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1)
505 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1)
506
507 szr_main = wx.BoxSizer(wx.VERTICAL)
508 szr_main.Add(self.__editarea, 1, wx.EXPAND)
509 szr_main.Add(szr_buttons, 0, wx.EXPAND)
510
511 self.SetSizerAndFit(szr_main)
512
513
514
516
517 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed)
518 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed)
519 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed)
520
521 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed)
522
523
524
525
526
527
528 return 1
529
531 if self.__editarea.save_data():
532 self.__editarea.Close()
533 self.EndModal(wx.ID_OK)
534 return
535 short_err = self.__editarea.get_short_error()
536 long_err = self.__editarea.get_long_error()
537 if (short_err is None) and (long_err is None):
538 long_err = _(
539 'Unspecified error saving data in edit area.\n\n'
540 'Programmer forgot to specify proper error\n'
541 'message in [%s].'
542 ) % self.__editarea.__class__.__name__
543 if short_err is not None:
544 gmDispatcher.send(signal = 'statustext', msg = short_err)
545 if long_err is not None:
546 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
547
549 self.__editarea.Close()
550 self.EndModal(wx.ID_CANCEL)
551
554
556 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
557
558 wx.Panel.__init__ (
559 self,
560 parent,
561 id,
562 pos = pos,
563 size = size,
564 style = style | wx.TAB_TRAVERSAL
565 )
566 self.SetBackgroundColour(wx.Colour(222,222,222))
567
568 self.data = None
569 self.fields = {}
570 self.prompts = {}
571 self._short_error = None
572 self._long_error = None
573 self._summary = None
574 self._patient = gmPerson.gmCurrentPatient()
575 self.__wxID_BTN_OK = wx.NewId()
576 self.__wxID_BTN_CLEAR = wx.NewId()
577 self.__do_layout()
578 self.__register_events()
579 self.Show()
580
581
582
584 """This needs to be overridden by child classes."""
585 self._long_error = _(
586 'Cannot save data from edit area.\n\n'
587 'Programmer forgot to override method:\n'
588 ' <%s.save_data>'
589 ) % self.__class__.__name__
590 return False
591
593 msg = _(
594 'Cannot reset fields in edit area.\n\n'
595 'Programmer forgot to override method:\n'
596 ' <%s.reset_ui>'
597 ) % self.__class__.__name__
598 gmGuiHelpers.gm_show_error(msg)
599
601 tmp = self._short_error
602 self._short_error = None
603 return tmp
604
606 tmp = self._long_error
607 self._long_error = None
608 return tmp
609
611 return _('<No embed string for [%s]>') % self.__class__.__name__
612
613
614
626
631
632
633
635 self.__deregister_events()
636 event.Skip()
637
639 """Only active if _make_standard_buttons was called in child class."""
640
641 try:
642 event.Skip()
643 if self.data is None:
644 self._save_new_entry()
645 self.reset_ui()
646 else:
647 self._save_modified_entry()
648 self.reset_ui()
649 except gmExceptions.InvalidInputError, err:
650
651
652 gmGuiHelpers.gm_show_error (err, _("Invalid Input"))
653 except:
654 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
655
657 """Only active if _make_standard_buttons was called in child class."""
658
659 self.reset_ui()
660 event.Skip()
661
663 self.__deregister_events()
664
665 if not self._patient.connected:
666 return True
667
668
669
670
671 return True
672 _log.error('[%s] lossage' % self.__class__.__name__)
673 return False
674
676 """Just before new patient becomes active."""
677
678 if not self._patient.connected:
679 return True
680
681
682
683
684 return True
685 _log.error('[%s] lossage' % self.__class__.__name__)
686 return False
687
689 """Just after new patient became active."""
690
691 self.reset_ui()
692
693
694
696
697
698 self._define_prompts()
699 self._define_fields(parent = self)
700 if len(self.fields) != len(self.prompts):
701 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
702 return None
703
704
705 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2)
706 color = richards_aqua
707 lines = self.prompts.keys()
708 lines.sort()
709 for line in lines:
710
711 label, color, weight = self.prompts[line]
712
713 prompt = wx.StaticText (
714 parent = self,
715 id = -1,
716 label = label,
717 style = wx.ALIGN_CENTRE
718 )
719
720 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
721 prompt.SetForegroundColour(color)
722 prompt.SetBackgroundColour(richards_light_gray)
723 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT)
724
725
726 szr_line = wx.BoxSizer(wx.HORIZONTAL)
727 positions = self.fields[line].keys()
728 positions.sort()
729 for pos in positions:
730 field, weight = self.fields[line][pos]
731
732 szr_line.Add(field, weight, wx.EXPAND)
733 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT)
734
735
736 szr_main_fgrid.AddGrowableCol(1)
737
738
739
740
741
742
743
744 self.SetSizerAndFit(szr_main_fgrid)
745
746
747
748
750 """Child classes override this to define their prompts using _add_prompt()"""
751 _log.error('missing override in [%s]' % self.__class__.__name__)
752
754 """Add a new prompt line.
755
756 To be used from _define_fields in child classes.
757
758 - label, the label text
759 - color
760 - weight, the weight given in sizing the various rows. 0 means the row
761 always has minimum size
762 """
763 self.prompts[line] = (label, color, weight)
764
766 """Defines the fields.
767
768 - override in child classes
769 - mostly uses _add_field()
770 """
771 _log.error('missing override in [%s]' % self.__class__.__name__)
772
773 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
774 if None in (line, pos, widget):
775 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
776 if not self.fields.has_key(line):
777 self.fields[line] = {}
778 self.fields[line][pos] = (widget, weight)
779
797
798
799
800
802 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
803 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER)
804 _decorate_editarea_field(self)
805
807 - def __init__(self, parent, id, pos, size, style):
808
809 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
810
811
812 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
813 self.SetBackgroundColour(wx.Colour(222,222,222))
814
815 self.data = None
816 self.fields = {}
817 self.prompts = {}
818
819 ID_BTN_OK = wx.NewId()
820 ID_BTN_CLEAR = wx.NewId()
821
822 self.__do_layout()
823
824
825
826
827
828
829 self._patient = gmPerson.gmCurrentPatient()
830 self.__register_events()
831 self.Show(True)
832
833
834
836
837 self._define_prompts()
838 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
839 self._define_fields(parent = self.fields_pnl)
840
841 szr_prompts = self.__generate_prompts()
842 szr_fields = self.__generate_fields()
843
844
845 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
846 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND)
847 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
848 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND)
849
850
851
852 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
853 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
854
855
856 self.SetAutoLayout(True)
857 self.SetSizer(self.szr_central_container)
858 self.szr_central_container.Fit(self)
859
861 if len(self.fields) != len(self.prompts):
862 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
863 return None
864
865 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
866 prompt_pnl.SetBackgroundColour(richards_light_gray)
867
868 color = richards_aqua
869 lines = self.prompts.keys()
870 lines.sort()
871 self.prompt_widget = {}
872 for line in lines:
873 label, color, weight = self.prompts[line]
874 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color)
875
876 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
877 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
878 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
879 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
880 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
881
882
883 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
884 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
885 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
886
887
888 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
889 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
890 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
891 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
892 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND)
893
894
895 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
896 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
897 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
898
899 return hszr_prompts
900
902 self.fields_pnl.SetBackgroundColour(wx.Colour(222,222,222))
903
904 vszr = wx.BoxSizer(wx.VERTICAL)
905 lines = self.fields.keys()
906 lines.sort()
907 self.field_line_szr = {}
908 for line in lines:
909 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL)
910 positions = self.fields[line].keys()
911 positions.sort()
912 for pos in positions:
913 field, weight = self.fields[line][pos]
914 self.field_line_szr[line].Add(field, weight, wx.EXPAND)
915 try:
916 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND)
917 except KeyError:
918 _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) ) )
919
920 self.fields_pnl.SetSizer(vszr)
921 vszr.Fit(self.fields_pnl)
922
923
924 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
925 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
926 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
927 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
928 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
929
930
931 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
932 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND)
933 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
934
935
936 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
937 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
938 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
939 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
940 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
941
942
943 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
944 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
945 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
946
947 return hszr_edit_fields
948
950
951 prompt = wx.StaticText(
952 parent,
953 -1,
954 aLabel,
955 style = wx.ALIGN_RIGHT
956 )
957 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
958 prompt.SetForegroundColour(aColor)
959 return prompt
960
961
962
964 """Add a new prompt line.
965
966 To be used from _define_fields in child classes.
967
968 - label, the label text
969 - color
970 - weight, the weight given in sizing the various rows. 0 means the rwo
971 always has minimum size
972 """
973 self.prompts[line] = (label, color, weight)
974
975 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
976 if None in (line, pos, widget):
977 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
978 if not self.fields.has_key(line):
979 self.fields[line] = {}
980 self.fields[line][pos] = (widget, weight)
981
983 """Defines the fields.
984
985 - override in child classes
986 - mostly uses _add_field()
987 """
988 _log.error('missing override in [%s]' % self.__class__.__name__)
989
991 _log.error('missing override in [%s]' % self.__class__.__name__)
992
1006
1009
1011 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__)
1012 _log.info('child classes of cEditArea *must* override this function')
1013 return False
1014
1015
1016
1018
1019 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed)
1020 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed)
1021
1022 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields)
1023
1024
1025 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection)
1026 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing)
1027 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection)
1028
1029 return 1
1030
1031
1032
1049
1051
1052 self.set_data()
1053 event.Skip()
1054
1055 - def on_post_patient_selection( self, **kwds):
1056
1057 self.set_data()
1058
1060
1061 if not self._patient.connected:
1062 return True
1063 if self._save_data():
1064 return True
1065 _log.error('[%s] lossage' % self.__class__.__name__)
1066 return False
1067
1069
1070 if not self._patient.connected:
1071 return True
1072 if self._save_data():
1073 return True
1074 _log.error('[%s] lossage' % self.__class__.__name__)
1075 return False
1076
1078 self.fields_pnl.Layout()
1079
1080 for i in self.field_line_szr.keys():
1081
1082 pos = self.field_line_szr[i].GetPosition()
1083
1084 self.prompt_widget[i].SetPosition((0, pos.y))
1085
1087 - def __init__(self, parent, id, aType = None):
1088
1089 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
1090
1091
1092 if aType not in _known_edit_area_types:
1093 _log.error('unknown edit area type: [%s]' % aType)
1094 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType
1095 self._type = aType
1096
1097
1098 cEditArea.__init__(self, parent, id)
1099
1100 self.input_fields = {}
1101
1102 self._postInit()
1103 self.old_data = {}
1104
1105 self._patient = gmPerson.gmCurrentPatient()
1106 self.Show(True)
1107
1108
1109
1110
1111
1112
1114
1115 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1116 prompt_pnl.SetBackgroundColour(richards_light_gray)
1117
1118 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2)
1119 color = richards_aqua
1120 for prompt in prompt_labels:
1121 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color)
1122 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1123 color = richards_blue
1124 gszr.RemoveGrowableRow (line-1)
1125
1126 prompt_pnl.SetSizer(gszr)
1127 gszr.Fit(prompt_pnl)
1128 prompt_pnl.SetAutoLayout(True)
1129
1130
1131 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1132 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1133 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1134 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
1135 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1136
1137
1138 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
1139 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
1140 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1141
1142
1143 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1144 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1145 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1146 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1147 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1148
1149
1150 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
1151 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
1152 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1153
1154 return hszr_prompts
1155
1157 _log.error('programmer forgot to define edit area lines for [%s]' % self._type)
1158 _log.info('child classes of gmEditArea *must* override this function')
1159 return []
1160
1162
1163 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1164 fields_pnl.SetBackgroundColour(wx.Colour(222,222,222))
1165
1166 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2)
1167
1168
1169 lines = self._make_edit_lines(parent = fields_pnl)
1170
1171 self.lines = lines
1172 if len(lines) != len(_prompt_defs[self._type]):
1173 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type)
1174 for line in lines:
1175 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT)
1176
1177 fields_pnl.SetSizer(gszr)
1178 gszr.Fit(fields_pnl)
1179 fields_pnl.SetAutoLayout(True)
1180
1181
1182 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1183 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
1184 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1185 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
1186 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
1187
1188
1189 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
1190 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND)
1191 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
1192
1193
1194 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1195 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
1196 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
1197 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
1198 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
1199
1200
1201 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1202 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
1203 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
1204
1205 return hszr_edit_fields
1206
1209
1214
1216 map = {}
1217 for k in self.input_fields.keys():
1218 map[k] = ''
1219 return map
1220
1221
1223 self._default_init_fields()
1224
1225
1226
1227
1228
1230 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1231
1232
1233 - def _postInit(self):
1234 """override for further control setup"""
1235 pass
1236
1237
1239 szr = wx.BoxSizer(wx.HORIZONTAL)
1240 szr.Add( widget, weight, wx.EXPAND)
1241 szr.Add( 0,0, spacerWeight, wx.EXPAND)
1242 return szr
1243
1245
1246 cb = wx.CheckBox( parent, -1, _(title))
1247 cb.SetForegroundColour( richards_blue)
1248 return cb
1249
1250
1251
1253 """this is a utlity method to add extra columns"""
1254
1255 if self.__class__.__dict__.has_key("extraColumns"):
1256 for x in self.__class__.extraColumns:
1257 lines = self._addColumn(parent, lines, x, weightMap)
1258 return lines
1259
1260
1261
1262 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1263 """
1264 # add ia extra column in the edit area.
1265 # preconditions:
1266 # parent is fields_pnl (weak);
1267 # self.input_fields exists (required);
1268 # ; extra is a list of tuples of format -
1269 # ( key for input_fields, widget label , widget class to instantiate )
1270 """
1271
1272 newlines = []
1273 i = 0
1274 for x in lines:
1275
1276 if weightMap.has_key( x):
1277 (existingWeight, extraWeight) = weightMap[x]
1278
1279 szr = wx.BoxSizer(wx.HORIZONTAL)
1280 szr.Add( x, existingWeight, wx.EXPAND)
1281 if i < len(extra) and extra[i] <> None:
1282
1283 (inputKey, widgetLabel, aclass) = extra[i]
1284 if aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1285 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) )
1286 widgetLabel = ""
1287
1288
1289 w = aclass( parent, -1, widgetLabel)
1290 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1291 w.SetForegroundColour(richards_blue)
1292
1293 szr.Add(w, extraWeight , wx.EXPAND)
1294
1295
1296 self.input_fields[inputKey] = w
1297
1298 newlines.append(szr)
1299 i += 1
1300 return newlines
1301
1321
1324
1327
1333
1344
1345 -class gmPastHistoryEditArea(gmEditArea):
1346
1347 - def __init__(self, parent, id):
1348 gmEditArea.__init__(self, parent, id, aType = 'past history')
1349
1350 - def _define_prompts(self):
1351 self._add_prompt(line = 1, label = _("When Noted"))
1352 self._add_prompt(line = 2, label = _("Laterality"))
1353 self._add_prompt(line = 3, label = _("Condition"))
1354 self._add_prompt(line = 4, label = _("Notes"))
1355 self._add_prompt(line = 6, label = _("Status"))
1356 self._add_prompt(line = 7, label = _("Progress Note"))
1357 self._add_prompt(line = 8, label = '')
1358
1359 - def _define_fields(self, parent):
1360
1361 self.fld_date_noted = gmDateTimeInput.gmDateInput(
1362 parent = parent,
1363 id = -1,
1364 style = wx.SIMPLE_BORDER
1365 )
1366 self._add_field(
1367 line = 1,
1368 pos = 1,
1369 widget = self.fld_date_noted,
1370 weight = 2
1371 )
1372 self._add_field(
1373 line = 1,
1374 pos = 2,
1375 widget = cPrompt_edit_area(parent,-1, _("Age")),
1376 weight = 0)
1377
1378 self.fld_age_noted = cEditAreaField(parent)
1379 self._add_field(
1380 line = 1,
1381 pos = 3,
1382 widget = self.fld_age_noted,
1383 weight = 2
1384 )
1385
1386
1387 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A"))
1388 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L"))
1389 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R"))
1390 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both"))
1391 self._add_field(
1392 line = 2,
1393 pos = 1,
1394 widget = self.fld_laterality_none,
1395 weight = 0
1396 )
1397 self._add_field(
1398 line = 2,
1399 pos = 2,
1400 widget = self.fld_laterality_left,
1401 weight = 0
1402 )
1403 self._add_field(
1404 line = 2,
1405 pos = 3,
1406 widget = self.fld_laterality_right,
1407 weight = 1
1408 )
1409 self._add_field(
1410 line = 2,
1411 pos = 4,
1412 widget = self.fld_laterality_both,
1413 weight = 1
1414 )
1415
1416 self.fld_condition= cEditAreaField(parent)
1417 self._add_field(
1418 line = 3,
1419 pos = 1,
1420 widget = self.fld_condition,
1421 weight = 6
1422 )
1423
1424 self.fld_notes= cEditAreaField(parent)
1425 self._add_field(
1426 line = 4,
1427 pos = 1,
1428 widget = self.fld_notes,
1429 weight = 6
1430 )
1431
1432 self.fld_significant= wx.CheckBox(
1433 parent,
1434 -1,
1435 _("significant"),
1436 style = wx.NO_BORDER
1437 )
1438 self.fld_active= wx.CheckBox(
1439 parent,
1440 -1,
1441 _("active"),
1442 style = wx.NO_BORDER
1443 )
1444
1445 self._add_field(
1446 line = 5,
1447 pos = 1,
1448 widget = self.fld_significant,
1449 weight = 0
1450 )
1451 self._add_field(
1452 line = 5,
1453 pos = 2,
1454 widget = self.fld_active,
1455 weight = 0
1456 )
1457
1458 self.fld_progress= cEditAreaField(parent)
1459 self._add_field(
1460 line = 6,
1461 pos = 1,
1462 widget = self.fld_progress,
1463 weight = 6
1464 )
1465
1466
1467 self._add_field(
1468 line = 7,
1469 pos = 4,
1470 widget = self._make_standard_buttons(parent),
1471 weight = 2
1472 )
1473
1474 - def _postInit(self):
1475 return
1476
1477 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus)
1478 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1479
1480 - def _ageKillFocus( self, event):
1481
1482 event.Skip()
1483 try :
1484 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() )
1485 self.fld_date_noted.SetValue( str (year) )
1486 except:
1487 pass
1488
1489 - def _getBirthYear(self):
1490 try:
1491 birthyear = int(str(self._patient['dob']).split('-')[0])
1492 except:
1493
1494 birthyear = 1
1495
1496 return birthyear
1497
1498 - def _yearKillFocus( self, event):
1499 event.Skip()
1500 try:
1501 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear()
1502 self.fld_age_noted.SetValue( str (age) )
1503 except:
1504 pass
1505
1506 __init_values = {
1507 "condition": "",
1508 "notes1": "",
1509 "notes2": "",
1510 "age": "",
1511
1512 "progress": "",
1513 "active": 1,
1514 "operation": 0,
1515 "confidential": 0,
1516 "significant": 1,
1517 "both": 0,
1518 "left": 0,
1519 "right": 0,
1520 "none" : 1
1521 }
1522
1523 - def _getDefaultAge(self):
1524 try:
1525
1526 return 1
1527 except:
1528 return 0
1529
1530 - def _get_init_values(self):
1531 values = gmPastHistoryEditArea.__init_values
1532 values["age"] = str( self._getDefaultAge())
1533 return values
1534
1535 - def _save_data(self):
1536 clinical = self._patient.get_emr().get_past_history()
1537 if self.getDataId() is None:
1538 id = clinical.create_history( self.get_fields_formatting_values() )
1539 self.setDataId(id)
1540 return
1541
1542 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1543
1544
1554
1556 self._add_prompt (line = 1, label = _ ("Specialty"))
1557 self._add_prompt (line = 2, label = _ ("Name"))
1558 self._add_prompt (line = 3, label = _ ("Address"))
1559 self._add_prompt (line = 4, label = _ ("Options"))
1560 self._add_prompt (line = 5, label = _("Text"), weight =6)
1561 self._add_prompt (line = 6, label = "")
1562
1564 self.fld_specialty = gmPhraseWheel.cPhraseWheel (
1565 parent = parent,
1566 id = -1,
1567 style = wx.SIMPLE_BORDER
1568 )
1569
1570 self._add_field (
1571 line = 1,
1572 pos = 1,
1573 widget = self.fld_specialty,
1574 weight = 1
1575 )
1576 self.fld_name = gmPhraseWheel.cPhraseWheel (
1577 parent = parent,
1578 id = -1,
1579 style = wx.SIMPLE_BORDER
1580 )
1581
1582 self._add_field (
1583 line = 2,
1584 pos = 1,
1585 widget = self.fld_name,
1586 weight = 1
1587 )
1588 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY)
1589
1590 self._add_field (
1591 line = 3,
1592 pos = 1,
1593 widget = self.fld_address,
1594 weight = 1
1595 )
1596
1597
1598 self.fld_name.add_callback_on_selection(self.setAddresses)
1599
1600 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER)
1601 self._add_field (
1602 line = 4,
1603 pos = 1,
1604 widget = self.fld_med,
1605 weight = 1
1606 )
1607 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER)
1608 self._add_field (
1609 line = 4,
1610 pos = 4,
1611 widget = self.fld_past,
1612 weight = 1
1613 )
1614 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE)
1615 self._add_field (
1616 line = 5,
1617 pos = 1,
1618 widget = self.fld_text,
1619 weight = 1)
1620
1621 self._add_field(
1622 line = 6,
1623 pos = 1,
1624 widget = self._make_standard_buttons(parent),
1625 weight = 1
1626 )
1627 return 1
1628
1630 """
1631 Doesn't accept any value as this doesn't make sense for this edit area
1632 """
1633 self.fld_specialty.SetValue ('')
1634 self.fld_name.SetValue ('')
1635 self.fld_address.Clear ()
1636 self.fld_address.SetValue ('')
1637 self.fld_med.SetValue (0)
1638 self.fld_past.SetValue (0)
1639 self.fld_text.SetValue ('')
1640 self.recipient = None
1641
1643 """
1644 Set the available addresses for the selected identity
1645 """
1646 if id is None:
1647 self.recipient = None
1648 self.fld_address.Clear ()
1649 self.fld_address.SetValue ('')
1650 else:
1651 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id)
1652 self.fld_address.Clear ()
1653 self.addr = self.recipient.getAddresses ('work')
1654 for i in self.addr:
1655 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i))
1656 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX)
1657 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL)
1658 if fax:
1659 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax))
1660 if email:
1661 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1662
1663 - def _save_new_entry(self):
1664 """
1665 We are always saving a "new entry" here because data_ID is always None
1666 """
1667 if not self.recipient:
1668 raise gmExceptions.InvalidInputError(_('must have a recipient'))
1669 if self.fld_address.GetSelection() == -1:
1670 raise gmExceptions.InvalidInputError(_('must select address'))
1671 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection())
1672 text = self.fld_text.GetValue()
1673 flags = {}
1674 flags['meds'] = self.fld_med.GetValue()
1675 flags['pasthx'] = self.fld_past.GetValue()
1676 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags):
1677 raise gmExceptions.InvalidInputError('error sending form')
1678
1679
1680
1681
1682
1690
1691
1692
1694 _log.debug("making prescription lines")
1695 lines = []
1696 self.txt_problem = cEditAreaField(parent)
1697 self.txt_class = cEditAreaField(parent)
1698 self.txt_generic = cEditAreaField(parent)
1699 self.txt_brand = cEditAreaField(parent)
1700 self.txt_strength= cEditAreaField(parent)
1701 self.txt_directions= cEditAreaField(parent)
1702 self.txt_for = cEditAreaField(parent)
1703 self.txt_progress = cEditAreaField(parent)
1704
1705 lines.append(self.txt_problem)
1706 lines.append(self.txt_class)
1707 lines.append(self.txt_generic)
1708 lines.append(self.txt_brand)
1709 lines.append(self.txt_strength)
1710 lines.append(self.txt_directions)
1711 lines.append(self.txt_for)
1712 lines.append(self.txt_progress)
1713 lines.append(self._make_standard_buttons(parent))
1714 self.input_fields = {
1715 "problem": self.txt_problem,
1716 "class" : self.txt_class,
1717 "generic" : self.txt_generic,
1718 "brand" : self.txt_brand,
1719 "strength": self.txt_strength,
1720 "directions": self.txt_directions,
1721 "for" : self.txt_for,
1722 "progress": self.txt_progress
1723
1724 }
1725
1726 return self._makeExtraColumns( parent, lines)
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1745
1746
1747
1748
1749
1750
1753 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT)
1754 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
1755 self.SetForegroundColour(aColor)
1756
1757
1758
1759
1760
1762 - def __init__(self, parent, id, prompt_labels):
1763 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1764 self.SetBackgroundColour(richards_light_gray)
1765 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2)
1766 color = richards_aqua
1767 for prompt_key in prompt_labels.keys():
1768 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color)
1769 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1770 color = richards_blue
1771 self.SetSizer(gszr)
1772 gszr.Fit(self)
1773 self.SetAutoLayout(True)
1774
1775
1776
1777
1778
1779
1780
1781 -class EditTextBoxes(wx.Panel):
1782 - def __init__(self, parent, id, editareaprompts, section):
1783 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1784 self.SetBackgroundColour(wx.Colour(222,222,222))
1785 self.parent = parent
1786
1787 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2)
1788
1789 if section == gmSECTION_SUMMARY:
1790 pass
1791 elif section == gmSECTION_DEMOGRAPHICS:
1792 pass
1793 elif section == gmSECTION_CLINICALNOTES:
1794 pass
1795 elif section == gmSECTION_FAMILYHISTORY:
1796 pass
1797 elif section == gmSECTION_PASTHISTORY:
1798 pass
1799
1800
1801 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize)
1802 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize)
1803 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER)
1804 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize)
1805 rbsizer = wx.BoxSizer(wx.HORIZONTAL)
1806 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND)
1807 rbsizer.Add(self.rb_sideright,1,wx.EXPAND)
1808 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND)
1809 szr1 = wx.BoxSizer(wx.HORIZONTAL)
1810 szr1.Add(self.txt_condition, 4, wx.EXPAND)
1811 szr1.Add(rbsizer, 3, wx.EXPAND)
1812
1813
1814
1815
1816 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize)
1817
1818 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize)
1819
1820 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize)
1821 szr4 = wx.BoxSizer(wx.HORIZONTAL)
1822 szr4.Add(self.txt_agenoted, 1, wx.EXPAND)
1823 szr4.Add(5, 0, 5)
1824
1825 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize)
1826 szr5 = wx.BoxSizer(wx.HORIZONTAL)
1827 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND)
1828 szr5.Add(5, 0, 5)
1829
1830 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1831 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1832 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1833 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1834 szr6 = wx.BoxSizer(wx.HORIZONTAL)
1835 szr6.Add(self.parent.cb_active, 1, wx.EXPAND)
1836 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND)
1837 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND)
1838 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND)
1839
1840 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize)
1841
1842 szr8 = wx.BoxSizer(wx.HORIZONTAL)
1843 szr8.Add(5, 0, 6)
1844 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND)
1845
1846 self.gszr.Add(szr1,0,wx.EXPAND)
1847 self.gszr.Add(self.txt_notes1,0,wx.EXPAND)
1848 self.gszr.Add(self.txt_notes2,0,wx.EXPAND)
1849 self.gszr.Add(szr4,0,wx.EXPAND)
1850 self.gszr.Add(szr5,0,wx.EXPAND)
1851 self.gszr.Add(szr6,0,wx.EXPAND)
1852 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND)
1853 self.gszr.Add(szr8,0,wx.EXPAND)
1854
1855
1856 elif section == gmSECTION_SCRIPT:
1857 pass
1858 elif section == gmSECTION_REQUESTS:
1859 pass
1860 elif section == gmSECTION_RECALLS:
1861 pass
1862 else:
1863 pass
1864
1865 self.SetSizer(self.gszr)
1866 self.gszr.Fit(self)
1867
1868 self.SetAutoLayout(True)
1869 self.Show(True)
1870
1872 self.btn_OK = wx.Button(self, -1, _("Ok"))
1873 self.btn_Clear = wx.Button(self, -1, _("Clear"))
1874 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
1875 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1)
1876 szr_buttons.Add(5, 0, 0)
1877 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1)
1878 return szr_buttons
1879
1881 - def __init__(self, parent, id, line_labels, section):
1882 _log.warning('***** old style EditArea instantiated, please convert *****')
1883
1884 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER)
1885 self.SetBackgroundColour(wx.Colour(222,222,222))
1886
1887
1888 prompts = gmPnlEditAreaPrompts(self, -1, line_labels)
1889
1890 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1891
1892 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1893 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1894 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND)
1895 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1896
1897 szr_prompts = wx.BoxSizer(wx.VERTICAL)
1898 szr_prompts.Add(prompts, 97, wx.EXPAND)
1899 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1900
1901
1902 edit_fields = EditTextBoxes(self, -1, line_labels, section)
1903
1904 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1905
1906 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray)
1907 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL)
1908 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND)
1909 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND)
1910
1911 szr_editarea = wx.BoxSizer(wx.VERTICAL)
1912 szr_editarea.Add(edit_fields, 92, wx.EXPAND)
1913 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND)
1914
1915
1916
1917 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1918 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1919 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1920 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1921 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1922
1923 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1924 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray)
1925 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL)
1926 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND)
1927 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND)
1928
1929
1930 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
1931 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND)
1932 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1933 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
1934 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND)
1935 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND)
1936
1937
1938
1939 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
1940 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
1941 self.SetSizer(self.szr_central_container)
1942 self.szr_central_container.Fit(self)
1943 self.SetAutoLayout(True)
1944 self.Show(True)
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
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
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 if __name__ == "__main__":
2222
2223
2228 self._add_prompt(line=1, label='line 1')
2229 self._add_prompt(line=2, label='buttons')
2231
2232 self.fld_substance = cEditAreaField(parent)
2233 self._add_field(
2234 line = 1,
2235 pos = 1,
2236 widget = self.fld_substance,
2237 weight = 1
2238 )
2239
2240 self._add_field(
2241 line = 2,
2242 pos = 1,
2243 widget = self._make_standard_buttons(parent),
2244 weight = 1
2245 )
2246
2247 app = wxPyWidgetTester(size = (400, 200))
2248 app.SetWidget(cTestEditArea)
2249 app.MainLoop()
2250
2251
2252
2253
2254
2255
2256
2257