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, os.path, datetime as pyDT, logging
      9
     10
     11  import wx
     12
     13
     14  from Gnumed.pycommon import gmGuiBroker, gmDispatcher, gmTools, gmCfg2, gmDateTime, gmI18N
     15  from Gnumed.business import gmPerson, gmEMRStructItems, gmAllergy
     16  from Gnumed.wxpython import gmGuiHelpers
     17  from Gnumed.wxpython import gmDemographicsWidgets
     18  from Gnumed.wxpython import gmAllergyWidgets
     19  from Gnumed.wxpython import gmPatSearchWidgets
     20  from Gnumed.wxpython import gmEMRStructWidgets
     21  from Gnumed.wxpython import gmPatPicWidgets
     22
     23
     24  _log = logging.getLogger('gm.ui')
     25
     26  #===========================================================
     27  from Gnumed.wxGladeWidgets import wxgTopPnl
     28
     29 -class cTopPnl(wxgTopPnl.wxgTopPnl):
     30
     31 -        def __init__(self, *args, **kwargs):
     32
     33                  wxgTopPnl.wxgTopPnl.__init__(self, *args, **kwargs)
     34
     35                  self.__gb = gmGuiBroker.GuiBroker()
     36
     37                  self.curr_pat = gmPerson.gmCurrentPatient()
     38
     39                  self.__init_ui()
     40                  self.__register_interests()
     41          #-------------------------------------------------------
     42 -        def __init_ui(self):
     43                  cfg = gmCfg2.gmCfgData()
     44                  if cfg.get(option = 'slave'):
     45                          self._TCTRL_patient_selector.SetEditable(0)
     46                          self._TCTRL_patient_selector.SetToolTip(None)
     47          #-------------------------------------------------------
     48 -        def __register_interests(self):
     49                  # events
     50                  wx.EVT_LEFT_DCLICK(self._TCTRL_allergies, self._on_allergies_dclicked)
     51
     52                  # client internal signals
     53                  gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._on_post_patient_selection)
     54                  gmDispatcher.connect(signal = u'allg_mod_db', receiver = self._on_allergies_change)
     55                  gmDispatcher.connect(signal = u'allg_state_mod_db', receiver = self._on_allergies_change)
     56                  gmDispatcher.connect(signal = u'name_mod_db', receiver = self._on_name_identity_change)
     57                  gmDispatcher.connect(signal = u'identity_mod_db', receiver = self._on_name_identity_change)
     58                  gmDispatcher.connect(signal = u'identity_tag_mod_db', receiver = self._on_tag_change)
     59          #----------------------------------------------
     60          # event handling
     61          #----------------------------------------------
     62 -        def _on_allergies_dclicked(self, evt):
     63                  if not self.curr_pat.connected:
     64                          gmDispatcher.send('statustext', msg = _('Cannot activate Allergy Manager. No active patient.'))
     65                          return
     66                  dlg = gmAllergyWidgets.cAllergyManagerDlg(parent=self, id=-1)
     67                  dlg.ShowModal()
     68                  return
     69          #----------------------------------------------
     70 -        def _on_tag_change(self):
     71                  wx.CallAfter(self.__update_tags)
     72          #----------------------------------------------
     73 -        def _on_name_identity_change(self):
     74                  wx.CallAfter(self.__update_age_label)
     75          #----------------------------------------------
     76 -        def _on_post_patient_selection(self, **kwargs):
     77                  # needed because GUI stuff can't be called from a thread (and that's
     78                  # where we are coming from via backend listener -> dispatcher)
     79                  wx.CallAfter(self.__on_post_patient_selection, **kwargs)
     80          #-------------------------------------------------------
     81 -        def _on_allergies_change(self, **kwargs):
     82                  wx.CallAfter(self.__update_allergies)
     83          #-------------------------------------------------------
     84          # internal API
     85          #-------------------------------------------------------
     86 -        def __on_post_patient_selection(self, **kwargs):
     87                  self.__update_age_label()
     88                  self.__update_allergies()
     89                  self.__update_tags()
     90          #-------------------------------------------------------
     91 -        def __update_tags(self):
     92                  self._PNL_tags.refresh(patient = self.curr_pat)
     93          #-------------------------------------------------------
     94 -        def __update_age_label(self):
     95
     96                  if self.curr_pat['deceased'] is None:
     97
     98                          if self.curr_pat.get_formatted_dob(format = '%m-%d') == pyDT.datetime.now(tz = gmDateTime.gmCurrentLocalTimezone).strftime('%m-%d'):
     99                                  template = _('%s  %s (%s today !)')
    100                          else:
    101                                  template = u'%s  %s (%s)'
    102
    103                          # FIXME: if the age is below, say, 2 hours we should fire
    104                          # a timer here that updates the age in increments of 1 minute ... :-)
    105                          age = template % (
    106                                  gmPerson.map_gender2symbol[self.curr_pat['gender']],
    107                                  self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()),
    108                                  self.curr_pat['medical_age']
    109                          )
    110
    111                          # Easter Egg ;-)
    112                          if self.curr_pat['lastnames'] == u'Leibner':
    113                                  if self.curr_pat['firstnames'] == u'Steffi':
    114                                          if self.curr_pat['preferred'] == u'Wildfang':
    115                                                  age = u'%s %s' % (gmTools.u_black_heart, age)
    116
    117                  else:
    118
    119                          template = u'%s  %s - %s (%s)'
    120                          age = template % (
    121                                  gmPerson.map_gender2symbol[self.curr_pat['gender']],
    122                                  self.curr_pat.get_formatted_dob(format = '%d.%b %Y', encoding = gmI18N.get_encoding()),
    123                                  self.curr_pat['deceased'].strftime('%d.%b %Y').decode(gmI18N.get_encoding()),
    124                                  self.curr_pat['medical_age']
    125                          )
    126
    127                  self._LBL_age.SetLabel(age)
    128          #-------------------------------------------------------
    129 -        def __update_allergies(self, **kwargs):
    130
    131                  emr = self.curr_pat.get_emr()
    132                  state = emr.allergy_state
    133
    134                  # state in tooltip
    135                  if state['last_confirmed'] is None:
    136                          confirmed = _('never')
    137                  else:
    138                          confirmed = state['last_confirmed'].strftime('%Y %B %d').decode(gmI18N.get_encoding())
    139                  tt = (state.state_string + (90 * u' '))[:90] + u'\n'
    140                  tt += _('last confirmed %s\n') % confirmed
    141                  tt += gmTools.coalesce(state['comment'], u'', _('Comment (%s): %%s') % state['modified_by'])
    142                  tt += u'\n'
    143
    144                  # allergies
    145                  tmp = []
    146                  for allergy in emr.get_allergies():
    147                          # in field: "true" allergies only, not intolerances
    148                          if allergy['type'] == 'allergy':
    149                                  tmp.append(allergy['descriptor'][:10].strip() + gmTools.u_ellipsis)
    150                          # in tooltip
    151                          if allergy['definite']:
    152                                  certainty = _('definite')
    153                          else:
    154                                  certainty = _('suspected')
    155                          reaction = gmTools.coalesce(allergy['reaction'], _('reaction not recorded'))
    156                          if len(reaction) > 50:
    157                                  reaction = reaction[:50] + gmTools.u_ellipsis
    158                          tt += u'%s (%s, %s): %s\n' % (
    159                                  allergy['descriptor'],
    160                                  allergy['l10n_type'],
    161                                  certainty,
    162                                  reaction
    163                          )
    164
    165                  if len(tmp) == 0:
    166                          tmp = state.state_symbol
    167                  else:
    168                          tmp = ','.join(tmp)
    169
    170                  if state['last_confirmed'] is not None:
    171                          tmp += state['last_confirmed'].strftime(' (%x)')
    172
    173                  self._TCTRL_allergies.SetValue(tmp)
    174                  self._TCTRL_allergies.SetToolTipString(tt)
    175
    176  #===========================================================
    177  if __name__ == "__main__":
    178          wx.InitAllImageHandlers()
    179          app = wxPyWidgetTester(size = (400, 200))
    180          app.SetWidget(cMainTopPanel, -1)
    181          app.SetWidget(cTopPanel, -1)
    182          app.MainLoop()
    183  #===========================================================
    184