Gnumed.wxpython.patient.gmGP_ScratchPadRecalls

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

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

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