Example #1
0
def update_loinc_reference_data():

    wx.BeginBusyCursor()

    gmDispatcher.send(signal='statustext',
                      msg=_('Updating LOINC data can take quite a while...'),
                      beep=True)

    # download
    loinc_zip = gmNetworkTools.download_file(
        url='http://www.gnumed.de/downloads/data/loinc/loinctab.zip',
        suffix='.zip')
    if loinc_zip is None:
        wx.EndBusyCursor()
        gmGuiHelpers.gm_show_warning(
            aTitle=_('Downloading LOINC'),
            aMessage=_('Error downloading the latest LOINC data.\n'))
        return False

    _log.debug('downloaded zipped LOINC data into [%s]', loinc_zip)

    loinc_dir = gmNetworkTools.unzip_data_pack(filename=loinc_zip)

    # split master data file
    data_fname, license_fname = gmLOINC.split_LOINCDBTXT(
        input_fname=os.path.join(loinc_dir, 'LOINCDB.TXT'))

    wx.EndBusyCursor()

    conn = gmAuthWidgets.get_dbowner_connection(
        procedure=_('importing LOINC reference data'))
    if conn is None:
        return False

    wx.BeginBusyCursor()

    # import data
    if gmLOINC.loinc_import(data_fname=data_fname,
                            license_fname=license_fname,
                            conn=conn):
        gmDispatcher.send(signal='statustext',
                          msg=_('Successfully imported LOINC reference data.'))
    else:
        gmDispatcher.send(signal='statustext',
                          msg=_('Importing LOINC reference data failed.'),
                          beep=True)

    wx.EndBusyCursor()
    return True
Example #2
0
def update_loinc_reference_data():

	wx.BeginBusyCursor()

	gmDispatcher.send(signal = 'statustext', msg = _('Updating LOINC data can take quite a while...'), beep = True)

	# download
	loinc_zip = gmNetworkTools.download_file(url = 'http://www.gnumed.de/downloads/data/loinc/loinctab.zip', suffix = '.zip')
	if loinc_zip is None:
		wx.EndBusyCursor()
		gmGuiHelpers.gm_show_warning (
			aTitle = _('Downloading LOINC'),
			aMessage = _('Error downloading the latest LOINC data.\n')
		)
		return False

	_log.debug('downloaded zipped LOINC data into [%s]', loinc_zip)

	loinc_dir = gmNetworkTools.unzip_data_pack(filename = loinc_zip)

	# split master data file
	data_fname, license_fname = gmLOINC.split_LOINCDBTXT(input_fname = os.path.join(loinc_dir, 'LOINCDB.TXT'))

	wx.EndBusyCursor()

	conn = gmAuthWidgets.get_dbowner_connection(procedure = _('importing LOINC reference data'))
	if conn is None:
		return False

	wx.BeginBusyCursor()

	# import data
	if gmLOINC.loinc_import(data_fname = data_fname, license_fname = license_fname, conn = conn):
		gmDispatcher.send(signal = 'statustext', msg = _('Successfully imported LOINC reference data.'))
	else:
		gmDispatcher.send(signal = 'statustext', msg = _('Importing LOINC reference data failed.'), beep = True)

	wx.EndBusyCursor()
	return True
