Gnumed.wxpython.gmLOINCWidgets

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

# Source Code for Module Gnumed.wxpython.gmLOINCWidgets

      1  # -*- coding: utf-8 -*-
      2
      3  #from __future__ import print_function
      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  #       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 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  #================================================================
     38 -def update_loinc_reference_data():
     39
     40          wx.BeginBusyCursor()
     41
     42          gmDispatcher.send(signal = 'statustext', msg = _('Updating LOINC data can take quite a while...'), beep = True)
     43
     44          # download
     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          # split master data file
     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          # import data
     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  #================================================================
     79 -class cLOINCPhraseWheel(gmPhraseWheel.cPhraseWheel):
     80
     81 -        def __init__(self, *args, **kwargs):
     82
     83                  gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs)
     84                  mp = gmLOINC.cLOINCMatchProvider()
     85                  mp.setThresholds(1, 2, 4)
     86                  #mp.print_queries = True
     87                  #mp.word_separators = '[ \t:@]+'
     88                  self.matcher = mp
     89                  self.selection_only = False
     90                  self.final_regex = r'\d{1,5}-\d{1}$'
     91                  self.SetToolTip(_('Select a LOINC (Logical Observation Identifiers Names and Codes).'))
     92
     93  #================================================================
     94  # main
     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