Package Gnumed :: Package wxpython :: Module gmCodingWidgets
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmCodingWidgets

  1  """GNUmed coding related widgets.""" 
  2  #================================================================ 
  3  __version__ = '$Revision: 1.4 $' 
  4  __author__ = 'karsten.hilbert@gmx.net' 
  5  __license__ = 'GPL (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  #================================================================ 
30 -def browse_coded_terms(parent=None, coding_systems=None, languages=None):
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.'), 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
71 -class cGenericCodesPhraseWheel(gmPhraseWheel.cMultiPhraseWheel):
72
73 - def __init__(self, *args, **kwargs):
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 AS data, 87 (code || ' (' || lang || ' - ' || coding_system || ' - ' || version || '): ' || term) AS list_label, 88 code AS field_label 89 FROM 90 ref.v_coded_terms 91 WHERE 92 term %(fragment_condition)s 93 OR 94 code %(fragment_condition)s 95 %(ctxt_system)s 96 %(ctxt_lang)s 97 98 ) AS applicable_codes 99 ORDER BY list_label 100 LIMIT 30 101 """ 102 ctxt = { 103 'ctxt_system': { # must be a TUPLE ! 104 'where_part': u'AND coding_system IN %(system)s', 105 'placeholder': u'system' 106 }, 107 'ctxt_lang': { 108 'where_part': u'AND lang = %(lang)s', 109 'placeholder': u'lang' 110 } 111 } 112 113 mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = ctxt) 114 mp.setThresholds(2, 4, 5) 115 mp.word_separators = '[ \t=+&/:-]+' 116 #mp.print_queries = True 117 118 self.phrase_separators = ';' 119 self.selection_only = False # not sure yet how this fares with multi-phrase input 120 self.SetToolTipString(_('Select one or more codes that apply.')) 121 self.matcher = mp
122 #------------------------------------------------------------
123 - def _get_data_tooltip(self):
124 if len(self.data) == 0: 125 return u'' 126 127 return u';\n'.join([ i['list_label'] for i in self.data.values() ]) + u';'
128 #================================================================ 129 # main 130 #---------------------------------------------------------------- 131 if __name__ == '__main__': 132 133 if len(sys.argv) < 2: 134 sys.exit() 135 136 if sys.argv[1] != 'test': 137 sys.exit() 138 139 from Gnumed.pycommon import gmI18N 140 gmI18N.activate_locale() 141 gmI18N.install_domain() 142 from Gnumed.pycommon import gmPG2 143 144 #--------------------------------------------------------
145 - def test_generic_codes_prw():
146 gmPG2.get_connection() 147 app = wx.PyWidgetTester(size = (500, 40)) 148 pw = cGenericCodesPhraseWheel(app.frame, -1) 149 #pw.set_context(context = u'zip', val = u'04318') 150 app.frame.Show(True) 151 app.MainLoop()
152 #-------------------------------------------------------- 153 test_generic_codes_prw() 154 155 #================================================================ 156