Example #3
0
def install_data_pack(data_pack=None):

	if data_pack is None:
		return False

	_log.info('attempting installation of data pack: %s', data_pack['name'])

	msg = _(
		'Note that GNUmed data packs are provided\n'
		'\n'
		'WITHOUT ANY GUARANTEE WHATSOEVER\n'
		'\n'
		'regarding their content.\n'
		'\n'
		'Despite data packs having been prepared with the\n'
		'utmost care you must still vigilantly apply caution,\n'
		'common sense, and due diligence to make sure you\n'
		'render appropriate care to your patients.\n'
		'\n'
		'Press [Yes] to declare agreement with this precaution.\n'
		'\n'
		'Press [No] to abort installation of the data pack.\n'
	)
	go_ahead = gmGuiHelpers.gm_show_question(msg, _('Terms of Data Pack Use'))
	if not go_ahead:
		_log.info('user did not agree to terms of data pack use')
		return True

	gm_dbo_conn = gmAuthWidgets.get_dbowner_connection(procedure = _('installing data pack'))
	if gm_dbo_conn is None:
		msg = _('Lacking permissions to install data pack.')
		gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
		return False

	wx.BeginBusyCursor()
	verified, data = gmNetworkTools.download_data_pack (
		data_pack['pack_url'],
		md5_url = data_pack['md5_url']
	)
	wx.EndBusyCursor()
	if not verified:
		_log.error('cannot download and verify data pack: %s', data_pack['name'])
		md5_expected, md5_calculated = data
		msg = _(
			'Cannot validate data pack.\n'
			'\n'
			'  name: %s\n'
			'  URL: %s\n'
			'\n'
			'  MD5\n'
			'   calculated: %s\n'
			'   expected: %s\n'
			'   source: %s\n'
			'\n'
			'You may want to try downloading again or you\n'
			'may need to contact your administrator.'
		) % (
			data_pack['name'],
			data_pack['pack_url'],
			md5_calculated,
			md5_expected,
			data_pack['md5_url']
		)
		gmGuiHelpers.gm_show_error(msg, _('Verifying data pack'))
		return False

	data_pack['local_archive'] = data

	wx.BeginBusyCursor()
	unzip_dir = gmNetworkTools.unzip_data_pack(filename = data)
	wx.EndBusyCursor()
	if unzip_dir is None:
		msg = _(
			'Cannot unpack data pack.\n'
			'\n'
			'  name: %s\n'
			'  URL: %s\n'
			'  local: %s\n'
			'\n'
			'You may want to try downloading again or you\n'
			'may need to contact your administrator.'
		) % (
			data_pack['name'],
			data_pack['pack_url'],
			data_pack['local_archive']
		)
		gmGuiHelpers.gm_show_error(msg, _('Unpacking data pack'))
		return False

	data_pack['unzip_dir'] = unzip_dir

	wx.BeginBusyCursor()
	try:
		installed = gmNetworkTools.install_data_pack(data_pack, gm_dbo_conn)
	finally:
		wx.EndBusyCursor()

	# check schema hash
	db_version = gmPG2.map_client_branch2required_db_version[_cfg.get(option = 'client_branch')]
	if not gmPG2.database_schema_compatible(version = db_version):
		if db_version != 0:
			msg = _(
				'Installation of data pack failed because\n'
				'it attempted to modify the database layout.\n'
				'\n'
				'  name: %s\n'
				'  URL: %s\n'
				'  local: %s\n'
				'\n'
				'You will need to contact your administrator.'
			) % (
				data_pack['name'],
				data_pack['pack_url'],
				data_pack['local_archive']
			)
			gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
			return False

	if not installed:
		msg = _(
			'Installation of data pack failed.\n'
			'\n'
			'  name: %s\n'
			'  URL: %s\n'
			'  local: %s\n'
			'\n'
			'You may want to try downloading again or you\n'
			'may need to contact your administrator.'
		) % (
			data_pack['name'],
			data_pack['pack_url'],
			data_pack['local_archive']
		)
		gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
		return False

	msg = _(
		'Successfully installed data pack.\n'
		'\n'
		'  name: %s\n'
		'  URL: %s\n'
	) % (
		data_pack['name'],
		data_pack['pack_url']
	)
	gmGuiHelpers.gm_show_info(msg, _('Installing data pack'))

	return True
