Package Gnumed :: Package wxpython :: Package gui :: Module gmDrugDisplay
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gui.gmDrugDisplay

  1  # -*- coding: utf-8 -*- 
  2  ############################################################################# 
  3  # 
  4  # gmDrugDisplay_RT  Feedback: anything which is incorrect or ambiguous please 
  5  #                   mailto rterry@gnumed.net 
  6  # --------------------------------------------------------------------------- 
  7  # 
  8  # @author: Dr. Richard Terry 
  9  # @author: Dr. Herb Horst 
 10  # @author: Hilmar Berger 
 11  # @acknowledgments: Gui screen Design taken with permission from 
 12  #                   DrsDesk MimsAnnual @ DrsDesk Software 1995-2002 
 13  #                   and @ Dr.R Terry 
 14  #                   Basic skeleton of this code written by Dr. H Horst 
 15  #                   heavily commented for learning purposes by Dr. R Terry 
 16  # @copyright: authors 
 17  # @license: GPL v2 or later (details at http://www.gnu.org) 
 18  # 
 19  # @TODO: 
 20  #        decision of text display wigit 
 21  #        why won't opening frame size be recognised 
 22  #        put in testing for null field in Display_PI 
 23  #        so as not to display a null field heading 
 24  #        Need config file with: 
 25  #        HTML font options for heading, subheading, subsubheading etc 
 26  ############################################################################ 
 27  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/gui/gmDrugDisplay.py,v $ 
 28  __version__ = "$Revision: 1.34 $" 
 29  __author__ = "H.Herb, R.Terry, H.Berger" 
 30   
 31  import string 
 32   
 33   
 34  import wx 
 35   
 36   
 37  _log = logging.getLogger('gm.ui') 
 38  if __name__ == "__main__": 
 39          # FIXME: standalone means diagnostics for now, 
 40          # later on, when AmisBrowser is one foot in the door 
 41          # to German doctors we'll change this again 
 42          _log.SetAllLogLevels(gmLog.lData) 
 43          _ = lambda x:x  # fool epydoc 
 44          from Gnumed.pycommon import gmI18N 
 45   
 46   
 47  from Gnumed.pycommon import gmDrugView, gmCfg, gmExceptions 
 48  from Gnumed.wxpython import gmGuiHelpers 
 49  from Gnumed.business import gmPraxis 
 50   
 51  _cfg = gmCfg.gmDefCfgFile 
 52  #============================================================ 
 53  # These constants are used when referring to menu items below 
 54  #============================================================ 
 55  ID_ABOUT = wx.NewId() 
 56  ID_CONTENTS = wx.NewId() 
 57  ID_EXIT  =  wx.NewId() 
 58  ID_OPEN= wx.NewId() 
 59  ID_HELP =  wx.NewId() 
 60  ID_TEXTCTRL =  wx.NewId() 
 61  ID_TEXT = wx.NewId() 
 62  ID_COMBO_PRODUCT = wx.NewId() 
 63  ID_RADIOBUTTON_BYANY = wx.NewId() 
 64  ID_RADIOBUTTON_BYPRODUCT = wx.NewId() 
 65  ID_RADIOBUTTON_BYGENERIC = wx.NewId() 
 66  ID_RADIOBUTTON_BYINDICATION = wx.NewId() 
 67  ID_LISTBOX_JUMPTO = wx.NewId() 
 68  ID_LISTCTRL_DRUGCHOICE = wx.NewId() 
 69  ID_BUTTON_PRESCRIBE = wx.NewId() 
 70  ID_BUTTON_DISPLAY = wx.NewId() 
 71  ID_BUTTON_PRINT = wx.NewId() 
 72  ID_BUTTON_BOOKMARK = wx.NewId() 
 73   
 74  MODE_PRODUCT = 0 
 75  MODE_GENERIC = 1 
 76  MODE_INDICATION = 2 
 77  MODE_ANY = 3    # search for product name and generic name 
 78   
 79  #============================================================ 
