1
2
3
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 from Gnumed.pycommon import gmDispatcher
26
27 from Gnumed.business import gmATC
28
29 from Gnumed.wxpython import gmAuthWidgets
30 from Gnumed.wxpython import gmListWidgets
31 from Gnumed.wxpython import gmPhraseWheel
32
33
34 _log = logging.getLogger('gm.ui.atc')
35
36
56
57 gmListWidgets.get_choices_from_list (
58 parent = parent,
59 msg = _('\nThe ATC codes as known to GNUmed.\n'),
60 caption = _('Showing ATC codes.'),
61 columns = [ 'ATC', _('Term'), _('Unit'), _('Route'), _('Comment'), _('Version'), _('Language') ],
62 single_selection = True,
63 refresh_callback = refresh
64 )
65
66
68
69 dlg = wx.FileDialog (
70 parent = None,
71 message = _('Choose an ATC import config file'),
72 defaultDir = os.path.expanduser(os.path.join('~', 'gnumed')),
73 defaultFile = '',
74 wildcard = "%s (*.conf)|*.conf|%s (*)|*" % (_('config files'), _('all files')),
75 style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
76 )
77
78 result = dlg.ShowModal()
79 if result == wx.ID_CANCEL:
80 return
81
82 cfg_file = dlg.GetPath()
83 dlg.DestroyLater()
84
85 conn = gmAuthWidgets.get_dbowner_connection(procedure = _('importing ATC reference data'))
86 if conn is None:
87 return False
88
89 wx.BeginBusyCursor()
90
91 if gmATC.atc_import(cfg_fname = cfg_file, conn = conn):
92 gmDispatcher.send(signal = 'statustext', msg = _('Successfully imported ATC reference data.'))
93 else:
94 gmDispatcher.send(signal = 'statustext', msg = _('Importing ATC reference data failed.'), beep = True)
95
96 wx.EndBusyCursor()
97 return True
98
99
101
103
104 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs)
105 query = """
106 SELECT DISTINCT ON (data)
107 data,
108 field_label,
109 list_label
110 FROM (
111 (
112 SELECT
113 code AS data,
114 (code || ': ' || term)
115 AS list_label,
116 (code || ' (' || term || ')')
117 AS field_label
118 FROM ref.atc
119 WHERE
120 term %(fragment_condition)s
121 OR
122 code %(fragment_condition)s
123 ) UNION ALL (
124 SELECT
125 atc as data,
126 (atc || ': ' || description)
127 AS list_label,
128 (atc || ' (' || description || ')')
129 AS field_label
130 FROM ref.substance
131 WHERE
132 description %(fragment_condition)s
133 OR
134 atc %(fragment_condition)s
135 ) UNION ALL (
136 SELECT
137 atc_code AS data,
138 (atc_code || ': ' || description || ' (' || preparation || ')')
139 AS list_label,
140 (atc_code || ': ' || description)
141 AS field_label
142 FROM ref.drug_product
143 WHERE
144 description %(fragment_condition)s
145 OR
146 atc_code %(fragment_condition)s
147 )
148 -- it would be nice to be able to include ref.vacc_indication but that's hard to do in SQL
149 ) AS candidates
150 WHERE data IS NOT NULL
151 ORDER BY data, list_label
152 LIMIT 50"""
153
154 mp = gmMatchProvider.cMatchProvider_SQL2(queries = query)
155 mp.setThresholds(1, 2, 4)
156
157 self.SetToolTip(_('Select an ATC (Anatomical-Therapeutic-Chemical) code.'))
158 self.matcher = mp
159 self.selection_only = True
160
161
162
163
164 if __name__ == '__main__':
165
166 if len(sys.argv) < 2:
167 sys.exit()
168
169 if sys.argv[1] != 'test':
170 sys.exit()
171
172 from Gnumed.pycommon import gmPG2
173
174
175 gmPG2.get_connection()
176 app = wx.PyWidgetTester(size = (600, 80))
177 app.SetWidget(cATCPhraseWheel, -1)
178 app.MainLoop()
179