| Home | Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed coding related widgets."""
2 #================================================================
3 __version__ = '$Revision: 1.4 $'
4 __author__ = 'karsten.hilbert@gmx.net'
5 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
6
7 # stdlib
8 import logging, sys
9
10
11 # 3rd party
12 import wx
13
14
15 # GNUmed
16 if __name__ == '__main__':
17 sys.path.insert(0, '../../')
18
19 from Gnumed.business import gmCoding
20 from Gnumed.pycommon import gmTools
21 from Gnumed.pycommon import gmMatchProvider
22 from Gnumed.wxpython import gmListWidgets
23 from Gnumed.wxpython import gmPhraseWheel
24
25
26 _log = logging.getLogger('gm.ui')
27 _log.info(__version__)
28
29 #================================================================
31
32 if parent is None:
33 parent = wx.GetApp().GetTopWindow()
34 #------------------------------------------------------------
35 def refresh(lctrl):
36 coded_terms = gmCoding.get_coded_terms (
37 coding_systems = coding_systems,
38 languages = languages,
39 order_by = u'term, coding_system, code'
40 )
41 items = [ [
42 ct['term'],
43 ct['code'],
44 ct['coding_system'],
45 gmTools.coalesce(ct['lang'], u''),
46 ct['version'],
47 ct['coding_system_long']
48 ] for ct in coded_terms ]
49 lctrl.set_string_items(items)
50 lctrl.set_data(coded_terms)
51 #------------------------------------------------------------
52 gmListWidgets.get_choices_from_list (
53 parent = parent,
54 msg = _('Coded terms known to GNUmed (may take a while to load).'),
55 caption = _('Showing coded terms.'),
56 columns = [ _('Term'), _('Code'), _('System'), _('Language'), _('Version'), _(u'Coding system details') ],
57 single_selection = True,
58 can_return_empty = True,
59 ignore_OK_button = True,
60 refresh_callback = refresh
61 # edit_callback=None,
62 # new_callback=None,
63 # delete_callback=None,
64 # left_extra_button=None,
65 # middle_extra_button=None,
66 # right_extra_button=None
67 )
68
69 #================================================================
70
72
74
75 super(cGenericCodesPhraseWheel, self).__init__(*args, **kwargs)
76
77 query = u"""
78 SELECT
79 -- DISTINCT ON (list_label)
80 data,
81 list_label,
82 field_label
83 FROM (
84
85 SELECT
86 pk_generic_code
87 AS data,
88 (code || ' (' || coding_system || '): ' || term || ' (' || version || coalesce(' - ' || lang, '') || ')')
89 AS list_label,
90 code AS
91 field_label
92 FROM
93 ref.v_coded_terms
94 WHERE
95 term %(fragment_condition)s
96 OR
97 code %(fragment_condition)s
98 %(ctxt_system)s
99 %(ctxt_lang)s
100
101 ) AS applicable_codes
102 ORDER BY list_label
103 LIMIT 30
104 """
105 ctxt = {
106 'ctxt_system': { # must be a TUPLE !
107 'where_part': u'AND coding_system IN %(system)s',
108 'placeholder': u'system'
109 },
110 'ctxt_lang': {
111 'where_part': u'AND lang = %(lang)s',
112 'placeholder': u'lang'
113 }
114 }
115
116 mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = ctxt)
117 mp.setThresholds(2, 4, 5)
118 mp.word_separators = '[ \t=+&/:-]+'
119 #mp.print_queries = True
120
121 self.phrase_separators = ';'
122 self.selection_only = False # not sure yet how this fares with multi-phrase input
123 self.SetToolTipString(_('Select one or more codes that apply.'))
124 self.matcher = mp
125 #------------------------------------------------------------
127 if len(self.data) == 0:
128 return u''
129
130 return u';\n'.join([ i['list_label'] for i in self.data.values() ]) + u';'
131 #------------------------------------------------------------
133 if len(codes) == 0:
134 return u'', {}
135
136 code_dict = {}
137 val = u''
138 for code in codes:
139 list_label = u'%s (%s): %s (%s - %s)' % (
140 code['code'],
141 code['name_short'],
142 code['term'],
143 code['version'],
144 code['lang']
145 )
146 field_label = code['code']
147 code_dict[field_label] = {'data': code['pk_generic_code'], 'field_label': field_label, 'list_label': list_label}
148 val += u'%s; ' % field_label
149
150 return val.strip(), code_dict
151 #================================================================
152 # main
153 #----------------------------------------------------------------
154 if __name__ == '__main__':
155
156 if len(sys.argv) < 2:
157 sys.exit()
158
159 if sys.argv[1] != 'test':
160 sys.exit()
161
162 from Gnumed.pycommon import gmI18N
163 gmI18N.activate_locale()
164 gmI18N.install_domain()
165 from Gnumed.pycommon import gmPG2
166
167 #--------------------------------------------------------
169 gmPG2.get_connection()
170 app = wx.PyWidgetTester(size = (500, 40))
171 pw = cGenericCodesPhraseWheel(app.frame, -1)
172 #pw.set_context(context = u'zip', val = u'04318')
173 app.frame.Show(True)
174 app.MainLoop()
175 #--------------------------------------------------------
176 test_generic_codes_prw()
177
178 #================================================================
179
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Oct 18 04:00:17 2011 | http://epydoc.sourceforge.net |