Package Gnumed :: Package wxpython :: Package patient :: Module gmGP_ScratchPadRecalls |
[frames] | no frames]

# Source Code for Module Gnumed.wxpython.patient.gmGP_ScratchPadRecalls

      1  # GNUmed ...
      2  # licnese: GPL v2 or later
      3
      4  #===============================================================
      5  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/patient/gmGP_ScratchPadRecalls.py,v $
      6  # $Id: gmGP_ScratchPadRecalls.py,v 1.19 2008-04-13 14:39:49 ncq Exp $
      7  __version__ = "$Revision: 1.19 $"
      8
      9  try:
     10          import wxversion
     11          import wx
     12  except ImportError:
     13          from wxPython import wx
     14
     15  import gmPlugin, gmShadow, gmDispatcher, gmPG2
     16  from  gmPatientHolder import PatientHolder
     17  scratchpaddata = {}
     18  recalldata = {}
     19
     20  query_scratchpad = "select id, timestamp, text, author from scratchpad where id_identity=%s"
     21  query_recalls = "select id, timestamp, reason from recalls where id_identity=%s"
     22
     23  #===============================================================
     24 -class ScratchPadRecalls(wxPanel, PatientHolder):
     25 -        def __init__(self, parent,id=-1):
     26                  self.patientID=None
     27                  wxPanel.__init__(self,parent,id,wxDefaultPosition,wxDefaultSize,style = wxRAISED_BORDER)
     28                  PatientHolder.__init__(self)
     29                  self.parent=parent
     30                  self.create_widgets()
     31                  self.layout_widgets()
     32                  self.register_interests()
     33                  self._con = gmPG.ConnectionPool()
     34
     35
     36
     37 -        def create_widgets(self):
     38                  self.lbl_fgcolour = wxColor(0,0,131)
     39                  self.list_fgcolour = wxColor(255,0,0)
     40                  self.lbl_font = wxFont(12,wxSWISS,wxNORMAL, wxBOLD,False,'')
     41                  #add a label which is the heading for the text data entry 'Scratchpad'
     42                  self.scratchpad_lbl = wxStaticText(self,-1, _("Scratch Pad"),style = wxALIGN_CENTRE) #add static text control for the capion
     43                  self.scratchpad_lbl.SetForegroundColour(self.lbl_fgcolour)               #set caption text colour
     44                  self.scratchpad_lbl.SetFont(self.lbl_font)
     45                  #Add a text control under that
     46                  self.scratchpad_txt = wxTextCtrl(self,-1,"",wxDefaultPosition,wxDefaultSize,0)
     47                  #Add a label for the recalls/reviews list
     48                  self.recalls_lbl = wxStaticText(self,-1, _("Recalls/Reviews"),style = wxALIGN_CENTRE) #add static text control for the capion
     49                  self.recalls_lbl.SetForegroundColour(self.lbl_fgcolour)               #set caption text colour
     50                  self.recalls_lbl.SetFont(self.lbl_font)
     51
     52                  #------------------------------------------------------------------------------
     53                  #Add a simple listcontrol under that for scratchpad items
     54                  #------------------------------------------------------------------------------
     55                  self.list_scratchpad = wxListCtrl(self, -1,  wxDefaultPosition, wxDefaultSize,wxLC_REPORT|wxLC_NO_HEADER|wxSUNKEN_BORDER)
     56                  self.list_scratchpad.SetForegroundColour(self.list_fgcolour)
     57                  self.list_scratchpad.InsertColumn(0, _("Logged"))
     58                  self.list_scratchpad.InsertColumn(1, "", wxLIST_FORMAT_LEFT)
     59
     60                  #--------------------------------------------------------------------------
     61                  #Add a simple listcontrol under that for recall items
     62                  #--------------------------------------------------------------------------
     63                  self.list_recalls = wxListCtrl(self, -1,  wxDefaultPosition, wxDefaultSize,wxLC_REPORT|wxLC_NO_HEADER|wxSUNKEN_BORDER)
     64                  self.list_recalls.SetForegroundColour(self.list_fgcolour)
     65                  self.list_recalls.InsertColumn(0, _("Recall or Review"))
     66                  self.list_recalls.InsertColumn(1, _("Status"), wxLIST_FORMAT_LEFT)
     67
     68 -        def layout_widgets(self):
     69                  self.sizer= wxBoxSizer(wxVERTICAL)
     70                  self.sizer.Add(self.scratchpad_lbl,0,wxEXPAND)
     71                  self.sizer.Add(self.scratchpad_txt,0,wxEXPAND)
     72                  #sizer.Add(10,10,0,wxEXPAND)
     73                  self.sizer.Add(self.list_scratchpad,30,wxEXPAND)
     74                  self.sizer.Add(self.recalls_lbl,0, wxEXPAND)
     75                  #sizer.Add(5,5,0,wxEXPAND)
     76                  self.sizer.Add(self.list_recalls,70,wxEXPAND)
     77                  self.SetSizer(self.sizer)  #set the sizer
     78                  self.sizer.Fit(self)             #set to minimum size as calculated by sizer
     79                  self.SetAutoLayout(True)                 #tell frame to use the sizer
     80                  self.Show(True)
     81
     82 -        def register_interests(self):
     83                  #gmDispatcher.connect(self.OnPatientID, gmSignals.post_patient_selection())
     84                  pass
     85
     86 -        def UpdateRecalls(self, patid):
     87                  self.list_scratchpad.DeleteAllItems()
     88                  if patid is None:
     89                          return
     90                  db = self._con.GetConnection('clinical')
     91                  cur = db.cursor()
     92                  cur.execute(query_recalls % str(patid))
     93                  fetched = cur.fetchall()
     94                  for index in range(len(fetched)):
     95                          row=fetched[index]
     96                          id=row[0]
     97                          #date=row[1].strftime("%d.%m.%y")
     98                          date=str(row[1])[:10]
     99                          text=row[2]
    100                          self.list_recalls.InsertStringItem(index, date )
    101                          self.list_recalls.SetStringItem(index, 1, text)
    102                          self.list_recalls.SetItemData(index, id)
    103                  self.list_recalls.SetColumnWidth(0, wxLIST_AUTOSIZE)
    104                  self.list_recalls.SetColumnWidth(1, 200)
    105
    106
    107 -        def UpdateScratchpad(self, patid):
    108                  self.list_scratchpad.DeleteAllItems()
    109                  self.scratchpad_txt.SetValue("")
    110                  if patid is None:
    111                          return
    112                  db = self._con.GetConnection('clinical')
    113                  cur = db.cursor()
    114                  cur.execute(query_scratchpad % str(patid))
    115                  fetched = cur.fetchall()
    116                  for index in range(len(fetched)):
    117                          row=fetched[index]
    118                          id=row[0]
    119                          #date=row[1].strftime("%d.%m.%y")
    120                          date=str(row[1])[:10]
    121                          reason=row[2]
    122                          self.list_scratchpad.InsertStringItem(index, date)
    123                          self.list_scratchpad.SetStringItem(index, 1, reason)
    124                          self.list_scratchpad.SetItemData(index, id)
    125                  self.list_scratchpad.SetColumnWidth(0, wxLIST_AUTOSIZE)
    126                  self.list_scratchpad.SetColumnWidth(1, 200)
    127
    128
    129 -        def OnPatientID(self, **kwargs):
    130                  "must be executed when the current patient changes. Updates all widgets accordingly"
    131                  if kwargs is None:
    132                          #new patient, blank widgets
    133                          self.UpdateRecalls(None)
    134                          self.UpdateSCratchpad(None)
    135                          return
    136
    137                  kwds = kwargs['kwds']
    138                  patid = kwds['ID']
    139                  self.UpdateRecalls(patid)
    140                  self.UpdateScratchpad(patid)
    141
    142  #===============================================================
    143 -class gmGP_ScratchPadRecalls (gmPlugin.wxBasePlugin):
    144      """
    145      Plugin to encapsulate the scratch pad and recalls
    146      """
    147 -    def name (self):
    148          return 'ScratchPadRecallsPlugin'
    149
    150 -    def register (self):
    151          mwm = self.gb['clinical.manager']
    152          mwm.RegisterRightSide ('scratchpad_recalls', ScratchPadRecalls
    153                                     (mwm.righthalfpanel, -1), position=2)
    154
    155 -    def unregister (self):
    156          self.gb['clinical.manager'].Unregister ('scratchpad_recalls')
    157
    158  #===============================================================
    159  # Main
    160  #===============================================================
    161  if __name__ == "__main__":
    162          app = wxPyWidgetTester(size = (400, 500))
    163          app.SetWidget(ScratchPadRecalls, -1)
    164          app.MainLoop()
    165  #===============================================================
    166  # $Log: gmGP_ScratchPadRecalls.py,v $
    167  # Revision 1.19  2008-04-13 14:39:49  ncq
    168  # - no more old style logging
    169  #
    170  # Revision 1.18  2008/01/30 14:03:42  ncq
    171  # - use signal names directly
    172  # - switch to std lib logging
    173  #
    174  # Revision 1.17  2006/05/15 13:42:02  ncq
    175  # - use new signals for activating_patient/patient_selected
    176  #
    177  # Revision 1.16  2005/09/26 18:01:53  ncq
    178  # - use proper way to import wx26 vs wx2.4
    179  # - note: THIS WILL BREAK RUNNING THE CLIENT IN SOME PLACES
    180  # - time for fixup
    181  #
    182  # Revision 1.15  2004/07/18 20:30:54  ncq
    183  # - wxPython.true/false -> Python.True/False as Python tells us to do
    184  #
    185  # Revision 1.14  2003/11/17 10:56:42  sjtan
    186  #
    187  # synced and commiting.
    188  #
    189  # Revision 1.2  2003/10/25 08:29:40  sjtan
    190  #
    191  # uses gmDispatcher to send new currentPatient objects to toplevel gmGP_ widgets. Proprosal to use
    192  # yaml serializer to store editarea data in  narrative text field of clin_root_item until
    193  # clin_root_item schema stabilizes.
    194  #
    195  # Revision 1.1  2003/10/23 06:02:40  sjtan
    196  #
    197  # manual edit areas modelled after r.terry's specs.
    198  #
    199  # Revision 1.13  2003/04/05 00:39:23  ncq
    200  # - "patient" is now "clinical", changed all the references
    201  #
    202  # Revision 1.12  2003/02/02 13:37:27  ncq
    203  # - typo
    204  #
    205  # Revision 1.11  2003/02/02 13:36:52  ncq
    206  # - cvs metadata keywords
    207  #
    208