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

Source Code for Module Gnumed.wxpython.gmATCWidgets

  1  # -*- coding: utf-8 -*- 
  2   
  3  #from __future__ import print_function 
  4   
  5  __doc__ = """GNUmed ATC handling widgets.""" 
  6   
  7  #================================================================ 
  8  __author__ = "Karsten Hilbert <Karsten.Hilbert@gmx.net>" 
  9  __license__ = "GPL v2 or later" 
 10   
 11  import logging 
 12  import sys 
 13  import os.path 
 14   
 15   
 16  import wx 
 17   
 18  if __name__ == '__main__': 
 19          sys.path.insert(0, '../../') 
 20          from Gnumed.pycommon import gmI18N 
 21          gmI18N.activate_locale() 
 22          gmI18N.install_domain(domain = 'gnumed') 
 23  from Gnumed.pycommon import gmTools 
 24  from Gnumed.pycommon import gmMatchProvider 
 25   
 26  from Gnumed.business import gmATC 
 27   
 28  from Gnumed.wxpython import gmAuthWidgets 
 29  from Gnumed.wxpython import gmListWidgets 
 30  from Gnumed.wxpython import gmPhraseWheel 
 31   
 32   
 33  _log = logging.getLogger('gm.ui.atc') 
 34   
 35  #============================================================ 
36 -def browse_atc_reference_deprecated(parent=None):
37 38 if parent is None: 39 parent = wx.GetApp().GetTopWindow() 40 #------------------------------------------------------------ 41 def refresh(lctrl): 42 atcs = gmATC.get_reference_atcs() 43 44 items = [ [ 45 a['atc'], 46 a['term'], 47 gmTools.coalesce(a['unit'], ''), 48 gmTools.coalesce(a['administrative_route'], ''), 49 gmTools.coalesce(a['comment'], ''), 50 a['version'], 51 a['lang'] 52 ] for a in atcs ] 53 lctrl.set_string_items(items) 54 lctrl.set_data(atcs)
55 #------------------------------------------------------------ 56 gmListWidgets.get_choices_from_list ( 57 parent = parent, 58 msg = _('\nThe ATC codes as known to GNUmed.\n'), 59 caption = _('Showing ATC codes.'), 60 columns = [ 'ATC', _('Term'), _('Unit'), _('Route'), _('Comment'), _('Version'), _('Language') ], 61 single_selection = True, 62 refresh_callback = refresh 63 ) 64 65 #============================================================
66 -def update_atc_reference_data():
67 68 dlg = wx.FileDialog ( 69 parent = None, 70 message = _('Choose an ATC import config file'), 71 defaultDir = os.path.expanduser(os.path.join('~', 'gnumed')), 72 defaultFile = '', 73 wildcard = "%s (*.conf)|*.conf|%s (*)|*" % (_('config files'), _('all files')), 74 style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST 75 ) 76 77 result = dlg.ShowModal() 78 if result == wx.ID_CANCEL: 79 return 80 81 cfg_file = dlg.GetPath() 82 dlg.DestroyLater() 83 84 conn = gmAuthWidgets.get_dbowner_connection(procedure = _('importing ATC reference data')) 85 if conn is None: 86 return False 87 88 wx.BeginBusyCursor() 89 90 if gmATC.atc_import(cfg_fname = cfg_file, conn = conn): 91 gmDispatcher.send(signal = 'statustext', msg = _('Successfully imported ATC reference data.')) 92 else: 93 gmDispatcher.send(signal = 'statustext', msg = _('Importing ATC reference data failed.'), beep = True) 94 95 wx.EndBusyCursor() 96 return True
97 98 #============================================================
99 -class cATCPhraseWheel(gmPhraseWheel.cPhraseWheel):
100
101 - def __init__(self, *args, **kwargs):
102 103 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 104 query = """ 105 SELECT DISTINCT ON (data) 106 data, 107 field_label, 108 list_label 109 FROM ( 110 ( 111 SELECT 112 code AS data, 113 (code || ': ' || term) 114 AS list_label, 115 (code || ' (' || term || ')') 116 AS field_label 117 FROM ref.atc 118 WHERE 119 term %(fragment_condition)s 120 OR 121 code %(fragment_condition)s 122 ) UNION ALL ( 123 SELECT 124 atc as data, 125 (atc || ': ' || description) 126 AS list_label, 127 (atc || ' (' || description || ')') 128 AS field_label 129 FROM ref.substance 130 WHERE 131 description %(fragment_condition)s 132 OR 133 atc %(fragment_condition)s 134 ) UNION ALL ( 135 SELECT 136 atc_code AS data, 137 (atc_code || ': ' || description || ' (' || preparation || ')') 138 AS list_label, 139 (atc_code || ': ' || description) 140 AS field_label 141 FROM ref.drug_product 142 WHERE 143 description %(fragment_condition)s 144 OR 145 atc_code %(fragment_condition)s 146 ) 147 -- it would be nice to be able to include ref.vacc_indication but that's hard to do in SQL 148 ) AS candidates 149 WHERE data IS NOT NULL 150 ORDER BY data, list_label 151 LIMIT 50""" 152 153 mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) 154 mp.setThresholds(1, 2, 4) 155 # mp.word_separators = '[ \t=+&:@]+' 156 self.SetToolTip(_('Select an ATC (Anatomical-Therapeutic-Chemical) code.')) 157 self.matcher = mp 158 self.selection_only = True
159 160 #============================================================ 161 # main 162 #------------------------------------------------------------ 163 if __name__ == '__main__': 164 165 if len(sys.argv) < 2: 166 sys.exit() 167 168 if sys.argv[1] != 'test': 169 sys.exit() 170 171 from Gnumed.pycommon import gmPG2 172 173 #---------------------------------------- 174 gmPG2.get_connection() 175 app = wx.PyWidgetTester(size = (600, 80)) 176 app.SetWidget(cATCPhraseWheel, -1) 177 app.MainLoop() 178