Trees | Indices | Help |
|
---|
|
1 """GNUmed data mining related widgets. 2 """ 3 #================================================================ 4 # $Source: /cvsroot/gnumed/gnumed/gnumed/client/wxpython/gmDataMiningWidgets.py,v $ 5 # $Id: gmDataMiningWidgets.py,v 1.14 2009/07/30 12:03:34 ncq Exp $ 6 __version__ = '$Revision: 1.14 $' 7 __author__ = 'karsten.hilbert@gmx.net' 8 __license__ = 'GPL (details at http://www.gnu.org)' 9 10 11 # stdlib 12 import sys, os, fileinput, webbrowser, logging 13 14 15 # 3rd party 16 import wx 17 18 19 # GNUmed 20 if __name__ == '__main__': 21 sys.path.insert(0, '../../') 22 from Gnumed.pycommon import gmDispatcher, gmMimeLib, gmTools, gmPG2, gmMatchProvider, gmI18N 23 from Gnumed.business import gmPerson, gmDataMining 24 from Gnumed.wxpython import gmGuiHelpers, gmListWidgets 25 from Gnumed.wxGladeWidgets import wxgPatientListingPnl, wxgDataMiningPnl 26 27 28 _log = logging.getLogger('gm.ui') 29 _log.info(__version__) 30 #================================================================3288 #================================================================34 """<patient_key> must index or name a column in self.__data""" 35 try: 36 self.patient_key = kwargs['patient_key'] 37 del kwargs['patient_key'] 38 except KeyError: 39 self.patient_key = None 40 41 gmListWidgets.cReportListCtrl.__init__(self, *args, **kwargs) 42 43 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_list_item_activated, self)44 #------------------------------------------------------------ 45 # event handling 46 #------------------------------------------------------------48 if self.patient_key is None: 49 gmDispatcher.send(signal = 'statustext', msg = _('List not known to be patient-related.')) 50 return 51 data = self.get_selected_item_data(only_one=True) 52 try: 53 pat_data = data[self.patient_key] 54 except (KeyError, IndexError, TypeError): 55 gmGuiHelpers.gm_show_info ( 56 _( 57 'Cannot activate patient.\n\n' 58 'The row does not contain a column\n' 59 'named or indexed "%s".\n\n' 60 ) % self.patient_key, 61 _('activating patient from list') 62 ) 63 return 64 try: 65 pat_pk = int(pat_data) 66 pat = gmPerson.cIdentity(aPK_obj = pat_pk) 67 except (ValueError, TypeError): 68 searcher = gmPerson.cPatientSearcher_SQL() 69 idents = searcher.get_identities(pat_data) 70 if len(idents) == 0: 71 gmDispatcher.send(signal = 'statustext', msg = _('No matching patient found.')) 72 return 73 if len(idents) == 1: 74 pat = idents[0] 75 else: 76 from Gnumed.wxpython import gmPatSearchWidgets 77 dlg = gmPatSearchWidgets.cSelectPersonFromListDlg(parent=wx.GetTopLevelParent(self), id=-1) 78 dlg.set_persons(persons=idents) 79 result = dlg.ShowModal() 80 if result == wx.ID_CANCEL: 81 dlg.Destroy() 82 return 83 pat = dlg.get_selected_person() 84 dlg.Destroy() 85 86 from Gnumed.wxpython import gmPatSearchWidgets 87 gmPatSearchWidgets.set_active_patient(patient = pat)90137 #================================================================92 93 try: 94 button_defs = kwargs['button_defs'][:5] 95 del kwargs['button_defs'] 96 except KeyError: 97 button_defs = [] 98 99 try: 100 msg = kwargs['message'] 101 del kwargs['message'] 102 except KeyError: 103 msg = None 104 105 wxgPatientListingPnl.wxgPatientListingPnl.__init__(self, *args, **kwargs) 106 107 if msg is not None: 108 self._lbl_msg.SetLabel(msg) 109 110 buttons = [self._BTN_1, self._BTN_2, self._BTN_3, self._BTN_4, self._BTN_5] 111 for idx in range(len(button_defs)): 112 button_def = button_defs[idx] 113 if button_def['label'].strip() == u'': 114 continue 115 buttons[idx].SetLabel(button_def['label']) 116 buttons[idx].SetToolTipString(button_def['tooltip']) 117 buttons[idx].Enable(True) 118 119 self.Fit()120 #------------------------------------------------------------ 121 # event handling 122 #------------------------------------------------------------ 125 #------------------------------------------------------------ 128 #------------------------------------------------------------ 131 #------------------------------------------------------------ 134 #------------------------------------------------------------139439 #================================================================ 440 # main 441 #---------------------------------------------------------------- 442 if __name__ == '__main__': 443 from Gnumed.pycommon import gmI18N, gmDateTime 444 445 gmI18N.activate_locale() 446 gmI18N.install_domain() 447 gmDateTime.init() 448 449 #------------------------------------------------------------141 wxgDataMiningPnl.wxgDataMiningPnl.__init__(self, *args, **kwargs) 142 143 self.__init_ui() 144 145 # make me a file drop target 146 dt = gmGuiHelpers.cFileDropTarget(self) 147 self.SetDropTarget(dt)148 #--------------------------------------------------------150 mp = gmMatchProvider.cMatchProvider_SQL2 ( 151 queries = [u'select distinct on (label) cmd, label from cfg.report_query where label %(fragment_condition)s or cmd %(fragment_condition)s'] 152 ) 153 mp.setThresholds(2,3,5) 154 self._PRW_report_name.matcher = mp 155 self._PRW_report_name.add_callback_on_selection(callback = self._on_report_selected) 156 self._PRW_report_name.add_callback_on_lose_focus(callback = self._auto_load_report)157 #--------------------------------------------------------159 if self._TCTRL_query.GetValue() == u'': 160 if self._PRW_report_name.GetData() is not None: 161 self._TCTRL_query.SetValue(self._PRW_report_name.GetData()) 162 self._BTN_run.SetFocus()163 #-------------------------------------------------------- 167 #-------------------------------------------------------- 168 # file drop target API 169 #--------------------------------------------------------171 # act on first file only 172 fname = filenames[0] 173 # act on text files only 174 mime_type = gmMimeLib.guess_mimetype(fname) 175 if not mime_type.startswith('text/'): 176 gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. Not a text file.') % fname, beep = True) 177 return False 178 # act on "small" files only 179 stat_val = os.stat(fname) 180 if stat_val.st_size > 2000: 181 gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. File too big (> 2000 bytes).') % fname, beep = True) 182 return False 183 # all checks passed 184 for line in fileinput.input(fname): 185 self._TCTRL_query.AppendText(line)186 #-------------------------------------------------------- 187 # notebook plugin API 188 #-------------------------------------------------------- 191 #-------------------------------------------------------- 192 # event handlers 193 #--------------------------------------------------------195 data = self._LCTRL_result.get_selected_item_data() 196 197 try: 198 pk_pat = data['pk_patient'] 199 except KeyError: 200 gmGuiHelpers.gm_show_warning ( 201 _( 202 'Cannot activate patient.\n\n' 203 'The report result list does not contain\n' 204 'a column named "pk_patient".\n\n' 205 'You may want to use the SQL "AS" column alias\n' 206 'syntax to make your query return such a column.\n' 207 ), 208 _('Activating patient from report result') 209 ) 210 return 211 212 try: 213 pat = gmPerson.cPatient(aPK_obj = pk_pat) 214 except StandardError: 215 gmGuiHelpers.gm_show_warning ( 216 _( 217 'Cannot activate patient.\n' 218 '\n' 219 'There does not seem to exist a patient\n' 220 'with an internal ID of [%s].\n' 221 ) % pk_pat, 222 _('Activating patient from report result') 223 ) 224 return 225 226 from Gnumed.wxpython import gmPatSearchWidgets 227 gmPatSearchWidgets.set_active_patient(patient = pat)228 #-------------------------------------------------------- 283 #-------------------------------------------------------- 288 #-------------------------------------------------------- 300 #-------------------------------------------------------- 306 #-------------------------------------------------------- 322 #-------------------------------------------------------- 372 #--------------------------------------------------------451 app = wx.PyWidgetTester(size = (400, 500)) 452 lst = cPatientListingCtrl(app.frame, patient_key = 0) 453 lst.set_columns(['name', 'comment']) 454 lst.set_string_items([ 455 ['Kirk', 'Kirk by name'], 456 ['#12', 'Kirk by ID'], 457 ['unknown', 'unknown patient'] 458 ]) 459 # app.SetWidget(cPatientListingCtrl, patient_key = 0) 460 app.frame.Show() 461 app.MainLoop()462 #------------------------------------------------------------ 463 464 test_pat_list_ctrl() 465 466 #================================================================ 467 # $Log: gmDataMiningWidgets.py,v $ 468 # Revision 1.14 2009/07/30 12:03:34 ncq 469 # - improved contribution email 470 # 471 # Revision 1.13 2009/07/18 11:46:53 ncq 472 # - be more robust in the face of non-existant patients being activated 473 # 474 # Revision 1.12 2009/07/15 12:21:10 ncq 475 # - auto-load report from db if name exists and query empty and name loses focus 476 # - clear results, too, on clear button 477 # - improved plot title 478 # - improved error handling around Gnuplot access 479 # - display # of results found 480 # 481 # Revision 1.11 2009/07/06 17:10:35 ncq 482 # - signal errors in sanity check of query before contributing 483 # - show warning before sending contribution 484 # - fix encoding of contribution email 485 # 486 # Revision 1.10 2009/06/04 16:30:30 ncq 487 # - use set active patient from pat search widgets 488 # 489 # Revision 1.9 2008/12/22 18:59:56 ncq 490 # - put \n before appended wrapper query because original query might have 491 # a line starting with "-- " as the last line ... 492 # 493 # Revision 1.8 2008/03/06 18:29:29 ncq 494 # - standard lib logging only 495 # 496 # Revision 1.7 2007/12/11 12:49:25 ncq 497 # - explicit signal handling 498 # 499 # Revision 1.6 2007/11/21 14:33:40 ncq 500 # - fix use of send_mail() 501 # 502 # Revision 1.5 2007/09/24 18:31:16 ncq 503 # - support visualizing data mining results 504 # 505 # Revision 1.4 2007/09/10 13:50:05 ncq 506 # - missing import 507 # 508 # Revision 1.3 2007/08/12 00:07:18 ncq 509 # - no more gmSignals.py 510 # 511 # Revision 1.2 2007/07/09 11:06:24 ncq 512 # - missing import 513 # 514 # Revision 1.1 2007/07/09 11:03:49 ncq 515 # - new file 516 # 517 # 518
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Feb 9 04:02:27 2010 | http://epydoc.sourceforge.net |