1
2
3
4 __license__ = 'GPL'
5 __version__ = "$Revision: 1.135 $"
6 __author__ = "R.Terry, K.Hilbert"
7
8
9 import logging, datetime as pydt
10
11
12 import wx
13
14
15 from Gnumed.pycommon import gmDispatcher, gmExceptions
16 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg, wxgGenericEditAreaDlg2
17
18
19 _log = logging.getLogger('gm.ui')
20 _log.info(__version__)
21
22 edit_area_modes = ['new', 'edit', 'new_from_existing']
23
25 """Mixin for edit area panels providing generic functionality.
26
27 #====================================================================
28 # Class definition:
29
30 from Gnumed.wxGladeWidgets import wxgXxxEAPnl
31
32 class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin):
33
34 def __init__(self, *args, **kwargs):
35
36 try:
37 data = kwargs['xxx']
38 del kwargs['xxx']
39 except KeyError:
40 data = None
41
42 wxgXxxEAPnl.wxgXxxPatientEAPnl.__init__(self, *args, **kwargs)
43 gmEditArea.cGenericEditAreaMixin.__init__(self)
44
45 # Code using this mixin should set mode and data
46 # after instantiating the class:
47 self.mode = 'new'
48 self.data = data
49 if data is not None:
50 self.mode = 'edit'
51
52 #self.__init_ui()
53 #----------------------------------------------------------------
54 # def __init_ui(self):
55 # # adjust phrasewheels etc
56 #----------------------------------------------------------------
57 # generic Edit Area mixin API
58 #----------------------------------------------------------------
59 def _valid_for_save(self):
60 return False
61 return True
62 #----------------------------------------------------------------
63 def _save_as_new(self):
64 # save the data as a new instance
65 data =
66
67 data[''] =
68 data[''] =
69
70 data.save()
71
72 # must be done very late or else the property access
73 # will refresh the display such that later field
74 # access will return empty values
75 self.data = data
76 return False
77 return True
78 #----------------------------------------------------------------
79 def _save_as_update(self):
80 # update self.data and save the changes
81 self.data[''] =
82 self.data[''] =
83 self.data[''] =
84 self.data.save()
85 return True
86 #----------------------------------------------------------------
87 def _refresh_as_new(self):
88 pass
89 #----------------------------------------------------------------
90 def _refresh_from_existing(self):
91 pass
92 #----------------------------------------------------------------
93 def _refresh_as_new_from_existing(self):
94 pass
95 #----------------------------------------------------------------
96 """
98 self.__mode = 'new'
99 self.__data = None
100 self.successful_save_msg = None
101 self._refresh_as_new()
102 self.__tctrl_validity_colors = {
103 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW),
104 False: 'pink'
105 }
106
109
111 if mode not in edit_area_modes:
112 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
113 if mode == 'edit':
114 if self.__data is None:
115 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
116 self.__mode = mode
117
118 mode = property(_get_mode, _set_mode)
119
122
124 if data is None:
125 if self.__mode == 'edit':
126 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
127 self.__data = data
128 self.refresh()
129
130 data = property(_get_data, _set_data)
131
133 """Invoked from the generic edit area dialog.
134
135 Invokes
136 _valid_for_save,
137 _save_as_new,
138 _save_as_update
139 on the implementing edit area as needed.
140
141 _save_as_* must set self.__data and return True/False
142 """
143 if not self._valid_for_save():
144 return False
145
146 if self.__mode in ['new', 'new_from_existing']:
147 if self._save_as_new():
148 self.mode = 'edit'
149 return True
150 return False
151
152 elif self.__mode == 'edit':
153 return self._save_as_update()
154
155 else:
156 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
157
159 """Invoked from the generic edit area dialog.
160
161 Invokes
162 _refresh_as_new
163 _refresh_from_existing
164 _refresh_as_new_from_existing
165 on the implementing edit area as needed.
166 """
167 if self.__mode == 'new':
168 return self._refresh_as_new()
169 elif self.__mode == 'edit':
170 return self._refresh_from_existing()
171 elif self.__mode == 'new_from_existing':
172 return self._refresh_as_new_from_existing()
173 else:
174 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
175
177 tctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
178 tctrl.Refresh()
179
181 """Dialog for parenting edit area panels with save/clear/next/cancel"""
182
183 _lucky_day = 1
184 _lucky_month = 4
185 _today = pydt.date.today()
186
188
189 new_ea = kwargs['edit_area']
190 del kwargs['edit_area']
191
192 if not isinstance(new_ea, cGenericEditAreaMixin):
193 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin')
194
195 try:
196 single_entry = kwargs['single_entry']
197 del kwargs['single_entry']
198 except KeyError:
199 single_entry = False
200
201 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs)
202
203 if cGenericEditAreaDlg2._today.day != cGenericEditAreaDlg2._lucky_day:
204 self._BTN_lucky.Enable(False)
205 self._BTN_lucky.Hide()
206 else:
207 if cGenericEditAreaDlg2._today.month != cGenericEditAreaDlg2._lucky_month:
208 self._BTN_lucky.Enable(False)
209 self._BTN_lucky.Hide()
210
211
212 old_ea = self._PNL_ea
213 ea_pnl_szr = old_ea.GetContainingSizer()
214 ea_pnl_parent = old_ea.GetParent()
215 ea_pnl_szr.Remove(old_ea)
216 old_ea.Destroy()
217 del old_ea
218 new_ea.Reparent(ea_pnl_parent)
219 self._PNL_ea = new_ea
220 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0)
221
222
223 if single_entry:
224 self._BTN_forward.Enable(False)
225 self._BTN_forward.Hide()
226
227 self._adjust_clear_revert_buttons()
228
229
230 self.Layout()
231 main_szr = self.GetSizer()
232 main_szr.Fit(self)
233 self.Refresh()
234
235 self._PNL_ea.refresh()
236
248
255
258
261
276
286
287
289 """Dialog for parenting edit area with save/clear/cancel"""
290
292
293 ea = kwargs['edit_area']
294 del kwargs['edit_area']
295
296 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs)
297
298 szr = self._PNL_ea.GetContainingSizer()
299 szr.Remove(self._PNL_ea)
300 ea.Reparent(self)
301 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4)
302 self._PNL_ea = ea
303
304 self.Layout()
305 szr = self.GetSizer()
306 szr.Fit(self)
307 self.Refresh()
308
309 self._PNL_ea.refresh()
310
318
321
322
323
324 import time
325
326 from Gnumed.business import gmPerson, gmDemographicRecord
327 from Gnumed.pycommon import gmGuiBroker
328 from Gnumed.wxpython import gmDateTimeInput, gmPhraseWheel, gmGuiHelpers
329
330 _gb = gmGuiBroker.GuiBroker()
331
332 gmSECTION_SUMMARY = 1
333 gmSECTION_DEMOGRAPHICS = 2
334 gmSECTION_CLINICALNOTES = 3
335 gmSECTION_FAMILYHISTORY = 4
336 gmSECTION_PASTHISTORY = 5
337 gmSECTION_SCRIPT = 8
338 gmSECTION_REQUESTS = 9
339 gmSECTION_REFERRALS = 11
340 gmSECTION_RECALLS = 12
341
342 richards_blue = wx.Colour(0,0,131)
343 richards_aqua = wx.Colour(0,194,197)
344 richards_dark_gray = wx.Color(131,129,131)
345 richards_light_gray = wx.Color(255,255,255)
346 richards_coloured_gray = wx.Color(131,129,131)
347
348
349 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox']
350
352 widget.SetForegroundColour(wx.Color(255, 0, 0))
353 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
354
367 if not isinstance(edit_area, cEditArea2):
368 raise gmExceptions.ConstructorError, '<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area)
369 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name)
370 self.__wxID_BTN_SAVE = wx.NewId()
371 self.__wxID_BTN_RESET = wx.NewId()
372 self.__editarea = edit_area
373 self.__do_layout()
374 self.__register_events()
375
376
377
380
382 self.__editarea.Reparent(self)
383
384 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save"))
385 self.__btn_SAVE.SetToolTipString(_('save entry into medical record'))
386 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset"))
387 self.__btn_RESET.SetToolTipString(_('reset entry'))
388 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
389 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel'))
390
391 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
392 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1)
393 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1)
394 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1)
395
396 szr_main = wx.BoxSizer(wx.VERTICAL)
397 szr_main.Add(self.__editarea, 1, wx.EXPAND)
398 szr_main.Add(szr_buttons, 0, wx.EXPAND)
399
400 self.SetSizerAndFit(szr_main)
401
402
403
405
406 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed)
407 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed)
408 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed)
409
410 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed)
411
412
413
414
415
416
417 return 1
418
420 if self.__editarea.save_data():
421 self.__editarea.Close()
422 self.EndModal(wx.ID_OK)
423 return
424 short_err = self.__editarea.get_short_error()
425 long_err = self.__editarea.get_long_error()
426 if (short_err is None) and (long_err is None):
427 long_err = _(
428 'Unspecified error saving data in edit area.\n\n'
429 'Programmer forgot to specify proper error\n'
430 'message in [%s].'
431 ) % self.__editarea.__class__.__name__
432 if short_err is not None:
433 gmDispatcher.send(signal = 'statustext', msg = short_err)
434 if long_err is not None:
435 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
436
438 self.__editarea.Close()
439 self.EndModal(wx.ID_CANCEL)
440
443
445 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
446
447 wx.Panel.__init__ (
448 self,
449 parent,
450 id,
451 pos = pos,
452 size = size,
453 style = style | wx.TAB_TRAVERSAL
454 )
455 self.SetBackgroundColour(wx.Color(222,222,222))
456
457 self.data = None
458 self.fields = {}
459 self.prompts = {}
460 self._short_error = None
461 self._long_error = None
462 self._summary = None
463 self._patient = gmPerson.gmCurrentPatient()
464 self.__wxID_BTN_OK = wx.NewId()
465 self.__wxID_BTN_CLEAR = wx.NewId()
466 self.__do_layout()
467 self.__register_events()
468 self.Show()
469
470
471
473 """This needs to be overridden by child classes."""
474 self._long_error = _(
475 'Cannot save data from edit area.\n\n'
476 'Programmer forgot to override method:\n'
477 ' <%s.save_data>'
478 ) % self.__class__.__name__
479 return False
480
482 msg = _(
483 'Cannot reset fields in edit area.\n\n'
484 'Programmer forgot to override method:\n'
485 ' <%s.reset_ui>'
486 ) % self.__class__.__name__
487 gmGuiHelpers.gm_show_error(msg)
488
490 tmp = self._short_error
491 self._short_error = None
492 return tmp
493
495 tmp = self._long_error
496 self._long_error = None
497 return tmp
498
500 return _('<No embed string for [%s]>') % self.__class__.__name__
501
502
503
515
520
521
522
524 self.__deregister_events()
525 event.Skip()
526
528 """Only active if _make_standard_buttons was called in child class."""
529
530 try:
531 event.Skip()
532 if self.data is None:
533 self._save_new_entry()
534 self.reset_ui()
535 else:
536 self._save_modified_entry()
537 self.reset_ui()
538 except gmExceptions.InvalidInputError, err:
539
540
541 gmGuiHelpers.gm_show_error (err, _("Invalid Input"))
542 except:
543 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
544
546 """Only active if _make_standard_buttons was called in child class."""
547
548 self.reset_ui()
549 event.Skip()
550
552 self.__deregister_events()
553
554 if not self._patient.connected:
555 return True
556
557
558
559
560 return True
561 _log.error('[%s] lossage' % self.__class__.__name__)
562 return False
563
565 """Just before new patient becomes active."""
566
567 if not self._patient.connected:
568 return True
569
570
571
572
573 return True
574 _log.error('[%s] lossage' % self.__class__.__name__)
575 return False
576
578 """Just after new patient became active."""
579
580 self.reset_ui()
581
582
583
585
586
587 self._define_prompts()
588 self._define_fields(parent = self)
589 if len(self.fields) != len(self.prompts):
590 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
591 return None
592
593
594 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2)
595 color = richards_aqua
596 lines = self.prompts.keys()
597 lines.sort()
598 for line in lines:
599
600 label, color, weight = self.prompts[line]
601
602 prompt = wx.StaticText (
603 parent = self,
604 id = -1,
605 label = label,
606 style = wx.ALIGN_CENTRE
607 )
608
609 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
610 prompt.SetForegroundColour(color)
611 prompt.SetBackgroundColour(richards_light_gray)
612 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT)
613
614
615 szr_line = wx.BoxSizer(wx.HORIZONTAL)
616 positions = self.fields[line].keys()
617 positions.sort()
618 for pos in positions:
619 field, weight = self.fields[line][pos]
620
621 szr_line.Add(field, weight, wx.EXPAND)
622 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT)
623
624
625 szr_main_fgrid.AddGrowableCol(1)
626
627
628
629
630
631
632
633 self.SetSizerAndFit(szr_main_fgrid)
634
635
636
637
639 """Child classes override this to define their prompts using _add_prompt()"""
640 _log.error('missing override in [%s]' % self.__class__.__name__)
641
643 """Add a new prompt line.
644
645 To be used from _define_fields in child classes.
646
647 - label, the label text
648 - color
649 - weight, the weight given in sizing the various rows. 0 means the row
650 always has minimum size
651 """
652 self.prompts[line] = (label, color, weight)
653
655 """Defines the fields.
656
657 - override in child classes
658 - mostly uses _add_field()
659 """
660 _log.error('missing override in [%s]' % self.__class__.__name__)
661
662 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
663 if None in (line, pos, widget):
664 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
665 if not self.fields.has_key(line):
666 self.fields[line] = {}
667 self.fields[line][pos] = (widget, weight)
668
686
687
688
689
691 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
692 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER)
693 _decorate_editarea_field(self)
694
696 - def __init__(self, parent, id, pos, size, style):
697
698 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
699
700
701 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
702 self.SetBackgroundColour(wx.Color(222,222,222))
703
704 self.data = None
705 self.fields = {}
706 self.prompts = {}
707
708 ID_BTN_OK = wx.NewId()
709 ID_BTN_CLEAR = wx.NewId()
710
711 self.__do_layout()
712
713
714
715
716
717
718 self._patient = gmPerson.gmCurrentPatient()
719 self.__register_events()
720 self.Show(True)
721
722
723
725
726 self._define_prompts()
727 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
728 self._define_fields(parent = self.fields_pnl)
729
730 szr_prompts = self.__generate_prompts()
731 szr_fields = self.__generate_fields()
732
733
734 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
735 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND)
736 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
737 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND)
738
739
740
741 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
742 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
743
744
745 self.SetAutoLayout(True)
746 self.SetSizer(self.szr_central_container)
747 self.szr_central_container.Fit(self)
748
750 if len(self.fields) != len(self.prompts):
751 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
752 return None
753
754 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
755 prompt_pnl.SetBackgroundColour(richards_light_gray)
756
757 color = richards_aqua
758 lines = self.prompts.keys()
759 lines.sort()
760 self.prompt_widget = {}
761 for line in lines:
762 label, color, weight = self.prompts[line]
763 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color)
764
765 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
766 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
767 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
768 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
769 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
770
771
772 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
773 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
774 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
775
776
777 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
778 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
779 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
780 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
781 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND)
782
783
784 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
785 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
786 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
787
788 return hszr_prompts
789
791 self.fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
792
793 vszr = wx.BoxSizer(wx.VERTICAL)
794 lines = self.fields.keys()
795 lines.sort()
796 self.field_line_szr = {}
797 for line in lines:
798 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL)
799 positions = self.fields[line].keys()
800 positions.sort()
801 for pos in positions:
802 field, weight = self.fields[line][pos]
803 self.field_line_szr[line].Add(field, weight, wx.EXPAND)
804 try:
805 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND)
806 except KeyError:
807 _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) ) )
808
809 self.fields_pnl.SetSizer(vszr)
810 vszr.Fit(self.fields_pnl)
811
812
813 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
814 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
815 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
816 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
817 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
818
819
820 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
821 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND)
822 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
823
824
825 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
826 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
827 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
828 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
829 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
830
831
832 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
833 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
834 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
835
836 return hszr_edit_fields
837
839
840 prompt = wx.StaticText(
841 parent,
842 -1,
843 aLabel,
844 style = wx.ALIGN_RIGHT
845 )
846 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
847 prompt.SetForegroundColour(aColor)
848 return prompt
849
850
851
853 """Add a new prompt line.
854
855 To be used from _define_fields in child classes.
856
857 - label, the label text
858 - color
859 - weight, the weight given in sizing the various rows. 0 means the rwo
860 always has minimum size
861 """
862 self.prompts[line] = (label, color, weight)
863
864 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
865 if None in (line, pos, widget):
866 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
867 if not self.fields.has_key(line):
868 self.fields[line] = {}
869 self.fields[line][pos] = (widget, weight)
870
872 """Defines the fields.
873
874 - override in child classes
875 - mostly uses _add_field()
876 """
877 _log.error('missing override in [%s]' % self.__class__.__name__)
878
880 _log.error('missing override in [%s]' % self.__class__.__name__)
881
895
898
900 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__)
901 _log.info('child classes of cEditArea *must* override this function')
902 return False
903
904
905
907
908 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed)
909 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed)
910
911 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields)
912
913
914 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection)
915 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing)
916 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection)
917
918 return 1
919
920
921
938
940
941 self.set_data()
942 event.Skip()
943
947
949
950 if not self._patient.connected:
951 return True
952 if self._save_data():
953 return True
954 _log.error('[%s] lossage' % self.__class__.__name__)
955 return False
956
958
959 if not self._patient.connected:
960 return True
961 if self._save_data():
962 return True
963 _log.error('[%s] lossage' % self.__class__.__name__)
964 return False
965
967 self.fields_pnl.Layout()
968
969 for i in self.field_line_szr.keys():
970
971 pos = self.field_line_szr[i].GetPosition()
972
973 self.prompt_widget[i].SetPosition((0, pos.y))
974
976 - def __init__(self, parent, id, aType = None):
977
978 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
979
980
981 if aType not in _known_edit_area_types:
982 _log.error('unknown edit area type: [%s]' % aType)
983 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType
984 self._type = aType
985
986
987 cEditArea.__init__(self, parent, id)
988
989 self.input_fields = {}
990
991 self._postInit()
992 self.old_data = {}
993
994 self._patient = gmPerson.gmCurrentPatient()
995 self.Show(True)
996
997
998
999
1000
1001
1003
1004 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1005 prompt_pnl.SetBackgroundColour(richards_light_gray)
1006
1007 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2)
1008 color = richards_aqua
1009 for prompt in prompt_labels:
1010 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color)
1011 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1012 color = richards_blue
1013 gszr.RemoveGrowableRow (line-1)
1014
1015 prompt_pnl.SetSizer(gszr)
1016 gszr.Fit(prompt_pnl)
1017 prompt_pnl.SetAutoLayout(True)
1018
1019
1020 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1021 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1022 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1023 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
1024 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1025
1026
1027 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
1028 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
1029 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1030
1031
1032 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1033 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1034 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1035 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1036 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1037
1038
1039 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
1040 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
1041 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1042
1043 return hszr_prompts
1044
1046 _log.error('programmer forgot to define edit area lines for [%s]' % self._type)
1047 _log.info('child classes of gmEditArea *must* override this function')
1048 return []
1049
1051
1052 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1053 fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
1054
1055 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2)
1056
1057
1058 lines = self._make_edit_lines(parent = fields_pnl)
1059
1060 self.lines = lines
1061 if len(lines) != len(_prompt_defs[self._type]):
1062 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type)
1063 for line in lines:
1064 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT)
1065
1066 fields_pnl.SetSizer(gszr)
1067 gszr.Fit(fields_pnl)
1068 fields_pnl.SetAutoLayout(True)
1069
1070
1071 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1072 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
1073 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1074 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
1075 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
1076
1077
1078 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
1079 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND)
1080 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
1081
1082
1083 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1084 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
1085 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
1086 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
1087 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
1088
1089
1090 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1091 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
1092 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
1093
1094 return hszr_edit_fields
1095
1098
1103
1105 map = {}
1106 for k in self.input_fields.keys():
1107 map[k] = ''
1108 return map
1109
1110
1112 self._default_init_fields()
1113
1114
1115
1116
1117
1119 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1120
1121
1122 - def _postInit(self):
1123 """override for further control setup"""
1124 pass
1125
1126
1128 szr = wx.BoxSizer(wx.HORIZONTAL)
1129 szr.Add( widget, weight, wx.EXPAND)
1130 szr.Add( 0,0, spacerWeight, wx.EXPAND)
1131 return szr
1132
1134
1135 cb = wx.CheckBox( parent, -1, _(title))
1136 cb.SetForegroundColour( richards_blue)
1137 return cb
1138
1139
1140
1142 """this is a utlity method to add extra columns"""
1143
1144 if self.__class__.__dict__.has_key("extraColumns"):
1145 for x in self.__class__.extraColumns:
1146 lines = self._addColumn(parent, lines, x, weightMap)
1147 return lines
1148
1149
1150
1151 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1152 """
1153 # add ia extra column in the edit area.
1154 # preconditions:
1155 # parent is fields_pnl (weak);
1156 # self.input_fields exists (required);
1157 # ; extra is a list of tuples of format -
1158 # ( key for input_fields, widget label , widget class to instantiate )
1159 """
1160
1161 newlines = []
1162 i = 0
1163 for x in lines:
1164
1165 if weightMap.has_key( x):
1166 (existingWeight, extraWeight) = weightMap[x]
1167
1168 szr = wx.BoxSizer(wx.HORIZONTAL)
1169 szr.Add( x, existingWeight, wx.EXPAND)
1170 if i < len(extra) and extra[i] <> None:
1171
1172 (inputKey, widgetLabel, aclass) = extra[i]
1173 if aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1174 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) )
1175 widgetLabel = ""
1176
1177
1178 w = aclass( parent, -1, widgetLabel)
1179 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1180 w.SetForegroundColour(richards_blue)
1181
1182 szr.Add(w, extraWeight , wx.EXPAND)
1183
1184
1185 self.input_fields[inputKey] = w
1186
1187 newlines.append(szr)
1188 i += 1
1189 return newlines
1190
1210
1213
1216
1222
1233
1241
1243 _log.debug("making family Hx lines")
1244 lines = []
1245 self.input_fields = {}
1246
1247
1248
1249 self.input_fields['name'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1250 self.input_fields['DOB'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1251 lbl_dob = self._make_prompt(parent, _(" Date of Birth "), richards_blue)
1252 szr = wx.BoxSizer(wx.HORIZONTAL)
1253 szr.Add(self.input_fields['name'], 4, wx.EXPAND)
1254 szr.Add(lbl_dob, 2, wx.EXPAND)
1255 szr.Add(self.input_fields['DOB'], 4, wx.EXPAND)
1256 lines.append(szr)
1257
1258
1259
1260 self.input_fields['relationship'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1261 szr = wx.BoxSizer(wx.HORIZONTAL)
1262 szr.Add(self.input_fields['relationship'], 4, wx.EXPAND)
1263 lines.append(szr)
1264
1265 self.input_fields['condition'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1266 self.cb_condition_confidential = wx.CheckBox(parent, -1, _("confidental"), wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER)
1267 szr = wx.BoxSizer(wx.HORIZONTAL)
1268 szr.Add(self.input_fields['condition'], 6, wx.EXPAND)
1269 szr.Add(self.cb_condition_confidential, 0, wx.EXPAND)
1270 lines.append(szr)
1271
1272 self.input_fields['comment'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1273 lines.append(self.input_fields['comment'])
1274
1275 lbl_onset = self._make_prompt(parent, _(" age onset "), richards_blue)
1276 self.input_fields['age onset'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1277
1278 lbl_caused_death = self._make_prompt(parent, _(" caused death "), richards_blue)
1279 self.input_fields['caused death'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1280 lbl_aod = self._make_prompt(parent, _(" age died "), richards_blue)
1281 self.input_fields['AOD'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1282 szr = wx.BoxSizer(wx.HORIZONTAL)
1283 szr.Add(lbl_onset, 0, wx.EXPAND)
1284 szr.Add(self.input_fields['age onset'], 1,wx.EXPAND)
1285 szr.Add(lbl_caused_death, 0, wx.EXPAND)
1286 szr.Add(self.input_fields['caused death'], 2,wx.EXPAND)
1287 szr.Add(lbl_aod, 0, wx.EXPAND)
1288 szr.Add(self.input_fields['AOD'], 1, wx.EXPAND)
1289 szr.Add(2, 2, 8)
1290 lines.append(szr)
1291
1292 self.input_fields['progress notes'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1293 lines.append(self.input_fields['progress notes'])
1294
1295 self.Btn_next_condition = wx.Button(parent, -1, _("Next Condition"))
1296 szr = wx.BoxSizer(wx.HORIZONTAL)
1297 szr.AddSpacer(10, 0, 0)
1298 szr.Add(self.Btn_next_condition, 0, wx.EXPAND | wx.ALL, 1)
1299 szr.Add(2, 1, 5)
1300 szr.Add(self._make_standard_buttons(parent), 0, wx.EXPAND)
1301 lines.append(szr)
1302
1303 return lines
1304
1307
1308
1309 -class gmPastHistoryEditArea(gmEditArea):
1310
1311 - def __init__(self, parent, id):
1312 gmEditArea.__init__(self, parent, id, aType = 'past history')
1313
1314 - def _define_prompts(self):
1315 self._add_prompt(line = 1, label = _("When Noted"))
1316 self._add_prompt(line = 2, label = _("Laterality"))
1317 self._add_prompt(line = 3, label = _("Condition"))
1318 self._add_prompt(line = 4, label = _("Notes"))
1319 self._add_prompt(line = 6, label = _("Status"))
1320 self._add_prompt(line = 7, label = _("Progress Note"))
1321 self._add_prompt(line = 8, label = '')
1322
1323 - def _define_fields(self, parent):
1324
1325 self.fld_date_noted = gmDateTimeInput.gmDateInput(
1326 parent = parent,
1327 id = -1,
1328 style = wx.SIMPLE_BORDER
1329 )
1330 self._add_field(
1331 line = 1,
1332 pos = 1,
1333 widget = self.fld_date_noted,
1334 weight = 2
1335 )
1336 self._add_field(
1337 line = 1,
1338 pos = 2,
1339 widget = cPrompt_edit_area(parent,-1, _("Age")),
1340 weight = 0)
1341
1342 self.fld_age_noted = cEditAreaField(parent)
1343 self._add_field(
1344 line = 1,
1345 pos = 3,
1346 widget = self.fld_age_noted,
1347 weight = 2
1348 )
1349
1350
1351 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A"))
1352 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L"))
1353 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R"))
1354 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both"))
1355 self._add_field(
1356 line = 2,
1357 pos = 1,
1358 widget = self.fld_laterality_none,
1359 weight = 0
1360 )
1361 self._add_field(
1362 line = 2,
1363 pos = 2,
1364 widget = self.fld_laterality_left,
1365 weight = 0
1366 )
1367 self._add_field(
1368 line = 2,
1369 pos = 3,
1370 widget = self.fld_laterality_right,
1371 weight = 1
1372 )
1373 self._add_field(
1374 line = 2,
1375 pos = 4,
1376 widget = self.fld_laterality_both,
1377 weight = 1
1378 )
1379
1380 self.fld_condition= cEditAreaField(parent)
1381 self._add_field(
1382 line = 3,
1383 pos = 1,
1384 widget = self.fld_condition,
1385 weight = 6
1386 )
1387
1388 self.fld_notes= cEditAreaField(parent)
1389 self._add_field(
1390 line = 4,
1391 pos = 1,
1392 widget = self.fld_notes,
1393 weight = 6
1394 )
1395
1396 self.fld_significant= wx.CheckBox(
1397 parent,
1398 -1,
1399 _("significant"),
1400 style = wx.NO_BORDER
1401 )
1402 self.fld_active= wx.CheckBox(
1403 parent,
1404 -1,
1405 _("active"),
1406 style = wx.NO_BORDER
1407 )
1408
1409 self._add_field(
1410 line = 5,
1411 pos = 1,
1412 widget = self.fld_significant,
1413 weight = 0
1414 )
1415 self._add_field(
1416 line = 5,
1417 pos = 2,
1418 widget = self.fld_active,
1419 weight = 0
1420 )
1421
1422 self.fld_progress= cEditAreaField(parent)
1423 self._add_field(
1424 line = 6,
1425 pos = 1,
1426 widget = self.fld_progress,
1427 weight = 6
1428 )
1429
1430
1431 self._add_field(
1432 line = 7,
1433 pos = 4,
1434 widget = self._make_standard_buttons(parent),
1435 weight = 2
1436 )
1437
1438 - def _postInit(self):
1439 return
1440
1441 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus)
1442 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1443
1444 - def _ageKillFocus( self, event):
1445
1446 event.Skip()
1447 try :
1448 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() )
1449 self.fld_date_noted.SetValue( str (year) )
1450 except:
1451 pass
1452
1453 - def _getBirthYear(self):
1454 try:
1455 birthyear = int(str(self._patient['dob']).split('-')[0])
1456 except:
1457 birthyear = time.localtime()[0]
1458
1459 return birthyear
1460
1461 - def _yearKillFocus( self, event):
1462 event.Skip()
1463 try:
1464 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear()
1465 self.fld_age_noted.SetValue( str (age) )
1466 except:
1467 pass
1468
1469 __init_values = {
1470 "condition": "",
1471 "notes1": "",
1472 "notes2": "",
1473 "age": "",
1474 "year": str(time.localtime()[0]),
1475 "progress": "",
1476 "active": 1,
1477 "operation": 0,
1478 "confidential": 0,
1479 "significant": 1,
1480 "both": 0,
1481 "left": 0,
1482 "right": 0,
1483 "none" : 1
1484 }
1485
1486 - def _getDefaultAge(self):
1487 try:
1488 return time.localtime()[0] - self._patient.getBirthYear()
1489 except:
1490 return 0
1491
1492 - def _get_init_values(self):
1493 values = gmPastHistoryEditArea.__init_values
1494 values["age"] = str( self._getDefaultAge())
1495 return values
1496
1497
1498 - def _save_data(self):
1499 clinical = self._patient.get_emr().get_past_history()
1500 if self.getDataId() is None:
1501 id = clinical.create_history( self.get_fields_formatting_values() )
1502 self.setDataId(id)
1503 return
1504
1505 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1506
1507
1517
1519 self._add_prompt (line = 1, label = _ ("Specialty"))
1520 self._add_prompt (line = 2, label = _ ("Name"))
1521 self._add_prompt (line = 3, label = _ ("Address"))
1522 self._add_prompt (line = 4, label = _ ("Options"))
1523 self._add_prompt (line = 5, label = _("Text"), weight =6)
1524 self._add_prompt (line = 6, label = "")
1525
1527 self.fld_specialty = gmPhraseWheel.cPhraseWheel (
1528 parent = parent,
1529 id = -1,
1530 style = wx.SIMPLE_BORDER
1531 )
1532
1533 self._add_field (
1534 line = 1,
1535 pos = 1,
1536 widget = self.fld_specialty,
1537 weight = 1
1538 )
1539 self.fld_name = gmPhraseWheel.cPhraseWheel (
1540 parent = parent,
1541 id = -1,
1542 style = wx.SIMPLE_BORDER
1543 )
1544
1545 self._add_field (
1546 line = 2,
1547 pos = 1,
1548 widget = self.fld_name,
1549 weight = 1
1550 )
1551 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY)
1552
1553 self._add_field (
1554 line = 3,
1555 pos = 1,
1556 widget = self.fld_address,
1557 weight = 1
1558 )
1559
1560
1561 self.fld_name.add_callback_on_selection(self.setAddresses)
1562
1563 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER)
1564 self._add_field (
1565 line = 4,
1566 pos = 1,
1567 widget = self.fld_med,
1568 weight = 1
1569 )
1570 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER)
1571 self._add_field (
1572 line = 4,
1573 pos = 4,
1574 widget = self.fld_past,
1575 weight = 1
1576 )
1577 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE)
1578 self._add_field (
1579 line = 5,
1580 pos = 1,
1581 widget = self.fld_text,
1582 weight = 1)
1583
1584 self._add_field(
1585 line = 6,
1586 pos = 1,
1587 widget = self._make_standard_buttons(parent),
1588 weight = 1
1589 )
1590 return 1
1591
1593 """
1594 Doesn't accept any value as this doesn't make sense for this edit area
1595 """
1596 self.fld_specialty.SetValue ('')
1597 self.fld_name.SetValue ('')
1598 self.fld_address.Clear ()
1599 self.fld_address.SetValue ('')
1600 self.fld_med.SetValue (0)
1601 self.fld_past.SetValue (0)
1602 self.fld_text.SetValue ('')
1603 self.recipient = None
1604
1606 """
1607 Set the available addresses for the selected identity
1608 """
1609 if id is None:
1610 self.recipient = None
1611 self.fld_address.Clear ()
1612 self.fld_address.SetValue ('')
1613 else:
1614 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id)
1615 self.fld_address.Clear ()
1616 self.addr = self.recipient.getAddresses ('work')
1617 for i in self.addr:
1618 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i))
1619 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX)
1620 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL)
1621 if fax:
1622 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax))
1623 if email:
1624 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1625
1626 - def _save_new_entry(self):
1627 """
1628 We are always saving a "new entry" here because data_ID is always None
1629 """
1630 if not self.recipient:
1631 raise gmExceptions.InvalidInputError(_('must have a recipient'))
1632 if self.fld_address.GetSelection() == -1:
1633 raise gmExceptions.InvalidInputError(_('must select address'))
1634 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection())
1635 text = self.fld_text.GetValue()
1636 flags = {}
1637 flags['meds'] = self.fld_med.GetValue()
1638 flags['pasthx'] = self.fld_past.GetValue()
1639 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags):
1640 raise gmExceptions.InvalidInputError('error sending form')
1641
1642
1643
1644
1645
1653
1654
1655
1657 _log.debug("making prescription lines")
1658 lines = []
1659 self.txt_problem = cEditAreaField(parent)
1660 self.txt_class = cEditAreaField(parent)
1661 self.txt_generic = cEditAreaField(parent)
1662 self.txt_brand = cEditAreaField(parent)
1663 self.txt_strength= cEditAreaField(parent)
1664 self.txt_directions= cEditAreaField(parent)
1665 self.txt_for = cEditAreaField(parent)
1666 self.txt_progress = cEditAreaField(parent)
1667
1668 lines.append(self.txt_problem)
1669 lines.append(self.txt_class)
1670 lines.append(self.txt_generic)
1671 lines.append(self.txt_brand)
1672 lines.append(self.txt_strength)
1673 lines.append(self.txt_directions)
1674 lines.append(self.txt_for)
1675 lines.append(self.txt_progress)
1676 lines.append(self._make_standard_buttons(parent))
1677 self.input_fields = {
1678 "problem": self.txt_problem,
1679 "class" : self.txt_class,
1680 "generic" : self.txt_generic,
1681 "brand" : self.txt_brand,
1682 "strength": self.txt_strength,
1683 "directions": self.txt_directions,
1684 "for" : self.txt_for,
1685 "progress": self.txt_progress
1686
1687 }
1688
1689 return self._makeExtraColumns( parent, lines)
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1708
1709
1710
1711
1712
1713
1716 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT)
1717 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
1718 self.SetForegroundColour(aColor)
1719
1720
1721
1722
1723
1725 - def __init__(self, parent, id, prompt_labels):
1726 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1727 self.SetBackgroundColour(richards_light_gray)
1728 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2)
1729 color = richards_aqua
1730 for prompt_key in prompt_labels.keys():
1731 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color)
1732 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1733 color = richards_blue
1734 self.SetSizer(gszr)
1735 gszr.Fit(self)
1736 self.SetAutoLayout(True)
1737
1738
1739
1740
1741
1742
1743
1744 -class EditTextBoxes(wx.Panel):
1745 - def __init__(self, parent, id, editareaprompts, section):
1746 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1747 self.SetBackgroundColour(wx.Color(222,222,222))
1748 self.parent = parent
1749
1750 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2)
1751
1752 if section == gmSECTION_SUMMARY:
1753 pass
1754 elif section == gmSECTION_DEMOGRAPHICS:
1755 pass
1756 elif section == gmSECTION_CLINICALNOTES:
1757 pass
1758 elif section == gmSECTION_FAMILYHISTORY:
1759 pass
1760 elif section == gmSECTION_PASTHISTORY:
1761 pass
1762
1763
1764 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize)
1765 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize)
1766 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER)
1767 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize)
1768 rbsizer = wx.BoxSizer(wx.HORIZONTAL)
1769 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND)
1770 rbsizer.Add(self.rb_sideright,1,wx.EXPAND)
1771 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND)
1772 szr1 = wx.BoxSizer(wx.HORIZONTAL)
1773 szr1.Add(self.txt_condition, 4, wx.EXPAND)
1774 szr1.Add(rbsizer, 3, wx.EXPAND)
1775
1776
1777
1778
1779 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize)
1780
1781 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize)
1782
1783 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize)
1784 szr4 = wx.BoxSizer(wx.HORIZONTAL)
1785 szr4.Add(self.txt_agenoted, 1, wx.EXPAND)
1786 szr4.Add(5, 0, 5)
1787
1788 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize)
1789 szr5 = wx.BoxSizer(wx.HORIZONTAL)
1790 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND)
1791 szr5.Add(5, 0, 5)
1792
1793 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1794 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1795 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1796 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1797 szr6 = wx.BoxSizer(wx.HORIZONTAL)
1798 szr6.Add(self.parent.cb_active, 1, wx.EXPAND)
1799 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND)
1800 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND)
1801 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND)
1802
1803 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize)
1804
1805 szr8 = wx.BoxSizer(wx.HORIZONTAL)
1806 szr8.Add(5, 0, 6)
1807 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND)
1808
1809 self.gszr.Add(szr1,0,wx.EXPAND)
1810 self.gszr.Add(self.txt_notes1,0,wx.EXPAND)
1811 self.gszr.Add(self.txt_notes2,0,wx.EXPAND)
1812 self.gszr.Add(szr4,0,wx.EXPAND)
1813 self.gszr.Add(szr5,0,wx.EXPAND)
1814 self.gszr.Add(szr6,0,wx.EXPAND)
1815 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND)
1816 self.gszr.Add(szr8,0,wx.EXPAND)
1817
1818
1819 elif section == gmSECTION_SCRIPT:
1820 pass
1821 elif section == gmSECTION_REQUESTS:
1822 pass
1823 elif section == gmSECTION_RECALLS:
1824 pass
1825 else:
1826 pass
1827
1828 self.SetSizer(self.gszr)
1829 self.gszr.Fit(self)
1830
1831 self.SetAutoLayout(True)
1832 self.Show(True)
1833
1835 self.btn_OK = wx.Button(self, -1, _("Ok"))
1836 self.btn_Clear = wx.Button(self, -1, _("Clear"))
1837 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
1838 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1)
1839 szr_buttons.Add(5, 0, 0)
1840 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1)
1841 return szr_buttons
1842
1844 - def __init__(self, parent, id, line_labels, section):
1845 _log.warning('***** old style EditArea instantiated, please convert *****')
1846
1847 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER)
1848 self.SetBackgroundColour(wx.Color(222,222,222))
1849
1850
1851 prompts = gmPnlEditAreaPrompts(self, -1, line_labels)
1852
1853 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1854
1855 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1856 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1857 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND)
1858 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1859
1860 szr_prompts = wx.BoxSizer(wx.VERTICAL)
1861 szr_prompts.Add(prompts, 97, wx.EXPAND)
1862 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1863
1864
1865 edit_fields = EditTextBoxes(self, -1, line_labels, section)
1866
1867 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1868
1869 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray)
1870 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL)
1871 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND)
1872 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND)
1873
1874 szr_editarea = wx.BoxSizer(wx.VERTICAL)
1875 szr_editarea.Add(edit_fields, 92, wx.EXPAND)
1876 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND)
1877
1878
1879
1880 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1881 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1882 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1883 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1884 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1885
1886 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1887 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray)
1888 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL)
1889 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND)
1890 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND)
1891
1892
1893 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
1894 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND)
1895 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1896 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
1897 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND)
1898 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND)
1899
1900
1901
1902 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
1903 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
1904 self.SetSizer(self.szr_central_container)
1905 self.szr_central_container.Fit(self)
1906 self.SetAutoLayout(True)
1907 self.Show(True)
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
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184 if __name__ == "__main__":
2185
2186
2191 self._add_prompt(line=1, label='line 1')
2192 self._add_prompt(line=2, label='buttons')
2194
2195 self.fld_substance = cEditAreaField(parent)
2196 self._add_field(
2197 line = 1,
2198 pos = 1,
2199 widget = self.fld_substance,
2200 weight = 1
2201 )
2202
2203 self._add_field(
2204 line = 2,
2205 pos = 1,
2206 widget = self._make_standard_buttons(parent),
2207 weight = 1
2208 )
2209
2210 app = wxPyWidgetTester(size = (400, 200))
2211 app.SetWidget(cTestEditArea)
2212 app.MainLoop()
2213
2214
2215
2216
2217
2218
2219
2220