| Home | Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed data mining related widgets.
2 """
3 #================================================================
4 # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/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 v2 or later (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, gmPersonSearch
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 #================================================================
32
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 = gmPersonSearch.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)
88 #================================================================
90
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 #------------------------------------------------------------
137 #================================================================
139
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"""
152 SELECT DISTINCT ON (label)
153 cmd,
154 label
155 FROM cfg.report_query
156 WHERE
157 label %(fragment_condition)s
158 OR
159 cmd %(fragment_condition)s
160 """]
161 )
162 mp.setThresholds(2,3,5)
163 self._PRW_report_name.matcher = mp
164 self._PRW_report_name.add_callback_on_selection(callback = self._on_report_selected)
165 self._PRW_report_name.add_callback_on_lose_focus(callback = self._auto_load_report)
166 #--------------------------------------------------------
168 if self._TCTRL_query.GetValue() == u'':
169 if self._PRW_report_name.GetData() is not None:
170 self._TCTRL_query.SetValue(self._PRW_report_name.GetData())
171 self._BTN_run.SetFocus()
172 #--------------------------------------------------------
176 #--------------------------------------------------------
177 # file drop target API
178 #--------------------------------------------------------
180 # act on first file only
181 fname = filenames[0]
182 # act on text files only
183 mime_type = gmMimeLib.guess_mimetype(fname)
184 if not mime_type.startswith('text/'):
185 gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. Not a text file.') % fname, beep = True)
186 return False
187 # act on "small" files only
188 stat_val = os.stat(fname)
189 if stat_val.st_size > 2000:
190 gmDispatcher.send(signal='statustext', msg = _('Cannot read SQL from [%s]. File too big (> 2000 bytes).') % fname, beep = True)
191 return False
192 # all checks passed
193 for line in fileinput.input(fname):
194 self._TCTRL_query.AppendText(line)
195 #--------------------------------------------------------
196 # notebook plugin API
197 #--------------------------------------------------------
200 #--------------------------------------------------------
201 # event handlers
202 #--------------------------------------------------------
204 data = self._LCTRL_result.get_selected_item_data()
205
206 try:
207 pk_pat = data['pk_patient']
208 except KeyError:
209 gmGuiHelpers.gm_show_warning (
210 _(
211 'Cannot activate patient.\n\n'
212 'The report result list does not contain\n'
213 'a column named "pk_patient".\n\n'
214 'You may want to use the SQL "AS" column alias\n'
215 'syntax to make your query return such a column.\n'
216 ),
217 _('Activating patient from report result')
218 )
219 return
220
221 try:
222 pat = gmPerson.cPatient(aPK_obj = pk_pat)
223 except StandardError:
224 gmGuiHelpers.gm_show_warning (
225 _(
226 'Cannot activate patient.\n'
227 '\n'
228 'There does not seem to exist a patient\n'
229 'with an internal ID of [%s].\n'
230 ) % pk_pat,
231 _('Activating patient from report result')
232 )
233 return
234
235 from Gnumed.wxpython import gmPatSearchWidgets
236 gmPatSearchWidgets.set_active_patient(patient = pat)
237 #--------------------------------------------------------
292 #--------------------------------------------------------
297 #--------------------------------------------------------
309 #--------------------------------------------------------
315 #--------------------------------------------------------
331 #--------------------------------------------------------
381 #--------------------------------------------------------
516 #================================================================
517 # main
518 #----------------------------------------------------------------
519 if __name__ == '__main__':
520 from Gnumed.pycommon import gmI18N, gmDateTime
521
522 gmI18N.activate_locale()
523 gmI18N.install_domain()
524 gmDateTime.init()
525
526 #------------------------------------------------------------
528 app = wx.PyWidgetTester(size = (400, 500))
529 lst = cPatientListingCtrl(app.frame, patient_key = 0)
530 lst.set_columns(['name', 'comment'])
531 lst.set_string_items([
532 ['Kirk', 'Kirk by name'],
533 ['#12', 'Kirk by ID'],
534 ['unknown', 'unknown patient']
535 ])
536 # app.SetWidget(cPatientListingCtrl, patient_key = 0)
537 app.frame.Show()
538 app.MainLoop()
539 #------------------------------------------------------------
540
541 test_pat_list_ctrl()
542
543 #================================================================
544
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Oct 18 04:00:18 2011 | http://epydoc.sourceforge.net |