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