1
2
3
4
5 __doc__ = """GNUmed LOINC 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
21
22
23 from Gnumed.pycommon import gmTools
24 from Gnumed.pycommon import gmMatchProvider
25 from Gnumed.pycommon import gmNetworkTools
26 from Gnumed.pycommon import gmDispatcher
27
28 from Gnumed.business import gmLOINC
29
30 from Gnumed.wxpython import gmAuthWidgets
31 from Gnumed.wxpython import gmGuiHelpers
32 from Gnumed.wxpython import gmPhraseWheel
33
34
35 _log = logging.getLogger('gm.ui.loinc')
36
37
39
40 wx.BeginBusyCursor()
41
42 gmDispatcher.send(signal = 'statustext', msg = _('Updating LOINC data can take quite a while...'), beep = True)
43
44
45 loinc_zip = gmNetworkTools.download_file(url = 'http://www.gnumed.de/downloads/data/loinc/loinctab.zip', suffix = '.zip')
46 if loinc_zip is None:
47 wx.EndBusyCursor()
48 gmGuiHelpers.gm_show_warning (
49 aTitle = _('Downloading LOINC'),
50 aMessage = _('Error downloading the latest LOINC data.\n')
51 )
52 return False
53
54 _log.debug('downloaded zipped LOINC data into [%s]', loinc_zip)
55
56 loinc_dir = gmNetworkTools.unzip_data_pack(filename = loinc_zip)
57
58
59 data_fname, license_fname = gmLOINC.split_LOINCDBTXT(input_fname = os.path.join(loinc_dir, 'LOINCDB.TXT'))
60
61 wx.EndBusyCursor()
62
63 conn = gmAuthWidgets.get_dbowner_connection(procedure = _('importing LOINC reference data'))
64 if conn is None:
65 return False
66
67 wx.BeginBusyCursor()
68
69
70 if gmLOINC.loinc_import(data_fname = data_fname, license_fname = license_fname, conn = conn):
71 gmDispatcher.send(signal = 'statustext', msg = _('Successfully imported LOINC reference data.'))
72 else:
73 gmDispatcher.send(signal = 'statustext', msg = _('Importing LOINC reference data failed.'), beep = True)
74
75 wx.EndBusyCursor()
76 return True
77
78
92
93
94
95
96 if __name__ == '__main__':
97
98 if len(sys.argv) < 2:
99 sys.exit()
100
101 if sys.argv[1] != 'test':
102 sys.exit()
103
104 from Gnumed.pycommon import gmPG2
105
106
107 gmPG2.get_connection()
108 app = wx.PyWidgetTester(size = (600, 80))
109 app.SetWidget(cLOINCPhraseWheel, -1)
110 app.MainLoop()
111