Example #4
0
def install_data_pack(data_pack=None):

    if data_pack is None:
        return False

    _log.info('attempting installation of data pack: %s', data_pack['name'])

    msg = _('Note that GNUmed data packs are provided\n'
            '\n'
            'WITHOUT ANY GUARANTEE WHATSOEVER\n'
            '\n'
            'regarding their content.\n'
            '\n'
            'Despite data packs having been prepared with the\n'
            'utmost care you must still vigilantly apply caution,\n'
            'common sense, and due diligence to make sure you\n'
            'render appropriate care to your patients.\n'
            '\n'
            'Press [Yes] to declare agreement with this precaution.\n'
            '\n'
            'Press [No] to abort installation of the data pack.\n')
    go_ahead = gmGuiHelpers.gm_show_question(msg, _('Terms of Data Pack Use'))
    if not go_ahead:
        _log.info('user did not agree to terms of data pack use')
        return True

    gm_dbo_conn = gmAuthWidgets.get_dbowner_connection(
        procedure=_('installing data pack'))
    if gm_dbo_conn is None:
        msg = _('Lacking permissions to install data pack.')
        gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
        return False

    wx.BeginBusyCursor()
    verified, data = gmNetworkTools.download_data_pack(
        data_pack['pack_url'], md5_url=data_pack['md5_url'])
    wx.EndBusyCursor()
    if not verified:
        _log.error('cannot download and verify data pack: %s',
                   data_pack['name'])
        md5_expected, md5_calculated = data
        msg = _('Cannot validate data pack.\n'
                '\n'
                '  name: %s\n'
                '  URL: %s\n'
                '\n'
                '  MD5\n'
                '   calculated: %s\n'
                '   expected: %s\n'
                '   source: %s\n'
                '\n'
                'You may want to try downloading again or you\n'
                'may need to contact your administrator.') % (
                    data_pack['name'], data_pack['pack_url'], md5_calculated,
                    md5_expected, data_pack['md5_url'])
        gmGuiHelpers.gm_show_error(msg, _('Verifying data pack'))
        return False

    data_pack['local_archive'] = data

    wx.BeginBusyCursor()
    unzip_dir = gmNetworkTools.unzip_data_pack(filename=data)
    wx.EndBusyCursor()
    if unzip_dir is None:
        msg = _('Cannot unpack data pack.\n'
                '\n'
                '  name: %s\n'
                '  URL: %s\n'
                '  local: %s\n'
                '\n'
                'You may want to try downloading again or you\n'
                'may need to contact your administrator.') % (
                    data_pack['name'], data_pack['pack_url'],
                    data_pack['local_archive'])
        gmGuiHelpers.gm_show_error(msg, _('Unpacking data pack'))
        return False

    data_pack['unzip_dir'] = unzip_dir

    wx.BeginBusyCursor()
    try:
        installed = gmNetworkTools.install_data_pack(data_pack, gm_dbo_conn)
    finally:
        wx.EndBusyCursor()

    # check schema hash
    db_version = gmPG2.map_client_branch2required_db_version[_cfg.get(
        option='client_branch')]
    if not gmPG2.database_schema_compatible(version=db_version):
        if db_version != 0:
            msg = _('Installation of data pack failed because\n'
                    'it attempted to modify the database layout.\n'
                    '\n'
                    '  name: %s\n'
                    '  URL: %s\n'
                    '  local: %s\n'
                    '\n'
                    'You will need to contact your administrator.') % (
                        data_pack['name'], data_pack['pack_url'],
                        data_pack['local_archive'])
            gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
            return False

    if not installed:
        msg = _('Installation of data pack failed.\n'
                '\n'
                '  name: %s\n'
                '  URL: %s\n'
                '  local: %s\n'
                '\n'
                'You may want to try downloading again or you\n'
                'may need to contact your administrator.') % (
                    data_pack['name'], data_pack['pack_url'],
                    data_pack['local_archive'])
        gmGuiHelpers.gm_show_error(msg, _('Installing data pack'))
        return False

    msg = _('Successfully installed data pack.\n'
            '\n'
            '  name: %s\n'
            '  URL: %s\n') % (data_pack['name'], data_pack['pack_url'])
    gmGuiHelpers.gm_show_info(msg, _('Installing data pack'))

    return True