80 -class DrugDisplay(wx.Panel):
81 """displays drug information in a convenience widget""" 82 83 NoDrugFoundMessageHTML = "<HTML><HEAD></HEAD><BODY BGCOLOR='#FFFFFF8'> <FONT SIZE=3>" + _("No matching drug found.") + "</FONT></BODY></HTML>" 84 WelcomeMessageHTML = "<HTML><HEAD></HEAD><BODY BGCOLOR='#FFFFFF8'> <FONT SIZE=3>" + _("Please enter at least three digits of the drug name.") + "</FONT></BODY></HTML>" 85
86 - def __init__(self, parent, id, pos = wxDefaultPosition, 87 size = wxDefaultSize, style = wx.TAB_TRAVERSAL):
88 89 wx.Panel.__init__(self, parent, id, pos, size, style) 90 91 # if we are not inside gnumed we won't get a definite answer on 92 # who and where we are. in this case try to get config source 93 # from main config file (see gmCfg on how the name of this file 94 # is determined 95 # this is necessary to enable stand alone use of the drug browser 96 currworkplace = gmPraxis.gmCurrentPraxisBranch().active_workplace 97 if currworkplace is None: 98 # assume we are outside gnumed 99 self.dbName = _cfg.get('DrugReferenceBrowser', 'drugDBname') 100 else: 101 self.dbName, match = gmCfg.getDBParam( 102 currworkplace, 103 option="DrugReferenceBrowser.drugDBName" 104 ) 105 106 if self.dbName is None: 107 if __name__ == '__main__': 108 title = _('Starting drug data browser') 109 msg = _('Cannot start the drug data browser.\n\n' 110 'There is no drug database specified in the configuration.') 111 gmGuiHelpers.gm_show_error(msg, title) 112 _log.Log(gmLog.lErr, "No drug database specified. Aborting drug browser.") 113 # FIXME: we shouldn't directly call Close() on the parent 114 # parent.Close() 115 raise gmExceptions.ConstructorError, "No drug database specified" 116 117 # initialize interface to drug database. 118 # this will fail if backend or config files are not available 119 try: 120 self.mDrugView=gmDrugView.DrugView(self.dbName) 121 except: 122 _log.LogException("Unhandled exception during DrugView API init.", sys.exc_info(), verbose = 0) 123 raise gmExceptions.ConstructorError, "Couldn't initialize DrugView API" 124 # return None 125 126 self.mode = MODE_PRODUCT 127 self.previousMode = MODE_PRODUCT 128 self.printer = wx.HtmlEasyPrinting() #printer object to print html page 129 self.mId = None 130 self.drugProductInfo = None 131 self.__mListCtrlItems = {} # array holding data on every row in the list 132 133 #------------------------------------------------------------- 134 # These things build the physical window that you see when 135 # the program boots. They each refer to a subroutine that 136 # is listed below by the same name eg def Menus_Create(self) 137 #------------------------------------------------------------- 138 self.GuiElements_Init() # add main gui elements 139 self.inDisplay_PI = 0 # first we display a drug list, not product info 140 self.GetDrugIssue() # ? 141 142 #-------------------------------------------------------------- 143 # handler declarations for DrugDisplay 144 # note handlers for menu in Menus_Create() 145 #-------------------------------------------------------------- 146 wx.EVT_BUTTON(self, ID_BUTTON_PRINT, self.OnPrint) 147 wx.EVT_BUTTON(self, ID_BUTTON_DISPLAY, self.OnDisplay) 148 wx.EVT_BUTTON(self, ID_BUTTON_PRESCRIBE, self.OnPrescribe) 149 wx.EVT_LISTBOX_DCLICK(self, ID_LISTBOX_JUMPTO, self.OnJumpToDblClick) 150 wx.EVT_LISTBOX(self, ID_LISTBOX_JUMPTO, self.OnJumpToSelected) 151 wx.EVT_LIST_ITEM_ACTIVATED(self, ID_LISTCTRL_DRUGCHOICE, self.OnDrugChoiceDblClick) 152 wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYINDICATION, self.OnSearchByIndication) 153 wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYGENERIC, self.OnSearchByGeneric) 154 wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYPRODUCT, self.OnSearchByProduct) 155 wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYANY, self.OnSearchByAny) 156 wx.EVT_TEXT(self, ID_COMBO_PRODUCT, self.OnProductKeyPressed) 157 wx.EVT_COMBOBOX(self, ID_COMBO_PRODUCT, self.OnProductSelected) 158 wx.EVT_BUTTON(self, wxID_OK, self.OnOk) 159 wx.EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) 160 wx.EVT_BUTTON(self,ID_BUTTON_BOOKMARK, self.OnBookmark)
161 #----------------------------------------------------------------------------------------------------------------------- 162
163 - def GuiElements_Init(self):
164 #-------------------------------------------------- 165 # create the controls for left hand side of screen 166 # 1)create the label 'Find' and the combo box the 167 # user will type the name of drug into 168 #-------------------------------------------------- 169 finddrug = wxStaticText( self, -1, _(" Find "), wxDefaultPosition, wxDefaultSize, 0 ) 170 finddrug.SetFont( wxFont( 14, wxSWISS, wx.NORMAL, wx.NORMAL ) ) 171 172 self.comboProduct = wxComboBox( 173 self, 174 ID_COMBO_PRODUCT, 175 "", 176 wxDefaultPosition, 177 wxSize(130,-1), 178 [] , 179 wxCB_DROPDOWN 180 ) 181 self.comboProduct.SetToolTip( wx.ToolTip(_("Enter the name of the drug you are interested in")) ) 182 self.btnBookmark = wx.Button( 183 self, 184 ID_BUTTON_BOOKMARK, 185 _("&Bookmark"), 186 wxDefaultPosition, 187 wxDefaultSize, 188 0 189 ) 190 #----------------------------------------------------------- 191 # create a sizer at topleft of screen to hold these controls 192 # and add them to it 193 #----------------------------------------------------------- 194 self.sizertopleft = wx.BoxSizer(wx.HORIZONTAL) 195 self.sizertopleft.Add( finddrug, 0, wxALIGN_CENTER_VERTICAL, 5 ) 196 self.sizertopleft.Add( self.comboProduct, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ) 197 self.sizertopleft.Add( self.btnBookmark, 0, wxALIGN_CENTER_VERTICAL, 5 ) 198 #--------------------------------------------------------------- 199 # next create the left sizer which will hold the drug list box 200 # and the html viewer 201 #--------------------------------------------------------------- 202 self.sizer_left = wx.BoxSizer( wx.VERTICAL ) 203 self.sizer_left.AddSpacer( 30, 10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 204 self.sizer_left.AddSizer( self.sizertopleft, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5) 205 self.sizer_left.AddSpacer( 1, 1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 206 self.listctrl_drugchoice=None 207 self.html_viewer=None 208 self.whichWidget = "listctrl_drugchoice" 209 self.ToggleWidget() 210 self.html_viewer.SetPage(self.WelcomeMessageHTML) 211 212 #------------------------------------------------------------------------ 213 # the search by option buttons sit on a wxStaticBoxSizer with wx.Vertical 214 # 1) create a wxStaticBox = bordered box with title search by 215 # 2) add this to the sizerSearchBy sizer 216 # 3) Add four radio buttons to this sizer 217 #------------------------------------------------------------------------ 218 sboxSearchBy = wxStaticBox( self, -1, _("Search by") ) 219 self.sizerSearchBy = wxStaticBoxSizer( sboxSearchBy, wx.VERTICAL ) 220 sboxSearchBy.SetFont( wxFont( 10, wxSWISS, wx.NORMAL, wx.NORMAL ) ) 221 222 self.rbtnSearchAny = wxRadioButton( self, ID_RADIOBUTTON_BYANY, _("Any"), wxDefaultPosition, wxDefaultSize, 0 ) 223 self.sizerSearchBy.Add( self.rbtnSearchAny, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 1 ) 224 self.rbtnSearchProduct = wxRadioButton( self, ID_RADIOBUTTON_BYPRODUCT, _("Product name"), wxDefaultPosition, wxDefaultSize, 0 ) 225 self.sizerSearchBy.Add( self.rbtnSearchProduct, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wx.TOP, 1 ) 226 self.rbtnSearchGeneric = wxRadioButton( self, ID_RADIOBUTTON_BYGENERIC, _("Generic name"), wxDefaultPosition, wxDefaultSize, 0 ) 227 self.sizerSearchBy.Add( self.rbtnSearchGeneric, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 1 ) 228 self.rbtnSearchIndication = wxRadioButton( self, ID_RADIOBUTTON_BYINDICATION, _("Indication"), wxDefaultPosition, wxDefaultSize, 0 ) 229 self.sizerSearchBy.Add( self.rbtnSearchIndication, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 1 ) 230 #------------------------------------------------------------------------- 231 # and the right hand side vertical side bar sizer 232 # 1) add a space at top to make the static text box even with the top 233 # of the main drug data display box 234 # 2) add the searchby static box with the radio buttons which is stuck on 235 # to its own sizer 236 # 3) add a spacer below this and above the list box underneath 237 #------------------------------------------------------------------------- 238 self.sizerVInteractionSidebar = wx.BoxSizer( wx.VERTICAL ) 239 self.sizerVInteractionSidebar.AddSpacer( 30, 10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 12 ) 240 self.sizerVInteractionSidebar.AddSizer( self.sizerSearchBy, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ) 241 self.sizerVInteractionSidebar.AddSpacer( 30, 10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 242 #-------------------------------------------------------------------------- 243 # 4) create a listbox that will be populated with labels to jump to within the 244 # product info text and add to the vertical side bar 245 #-------------------------------------------------------------------------- 246 self.listbox_jumpto = wx.ListBox( self, ID_LISTBOX_JUMPTO, wxDefaultPosition, wxSize(150,100), 247 [] , wx.LB_SINGLE ) 248 self.sizerVInteractionSidebar.Add( self.listbox_jumpto, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 10 ) 249 #-------------------------------------------------------------------------- 250 # 5) Add another spacer underneath this listbox 251 #-------------------------------------------------------------------------- 252 self.sizerVInteractionSidebar.AddSpacer( 20, 10, 0, wxALIGN_CENTRE|wxALL, 1 ) 253 self.btnPrescribe = wx.Button( self, ID_BUTTON_PRESCRIBE, _("&Prescribe"), wxDefaultPosition, wxDefaultSize, 0 ) 254 self.sizerVInteractionSidebar.Add( self.btnPrescribe, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 255 self.btnDisplay = wx.Button( self, ID_BUTTON_DISPLAY, _("&Display"), wxDefaultPosition, wxDefaultSize, 0 ) 256 self.sizerVInteractionSidebar.Add( self.btnDisplay, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 257 self.btnPrint = wx.Button( self, ID_BUTTON_PRINT, _("&Print"), wxDefaultPosition, wxDefaultSize, 0 ) 258 self.sizerVInteractionSidebar.Add( self.btnPrint, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 1 ) 259 #----------------------------------------------- 260 # finally create the main sizer to hold the rest 261 # and all the sizers to the main sizer 262 #--------------------------------------------- 263 self.sizermain = wx.BoxSizer(wx.HORIZONTAL) 264 self.sizermain.AddSizer(self.sizer_left, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 7) 265 self.sizermain.AddSizer(self.sizerVInteractionSidebar, 0, wxGROW|wxALIGN_LEFT|wxALL, 8) 266 self.SetAutoLayout( True ) 267 self.SetSizer( self.sizermain ) 268 self.sizermain.Fit( self ) 269 self.sizermain.SetSizeHints( self )
270 271 #---------------------------------------------------------------------------------------------------------------------- 272 #-------------------------------- 273 # methods for DrugDisplay 274 #-------------------------------- 275
276 - def OnDrugChoiceDblClick(self,event):
277 """ 278 handle double clicks in list of drugs / substances. 279 """ 280 # get row of selected event 281 item = event.GetData() 282 # get drug id and query mode 283 mode, code = self.__mListCtrlItems[item] 284 # gmLog.gmDefLog.Log (gmLog.lData, "mode %s ,text code: %s" % (mode,code) ) 285 # show detailed info 286 if mode == MODE_PRODUCT: 287 self.ToggleWidget () 288 self.Display_PI (code) 289 elif mode == MODE_GENERIC: 290 self.Display_Generic (code) 291 elif mode == MODE_INDICATION: 292 pass 293 return
294 295 #----------------------------------------------------------------------------------------------------------------------
296 - def GetDrugIssue(self):
297 # diplay some info on what database we are currently using 298 self.SetTitle(self.dbName) 299 # gmLog.gmDefLog.Log (gmLog.lData, "got the issue date") 300 return True
301 302 303 #----------------------------------------------------------------------------------------------------------------------
304 - def OnBookmark(self,event):
305 pass
306 307 #-----------------------------------------------------------------------------------------------------------------------------
308 - def ToggleWidget(self):
309 """ 310 Swaps listctrl to HTML viewer widget and vice versa. 311 """ 312 if self.whichWidget == "listctrl_drugchoice": 313 if self.html_viewer is not None: 314 return 315 if self.listctrl_drugchoice is not None: 316 self.sizer_left.Remove(self.listctrl_drugchoice) 317 self.listctrl_drugchoice = None 318 self.html_viewer = wx.HtmlWindow(self, -1, size=(400, 200)) 319 self.sizer_left.Add( self.html_viewer, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL, 5 ) 320 self.sizer_left.Layout() 321 self.whichWidget="html_viewer" 322 else: 323 if self.listctrl_drugchoice is not None: 324 return 325 if self.html_viewer is not None: 326 self.sizer_left.Remove(self.html_viewer) 327 self.html_viewer = None 328 self.listctrl_drugchoice = wx.ListCtrl(self, ID_LISTCTRL_DRUGCHOICE, wxDefaultPosition, wxSize(400,200), style=wx.LC_SINGLE_SEL | wx.LC_REPORT ) 329 self.sizer_left.Add( self.listctrl_drugchoice, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL, 5 ) 330 self.sizer_left.Layout() 331 self.whichWidget="listctrl_drugchoice"
332 333 #-----------------------------------------------------------------------------------------------------------------------------
334 - def Drug_Find(self):
335 #-------------------------------------------------------- 336 # using text in listctrl_drugchoice to find any similar drugs 337 #-------------------------------------------------------- 338 self.mId = None 339 drugtofind = string.lower(self.comboProduct.GetValue()) 340 # if we entered *, show all entries found in index (that might take time) 341 searchmode = 'exact' 342 if drugtofind == '***': 343 searchmode = 'complete' 344 345 # tell the DrugView abstraction layer to do an index search 346 # on product/generic/indication 347 # expect a dictionary containing at least name & ID 348 # qtype will be set by radiobuttons 349 # qtype and ID form (virtually) a unique ID that can be used to access other data in the db 350 351 qtype = self.mode 352 result = self.mDrugView.SearchIndex(self.mode,drugtofind,searchmode) 353 354 # no drug found for this name 355 if result is None or len(result['id']) < 1: 356 # tell everybody that we didn't find a match 357 self.mId = None 358 self.drugProductInfo = None 359 # display message 360 if self.whichWidget == 'listctrl_drugchoice': 361 self.ToggleWidget () 362 self.html_viewer.SetPage(self.NoDrugFoundMessageHTML) 363 return 364 365 numOfRows = len(result['id']) 366 # found exactly one drug 367 if numOfRows == 1: 368 seld.mId = result['id'] 369 # if we found a drug *product*, show the product info 370 if qtype == MODE_PRODUCT: 371 if self.whichWidget == 'listctrl_drugchoice': 372 self.ToggleWidget () 373 self.Display_PI (self.mId) 374 elif self.mId != self.mLastId: # don't change unless different drug 375 self.Display_PI (self.mId) 376 self.mLastId = self.mId 377 # if we found a generic substance name, show all products 378 # containing this generic 379 elif qtype == MODE_GENERIC: 380 self.Display_Generic (self.mId) 381 # if we are browsing indications, show all generics + products 382 # that match. Display Indication 383 elif qtype == MODE_INDICATION: 384 self.Display_Indication(self.mId) 385 386 # we have more than one result 387 # -> display a list of all matching names 388 else: 389 if self.whichWidget == 'html_viewer': 390 self.ToggleWidget () 391 # show list 392 self.BuildListCtrl(result,qtype)
393 394 #---------------------------------------------------------------------------------------------------------------------------
395 - def Display_Generic (self, aId):
396 """ 397 Find all drug products that contain a certain generic substance and 398 display them 399 """ 400 productsList=self.mDrugView.getProductsForGeneric(aId) 401 402 if type(productsList['name']) == type([]): 403 res_num=len (productsList['name']) 404 else: 405 res_num = 1 406 407 qtype = MODE_PRODUCT 408 # no product - should be an error, but AMIS allows that :( 409 if productsList is None or res_num == 0: 410 gmLog.gmDefLog.Log (gmLog.lWarn, "No drug product available containing generic ID: %s" % str(aId) ) 411 if self.whichWidget == 'listctrl_drugchoice': 412 self.ToggleWidget () 413 self.html_viewer.SetPage(self.NoDrugFoundMessageHTML) 414 return None 415 # one product, so display product information 416 if res_num == 1: 417 if self.whichWidget == 'listctrl_drugchoice': 418 self.ToggleWidget () 419 self.Display_PI (productsList['id']) 420 else: 421 # multiple products, display list 422 if self.whichWidget == 'html_viewer': 423 self.ToggleWidget () 424 # show list 425 self.BuildListCtrl(productsList,qtype) 426 427 return True
428 429 #-----------------------------------------------------------------
430 - def BuildListCtrl(self, aDataDict=None, dtype=None):
431 """ 432 Sets all the ListCtrl widget to display the items found in 433 a database search. 434 The DataDict must at least have the keys 'id' and 'name', all 435 additional columns will be displayed in alphabetical order. 436 Column names will be derived from key names. 437 """ 438 # clear old data 439 self.listctrl_drugchoice.ClearAll () 440 self.__mListCtrlItems = {} 441 442 if aDataDict is None or not ('id' in aDataDict & 'name' in aDataDict): 443 _log.Log(gmLog.lWarn, "No data to build list control.") 444 return None 445 #print "1:", aDataDict['id'] 446 # get column names from aDataDict key names 447 # remove 'id' and display name at leftmost position 448 columns = aDataDict.keys() 449 columns.remove('id') 450 columns.remove('name') 451 columns.insert(0,'name') 452 453 # number of rows (products, drugs, substances etc.) found 454 numOfRows = len(aDataDict['id']) 455 456 # set column names 457 # add columns for each parameter fetched 458 col_no = 0 459 for col in columns: 460 self.listctrl_drugchoice.InsertColumn(col_no, col) 461 col_no += 1 462 # hide ListCtrl for performance reasons 463 self.listctrl_drugchoice.Hide() 464 # loop through all products (rows) 465 for row in range(0,numOfRows): 466 col_no = 0 467 # for each product, display all parameters available 468 # code taken from gmSQLListCtrl.py 469 for col in columns: 470 # item text 471 item_text = str(aDataDict[col][row]) 472 473 # if first column, insert new column and 474 # and store pointer to item data (type,id) 475 if col_no == 0: 476 item=self.listctrl_drugchoice.InsertItem (row,item_text) 477 self.listctrl_drugchoice.SetItemData(item,item) 478 id = aDataDict['id'][row] 479 # set data as type and database ID 480 self.__mListCtrlItems[item]=(dtype,id) 481 else: 482 self.listctrl_drugchoice.SetItem(row,col_no,item_text) 483 col_no += 1 484 # finally set column widths to AUTOSIZE 485 for i in range(0,len(columns)): 486 self.listctrl_drugchoice.SetColumnWidth(i, wx.LIST_AUTOSIZE) 487 # set focus to first item 488 firstItemState=self.listctrl_drugchoice.GetItemState(0,wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED) 489 self.listctrl_drugchoice.SetItemState(0,wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED, wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED) 490 # show the listctrl 491 self.listctrl_drugchoice.Show() 492 # save data for further use 493 self.LastDataDict = aDataDict 494 return
495 496 #-----------------------------------------------------------------------------------------------------------------------------
497 - def Display_PI(self, aId=None):
498 """ 499 Shows product information on a drug specified by aID. 500 """ 501 # this is to stop recursion! 502 self.inDisplay_PI = 1 503 # if no aId has been specified, return 504 if aId == None: 505 return None 506 # remember Id for further use (display refresh etc.) 507 self.mId = aId 508 # getProductInfo returns a HTML-formatted page 509 (self.drugProductInfo,self.drugPIHeaders)=self.mDrugView.getProductInfo(aId) 510 # self.comboProduct.SetValue(result[0]['product']) 511 self.inDisplay_PI = 0 512 # show info page 513 self.html_viewer.SetPage(self.drugProductInfo) 514 # set jumpbox items 515 self.listbox_jumpto.Clear() 516 self.listbox_jumpto.InsertItems(self.drugPIHeaders,0) 517 return True
518 519 #--------------------------------------------------------------------------------------------------------------------------------------------------
520 - def TransferDataToWindow(self):
521 gmLog.gmDefLog.Log (gmLog.lData, "Transfer data to Window") 522 return True
523
524 - def TransferDataFromWindow(self):
525 return True
526 527 # handler implementations for DrugDisplay 528
529 - def OnPrint(self, event):
530 """ 531 If product info is available, print it. 532 """ 533 if not self.drugProductInfo is None: 534 self.printer.PrintText(self.drugProductInfo) 535 return True
536
537 - def OnDisplay(self, event):
538 """ 539 Redisplay product info. 540 """ 541 if not self.mId is None: 542 self.Display_PI(self.mId) 543 pass
544
545 - def OnPrescribe(self, event):
546 pass
547
548 - def OnJumpToDblClick(self, event):
549 pass
550
551 - def OnJumpToSelected(self, event):
552 """ 553 Jump to product info section selected by double-clicking a line in jumpbox. 554 """ 555 tagname = self.listbox_jumpto.GetString(self.listbox_jumpto.GetSelection()) 556 self.html_viewer.LoadPage('#' + tagname)
557 558 #--------------- handler for query mode radiobuttons --------------------
559 - def OnSearchByIndication(self, event):
560 self.mode = MODE_INDICATION 561 self.ClearInfo()
562
563 - def OnSearchByGeneric(self, event):
564 self.mode = MODE_GENERIC 565 self.ClearInfo()
566
567 - def OnSearchByProduct(self, event):
568 self.mode = MODE_PRODUCT 569 self.ClearInfo()
570
571 - def OnSearchByAny(self, event):
572 self.mode = MODE_ANY 573 self.ClearInfo()
574 575 # Rewrote this
576 - def OnProductKeyPressed(self, event):
577 # first, do not recur when setting the box ourselves! 578 if not self.inDisplay_PI: 579 entry_string = self.comboProduct.GetValue() 580 # wait until at least 3 letters has been entered 581 # to reduce result set 582 if len(entry_string) > 2: 583 self.Drug_Find()
584 585
586 - def OnProductSelected(self, event):
587 #---------------------------------------------- 588 # get product information for drug in the combo 589 #---------------------------------------------- 590 #self.comboProduct.SetValue(self.comboProduct.GetString(1)) 591 #self.Drug_Find() 592 pass
593
594 - def OnOk(self, event):
595 event.Skip(True)
596
597 - def OnCancel(self, event):
598 event.Skip(True)
599
600 - def ClearInfo(self):
601 """clears the search result list and jumpbox when query mode changed.""" 602 if self.mode == self.previousMode: 603 return 604 self.previousMode = self.mode 605 if self.listctrl_drugchoice is not None: 606 self.listctrl_drugchoice.ClearAll() 607 else: 608 self.ToggleWidget() 609 self.listbox_jumpto.Clear() 610 self.comboProduct.SetValue("") 611 # display welcome message 612 self.whichWidget = "listctrl_drugchoice" 613 self.ToggleWidget() 614 self.html_viewer.SetPage(self.WelcomeMessageHTML)
615 616 #================================================== 617 # Shall we just test this module? 618 if __name__ == "__main__": 619 _ = lambda x:x 620 app = wxPyWidgetTester(size = (640, 400)) 621 app.SetWidget(DrugDisplay, -1) 622 app.MainLoop() 623 else: 624 #================================================= 625 # make this into GNUMed plugin 626 627 from Gnumed.pycommon import gmI18N 628 from Gnumed.wxpython import gmPlugin 629
630 - class gmDrugDisplay (gmPlugin.cNotebookPlugin):
631
632 - def name (self):
633 return _("DrugBrowser")
634
635 - def MenuInfo (self):
636 return ("view", _("&DrugBrowser"))
637
638 - def GetWidget (self, parent):
639 return DrugDisplay (parent, -1)
640 641 #================================================== 642