| 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
126 self.add_callback_on_lose_focus(callback = self.__on_losing_focus)
127 #------------------------------------------------------------
129 self._adjust_data_after_text_update()
130 if self.GetValue().strip() == u'':
131 return
132
133 if len(self.data) != len(self.displayed_strings):
134 self.display_as_valid(valid = False, partially_invalid = True)
135 return
136
137 self.display_as_valid(valid = True)
138 #------------------------------------------------------------
140 if len(self.data) == 0:
141 return u''
142
143 return u';\n'.join([ i['list_label'] for i in self.data.values() ]) + u';'
144 #------------------------------------------------------------
146 if len(codes) == 0:
147 return u'', {}
148
149 code_dict = {}
150 val = u''
151 for code in codes:
152 list_label = u'%s (%s): %s (%s - %s)' % (
153 code['code'],
154 code['name_short'],
155 code['term'],
156 code['version'],
157 code['lang']
158 )
159 field_label = code['code']
160 code_dict[field_label] = {'data': code['pk_generic_code'], 'field_label': field_label, 'list_label': list_label}
161 val += u'%s; ' % field_label
162
163 return val.strip(), code_dict
164 #================================================================
165 # main
166 #----------------------------------------------------------------
167 if __name__ == '__main__':
168
169 if len(sys.argv) < 2:
170 sys.exit()
171
172 if sys.argv[1] != 'test':
173 sys.exit()
174
175 from Gnumed.pycommon import gmI18N
176 gmI18N.activate_locale()
177 gmI18N.install_domain()
178 from Gnumed.pycommon import gmPG2
179
180 #--------------------------------------------------------
182 gmPG2.get_connection()
183 app = wx.PyWidgetTester(size = (500, 40))
184 pw = cGenericCodesPhraseWheel(app.frame, -1)
185 #pw.set_context(context = u'zip', val = u'04318')
186 app.frame.Show(True)
187 app.MainLoop()
188 #--------------------------------------------------------
189 test_generic_codes_prw()
190
191 #================================================================
192
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Dec 5 03:59:50 2011 | http://epydoc.sourceforge.net |