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