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