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.wxgXxxEAPnl.__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 # remove when implemented:
61 return False
62
63 validity = True
64
65 if self._TCTRL_xxx.GetValue().strip() == u'':
66 validity = False
67 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = False)
68 else:
69 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = True)
70
71 if self._PRW_xxx.GetData() is None:
72 validity = False
73 self._PRW_xxx.display_as_valid(False)
74 else:
75 self._PRW_xxx.display_as_valid(True)
76
77 return validity
78 #----------------------------------------------------------------
79 def _save_as_new(self):
80 # save the data as a new instance
81 data = gmXXXX.create_xxxx()
82
83 data[''] = self._
84 data[''] = self._
85
86 data.save()
87
88 # must be done very late or else the property access
89 # will refresh the display such that later field
90 # access will return empty values
91 self.data = data
92 return False
93 return True
94 #----------------------------------------------------------------
95 def _save_as_update(self):
96 # update self.data and save the changes
97 self.data[''] = self._TCTRL_xxx.GetValue().strip()
98 self.data[''] = self._PRW_xxx.GetData()
99 self.data[''] = self._CHBOX_xxx.GetValue()
100 self.data.save()
101 return True
102 #----------------------------------------------------------------
103 def _refresh_as_new(self):
104 pass
105 #----------------------------------------------------------------
106 def _refresh_as_new_from_existing(self):
107 self._refresh_as_new()
108 #----------------------------------------------------------------
109 def _refresh_from_existing(self):
110 pass
111 #----------------------------------------------------------------
112 """
114 self.__mode = 'new'
115 self.__data = None
116 self.successful_save_msg = None
117 self._refresh_as_new()
118 self.__tctrl_validity_colors = {
119 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW),
120 False: 'pink'
121 }
122
125
127 if mode not in edit_area_modes:
128 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
129 if mode == 'edit':
130 if self.__data is None:
131 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
132
133 prev_mode = self.__mode
134 self.__mode = mode
135 if mode != prev_mode:
136 self.refresh()
137
138 mode = property(_get_mode, _set_mode)
139
142
144 if data is None:
145 if self.__mode == 'edit':
146 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
147 self.__data = data
148 self.refresh()
149
150 data = property(_get_data, _set_data)
151
153 """Invoked from the generic edit area dialog.
154
155 Invokes
156 _valid_for_save,
157 _save_as_new,
158 _save_as_update
159 on the implementing edit area as needed.
160
161 _save_as_* must set self.__data and return True/False
162 """
163 if not self._valid_for_save():
164 return False
165
166 if self.__mode in ['new', 'new_from_existing']:
167 if self._save_as_new():
168 self.mode = 'edit'
169 return True
170 return False
171
172 elif self.__mode == 'edit':
173 return self._save_as_update()
174
175 else:
176 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
177
179 """Invoked from the generic edit area dialog.
180
181 Invokes
182 _refresh_as_new()
183 _refresh_from_existing()
184 _refresh_as_new_from_existing()
185 on the implementing edit area as needed.
186
187 Then calls _valid_for_save().
188 """
189 if self.__mode == 'new':
190 result = self._refresh_as_new()
191 self._valid_for_save()
192 return result
193 elif self.__mode == 'edit':
194 result = self._refresh_from_existing()
195 return result
196 elif self.__mode == 'new_from_existing':
197 result = self._refresh_as_new_from_existing()
198 self._valid_for_save()
199 return result
200 else:
201 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
202
204 tctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
205 tctrl.Refresh()
206
208 ctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
209 ctrl.Refresh()
210
212 """Dialog for parenting edit area panels with save/clear/next/cancel"""
213
214 _lucky_day = 1
215 _lucky_month = 4
216 _today = pydt.date.today()
217
219
220 new_ea = kwargs['edit_area']
221 del kwargs['edit_area']
222
223 if not isinstance(new_ea, cGenericEditAreaMixin):
224 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin')
225
226 try:
227 single_entry = kwargs['single_entry']
228 del kwargs['single_entry']
229 except KeyError:
230 single_entry = False
231
232 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs)
233
234 self.left_extra_button = None
235
236 if cGenericEditAreaDlg2._today.day != cGenericEditAreaDlg2._lucky_day:
237 self._BTN_lucky.Enable(False)
238 self._BTN_lucky.Hide()
239 else:
240 if cGenericEditAreaDlg2._today.month != cGenericEditAreaDlg2._lucky_month:
241 self._BTN_lucky.Enable(False)
242 self._BTN_lucky.Hide()
243
244
245 old_ea = self._PNL_ea
246 ea_pnl_szr = old_ea.GetContainingSizer()
247 ea_pnl_parent = old_ea.GetParent()
248 ea_pnl_szr.Remove(old_ea)
249 old_ea.Destroy()
250 del old_ea
251 new_ea.Reparent(ea_pnl_parent)
252 self._PNL_ea = new_ea
253 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0)
254
255
256 if single_entry:
257 self._BTN_forward.Enable(False)
258 self._BTN_forward.Hide()
259
260 self._adjust_clear_revert_buttons()
261
262
263 self.Layout()
264 main_szr = self.GetSizer()
265 main_szr.Fit(self)
266 self.Refresh()
267
268 self._PNL_ea.refresh()
269
281
288
291
294
309
319
328
329
330
346
347 left_extra_button = property(lambda x:x, _set_left_extra_button)
348
349
351 """Dialog for parenting edit area with save/clear/cancel"""
352
354
355 ea = kwargs['edit_area']
356 del kwargs['edit_area']
357
358 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs)
359
360 szr = self._PNL_ea.GetContainingSizer()
361 szr.Remove(self._PNL_ea)
362 ea.Reparent(self)
363 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4)
364 self._PNL_ea = ea
365
366 self.Layout()
367 szr = self.GetSizer()
368 szr.Fit(self)
369 self.Refresh()
370
371 self._PNL_ea.refresh()
372
380
383
384
385
386
387
388
389 from Gnumed.pycommon import gmGuiBroker
390
391
392 _gb = gmGuiBroker.GuiBroker()
393
394 gmSECTION_SUMMARY = 1
395 gmSECTION_DEMOGRAPHICS = 2
396 gmSECTION_CLINICALNOTES = 3
397 gmSECTION_FAMILYHISTORY = 4
398 gmSECTION_PASTHISTORY = 5
399 gmSECTION_SCRIPT = 8
400 gmSECTION_REQUESTS = 9
401 gmSECTION_REFERRALS = 11
402 gmSECTION_RECALLS = 12
403
404 richards_blue = wx.Colour(0,0,131)
405 richards_aqua = wx.Colour(0,194,197)
406 richards_dark_gray = wx.Color(131,129,131)
407 richards_light_gray = wx.Color(255,255,255)
408 richards_coloured_gray = wx.Color(131,129,131)
409
410
411 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox']
412
414 widget.SetForegroundColour(wx.Color(255, 0, 0))
415 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
416
429 if not isinstance(edit_area, cEditArea2):
430 raise gmExceptions.ConstructorError, '<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area)
431 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name)
432 self.__wxID_BTN_SAVE = wx.NewId()
433 self.__wxID_BTN_RESET = wx.NewId()
434 self.__editarea = edit_area
435 self.__do_layout()
436 self.__register_events()
437
438
439
442
444 self.__editarea.Reparent(self)
445
446 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save"))
447 self.__btn_SAVE.SetToolTipString(_('save entry into medical record'))
448 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset"))
449 self.__btn_RESET.SetToolTipString(_('reset entry'))
450 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
451 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel'))
452
453 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
454 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1)
455 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1)
456 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1)
457
458 szr_main = wx.BoxSizer(wx.VERTICAL)
459 szr_main.Add(self.__editarea, 1, wx.EXPAND)
460 szr_main.Add(szr_buttons, 0, wx.EXPAND)
461
462 self.SetSizerAndFit(szr_main)
463
464
465
467
468 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed)
469 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed)
470 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed)
471
472 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed)
473
474
475
476
477
478
479 return 1
480
482 if self.__editarea.save_data():
483 self.__editarea.Close()
484 self.EndModal(wx.ID_OK)
485 return
486 short_err = self.__editarea.get_short_error()
487 long_err = self.__editarea.get_long_error()
488 if (short_err is None) and (long_err is None):
489 long_err = _(
490 'Unspecified error saving data in edit area.\n\n'
491 'Programmer forgot to specify proper error\n'
492 'message in [%s].'
493 ) % self.__editarea.__class__.__name__
494 if short_err is not None:
495 gmDispatcher.send(signal = 'statustext', msg = short_err)
496 if long_err is not None:
497 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
498
500 self.__editarea.Close()
501 self.EndModal(wx.ID_CANCEL)
502
505
507 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
508
509 wx.Panel.__init__ (
510 self,
511 parent,
512 id,
513 pos = pos,
514 size = size,
515 style = style | wx.TAB_TRAVERSAL
516 )
517 self.SetBackgroundColour(wx.Color(222,222,222))
518
519 self.data = None
520 self.fields = {}
521 self.prompts = {}
522 self._short_error = None
523 self._long_error = None
524 self._summary = None
525 self._patient = gmPerson.gmCurrentPatient()
526 self.__wxID_BTN_OK = wx.NewId()
527 self.__wxID_BTN_CLEAR = wx.NewId()
528 self.__do_layout()
529 self.__register_events()
530 self.Show()
531
532
533
535 """This needs to be overridden by child classes."""
536 self._long_error = _(
537 'Cannot save data from edit area.\n\n'
538 'Programmer forgot to override method:\n'
539 ' <%s.save_data>'
540 ) % self.__class__.__name__
541 return False
542
544 msg = _(
545 'Cannot reset fields in edit area.\n\n'
546 'Programmer forgot to override method:\n'
547 ' <%s.reset_ui>'
548 ) % self.__class__.__name__
549 gmGuiHelpers.gm_show_error(msg)
550
552 tmp = self._short_error
553 self._short_error = None
554 return tmp
555
557 tmp = self._long_error
558 self._long_error = None
559 return tmp
560
562 return _('<No embed string for [%s]>') % self.__class__.__name__
563
564
565
577
582
583
584
586 self.__deregister_events()
587 event.Skip()
588
590 """Only active if _make_standard_buttons was called in child class."""
591
592 try:
593 event.Skip()
594 if self.data is None:
595 self._save_new_entry()
596 self.reset_ui()
597 else:
598 self._save_modified_entry()
599 self.reset_ui()
600 except gmExceptions.InvalidInputError, err:
601
602
603 gmGuiHelpers.gm_show_error (err, _("Invalid Input"))
604 except:
605 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
606
608 """Only active if _make_standard_buttons was called in child class."""
609
610 self.reset_ui()
611 event.Skip()
612
614 self.__deregister_events()
615
616 if not self._patient.connected:
617 return True
618
619
620
621
622 return True
623 _log.error('[%s] lossage' % self.__class__.__name__)
624 return False
625
627 """Just before new patient becomes active."""
628
629 if not self._patient.connected:
630 return True
631
632
633
634
635 return True
636 _log.error('[%s] lossage' % self.__class__.__name__)
637 return False
638
640 """Just after new patient became active."""
641
642 self.reset_ui()
643
644
645
647
648
649 self._define_prompts()
650 self._define_fields(parent = self)
651 if len(self.fields) != len(self.prompts):
652 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
653 return None
654
655
656 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2)
657 color = richards_aqua
658 lines = self.prompts.keys()
659 lines.sort()
660 for line in lines:
661
662 label, color, weight = self.prompts[line]
663
664 prompt = wx.StaticText (
665 parent = self,
666 id = -1,
667 label = label,
668 style = wx.ALIGN_CENTRE
669 )
670
671 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
672 prompt.SetForegroundColour(color)
673 prompt.SetBackgroundColour(richards_light_gray)
674 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT)
675
676
677 szr_line = wx.BoxSizer(wx.HORIZONTAL)
678 positions = self.fields[line].keys()
679 positions.sort()
680 for pos in positions:
681 field, weight = self.fields[line][pos]
682
683 szr_line.Add(field, weight, wx.EXPAND)
684 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT)
685
686
687 szr_main_fgrid.AddGrowableCol(1)
688
689
690
691
692
693
694
695 self.SetSizerAndFit(szr_main_fgrid)
696
697
698
699
701 """Child classes override this to define their prompts using _add_prompt()"""
702 _log.error('missing override in [%s]' % self.__class__.__name__)
703
705 """Add a new prompt line.
706
707 To be used from _define_fields in child classes.
708
709 - label, the label text
710 - color
711 - weight, the weight given in sizing the various rows. 0 means the row
712 always has minimum size
713 """
714 self.prompts[line] = (label, color, weight)
715
717 """Defines the fields.
718
719 - override in child classes
720 - mostly uses _add_field()
721 """
722 _log.error('missing override in [%s]' % self.__class__.__name__)
723
724 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
725 if None in (line, pos, widget):
726 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
727 if not self.fields.has_key(line):
728 self.fields[line] = {}
729 self.fields[line][pos] = (widget, weight)
730
748
749
750
751
753 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
754 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER)
755 _decorate_editarea_field(self)
756
758 - def __init__(self, parent, id, pos, size, style):
759
760 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
761
762
763 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
764 self.SetBackgroundColour(wx.Color(222,222,222))
765
766 self.data = None
767 self.fields = {}
768 self.prompts = {}
769
770 ID_BTN_OK = wx.NewId()
771 ID_BTN_CLEAR = wx.NewId()
772
773 self.__do_layout()
774
775
776
777
778
779
780 self._patient = gmPerson.gmCurrentPatient()
781 self.__register_events()
782 self.Show(True)
783
784
785
787
788 self._define_prompts()
789 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
790 self._define_fields(parent = self.fields_pnl)
791
792 szr_prompts = self.__generate_prompts()
793 szr_fields = self.__generate_fields()
794
795
796 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
797 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND)
798 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
799 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND)
800
801
802
803 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
804 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
805
806
807 self.SetAutoLayout(True)
808 self.SetSizer(self.szr_central_container)
809 self.szr_central_container.Fit(self)
810
812 if len(self.fields) != len(self.prompts):
813 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
814 return None
815
816 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
817 prompt_pnl.SetBackgroundColour(richards_light_gray)
818
819 color = richards_aqua
820 lines = self.prompts.keys()
821 lines.sort()
822 self.prompt_widget = {}
823 for line in lines:
824 label, color, weight = self.prompts[line]
825 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color)
826
827 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
828 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
829 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
830 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
831 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
832
833
834 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
835 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
836 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
837
838
839 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
840 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
841 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
842 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
843 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND)
844
845
846 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
847 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
848 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
849
850 return hszr_prompts
851
853 self.fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
854
855 vszr = wx.BoxSizer(wx.VERTICAL)
856 lines = self.fields.keys()
857 lines.sort()
858 self.field_line_szr = {}
859 for line in lines:
860 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL)
861 positions = self.fields[line].keys()
862 positions.sort()
863 for pos in positions:
864 field, weight = self.fields[line][pos]
865 self.field_line_szr[line].Add(field, weight, wx.EXPAND)
866 try:
867 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND)
868 except KeyError:
869 _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) ) )
870
871 self.fields_pnl.SetSizer(vszr)
872 vszr.Fit(self.fields_pnl)
873
874
875 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
876 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
877 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
878 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
879 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
880
881
882 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
883 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND)
884 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
885
886
887 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
888 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
889 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
890 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
891 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
892
893
894 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
895 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
896 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
897
898 return hszr_edit_fields
899
901
902 prompt = wx.StaticText(
903 parent,
904 -1,
905 aLabel,
906 style = wx.ALIGN_RIGHT
907 )
908 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
909 prompt.SetForegroundColour(aColor)
910 return prompt
911
912
913
915 """Add a new prompt line.
916
917 To be used from _define_fields in child classes.
918
919 - label, the label text
920 - color
921 - weight, the weight given in sizing the various rows. 0 means the rwo
922 always has minimum size
923 """
924 self.prompts[line] = (label, color, weight)
925
926 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
927 if None in (line, pos, widget):
928 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
929 if not self.fields.has_key(line):
930 self.fields[line] = {}
931 self.fields[line][pos] = (widget, weight)
932
934 """Defines the fields.
935
936 - override in child classes
937 - mostly uses _add_field()
938 """
939 _log.error('missing override in [%s]' % self.__class__.__name__)
940
942 _log.error('missing override in [%s]' % self.__class__.__name__)
943
957
960
962 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__)
963 _log.info('child classes of cEditArea *must* override this function')
964 return False
965
966
967
969
970 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed)
971 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed)
972
973 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields)
974
975
976 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection)
977 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing)
978 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection)
979
980 return 1
981
982
983
1000
1002
1003 self.set_data()
1004 event.Skip()
1005
1006 - def on_post_patient_selection( self, **kwds):
1007
1008 self.set_data()
1009
1011
1012 if not self._patient.connected:
1013 return True
1014 if self._save_data():
1015 return True
1016 _log.error('[%s] lossage' % self.__class__.__name__)
1017 return False
1018
1020
1021 if not self._patient.connected:
1022 return True
1023 if self._save_data():
1024 return True
1025 _log.error('[%s] lossage' % self.__class__.__name__)
1026 return False
1027
1029 self.fields_pnl.Layout()
1030
1031 for i in self.field_line_szr.keys():
1032
1033 pos = self.field_line_szr[i].GetPosition()
1034
1035 self.prompt_widget[i].SetPosition((0, pos.y))
1036
1038 - def __init__(self, parent, id, aType = None):
1039
1040 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
1041
1042
1043 if aType not in _known_edit_area_types:
1044 _log.error('unknown edit area type: [%s]' % aType)
1045 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType
1046 self._type = aType
1047
1048
1049 cEditArea.__init__(self, parent, id)
1050
1051 self.input_fields = {}
1052
1053 self._postInit()
1054 self.old_data = {}
1055
1056 self._patient = gmPerson.gmCurrentPatient()
1057 self.Show(True)
1058
1059
1060
1061
1062
1063
1065
1066 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1067 prompt_pnl.SetBackgroundColour(richards_light_gray)
1068
1069 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2)
1070 color = richards_aqua
1071 for prompt in prompt_labels:
1072 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color)
1073 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1074 color = richards_blue
1075 gszr.RemoveGrowableRow (line-1)
1076
1077 prompt_pnl.SetSizer(gszr)
1078 gszr.Fit(prompt_pnl)
1079 prompt_pnl.SetAutoLayout(True)
1080
1081
1082 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1083 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1084 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1085 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
1086 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1087
1088
1089 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
1090 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
1091 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1092
1093
1094 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1095 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1096 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1097 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1098 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1099
1100
1101 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
1102 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
1103 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1104
1105 return hszr_prompts
1106
1108 _log.error('programmer forgot to define edit area lines for [%s]' % self._type)
1109 _log.info('child classes of gmEditArea *must* override this function')
1110 return []
1111
1113
1114 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1115 fields_pnl.SetBackgroundColour(wx.Color(222,222,222))
1116
1117 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2)
1118
1119
1120 lines = self._make_edit_lines(parent = fields_pnl)
1121
1122 self.lines = lines
1123 if len(lines) != len(_prompt_defs[self._type]):
1124 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type)
1125 for line in lines:
1126 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT)
1127
1128 fields_pnl.SetSizer(gszr)
1129 gszr.Fit(fields_pnl)
1130 fields_pnl.SetAutoLayout(True)
1131
1132
1133 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1134 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
1135 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1136 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
1137 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
1138
1139
1140 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
1141 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND)
1142 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
1143
1144
1145 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1146 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
1147 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
1148 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
1149 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
1150
1151
1152 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1153 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
1154 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
1155
1156 return hszr_edit_fields
1157
1160
1165
1167 map = {}
1168 for k in self.input_fields.keys():
1169 map[k] = ''
1170 return map
1171
1172
1174 self._default_init_fields()
1175
1176
1177
1178
1179
1181 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1182
1183
1184 - def _postInit(self):
1185 """override for further control setup"""
1186 pass
1187
1188
1190 szr = wx.BoxSizer(wx.HORIZONTAL)
1191 szr.Add( widget, weight, wx.EXPAND)
1192 szr.Add( 0,0, spacerWeight, wx.EXPAND)
1193 return szr
1194
1196
1197 cb = wx.CheckBox( parent, -1, _(title))
1198 cb.SetForegroundColour( richards_blue)
1199 return cb
1200
1201
1202
1204 """this is a utlity method to add extra columns"""
1205
1206 if self.__class__.__dict__.has_key("extraColumns"):
1207 for x in self.__class__.extraColumns:
1208 lines = self._addColumn(parent, lines, x, weightMap)
1209 return lines
1210
1211
1212
1213 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1214 """
1215 # add ia extra column in the edit area.
1216 # preconditions:
1217 # parent is fields_pnl (weak);
1218 # self.input_fields exists (required);
1219 # ; extra is a list of tuples of format -
1220 # ( key for input_fields, widget label , widget class to instantiate )
1221 """
1222
1223 newlines = []
1224 i = 0
1225 for x in lines:
1226
1227 if weightMap.has_key( x):
1228 (existingWeight, extraWeight) = weightMap[x]
1229
1230 szr = wx.BoxSizer(wx.HORIZONTAL)
1231 szr.Add( x, existingWeight, wx.EXPAND)
1232 if i < len(extra) and extra[i] <> None:
1233
1234 (inputKey, widgetLabel, aclass) = extra[i]
1235 if aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1236 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) )
1237 widgetLabel = ""
1238
1239
1240 w = aclass( parent, -1, widgetLabel)
1241 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1242 w.SetForegroundColour(richards_blue)
1243
1244 szr.Add(w, extraWeight , wx.EXPAND)
1245
1246
1247 self.input_fields[inputKey] = w
1248
1249 newlines.append(szr)
1250 i += 1
1251 return newlines
1252
1272
1275
1278
1284
1295
1303
1305 _log.debug("making family Hx lines")
1306 lines = []
1307 self.input_fields = {}
1308
1309
1310
1311 self.input_fields['name'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1312 self.input_fields['DOB'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1313 lbl_dob = self._make_prompt(parent, _(" Date of Birth "), richards_blue)
1314 szr = wx.BoxSizer(wx.HORIZONTAL)
1315 szr.Add(self.input_fields['name'], 4, wx.EXPAND)
1316 szr.Add(lbl_dob, 2, wx.EXPAND)
1317 szr.Add(self.input_fields['DOB'], 4, wx.EXPAND)
1318 lines.append(szr)
1319
1320
1321
1322 self.input_fields['relationship'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1323 szr = wx.BoxSizer(wx.HORIZONTAL)
1324 szr.Add(self.input_fields['relationship'], 4, wx.EXPAND)
1325 lines.append(szr)
1326
1327 self.input_fields['condition'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1328 self.cb_condition_confidential = wx.CheckBox(parent, -1, _("confidental"), wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER)
1329 szr = wx.BoxSizer(wx.HORIZONTAL)
1330 szr.Add(self.input_fields['condition'], 6, wx.EXPAND)
1331 szr.Add(self.cb_condition_confidential, 0, wx.EXPAND)
1332 lines.append(szr)
1333
1334 self.input_fields['comment'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1335 lines.append(self.input_fields['comment'])
1336
1337 lbl_onset = self._make_prompt(parent, _(" age onset "), richards_blue)
1338 self.input_fields['age onset'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1339
1340 lbl_caused_death = self._make_prompt(parent, _(" caused death "), richards_blue)
1341 self.input_fields['caused death'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1342 lbl_aod = self._make_prompt(parent, _(" age died "), richards_blue)
1343 self.input_fields['AOD'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1344 szr = wx.BoxSizer(wx.HORIZONTAL)
1345 szr.Add(lbl_onset, 0, wx.EXPAND)
1346 szr.Add(self.input_fields['age onset'], 1,wx.EXPAND)
1347 szr.Add(lbl_caused_death, 0, wx.EXPAND)
1348 szr.Add(self.input_fields['caused death'], 2,wx.EXPAND)
1349 szr.Add(lbl_aod, 0, wx.EXPAND)
1350 szr.Add(self.input_fields['AOD'], 1, wx.EXPAND)
1351 szr.Add(2, 2, 8)
1352 lines.append(szr)
1353
1354 self.input_fields['progress notes'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize)
1355 lines.append(self.input_fields['progress notes'])
1356
1357 self.Btn_next_condition = wx.Button(parent, -1, _("Next Condition"))
1358 szr = wx.BoxSizer(wx.HORIZONTAL)
1359 szr.AddSpacer(10, 0, 0)
1360 szr.Add(self.Btn_next_condition, 0, wx.EXPAND | wx.ALL, 1)
1361 szr.Add(2, 1, 5)
1362 szr.Add(self._make_standard_buttons(parent), 0, wx.EXPAND)
1363 lines.append(szr)
1364
1365 return lines
1366
1369
1370
1371 -class gmPastHistoryEditArea(gmEditArea):
1372
1373 - def __init__(self, parent, id):
1374 gmEditArea.__init__(self, parent, id, aType = 'past history')
1375
1376 - def _define_prompts(self):
1377 self._add_prompt(line = 1, label = _("When Noted"))
1378 self._add_prompt(line = 2, label = _("Laterality"))
1379 self._add_prompt(line = 3, label = _("Condition"))
1380 self._add_prompt(line = 4, label = _("Notes"))
1381 self._add_prompt(line = 6, label = _("Status"))
1382 self._add_prompt(line = 7, label = _("Progress Note"))
1383 self._add_prompt(line = 8, label = '')
1384
1385 - def _define_fields(self, parent):
1386
1387 self.fld_date_noted = gmDateTimeInput.gmDateInput(
1388 parent = parent,
1389 id = -1,
1390 style = wx.SIMPLE_BORDER
1391 )
1392 self._add_field(
1393 line = 1,
1394 pos = 1,
1395 widget = self.fld_date_noted,
1396 weight = 2
1397 )
1398 self._add_field(
1399 line = 1,
1400 pos = 2,
1401 widget = cPrompt_edit_area(parent,-1, _("Age")),
1402 weight = 0)
1403
1404 self.fld_age_noted = cEditAreaField(parent)
1405 self._add_field(
1406 line = 1,
1407 pos = 3,
1408 widget = self.fld_age_noted,
1409 weight = 2
1410 )
1411
1412
1413 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A"))
1414 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L"))
1415 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R"))
1416 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both"))
1417 self._add_field(
1418 line = 2,
1419 pos = 1,
1420 widget = self.fld_laterality_none,
1421 weight = 0
1422 )
1423 self._add_field(
1424 line = 2,
1425 pos = 2,
1426 widget = self.fld_laterality_left,
1427 weight = 0
1428 )
1429 self._add_field(
1430 line = 2,
1431 pos = 3,
1432 widget = self.fld_laterality_right,
1433 weight = 1
1434 )
1435 self._add_field(
1436 line = 2,
1437 pos = 4,
1438 widget = self.fld_laterality_both,
1439 weight = 1
1440 )
1441
1442 self.fld_condition= cEditAreaField(parent)
1443 self._add_field(
1444 line = 3,
1445 pos = 1,
1446 widget = self.fld_condition,
1447 weight = 6
1448 )
1449
1450 self.fld_notes= cEditAreaField(parent)
1451 self._add_field(
1452 line = 4,
1453 pos = 1,
1454 widget = self.fld_notes,
1455 weight = 6
1456 )
1457
1458 self.fld_significant= wx.CheckBox(
1459 parent,
1460 -1,
1461 _("significant"),
1462 style = wx.NO_BORDER
1463 )
1464 self.fld_active= wx.CheckBox(
1465 parent,
1466 -1,
1467 _("active"),
1468 style = wx.NO_BORDER
1469 )
1470
1471 self._add_field(
1472 line = 5,
1473 pos = 1,
1474 widget = self.fld_significant,
1475 weight = 0
1476 )
1477 self._add_field(
1478 line = 5,
1479 pos = 2,
1480 widget = self.fld_active,
1481 weight = 0
1482 )
1483
1484 self.fld_progress= cEditAreaField(parent)
1485 self._add_field(
1486 line = 6,
1487 pos = 1,
1488 widget = self.fld_progress,
1489 weight = 6
1490 )
1491
1492
1493 self._add_field(
1494 line = 7,
1495 pos = 4,
1496 widget = self._make_standard_buttons(parent),
1497 weight = 2
1498 )
1499
1500 - def _postInit(self):
1501 return
1502
1503 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus)
1504 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1505
1506 - def _ageKillFocus( self, event):
1507
1508 event.Skip()
1509 try :
1510 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() )
1511 self.fld_date_noted.SetValue( str (year) )
1512 except:
1513 pass
1514
1515 - def _getBirthYear(self):
1516 try:
1517 birthyear = int(str(self._patient['dob']).split('-')[0])
1518 except:
1519
1520 birthyear = 1
1521
1522 return birthyear
1523
1524 - def _yearKillFocus( self, event):
1525 event.Skip()
1526 try:
1527 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear()
1528 self.fld_age_noted.SetValue( str (age) )
1529 except:
1530 pass
1531
1532 __init_values = {
1533 "condition": "",
1534 "notes1": "",
1535 "notes2": "",
1536 "age": "",
1537
1538 "progress": "",
1539 "active": 1,
1540 "operation": 0,
1541 "confidential": 0,
1542 "significant": 1,
1543 "both": 0,
1544 "left": 0,
1545 "right": 0,
1546 "none" : 1
1547 }
1548
1549 - def _getDefaultAge(self):
1550 try:
1551
1552 return 1
1553 except:
1554 return 0
1555
1556 - def _get_init_values(self):
1557 values = gmPastHistoryEditArea.__init_values
1558 values["age"] = str( self._getDefaultAge())
1559 return values
1560
1561 - def _save_data(self):
1562 clinical = self._patient.get_emr().get_past_history()
1563 if self.getDataId() is None:
1564 id = clinical.create_history( self.get_fields_formatting_values() )
1565 self.setDataId(id)
1566 return
1567
1568 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1569
1570
1580
1582 self._add_prompt (line = 1, label = _ ("Specialty"))
1583 self._add_prompt (line = 2, label = _ ("Name"))
1584 self._add_prompt (line = 3, label = _ ("Address"))
1585 self._add_prompt (line = 4, label = _ ("Options"))
1586 self._add_prompt (line = 5, label = _("Text"), weight =6)
1587 self._add_prompt (line = 6, label = "")
1588
1590 self.fld_specialty = gmPhraseWheel.cPhraseWheel (
1591 parent = parent,
1592 id = -1,
1593 style = wx.SIMPLE_BORDER
1594 )
1595
1596 self._add_field (
1597 line = 1,
1598 pos = 1,
1599 widget = self.fld_specialty,
1600 weight = 1
1601 )
1602 self.fld_name = gmPhraseWheel.cPhraseWheel (
1603 parent = parent,
1604 id = -1,
1605 style = wx.SIMPLE_BORDER
1606 )
1607
1608 self._add_field (
1609 line = 2,
1610 pos = 1,
1611 widget = self.fld_name,
1612 weight = 1
1613 )
1614 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY)
1615
1616 self._add_field (
1617 line = 3,
1618 pos = 1,
1619 widget = self.fld_address,
1620 weight = 1
1621 )
1622
1623
1624 self.fld_name.add_callback_on_selection(self.setAddresses)
1625
1626 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER)
1627 self._add_field (
1628 line = 4,
1629 pos = 1,
1630 widget = self.fld_med,
1631 weight = 1
1632 )
1633 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER)
1634 self._add_field (
1635 line = 4,
1636 pos = 4,
1637 widget = self.fld_past,
1638 weight = 1
1639 )
1640 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE)
1641 self._add_field (
1642 line = 5,
1643 pos = 1,
1644 widget = self.fld_text,
1645 weight = 1)
1646
1647 self._add_field(
1648 line = 6,
1649 pos = 1,
1650 widget = self._make_standard_buttons(parent),
1651 weight = 1
1652 )
1653 return 1
1654
1656 """
1657 Doesn't accept any value as this doesn't make sense for this edit area
1658 """
1659 self.fld_specialty.SetValue ('')
1660 self.fld_name.SetValue ('')
1661 self.fld_address.Clear ()
1662 self.fld_address.SetValue ('')
1663 self.fld_med.SetValue (0)
1664 self.fld_past.SetValue (0)
1665 self.fld_text.SetValue ('')
1666 self.recipient = None
1667
1669 """
1670 Set the available addresses for the selected identity
1671 """
1672 if id is None:
1673 self.recipient = None
1674 self.fld_address.Clear ()
1675 self.fld_address.SetValue ('')
1676 else:
1677 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id)
1678 self.fld_address.Clear ()
1679 self.addr = self.recipient.getAddresses ('work')
1680 for i in self.addr:
1681 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i))
1682 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX)
1683 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL)
1684 if fax:
1685 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax))
1686 if email:
1687 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1688
1689 - def _save_new_entry(self):
1690 """
1691 We are always saving a "new entry" here because data_ID is always None
1692 """
1693 if not self.recipient:
1694 raise gmExceptions.InvalidInputError(_('must have a recipient'))
1695 if self.fld_address.GetSelection() == -1:
1696 raise gmExceptions.InvalidInputError(_('must select address'))
1697 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection())
1698 text = self.fld_text.GetValue()
1699 flags = {}
1700 flags['meds'] = self.fld_med.GetValue()
1701 flags['pasthx'] = self.fld_past.GetValue()
1702 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags):
1703 raise gmExceptions.InvalidInputError('error sending form')
1704
1705
1706
1707
1708
1716
1717
1718
1720 _log.debug("making prescription lines")
1721 lines = []
1722 self.txt_problem = cEditAreaField(parent)
1723 self.txt_class = cEditAreaField(parent)
1724 self.txt_generic = cEditAreaField(parent)
1725 self.txt_brand = cEditAreaField(parent)
1726 self.txt_strength= cEditAreaField(parent)
1727 self.txt_directions= cEditAreaField(parent)
1728 self.txt_for = cEditAreaField(parent)
1729 self.txt_progress = cEditAreaField(parent)
1730
1731 lines.append(self.txt_problem)
1732 lines.append(self.txt_class)
1733 lines.append(self.txt_generic)
1734 lines.append(self.txt_brand)
1735 lines.append(self.txt_strength)
1736 lines.append(self.txt_directions)
1737 lines.append(self.txt_for)
1738 lines.append(self.txt_progress)
1739 lines.append(self._make_standard_buttons(parent))
1740 self.input_fields = {
1741 "problem": self.txt_problem,
1742 "class" : self.txt_class,
1743 "generic" : self.txt_generic,
1744 "brand" : self.txt_brand,
1745 "strength": self.txt_strength,
1746 "directions": self.txt_directions,
1747 "for" : self.txt_for,
1748 "progress": self.txt_progress
1749
1750 }
1751
1752 return self._makeExtraColumns( parent, lines)
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1771
1772
1773
1774
1775
1776
1779 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT)
1780 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
1781 self.SetForegroundColour(aColor)
1782
1783
1784
1785
1786
1788 - def __init__(self, parent, id, prompt_labels):
1789 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1790 self.SetBackgroundColour(richards_light_gray)
1791 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2)
1792 color = richards_aqua
1793 for prompt_key in prompt_labels.keys():
1794 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color)
1795 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1796 color = richards_blue
1797 self.SetSizer(gszr)
1798 gszr.Fit(self)
1799 self.SetAutoLayout(True)
1800
1801
1802
1803
1804
1805
1806
1807 -class EditTextBoxes(wx.Panel):
1808 - def __init__(self, parent, id, editareaprompts, section):
1809 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1810 self.SetBackgroundColour(wx.Color(222,222,222))
1811 self.parent = parent
1812
1813 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2)
1814
1815 if section == gmSECTION_SUMMARY:
1816 pass
1817 elif section == gmSECTION_DEMOGRAPHICS:
1818 pass
1819 elif section == gmSECTION_CLINICALNOTES:
1820 pass
1821 elif section == gmSECTION_FAMILYHISTORY:
1822 pass
1823 elif section == gmSECTION_PASTHISTORY:
1824 pass
1825
1826
1827 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize)
1828 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize)
1829 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER)
1830 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize)
1831 rbsizer = wx.BoxSizer(wx.HORIZONTAL)
1832 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND)
1833 rbsizer.Add(self.rb_sideright,1,wx.EXPAND)
1834 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND)
1835 szr1 = wx.BoxSizer(wx.HORIZONTAL)
1836 szr1.Add(self.txt_condition, 4, wx.EXPAND)
1837 szr1.Add(rbsizer, 3, wx.EXPAND)
1838
1839
1840
1841
1842 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize)
1843
1844 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize)
1845
1846 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize)
1847 szr4 = wx.BoxSizer(wx.HORIZONTAL)
1848 szr4.Add(self.txt_agenoted, 1, wx.EXPAND)
1849 szr4.Add(5, 0, 5)
1850
1851 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize)
1852 szr5 = wx.BoxSizer(wx.HORIZONTAL)
1853 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND)
1854 szr5.Add(5, 0, 5)
1855
1856 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1857 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1858 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1859 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1860 szr6 = wx.BoxSizer(wx.HORIZONTAL)
1861 szr6.Add(self.parent.cb_active, 1, wx.EXPAND)
1862 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND)
1863 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND)
1864 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND)
1865
1866 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize)
1867
1868 szr8 = wx.BoxSizer(wx.HORIZONTAL)
1869 szr8.Add(5, 0, 6)
1870 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND)
1871
1872 self.gszr.Add(szr1,0,wx.EXPAND)
1873 self.gszr.Add(self.txt_notes1,0,wx.EXPAND)
1874 self.gszr.Add(self.txt_notes2,0,wx.EXPAND)
1875 self.gszr.Add(szr4,0,wx.EXPAND)
1876 self.gszr.Add(szr5,0,wx.EXPAND)
1877 self.gszr.Add(szr6,0,wx.EXPAND)
1878 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND)
1879 self.gszr.Add(szr8,0,wx.EXPAND)
1880
1881
1882 elif section == gmSECTION_SCRIPT:
1883 pass
1884 elif section == gmSECTION_REQUESTS:
1885 pass
1886 elif section == gmSECTION_RECALLS:
1887 pass
1888 else:
1889 pass
1890
1891 self.SetSizer(self.gszr)
1892 self.gszr.Fit(self)
1893
1894 self.SetAutoLayout(True)
1895 self.Show(True)
1896
1898 self.btn_OK = wx.Button(self, -1, _("Ok"))
1899 self.btn_Clear = wx.Button(self, -1, _("Clear"))
1900 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
1901 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1)
1902 szr_buttons.Add(5, 0, 0)
1903 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1)
1904 return szr_buttons
1905
1907 - def __init__(self, parent, id, line_labels, section):
1908 _log.warning('***** old style EditArea instantiated, please convert *****')
1909
1910 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER)
1911 self.SetBackgroundColour(wx.Color(222,222,222))
1912
1913
1914 prompts = gmPnlEditAreaPrompts(self, -1, line_labels)
1915
1916 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1917
1918 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1919 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1920 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND)
1921 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1922
1923 szr_prompts = wx.BoxSizer(wx.VERTICAL)
1924 szr_prompts.Add(prompts, 97, wx.EXPAND)
1925 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1926
1927
1928 edit_fields = EditTextBoxes(self, -1, line_labels, section)
1929
1930 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1931
1932 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray)
1933 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL)
1934 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND)
1935 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND)
1936
1937 szr_editarea = wx.BoxSizer(wx.VERTICAL)
1938 szr_editarea.Add(edit_fields, 92, wx.EXPAND)
1939 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND)
1940
1941
1942
1943 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1944 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1945 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1946 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1947 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1948
1949 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1950 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray)
1951 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL)
1952 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND)
1953 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND)
1954
1955
1956 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
1957 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND)
1958 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1959 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
1960 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND)
1961 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND)
1962
1963
1964
1965 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
1966 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
1967 self.SetSizer(self.szr_central_container)
1968 self.szr_central_container.Fit(self)
1969 self.SetAutoLayout(True)
1970 self.Show(True)
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
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 if __name__ == "__main__":
2248
2249
2254 self._add_prompt(line=1, label='line 1')
2255 self._add_prompt(line=2, label='buttons')
2257
2258 self.fld_substance = cEditAreaField(parent)
2259 self._add_field(
2260 line = 1,
2261 pos = 1,
2262 widget = self.fld_substance,
2263 weight = 1
2264 )
2265
2266 self._add_field(
2267 line = 2,
2268 pos = 1,
2269 widget = self._make_standard_buttons(parent),
2270 weight = 1
2271 )
2272
2273 app = wxPyWidgetTester(size = (400, 200))
2274 app.SetWidget(cTestEditArea)
2275 app.MainLoop()
2276
2277
2278
2279
2280
2281
2282
2283