Home | Trees | Indices | Help |
|
---|
|
1 """GNUmed data mining related widgets.""" 2 3 #================================================================ 4 __author__ = 'karsten.hilbert@gmx.net' 5 __license__ = 'GPL v2 or later (details at http://www.gnu.org)' 6 7 8 # stdlib 9 import sys 10 import os 11 import fileinput 12 import 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 23 from Gnumed.pycommon import gmMimeLib 24 from Gnumed.pycommon import gmTools 25 from Gnumed.pycommon import gmPG2 26 from Gnumed.pycommon import gmMatchProvider 27 from Gnumed.pycommon import gmI18N 28 from Gnumed.pycommon import gmNetworkTools 29 30 from Gnumed.business import gmPerson 31 from Gnumed.business import gmDataMining 32 from Gnumed.business import gmPersonSearch 33 34 from Gnumed.wxpython import gmGuiHelpers 35 from Gnumed.wxpython import gmListWidgets 36 37 38 _log = logging.getLogger('gm.ui') 39 #================================================================41119 120 #================================================================ 121 from Gnumed.wxGladeWidgets import wxgPatientListingPnl 12243 """<patient_key> must index or name a column in self.__data""" 44 try: 45 self.patient_key = kwargs['patient_key'] 46 del kwargs['patient_key'] 47 except KeyError: 48 self.patient_key = None 49 50 gmListWidgets.cReportListCtrl.__init__(self, *args, **kwargs) 51 52 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_list_item_activated, self)53 #------------------------------------------------------------55 if self.patient_key is not None: 56 try: 57 data[self.pk_patient] 58 return self.patient_key 59 except (KeyError, IndexError, TypeError): 60 _log.error('misconfigured identifier column <%s>', self.patient_key) 61 62 _log.debug('identifier column not configured, trying to detect') 63 64 if data.has_key('pk_patient'): 65 return u'pk_patient' 66 67 if data.has_key('pk_identity'): 68 return u'pk_identity' 69 70 return gmListWidgets.get_choices_from_list ( 71 parent = self, 72 msg = _( 73 'The report result list does not contain any columns\n' 74 'named "%s", "pk_patient", or "pk_identity".\n' 75 '\n' 76 'Select the column which contains patient IDs:\n' 77 ) % self.patient_key, 78 caption = _('Choose column from query results ...'), 79 choices = data.keys(), 80 columns = [_('Column name')], 81 single_selection = True 82 )83 #------------------------------------------------------------ 84 # event handling 85 #------------------------------------------------------------87 data = self.get_selected_item_data(only_one=True) 88 pk_pat_col = self.__get_patient_pk_column(data = data) 89 90 if pk_pat_col is None: 91 gmDispatcher.send(signal = 'statustext', msg = _('List not known to be patient-related.')) 92 return 93 94 pat_data = data[pk_pat_col] 95 try: 96 pat_pk = int(pat_data) 97 pat = gmPerson.cIdentity(aPK_obj = pat_pk) 98 except (ValueError, TypeError): 99 searcher = gmPersonSearch.cPatientSearcher_SQL() 100 idents = searcher.get_identities(pat_data) 101 if len(idents) == 0: 102 gmDispatcher.send(signal = 'statustext', msg = _('No matching patient found.')) 103 return 104 if len(idents) == 1: 105 pat = idents[0] 106 else: 107 from Gnumed.wxpython import gmPatSearchWidgets 108 dlg = gmPatSearchWidgets.cSelectPersonFromListDlg(parent=wx.GetTopLevelParent(self), id=-1) 109 dlg.set_persons(persons=idents) 110 result = dlg.ShowModal() 111 if result == wx.ID_CANCEL: 112 dlg.Destroy() 113 return 114 pat = dlg.get_selected_person() 115 dlg.Destroy() 116 117 from Gnumed.wxpython import gmPatSearchWidgets 118 gmPatSearchWidgets.set_active_patient(patient = pat)124171 172 #================================================================ 173 from Gnumed.wxGladeWidgets import wxgDataMiningPnl 174126 127 try: 128 button_defs = kwargs['button_defs'][:5] 129 del kwargs['button_defs'] 130 except KeyError: 131 button_defs = [] 132 133 try: 134 msg = kwargs['message'] 135 del kwargs['message'] 136 except KeyError: 137 msg = None 138 139 wxgPatientListingPnl.wxgPatientListingPnl.__init__(self, *args, **kwargs) 140 141 if msg is not None: 142 self._lbl_msg.SetLabel(msg) 143 144 buttons = [self._BTN_1, self._BTN_2, self._BTN_3, self._BTN_4, self._BTN_5] 145 for idx in range(len(button_defs)): 146 button_def = button_defs[idx] 147 if button_def['label'].strip() == u'': 148 continue 149 buttons[idx].SetLabel(button_def['label']) 150 buttons[idx].SetToolTipString(button_def['tooltip']) 151 buttons[idx].Enable(True) 152 153 self.Fit()154 #------------------------------------------------------------ 155 # event handling 156 #------------------------------------------------------------158 event.Skip()159 #------------------------------------------------------------161 event.Skip()162 #------------------------------------------------------------164 event.Skip()165 #------------------------------------------------------------167 event.Skip()168 #------------------------------------------------------------170 event.Skip()176519 #================================================================ 520 # main 521 #---------------------------------------------------------------- 522 if __name__ == '__main__': 523 from Gnumed.pycommon import gmI18N, gmDateTime 524 525 gmI18N.activate_locale() 526 gmI18N.install_domain() 527 gmDateTime.init() 528 529 #------------------------------------------------------------178 wxgDataMiningPnl.wxgDataMiningPnl.__init__(self, *args, **kwargs) 179 180 self.__init_ui() 181 182 # make me a file drop target 183 dt = gmGuiHelpers.cFileDropTarget(self) 184 self.SetDropTarget(dt)185 #--------------------------------------------------------187 mp = gmMatchProvider.cMatchProvider_SQL2 ( 188 queries = [u""" 189 SELECT DISTINCT ON (label) 190 cmd, 191 label 192 FROM cfg.report_query 193 WHERE 194 label %(fragment_condition)s 195 OR 196 cmd %(fragment_condition)s 197 """] 198 ) 199 mp.setThresholds(2,3,5) 200 self._PRW_report_name.matcher = mp 201 self._PRW_report_name.add_callback_on_selection(callback = self._on_report_selected) 202 self._PRW_report_name.add_callback_on_lose_focus(callback = self._auto_load_report)203 #--------------------------------------------------------205 if self._TCTRL_query.GetValue() == u'': 206 if self._PRW_report_name.GetData() is not None: 207 self._TCTRL_query.SetValue(self._PRW_report_name.GetData()) 208 self._BTN_run.SetFocus()209 #-------------------------------------------------------- 213 #-------------------------------------------------------- 214 # file drop target API 215 #--------------------------------------------------------217 # act on first file only 218 fname = filenames[0] 219 _log.debug('importing SQL from <%s>', fname) 220 # act on text files only 221 mime_type = gmMimeLib.guess_mimetype(fname) 222 _log.debug('mime type: %s', mime_type) 223 if not mime_type.startswith('text/'): 224 _log.debug('not a text file') 225 gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. Not a text file.') % fname, beep = True) 226 return False 227 # # act on "small" files only 228 # stat_val = os.stat(fname) 229 # if stat_val.st_size > 5000: 230 # gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. File too big (> 2000 bytes).') % fname, beep = True) 231 # return False 232 # all checks passed 233 for line in fileinput.input(fname): 234 self._TCTRL_query.AppendText(line)235 #-------------------------------------------------------- 236 # notebook plugin API 237 #-------------------------------------------------------- 240 #-------------------------------------------------------- 241 # event handlers 242 #-------------------------------------------------------- 300 #-------------------------------------------------------- 304 #-------------------------------------------------------- 316 #-------------------------------------------------------- 321 #-------------------------------------------------------- 337 #-------------------------------------------------------- 387 #--------------------------------------------------------531 app = wx.PyWidgetTester(size = (400, 500)) 532 lst = cPatientListingCtrl(app.frame, patient_key = 0) 533 lst.set_columns(['name', 'comment']) 534 lst.set_string_items([ 535 ['Kirk', 'Kirk by name'], 536 ['#12', 'Kirk by ID'], 537 ['unknown', 'unknown patient'] 538 ]) 539 # app.SetWidget(cPatientListingCtrl, patient_key = 0) 540 app.frame.Show() 541 app.MainLoop()542 #------------------------------------------------------------ 543 544 test_pat_list_ctrl() 545
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Jun 10 03:56:55 2013 | http://epydoc.sourceforge.net |