Package Gnumed :: Package wxpython :: Module gmTopPanel
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmTopPanel

  1  # GNUmed 
  2   
  3  #=========================================================== 
  4  __author__  = "R.Terry <rterry@gnumed.net>, I.Haywood <i.haywood@ugrad.unimelb.edu.au>, K.Hilbert <Karsten.Hilbert@gmx.net>" 
  5  __license__ = "GPL v2 or later" 
  6   
  7   
  8  import sys 
  9  import os.path 
 10  import datetime as pyDT 
 11  import logging 
 12   
 13   
 14  import wx 
 15   
 16   
 17  from Gnumed.pycommon import gmGuiBroker 
 18  from Gnumed.pycommon import gmDispatcher 
 19  from Gnumed.pycommon import gmTools 
 20  from Gnumed.pycommon import gmCfg2 
 21  from Gnumed.pycommon import gmDateTime 
 22  from Gnumed.pycommon import gmI18N 
 23   
 24  from Gnumed.business import gmPerson 
 25  from Gnumed.business import gmEMRStructItems 
 26  from Gnumed.business import gmAllergy 
 27   
 28  from Gnumed.wxpython import gmGuiHelpers 
 29  from Gnumed.wxpython import gmDemographicsWidgets 
 30  from Gnumed.wxpython import gmAllergyWidgets 
 31  from Gnumed.wxpython import gmPatSearchWidgets 
 32  from Gnumed.wxpython import gmEMRStructWidgets 
 33  from Gnumed.wxpython import gmPatPicWidgets 
 34   
 35   
 36  _log = logging.getLogger('gm.ui') 
 37   
 38  #=========================================================== 
 39  from Gnumed.wxGladeWidgets import wxgTopPnl 
 40   
