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