41 -class cTopPnl(wxgTopPnl.wxgTopPnl):
42
43 - def __init__(self, *args, **kwargs):
44 45 wxgTopPnl.wxgTopPnl.__init__(self, *args, **kwargs) 46 47 self.__gb = gmGuiBroker.GuiBroker() 48 49 self.curr_pat = gmPerson.gmCurrentPatient() 50 51 self.__init_ui() 52 self.__register_interests()
53 #-------------------------------------------------------
54 - def __init_ui(self):
55 cfg = gmCfg2.gmCfgData() 56 if cfg.get(option = 'slave'): 57 self._TCTRL_patient_selector.SetEditable(0) 58 self._TCTRL_patient_selector.SetToolTip(None)
59 #-------------------------------------------------------
60 - def __register_interests(self):
61 # events 62 wx.EVT_LEFT_DCLICK(self._TCTRL_allergies, self._on_allergies_dclicked) 63 64 # client internal signals 65 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._on_post_patient_selection) 66 gmDispatcher.connect(signal = u'clin.allgergy_mod_db', receiver = self._on_allergies_change) 67 gmDispatcher.connect(signal = u'clin.allergy_state_mod_db', receiver = self._on_allergies_change) 68 gmDispatcher.connect(signal = u'dem.names_mod_db', receiver = self._on_name_identity_change) 69 gmDispatcher.connect(signal = u'dem.identity_mod_db', receiver = self._on_name_identity_change) 70 gmDispatcher.connect(signal = u'dem.identity_tag_mod_db', receiver = self._on_tag_change) 71 72 gmDispatcher.connect(signal = u'focus_patient_search', receiver = self._on_focus_patient_search)
73 #---------------------------------------------- 74 # event handling 75 #----------------------------------------------
76 - def _on_allergies_dclicked(self, evt):
77 if not self.curr_pat.connected: 78 gmDispatcher.send('statustext', msg = _('Cannot activate Allergy Manager. No active patient.')) 79 return 80 dlg = gmAllergyWidgets.cAllergyManagerDlg(parent=self, id=-1) 81 dlg.ShowModal() 82 return
83 #----------------------------------------------
84 - def _on_tag_change(self):
85 wx.CallAfter(self.__update_tags)
86 #----------------------------------------------
87 - def _on_name_identity_change(self):
88 wx.CallAfter(self.__update_age_label)
89 #----------------------------------------------
90 - def _on_post_patient_selection(self, **kwargs):
91 # needed because GUI stuff can't be called from a thread (and that's 92 # where we are coming from via backend listener -> dispatcher) 93 wx.CallAfter(self.__on_post_patient_selection, **kwargs)
94 #-------------------------------------------------------
95 - def _on_allergies_change(self, **kwargs):
96 wx.CallAfter(self.__update_allergies)
97 #-------------------------------------------------------
98 - def _on_focus_patient_search(self, **kwargs):
99 wx.CallAfter(self._TCTRL_patient_selector.SetFocus)
100 #------------------------------------------------------- 101 # internal API 102 #-------------------------------------------------------
103 - def __on_post_patient_selection(self, **kwargs):
104 self.__update_age_label() 105 self.__update_allergies() 106 self.__update_tags()
107 #-------------------------------------------------------
108 - def __update_tags(self):
109 self._PNL_tags.refresh(patient = self.curr_pat)
110 #-------------------------------------------------------
111 - def __update_age_label(self):
112 113 tt = _('Gender: %s (%s) - %s\n') % ( 114 self.curr_pat.gender_symbol, 115 self.curr_pat['gender'], 116 self.curr_pat.gender_string 117 ) 118 tt += _('Born: %s\n') % self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()) 119 120 if self.curr_pat['deceased'] is None: 121 122 if self.curr_pat.get_formatted_dob(format = '%m-%d') == pyDT.datetime.now(tz = gmDateTime.gmCurrentLocalTimezone).strftime('%m-%d'): 123 template = _('%s %s (%s today !)') 124 tt += _("\nToday is the patient's birtday !\n\n") 125 else: 126 template = u'%s %s (%s)' 127 128 tt += _('Age: %s\n') % self.curr_pat['medical_age'] 129 130 # FIXME: if the age is below, say, 2 hours we should fire 131 # a timer here that updates the age in increments of 1 minute ... :-) 132 age = template % ( 133 gmPerson.map_gender2symbol[self.curr_pat['gender']], 134 self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()), 135 self.curr_pat['medical_age'] 136 ) 137 138 # Easter Egg ;-) 139 if self.curr_pat['lastnames'] == u'Leibner': 140 if self.curr_pat['firstnames'] == u'Steffi': 141 if self.curr_pat['preferred'] == u'Wildfang': 142 age = u'%s %s' % (gmTools.u_black_heart, age) 143 144 else: 145 146 tt += _('Died: %s\n') % gmDateTime.pydt_strftime(self.curr_pat['deceased'], '%d.%b %Y') 147 tt += _('At age: %s\n') % self.curr_pat['medical_age'] 148 149 template = u'%s %s - %s (%s)' 150 age = template % ( 151 gmPerson.map_gender2symbol[self.curr_pat['gender']], 152 self.curr_pat.get_formatted_dob(format = '%d.%b %Y', encoding = gmI18N.get_encoding()), 153 gmDateTime.pydt_strftime(self.curr_pat['deceased'], '%Y %b %d'), 154 self.curr_pat['medical_age'] 155 ) 156 157 if self.curr_pat['dob_is_estimated']: 158 tt += _(' (date of birth and age are estimated)\n') 159 160 self._LBL_age.SetLabel(age) 161 self._LBL_age.SetToolTipString(tt)
162 #-------------------------------------------------------
163 - def __update_allergies(self, **kwargs):
164 165 show_red = True 166 167 emr = self.curr_pat.get_emr() 168 state = emr.allergy_state 169 170 # state in tooltip 171 if state['last_confirmed'] is None: 172 confirmed = _('never') 173 else: 174 confirmed = gmDateTime.pydt_strftime(state['last_confirmed'], '%Y %b %d') 175 tt = (state.state_string + (90 * u' '))[:90] + u'\n' 176 tt += _('last confirmed %s\n') % confirmed 177 tt += gmTools.coalesce(state['comment'], u'', _('Comment (%s): %%s') % state['modified_by']) 178 tt += u'\n' 179 180 # allergies 181 display = [] 182 for allergy in emr.get_allergies(): 183 # in field: "true" allergies only, not intolerances 184 if allergy['type'] == u'allergy': 185 display.append(allergy['descriptor'][:10].strip() + gmTools.u_ellipsis) 186 # in tooltip 187 if allergy['definite']: 188 certainty = _('definite') 189 else: 190 certainty = _('suspected') 191 reaction = gmTools.coalesce(allergy['reaction'], _('reaction not recorded')) 192 if len(reaction) > 50: 193 reaction = reaction[:50] + gmTools.u_ellipsis 194 tt += u'%s (%s, %s): %s\n' % ( 195 allergy['descriptor'], 196 allergy['l10n_type'], 197 certainty, 198 reaction 199 ) 200 201 if len(display) == 0: 202 display = state.state_symbol 203 if display == gmTools.u_diameter: 204 show_red = False 205 else: 206 display = ','.join(display) 207 208 if state['last_confirmed'] is not None: 209 display += gmDateTime.pydt_strftime(state['last_confirmed'], ' (%Y %b)') 210 211 if show_red: 212 self._LBL_allergies.SetForegroundColour('red') 213 self._TCTRL_allergies.SetForegroundColour('red') 214 else: 215 self._LBL_allergies.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)) 216 self._TCTRL_allergies.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)) 217 218 self._TCTRL_allergies.SetValue(display) 219 self._TCTRL_allergies.SetToolTipString(tt)
220 221 #=========================================================== 222 if __name__ == "__main__": 223 wx.InitAllImageHandlers() 224 app = wxPyWidgetTester(size = (400, 200)) 225 app.SetWidget(cMainTopPanel, -1) 226 app.SetWidget(cTopPanel, -1) 227 app.MainLoop() 228 #=========================================================== 229