示例#1
0
def manage_comm_channel_types(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#------------------------------------------------------------
	def delete(channel=None):
		return gmDemographicRecord.delete_comm_channel_type(pk_channel_type = channel['pk'])
	#------------------------------------------------------------
	def refresh(lctrl):
		wx.BeginBusyCursor()
		channel_types = gmDemographicRecord.get_comm_channel_types()
		lctrl.set_string_items([ (ct['l10n_description'], ct['description'], ct['pk']) for ct in channel_types ])
		lctrl.set_data(channel_types)
		wx.EndBusyCursor()
	#------------------------------------------------------------
	msg = _('\nThis lists the communication channel types known to GNUmed.\n')

	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Managing communication types ...'),
		columns = [_('Channel'), _('System type'), '#'],
		single_selection = True,
		#new_callback = edit,
		#edit_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh
	)
示例#2
0
def manage_vaccination_indications(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def refresh(lctrl):
		inds = gmVaccination.get_indications(order_by = 'l10n_description')

		items = [ [
			i['l10n_description'],
			gmTools.coalesce (
				i['atcs_single_indication'],
				u'',
				u'%s'
			),
			gmTools.coalesce (
				i['atcs_combi_indication'],
				u'',
				u'%s'
			),
			u'%s' % i['id']
		] for i in inds ]

		lctrl.set_string_items(items)
		lctrl.set_data(inds)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nConditions preventable by vaccination as currently known to GNUmed.\n'),
		caption = _('Showing vaccination preventable conditions.'),
		columns = [ _('Condition'), _('ATCs: single-condition vaccines'), _('ATCs: multi-condition vaccines'), u'#' ],
		single_selection = True,
		refresh_callback = refresh
	)
示例#3
0
def manage_encounter_types(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#--------------------
	def edit(enc_type=None):
		return edit_encounter_type(parent = parent, encounter_type = enc_type)
	#--------------------
	def delete(enc_type=None):
		if gmEMRStructItems.delete_encounter_type(description = enc_type['description']):
			return True
		gmDispatcher.send (
			signal = u'statustext',
			msg = _('Cannot delete encounter type [%s]. It is in use.') % enc_type['l10n_description'],
			beep = True
		)
		return False
	#--------------------
	def refresh(lctrl):
		enc_types = gmEMRStructItems.get_encounter_types()
		lctrl.set_string_items(items = enc_types)
	#--------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nSelect the encounter type you want to edit !\n'),
		caption = _('Managing encounter types ...'),
		columns = [_('Local name'), _('Encounter type')],
		single_selection = True,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh
	)
示例#4
0
def browse_atc_reference_deprecated(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def refresh(lctrl):
		atcs = gmATC.get_reference_atcs()

		items = [ [
			a['atc'],
			a['term'],
			gmTools.coalesce(a['unit'], ''),
			gmTools.coalesce(a['administrative_route'], ''),
			gmTools.coalesce(a['comment'], ''),
			a['version'],
			a['lang']
		] for a in atcs ]
		lctrl.set_string_items(items)
		lctrl.set_data(atcs)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nThe ATC codes as known to GNUmed.\n'),
		caption = _('Showing ATC codes.'),
		columns = [ 'ATC', _('Term'), _('Unit'), _('Route'), _('Comment'), _('Version'), _('Language') ],
		single_selection = True,
		refresh_callback = refresh
	)
示例#5
0
def browse_atc_reference_deprecated(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
    #------------------------------------------------------------
    def refresh(lctrl):
        atcs = gmATC.get_reference_atcs()

        items = [[
            a['atc'], a['term'],
            gmTools.coalesce(a['unit'], ''),
            gmTools.coalesce(a['administrative_route'], ''),
            gmTools.coalesce(a['comment'], ''), a['version'], a['lang']
        ] for a in atcs]
        lctrl.set_string_items(items)
        lctrl.set_data(atcs)

    #------------------------------------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('\nThe ATC codes as known to GNUmed.\n'),
        caption=_('Showing ATC codes.'),
        columns=[
            'ATC',
            _('Term'),
            _('Unit'),
            _('Route'),
            _('Comment'),
            _('Version'),
            _('Language')
        ],
        single_selection=True,
        refresh_callback=refresh)
示例#6
0
def manage_comm_channel_types(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #------------------------------------------------------------
    def delete(channel=None):
        return gmDemographicRecord.delete_comm_channel_type(
            pk_channel_type=channel['pk'])

    #------------------------------------------------------------
    def refresh(lctrl):
        wx.BeginBusyCursor()
        channel_types = gmDemographicRecord.get_comm_channel_types()
        lctrl.set_string_items([(ct['l10n_description'], ct['description'],
                                 ct['pk']) for ct in channel_types])
        lctrl.set_data(channel_types)
        wx.EndBusyCursor()

    #------------------------------------------------------------
    msg = _('\nThis lists the communication channel types known to GNUmed.\n')

    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Managing communication types ...'),
        columns=[_('Channel'), _('System type'), '#'],
        single_selection=True,
        #new_callback = edit,
        #edit_callback = edit,
        delete_callback=delete,
        refresh_callback=refresh)
示例#7
0
def manage_encounter_types(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#--------------------
	def edit(enc_type=None):
		return edit_encounter_type(parent = parent, encounter_type = enc_type)
	#--------------------
	def delete(enc_type=None):
		if gmEMRStructItems.delete_encounter_type(description = enc_type['description']):
			return True
		gmDispatcher.send (
			signal = 'statustext',
			msg = _('Cannot delete encounter type [%s]. It is in use.') % enc_type['l10n_description'],
			beep = True
		)
		return False
	#--------------------
	def refresh(lctrl):
		enc_types = gmEMRStructItems.get_encounter_types()
		lctrl.set_string_items(items = enc_types)
	#--------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nSelect the encounter type you want to edit !\n'),
		caption = _('Managing encounter types ...'),
		columns = [_('Local name'), _('Encounter type')],
		single_selection = True,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh
	)
示例#8
0
def manage_hospital_stays(parent=None):

	pat = gmPerson.gmCurrentPatient()
	emr = pat.emr

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#-----------------------------------------
	def get_tooltip(stay=None):
		if stay is None:
			return None
		return stay.format (
			include_procedures = True,
			include_docs = True
		)

	#-----------------------------------------
	def edit(stay=None):
		return edit_hospital_stay(parent = parent, hospital_stay = stay)

	#-----------------------------------------
	def delete(stay=None):
		if gmEMRStructItems.delete_hospital_stay(stay = stay['pk_hospital_stay']):
			return True
		gmDispatcher.send (
			signal = 'statustext',
			msg = _('Cannot delete hospitalization.'),
			beep = True
		)
		return False

	#-----------------------------------------
	def refresh(lctrl):
		stays = emr.get_hospital_stays()
		items = [
			[
				s['admission'].strftime('%Y-%m-%d'),
				gmTools.coalesce(s['discharge'], '', function_initial = ('strftime', '%Y-%m-%d')),
				s['episode'],
				'%s @ %s' % (s['ward'], s['hospital'])
			] for s in stays
		]
		lctrl.set_string_items(items = items)
		lctrl.set_data(data = stays)
	#-----------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _("The patient's hospitalizations:\n"),
		caption = _('Editing hospitalizations ...'),
		columns = [_('Admission'), _('Discharge'), _('Reason'), _('Hospital')],
		single_selection = True,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh,
		list_tooltip_callback = get_tooltip
	)
示例#9
0
def manage_data_packs(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #--------------------------------------------
    def validate_url(url):
        return True, url

    #--------------------------------------------
    def configure_dpl_url(item):
        gmCfgWidgets.configure_string_option(
            parent=parent,
            message=_('Please enter the URL under which to load\n'
                      'the list of available data packs.\n'
                      '\n'
                      'The default URL is:\n'
                      '\n'
                      ' [%s]\n') % default_dpl_url,
            option=dpl_url_option,
            bias=u'workplace',
            default_value=default_dpl_url,
            validator=validate_url)
        return True

    #--------------------------------------------
    def refresh(lctrl):
        items, data = load_data_packs_list()
        lctrl.set_string_items(items)
        lctrl.set_data(data)

    #--------------------------------------------
    lb_tt = _('Install the selected data pack.\n'
              '\n'
              'This can take quite a while depending on\n'
              'the amount of data to be installed.\n'
              '\n'
              'GNUmed will block until installation is\n'
              'complete and eventually inform you of\n'
              'success or failure.')
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('Data packs available for installation into this v%s database.\n'
              ) % (_cfg.get(option='database_version')),
        caption=_('Showing data packs.'),
        columns=[_('Data pack'),
                 _('min DB'),
                 _('max DB'),
                 _('Source')],
        single_selection=True,
        can_return_empty=False,
        ignore_OK_button=True,
        refresh_callback=refresh,
        left_extra_button=(_('&Install'), lb_tt, install_data_pack),
        #		middle_extra_button=None,
        right_extra_button=(_('&Configure'),
                            _('Configure the data packs list source'),
                            configure_dpl_url))
示例#10
0
def manage_suppressed_hints(parent=None, pk_identity=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def get_tooltip(item):
		if item is None:
			return None
		return item.format()
	#------------------------------------------------------------
	def manage_hints(item):
		manage_dynamic_hints(parent = parent)
		return True
	#------------------------------------------------------------
	def del_hint(hint=None):
		if hint is None:
			return False
		really_delete = gmGuiHelpers.gm_show_question (
			title = _('Deleting suppressed dynamic hint'),
			question = _('Really delete the suppression of this dynamic hint ?\n\n [%s]') % hint['title']
		)
		if not really_delete:
			return False
		gmAutoHints.delete_suppressed_hint(pk_suppressed_hint = hint['pk_suppressed_hint'])
		return True
	#------------------------------------------------------------
	def refresh(lctrl):
		hints = gmAutoHints.get_suppressed_hints(pk_identity = pk_identity, order_by = u'title')
		items = [ [
			h['title'],
			gmDateTime.pydt_strftime(h['suppressed_when'], '%Y %b %d'),
			h['suppressed_by'],
			h['rationale'],
			gmTools.bool2subst(h['is_active'], gmTools.u_checkmark_thin, u''),
			h['source'][:30],
			gmTools.coalesce(h['url'], u'')[:60],
			h['pk_hint']
		] for h in hints ]
		lctrl.set_string_items(items)
		lctrl.set_data(hints)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nDynamic hints suppressed in this patient.\n'),
		caption = _('Showing suppressed dynamic hints.'),
		columns = [ _('Title'), _('When'), _('By'), _('Rationale'), _('Active'), _('Source'), u'URL', u'Hint #' ],
		single_selection = True,
		ignore_OK_button = True,
		refresh_callback = refresh,
		delete_callback = del_hint,
		right_extra_button = (
			_('Manage hints'),
			_('Manage automatic dynamic hints'),
			manage_hints
		),
		list_tooltip_callback = get_tooltip
	)
示例#11
0
def manage_family_history(parent=None):

	pat = gmPerson.gmCurrentPatient()
	emr = pat.emr

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#-----------------------------------------
	def edit(family_history=None):
		return edit_family_history(parent = parent, family_history = family_history)
	#-----------------------------------------
	def delete(family_history=None):
		if gmFamilyHistory.delete_family_history(pk_family_history = family_history['pk_family_history']):
			return True

		gmDispatcher.send (
			signal = 'statustext',
			msg = _('Cannot delete family history item.'),
			beep = True
		)
		return False
	#------------------------------------------------------------
	def refresh(lctrl):
		fhx = emr.get_family_history()
		items = [ [
			f['l10n_relation'],
			f['condition'],
			gmTools.bool2subst(f['contributed_to_death'], _('yes'), _('no'), '?'),
			gmTools.coalesce(f['age_noted'], ''),
			gmDateTime.format_interval (
				interval = f['age_of_death'],
				accuracy_wanted = gmDateTime.acc_years,
				none_string = ''
			),
			gmTools.coalesce(f['name_relative'], ''),
			gmTools.coalesce(f['dob_relative'], '', function_initial = ('strftime', '%Y-%m-%d'))
		] for f in fhx ]
		lctrl.set_string_items(items)
		lctrl.set_data(fhx)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('Family history of this patient.'),
		caption = _('Showing family history.'),
		columns = [ _('Relationship'), _('Condition'), _('Fatal'), _('Noted'), _('Died'), _('Name'), _('Born') ],
		single_selection = True,
		can_return_empty = True,
		ignore_OK_button = True,
		refresh_callback = refresh,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete
#		left_extra_button=None,
#		middle_extra_button=None,
#		right_extra_button=None
	)
示例#12
0
def manage_suppressed_hints(parent=None, pk_identity=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def get_tooltip(item):
		if item is None:
			return None
		return item.format()
	#------------------------------------------------------------
	def manage_hints(item):
		manage_dynamic_hints(parent = parent)
		return True
	#------------------------------------------------------------
	def del_hint(hint=None):
		if hint is None:
			return False
		really_delete = gmGuiHelpers.gm_show_question (
			title = _('Deleting suppressed dynamic hint'),
			question = _('Really delete the suppression of this dynamic hint ?\n\n [%s]') % hint['title']
		)
		if not really_delete:
			return False
		gmAutoHints.delete_suppressed_hint(pk_suppressed_hint = hint['pk_suppressed_hint'])
		return True
	#------------------------------------------------------------
	def refresh(lctrl):
		hints = gmAutoHints.get_suppressed_hints(pk_identity = pk_identity, order_by = 'title')
		items = [ [
			h['title'],
			gmDateTime.pydt_strftime(h['suppressed_when'], '%Y %b %d'),
			h['suppressed_by'],
			h['rationale'],
			gmTools.bool2subst(h['is_active'], gmTools.u_checkmark_thin, ''),
			h['source'][:30],
			gmTools.coalesce(h['url'], '')[:60],
			h['pk_hint']
		] for h in hints ]
		lctrl.set_string_items(items)
		lctrl.set_data(hints)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nDynamic hints suppressed in this patient.\n'),
		caption = _('Showing suppressed dynamic hints.'),
		columns = [ _('Title'), _('When'), _('By'), _('Rationale'), _('Active'), _('Source'), 'URL', 'Hint #' ],
		single_selection = True,
		ignore_OK_button = True,
		refresh_callback = refresh,
		delete_callback = del_hint,
		right_extra_button = (
			_('Manage hints'),
			_('Manage automatic dynamic hints'),
			manage_hints
		),
		list_tooltip_callback = get_tooltip
	)
示例#13
0
def manage_hospital_stays(parent=None):

    pat = gmPerson.gmCurrentPatient()
    emr = pat.emr

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #-----------------------------------------
    def get_tooltip(stay=None):
        if stay is None:
            return None
        return stay.format(include_procedures=True, include_docs=True)

    #-----------------------------------------
    def edit(stay=None):
        return edit_hospital_stay(parent=parent, hospital_stay=stay)

    #-----------------------------------------
    def delete(stay=None):
        if gmEMRStructItems.delete_hospital_stay(
                stay=stay['pk_hospital_stay']):
            return True
        gmDispatcher.send(signal='statustext',
                          msg=_('Cannot delete hospitalization.'),
                          beep=True)
        return False

    #-----------------------------------------
    def refresh(lctrl):
        stays = emr.get_hospital_stays()
        items = [[
            s['admission'].strftime('%Y-%m-%d'),
            gmTools.coalesce(s['discharge'],
                             '',
                             function_initial=('strftime', '%Y-%m-%d')),
            s['episode'],
            '%s @ %s' % (s['ward'], s['hospital'])
        ] for s in stays]
        lctrl.set_string_items(items=items)
        lctrl.set_data(data=stays)

    #-----------------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_("The patient's hospitalizations:\n"),
        caption=_('Editing hospitalizations ...'),
        columns=[_('Admission'),
                 _('Discharge'),
                 _('Reason'),
                 _('Hospital')],
        single_selection=True,
        edit_callback=edit,
        new_callback=edit,
        delete_callback=delete,
        refresh_callback=refresh,
        list_tooltip_callback=get_tooltip)
示例#14
0
def manage_family_history(parent=None):

	pat = gmPerson.gmCurrentPatient()
	emr = pat.get_emr()

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#-----------------------------------------
	def edit(family_history=None):
		return edit_family_history(parent = parent, family_history = family_history)
	#-----------------------------------------
	def delete(family_history=None):
		if gmFamilyHistory.delete_family_history(pk_family_history = family_history['pk_family_history']):
			return True

		gmDispatcher.send (
			signal = u'statustext',
			msg = _('Cannot delete family history item.'),
			beep = True
		)
		return False
	#------------------------------------------------------------
	def refresh(lctrl):
		fhx = emr.get_family_history()
		items = [ [
			f['l10n_relation'],
			f['condition'],
			gmTools.bool2subst(f['contributed_to_death'], _('yes'), _('no'), u'?'),
			gmTools.coalesce(f['age_noted'], u''),
			gmDateTime.format_interval (
				interval = f['age_of_death'],
				accuracy_wanted = gmDateTime.acc_years,
				none_string = u''
			),
			gmTools.coalesce(f['name_relative'], u''),
			gmTools.coalesce(f['dob_relative'], u'', function_initial = ('strftime', '%Y-%m-%d'))
		] for f in fhx ]
		lctrl.set_string_items(items)
		lctrl.set_data(fhx)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('Family history of this patient.'),
		caption = _('Showing family history.'),
		columns = [ _('Relationship'), _('Condition'), _('Fatal'), _('Noted'), _('Died'), _('Name'), _('Born') ],
		single_selection = True,
		can_return_empty = True,
		ignore_OK_button = True,
		refresh_callback = refresh,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete
#		left_extra_button=None,
#		middle_extra_button=None,
#		right_extra_button=None
	)
def configure_keyword_text_expansion(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #----------------------
    def delete(expansion=None):
        gmKeywordExpansion.delete_keyword_expansion(
            pk=expansion['pk_expansion'])
        return True

    #----------------------
    def edit(expansion=None):
        ea = cTextExpansionEditAreaPnl(parent, -1, expansion=expansion)
        dlg = gmEditArea.cGenericEditAreaDlg2(parent, -1, edit_area=ea)
        if expansion is None:
            title = _('Adding keyword expansion')
        else:
            title = _('Editing keyword expansion "%s"') % expansion['keyword']
        dlg.SetTitle(title)
        if dlg.ShowModal() == wx.ID_OK:
            return True

        return False

    #----------------------
    def tooltip(expansion):
        return expansion.format()

    #----------------------
    def refresh(lctrl=None):
        expansions = gmKeywordExpansion.get_keyword_expansions(
            order_by=u'is_textual DESC, keyword, public_expansion',
            force_reload=True)
        items = [[
            e['keyword'],
            gmTools.bool2subst(e['is_textual'], _('text'), _('data')),
            gmTools.bool2subst(e['public_expansion'], _('public'),
                               _('private'))
        ] for e in expansions]
        lctrl.set_string_items(items)
        lctrl.set_data(expansions)

    #----------------------

    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('\nSelect the keyword you want to edit !\n'),
        caption=_('Editing keyword-based expansions ...'),
        columns=[_('Keyword'), _('Type'), _('Scope')],
        single_selection=True,
        edit_callback=edit,
        new_callback=edit,
        delete_callback=delete,
        refresh_callback=refresh,
        list_tooltip_callback=tooltip)
示例#16
0
def configure_keyword_text_expansion(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#----------------------
	def delete(expansion=None):
		gmKeywordExpansion.delete_keyword_expansion(pk = expansion['pk_expansion'])
		return True
	#----------------------
	def edit(expansion=None):
		ea = cTextExpansionEditAreaPnl(parent, -1, expansion = expansion)
		dlg = gmEditArea.cGenericEditAreaDlg2(parent, -1, edit_area = ea)
		if expansion is None:
			title = _('Adding keyword expansion')
		else:
			title = _('Editing keyword expansion "%s"') % expansion['keyword']
		dlg.SetTitle(title)
		if dlg.ShowModal() == wx.ID_OK:
			return True

		return False
	#----------------------
	def tooltip(expansion):
		return expansion.format()
	#----------------------
	def refresh(lctrl=None):
		expansions = gmKeywordExpansion.get_keyword_expansions(order_by = 'is_textual DESC, keyword, public_expansion', force_reload = True)
		items = [[
				e['keyword'],
				gmTools.bool2subst(e['is_textual'], _('text'), _('data')),
				gmTools.bool2subst(e['public_expansion'], _('public'), _('private'))
			] for e in expansions
		]
		lctrl.set_string_items(items)
		lctrl.set_data(expansions)
	#----------------------

	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('\nSelect the keyword you want to edit !\n'),
		caption = _('Editing keyword-based expansions ...'),
		columns = [_('Keyword'), _('Type'), _('Scope')],
		single_selection = True,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh,
		list_tooltip_callback = tooltip
	)
示例#17
0
    def _on_visualize_button_pressed(self, evt):

        try:
            # better fail early
            import Gnuplot
        except ImportError:
            gmGuiHelpers.gm_show_info(
                aMessage=_('Cannot import "Gnuplot" python module.'),
                aTitle=_('Query result visualizer'))
            return

        x_col = gmListWidgets.get_choices_from_list(
            parent=self,
            msg=_('Choose a column to be used as the X-Axis:'),
            caption=_('Choose column from query results ...'),
            choices=self.query_results[0].keys(),
            columns=[_('Column name')],
            single_selection=True)
        if x_col is None:
            return

        y_col = gmListWidgets.get_choices_from_list(
            parent=self,
            msg=_('Choose a column to be used as the Y-Axis:'),
            caption=_('Choose column from query results ...'),
            choices=self.query_results[0].keys(),
            columns=[_('Column name')],
            single_selection=True)
        if y_col is None:
            return

        # FIXME: support debugging (debug=1) depending on --debug
        gp = Gnuplot.Gnuplot(persist=1)
        if self._PRW_report_name.GetValue().strip() != '':
            gp.title(
                _('GNUmed report: %s') %
                self._PRW_report_name.GetValue().strip()[:40])
        else:
            gp.title(_('GNUmed report results'))
        gp.xlabel(x_col)
        gp.ylabel(y_col)
        try:
            gp.plot([[r[x_col], r[y_col]] for r in self.query_results])
        except Exception:
            _log.exception('unable to plot results from [%s:%s]' %
                           (x_col, y_col))
            gmDispatcher.send(signal='statustext',
                              msg=_('Error plotting data.'),
                              beep=True)
示例#18
0
def manage_reminders(parent=None, patient=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
    #------------------------------------------------------------
    def refresh(lctrl):
        reminders = gmProviderInbox.get_reminders(pk_patient=patient)
        items = [[
            gmTools.bool2subst(r['is_overdue'], _('overdue for %s'),
                               _('due in %s')) %
            gmDateTime.format_interval_medically(r['interval_due']),
            r['comment'], r['pk_inbox_message']
        ] for r in reminders]
        lctrl.set_string_items(items)
        lctrl.set_data(reminders)

    #------------------------------------------------------------
    return gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=None,
        caption=_('Reminders for the current patient'),
        columns=[_('Status'), _('Subject'), '#'],
        single_selection=False,
        can_return_empty=True,
        ignore_OK_button=False,
        refresh_callback=refresh
        #		edit_callback=None,
        #		new_callback=None,
        #		delete_callback=None,
        #		left_extra_button=None,
        #		middle_extra_button=None,
        #		right_extra_button=None
    )
示例#19
0
def select_address(missing=None, person=None):

    #--------------------------
    def calculate_tooltip(adr):
        return u'\n'.join(adr.format())

    #--------------------------
    addresses = person.get_addresses()
    if len(addresses) == 0:
        return None

    msg = _(
        'There is no [%s] address registered with this patient.\n\n'
        'Please select the address you would like to use instead:') % missing
    choices = [[
        a['l10n_address_type'],
        u'%s %s%s, %s %s, %s' %
        (a['street'], a['number'], gmTools.coalesce(a['subunit'], u'', u'/%s'),
         a['postcode'], a['urb'], a['l10n_country'])
    ] for a in addresses]

    return gmListWidgets.get_choices_from_list(
        msg=msg,
        caption=_('Selecting address by type'),
        columns=[_('Type'), _('Address')],
        choices=choices,
        data=addresses,
        single_selection=True,
        list_tooltip_callback=calculate_tooltip)
示例#20
0
def manage_reminders(parent=None, patient=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def refresh(lctrl):
		reminders = gmProviderInbox.get_reminders(pk_patient = patient)
		items = [ [
			gmTools.bool2subst (
				r['is_overdue'],
				_('overdue for %s'),
				_('due in %s')
			) % gmDateTime.format_interval_medically(r['interval_due']),
			r['comment'],
			r['pk_inbox_message']
		] for r in reminders ]
		lctrl.set_string_items(items)
		lctrl.set_data(reminders)
	#------------------------------------------------------------
	return gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = None,
		caption = _('Reminders for the current patient'),
		columns = [ _('Status'), _('Subject'), '#' ],
		single_selection = False,
		can_return_empty = True,
		ignore_OK_button = False,
		refresh_callback = refresh
#		edit_callback=None,
#		new_callback=None,
#		delete_callback=None,
#		left_extra_button=None,
#		middle_extra_button=None,
#		right_extra_button=None
	)
示例#21
0
	def _on_visualize_button_pressed(self, evt):

		try:
			# better fail early
			import Gnuplot
		except ImportError:
			gmGuiHelpers.gm_show_info (
				aMessage = _('Cannot import "Gnuplot" python module.'),
				aTitle = _('Query result visualizer')
			)
			return

		x_col = gmListWidgets.get_choices_from_list (
			parent = self,
			msg = _('Choose a column to be used as the X-Axis:'),
			caption = _('Choose column from query results ...'),
			choices = self.query_results[0].keys(),
			columns = [_('Column name')],
			single_selection = True
		)
		if x_col is None:
			return

		y_col = gmListWidgets.get_choices_from_list (
			parent = self,
			msg = _('Choose a column to be used as the Y-Axis:'),
			caption = _('Choose column from query results ...'),
			choices = self.query_results[0].keys(),
			columns = [_('Column name')],
			single_selection = True
		)
		if y_col is None:
			return

		# FIXME: support debugging (debug=1) depending on --debug
		gp = Gnuplot.Gnuplot(persist=1)
		if self._PRW_report_name.GetValue().strip() != '':
			gp.title(_('GNUmed report: %s') % self._PRW_report_name.GetValue().strip()[:40])
		else:
			gp.title(_('GNUmed report results'))
		gp.xlabel(x_col)
		gp.ylabel(y_col)
		try:
			gp.plot([ [r[x_col], r[y_col]] for r in self.query_results ])
		except Exception:
			_log.exception('unable to plot results from [%s:%s]' % (x_col, y_col))
			gmDispatcher.send(signal = 'statustext', msg = _('Error plotting data.'), beep = True)
示例#22
0
def manage_substance_abuse(parent=None, patient=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

#	#------------------------------------------------------------
#	def add_from_db(substance):
#		drug_db = get_drug_database(parent = parent, patient = gmPerson.gmCurrentPatient())
#		if drug_db is None:
#			return False
#		drug_db.import_drugs()
#		return True
#	#------------------------------------------------------------

    def edit(intake=None):
        return edit_substance_abuse(parent=parent,
                                    intake=intake,
                                    patient=patient)

    #------------------------------------------------------------
    def delete(intake):
        return intake.delete()

    #------------------------------------------------------------
    def get_tooltip(intake=None):
        return intake.format(single_line=False)

    #------------------------------------------------------------
    def refresh(lctrl):
        intakes = patient.emr.abused_substances
        items = []
        for i in intakes:
            items.append([
                i['substance'], i.harmful_use_type_string,
                gmDateTime.pydt_strftime(i['last_checked_when'],
                                         '%b %Y',
                                         none_str='')
            ])
        lctrl.set_string_items(items)
        lctrl.set_data(intakes)

    #------------------------------------------------------------
    if len(patient.emr.abused_substances) == 0:
        edit()

    msg = _('Substances abused by the patient:')

    return gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Showing abused substances.'),
        columns=[_('Intake'), _('Status'),
                 _('Last confirmed')],
        single_selection=False,
        new_callback=edit,
        edit_callback=edit,
        delete_callback=delete,
        refresh_callback=refresh,
        list_tooltip_callback=get_tooltip)
示例#23
0
def manage_external_care(parent=None):

	pat = gmPerson.gmCurrentPatient()
	emr = pat.get_emr()

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#-----------------------------------------
	def edit(external_care_item=None):
		return edit_external_care_item(parent = parent, external_care_item = external_care_item)
	#-----------------------------------------
	def delete(external_care_item=None):
		if gmExternalCare.delete_external_care_item(pk_external_care = external_care_item['pk_external_care']):
			return True

		gmDispatcher.send (
			signal = u'statustext',
			msg = _('Cannot delete external care item.'),
			beep = True
		)
		return False
	#------------------------------------------------------------
	def get_tooltip(data):
		if data is None:
			return None
		return u'\n'.join(data.format(with_health_issue = True))
	#------------------------------------------------------------
	def refresh(lctrl):
		care = emr.get_external_care_items(order_by = u'issue, provider, unit, organization')
		items = [ [
			u'%s @ %s' % (
				c['unit'],
				c['organization']
			),
			gmTools.coalesce(c['provider'], u''),
			c['issue'],
			gmTools.coalesce(c['comment'], u'')
		] for c in care ]
		lctrl.set_string_items(items)
		lctrl.set_data(care)
	#------------------------------------------------------------
	return gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('External care of this patient.'),
		caption = _('Showing external care network.'),
		columns = [ _('Location'), _('Provider'), _('Care issue'), _('Comment') ],
		single_selection = False,
		can_return_empty = True,
		ignore_OK_button = False,
		refresh_callback = refresh,
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		list_tooltip_callback = get_tooltip
#		left_extra_button=None,		# manage orgs
#		middle_extra_button=None,	# manage issues
#		right_extra_button=None
	)
示例#24
0
    def edit_old(workplace=None):

        available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui')

        dbcfg = gmCfg.cCfgSQL()

        if workplace is None:
            dlg = wx.TextEntryDialog(
                parent=parent,
                message=_('Enter a descriptive name for the new workplace:'),
                caption=_('Configuring GNUmed workplaces ...'),
                defaultValue=u'',
                style=wx.OK | wx.CENTRE)
            dlg.ShowModal()
            workplace = dlg.GetValue().strip()
            if workplace == u'':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new workplace without a name.'),
                    _('Configuring GNUmed workplaces ...'))
                return False
            curr_plugins = []
            choices = available_plugins
        else:
            curr_plugins = gmTools.coalesce(
                dbcfg.get2(option=u'horstspace.notebook.plugin_load_order',
                           workplace=workplace,
                           bias='workplace'), [])
            choices = curr_plugins[:]
            for p in available_plugins:
                if p not in choices:
                    choices.append(p)

        sels = range(len(curr_plugins))
        new_plugins = gmListWidgets.get_choices_from_list(
            parent=parent,
            msg=_('\n'
                  'Select the plugin(s) to be loaded the next time\n'
                  'the client is restarted under the workplace:\n'
                  '\n'
                  ' [%s]'
                  '\n') % workplace,
            caption=_('Configuring GNUmed workplaces ...'),
            choices=choices,
            selections=sels,
            columns=[_('Plugins')],
            single_selection=False)

        if new_plugins == curr_plugins:
            return True

        if new_plugins is None:
            return True

        dbcfg.set(option=u'horstspace.notebook.plugin_load_order',
                  value=new_plugins,
                  workplace=workplace)

        return True
示例#25
0
def expand_keyword(parent=None, keyword=None, show_list=False):
	"""Expand keyword and replace inside it.

	Returns:
		None: aborted or no expansion available
		u'': empty expansion
		u'<text>' the expansion
	"""
	if keyword is None:
		return None

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if show_list:
		candidates = gmKeywordExpansion.get_matching_textual_keywords(fragment = keyword)
		if len(candidates) == 0:
			return None
		if len(candidates) == 1:
			keyword = candidates[0]
		else:
			keyword = gmListWidgets.get_choices_from_list (
				parent = parent,
				msg = _(
					'Several macro keywords match the fragment [%s].\n'
					'\n'
					'Please select the expansion you want to happen.'
				) % keyword,
				caption = _('Selecting text macro'),
				choices = candidates,
				columns = [_('Keyword')],
				single_selection = True,
				can_return_empty = False
			)
			if keyword is None:
				return None

	expansion = gmKeywordExpansion.expand_keyword(keyword = keyword)

	# not found
	if expansion is None:
		return None

	# no replacement necessary:
	if expansion.strip() == u'':
		return expansion

	if regex.search(_text_expansion_fillin_regex, expansion) is not None:
		dlg = cTextExpansionFillInDlg(None, -1)
		dlg.keyword = keyword
		dlg.expansion = expansion
		button = dlg.ShowModal()
		if button == wx.ID_OK:
			expansion = dlg.filled_in_expansion
		dlg.Destroy()

	return expansion
示例#26
0
    def __get_patient_pk_data_key(self, data=None):
        if self.data is None:
            return None

        if len(self.data) == 0:
            return None

        if data is None:
            data = self.get_selected_item_data(only_one=True)

        if data is None:
            data = self.get_item_data(item_idx=0)

        if data is None:
            return None

        if self.patient_key is not None:
            try:
                data[self.patient_key]
                return self.patient_key
            except (KeyError, IndexError, TypeError):
                # programming error
                _log.error('misconfigured identifier column <%s>',
                           self.patient_key)

        _log.debug('identifier column not configured, trying to detect')

        if 'pk_patient' in data:
            return 'pk_patient'

        if 'fk_patient' in data:
            return 'fk_patient'

        if 'pk_identity' in data:
            return 'pk_identity'

        if 'fk_identity' in data:
            return 'fk_identity'

        if 'id_identity' in data:
            return 'id_identity'

        return gmListWidgets.get_choices_from_list(
            parent=self,
            msg=
            _('The report result list does not contain any of the following columns:\n'
              '\n'
              ' <%s> / pk_patient / fk_patient\n'
              ' pk_identity / fk_identity / id_identity\n'
              '\n'
              'Select the column which contains patient IDs:\n') %
            self.patient_key,
            caption=_('Choose column from query results ...'),
            choices=data.keys(),
            columns=[_('Column name')],
            single_selection=True)
示例#27
0
	def __get_patient_pk_data_key(self, data=None):
		if self.data is None:
			return None

		if len(self.data) == 0:
			return None

		if data is None:
			data = self.get_selected_item_data(only_one = True)

		if data is None:
			data = self.get_item_data(item_idx = 0)

		if data is None:
			return None

		if self.patient_key is not None:
			try:
				data[self.patient_key]
				return self.patient_key
			except (KeyError, IndexError, TypeError):
				# programming error
				_log.error('misconfigured identifier column <%s>', self.patient_key)

		_log.debug('identifier column not configured, trying to detect')

		if 'pk_patient' in data:
			return 'pk_patient'

		if 'fk_patient' in data:
			return 'fk_patient'

		if 'pk_identity' in data:
			return 'pk_identity'

		if 'fk_identity' in data:
			return 'fk_identity'

		if 'id_identity' in data:
			return 'id_identity'

		return gmListWidgets.get_choices_from_list (
			parent = self,
			msg = _(
				'The report result list does not contain any of the following columns:\n'
				'\n'
				' <%s> / pk_patient / fk_patient\n'
				' pk_identity / fk_identity / id_identity\n'
				'\n'
				'Select the column which contains patient IDs:\n'
			) % self.patient_key,
			caption = _('Choose column from query results ...'),
			choices = data.keys(),
			columns = [_('Column name')],
			single_selection = True
		)
示例#28
0
def expand_keyword(parent=None, keyword=None, show_list_if_needed=False):
	"""Expand keyword and replace inside it.

	Returns:
		None: aborted or no expansion available
		u'': empty expansion
		u'<text>' the expansion
	"""
	if keyword is None:
		return None
	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if show_list_if_needed:
		candidates = gmKeywordExpansion.get_matching_textual_keywords(fragment = keyword)
		if len(candidates) == 0:
			return None
		if len(candidates) == 1:
			keyword = candidates[0]
		else:
			keyword = gmListWidgets.get_choices_from_list (
				parent = parent,
				msg = _(
					'Several macro keywords match the fragment [%s].\n'
					'\n'
					'Please select the expansion you want to happen.'
				) % keyword,
				caption = _('Selecting text macro'),
				choices = candidates,
				columns = [_('Keyword')],
				single_selection = True,
				can_return_empty = False
			)
			if keyword is None:
				return None

	expansion = gmKeywordExpansion.expand_keyword(keyword = keyword)

	# not found
	if expansion is None:
		return None

	# no replacement necessary:
	if expansion.strip() == '':
		return expansion

	if regex.search(_text_expansion_fillin_regex, expansion) is not None:
		dlg = cTextExpansionFillInDlg(None, -1)
		dlg.keyword = keyword
		dlg.expansion = expansion
		button = dlg.ShowModal()
		if button == wx.ID_OK:
			expansion = dlg.filled_in_expansion
		dlg.Destroy()

	return expansion
示例#29
0
def manage_form_templates(parent=None,
                          template_types=None,
                          active_only=False,
                          excluded_types=None,
                          msg=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #-------------------------
    def edit(template=None):
        return edit_template(parent=parent, template=template)

    #-------------------------
    def delete(template):
        delete = gmGuiHelpers.gm_show_question(
            aTitle=_('Deleting form template.'),
            aMessage=_('Are you sure you want to delete\n'
                       'the following form template ?\n\n'
                       ' "%s (%s)"\n\n'
                       'You can only delete templates which\n'
                       'have not yet been used to generate\n'
                       'any forms from.') %
            (template['name_long'], template['external_version']))
        if delete:
            # FIXME: make this a priviledged operation ?
            gmForms.delete_form_template(template=template)
            return True
        return False

    #-------------------------
    def refresh(lctrl):
        templates = gmForms.get_form_templates(active_only=active_only,
                                               template_types=template_types,
                                               excluded_types=excluded_types)
        lctrl.set_string_items(items=[[
            t['name_long'], t['external_version'], gmForms.form_engine_names[
                t['engine']]
        ] for t in templates])
        lctrl.set_data(data=templates)

    #-------------------------
    template = gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Select letter or form template.'),
        columns=[_('Template'), _('Version'),
                 _('Type')],
        edit_callback=edit,
        new_callback=edit,
        delete_callback=delete,
        refresh_callback=refresh,
        single_selection=True)

    return template
示例#30
0
def configure_string_from_list_option(parent=None,
                                      message=None,
                                      option=None,
                                      bias='user',
                                      default_value='',
                                      choices=None,
                                      columns=None,
                                      data=None,
                                      caption=None):

    dbcfg = gmCfg.cCfgSQL()

    current_value = dbcfg.get2(
        option=option,
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        bias=bias,
        default=default_value)

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    if caption is None:
        caption = _('Configuration')

    selections = None
    if current_value is not None:
        try:
            selections = [choices.index(current_value)]
        except ValueError:
            pass

    choice = gmListWidgets.get_choices_from_list(parent=parent,
                                                 msg=message,
                                                 caption=caption,
                                                 choices=choices,
                                                 columns=columns,
                                                 data=data,
                                                 selections=selections,
                                                 single_selection=True,
                                                 can_return_empty=False)

    # aborted
    if choice is None:
        return

    # same value selected again
    if choice == current_value:
        return

    dbcfg = gmCfg.cCfgSQL()
    dbcfg.set(workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
              option=option,
              value=choice)

    return
示例#31
0
def manage_substance_abuse(parent=None, patient=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

#	#------------------------------------------------------------
#	def add_from_db(substance):
#		drug_db = get_drug_database(parent = parent, patient = gmPerson.gmCurrentPatient())
#		if drug_db is None:
#			return False
#		drug_db.import_drugs()
#		return True
#	#------------------------------------------------------------
	def edit(intake=None):
		return edit_substance_abuse(parent = parent, intake = intake, patient = patient)

	#------------------------------------------------------------
	def delete(intake):
		return intake.delete()

	#------------------------------------------------------------
	def get_tooltip(intake=None):
		return intake.format(single_line = False)

	#------------------------------------------------------------
	def refresh(lctrl):
		intakes = patient.emr.abused_substances
		items = []
		for i in intakes:
			items.append ([
				i['substance'],
				i.harmful_use_type_string,
				gmDateTime.pydt_strftime(i['last_checked_when'], '%b %Y', none_str = '')
			])
		lctrl.set_string_items(items)
		lctrl.set_data(intakes)

	#------------------------------------------------------------
	if len(patient.emr.abused_substances) == 0:
		edit()

	msg = _('Substances abused by the patient:')

	return gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Showing abused substances.'),
		columns = [ _('Intake'), _('Status'), _('Last confirmed') ],
		single_selection = False,
		new_callback = edit,
		edit_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh,
		list_tooltip_callback = get_tooltip
	)
示例#32
0
def browse_coded_terms(parent=None, coding_systems=None, languages=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
    #------------------------------------------------------------
    def refresh(lctrl):
        coded_terms = gmCoding.get_coded_terms(
            coding_systems=coding_systems,
            languages=languages,
            order_by='term, coding_system, code')
        items = [[
            ct['term'], ct['code'], ct['coding_system'],
            gmTools.coalesce(ct['lang'], ''), ct['version'],
            ct['coding_system_long']
        ] for ct in coded_terms]
        lctrl.set_string_items(items)
        lctrl.set_data(coded_terms)

    #------------------------------------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('Coded terms known to GNUmed (may take a while to load).'),
        caption=_('Showing coded terms.'),
        columns=[
            _('Term'),
            _('Code'),
            _('System'),
            _('Language'),
            _('Version'),
            _('Coding system details')
        ],
        single_selection=True,
        can_return_empty=True,
        ignore_OK_button=True,
        refresh_callback=refresh
        #		edit_callback=None,
        #		new_callback=None,
        #		delete_callback=None,
        #		left_extra_button=None,
        #		middle_extra_button=None,
        #		right_extra_button=None
    )
示例#33
0
def show_audit_trail(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    conn = gmAuthWidgets.get_dbowner_connection(
        procedure=_('showing audit trail'))
    if conn is None:
        return False

    #-----------------------------------
    def refresh(lctrl):
        cmd = u'SELECT * FROM audit.v_audit_trail ORDER BY audit_when_ts'
        rows, idx = gmPG2.run_ro_queries(link_obj=conn,
                                         queries=[{
                                             'cmd': cmd
                                         }],
                                         get_col_idx=False)
        lctrl.set_string_items([[
            r['event_when'], r['event_by'],
            u'%s %s %s' %
            (gmTools.coalesce(r['row_version_before'],
                              gmTools.u_diameter), gmTools.u_arrow2right,
             gmTools.coalesce(r['row_version_after'], gmTools.u_diameter)),
            r['event_table'], r['event'], r['pk_audit']
        ] for r in rows])

    #-----------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=u'',
        caption=_('GNUmed database audit log ...'),
        columns=[
            _('When'),
            _('Who'),
            _('Revisions'),
            _('Table'),
            _('Event'), '#'
        ],
        single_selection=True,
        refresh_callback=refresh)
示例#34
0
	def __replace_keyword_with_expansion(self, keyword=None, position=None, show_list=False):

		expansion = expand_keyword(parent = self, keyword = keyword, show_list = show_list)

		if expansion is None:
			return

		if expansion == u'':
			return

		if not self.IsMultiLine():
			expansion_lines = gmTools.strip_leading_empty_lines (
				lines = gmTools.strip_trailing_empty_lines (
					text = expansion,
					return_list = True
				),
				return_list = True
			)
			if len(expansion_lines) == 0:
				return
			if len(expansion_lines) == 1:
				expansion = expansion_lines[0]
			else:
				msg = _(
					'The fragment <%s> expands to multiple lines !\n'
					'\n'
					'This text field can hold one line only, hwoever.\n'
					'\n'
					'Please select the line you want to insert:'
				) % keyword
				expansion = gmListWidgets.get_choices_from_list (
					parent = self,
					msg = msg,
					caption = _('Adapting multi-line expansion to single-line text field'),
					choices = expansion_lines,
					selections = [0],
					columns = [_('Keyword expansion lines')],
					single_selection = True,
					can_return_empty = False
				)
				if expansion is None:
					return

		self.Replace (
			position,
			position + len(keyword),
			expansion
		)

		self.SetInsertionPoint(position + len(expansion) + 1)
		self.ShowPosition(position + len(expansion) + 1)

		return
示例#35
0
def manage_regions(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #------------------------------------------------------------
    def delete(region=None):
        return delete_region(parent=parent, region=region['pk_region'])

    #------------------------------------------------------------
    def edit(region=None):
        return edit_region(parent=parent, region=region)

    #------------------------------------------------------------
    def refresh(lctrl):
        wx.BeginBusyCursor()
        provinces = gmDemographicRecord.get_regions()
        lctrl.set_string_items([(p['l10n_country'], p['l10n_region'])
                                for p in provinces])
        lctrl.set_data(provinces)
        wx.EndBusyCursor()

    #------------------------------------------------------------
    msg = _(
        'This list shows the regions known to GNUmed.\n'
        '\n'
        'In your jurisdiction "region" may correspond to either of "state",\n'
        '"county", "province", "territory", "arrondissement", "department,"\n'
        '"prefecture", "kanton", or some such term.\n')

    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Editing regions ...'),
        columns=[_('Country'), _('Region')],
        single_selection=True,
        new_callback=edit,
        #edit_callback = edit,
        delete_callback=delete,
        refresh_callback=refresh)
示例#36
0
def search_narrative_across_emrs(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	search_term_dlg = wx.TextEntryDialog (
		parent,
		_('Enter (regex) term to search for across all EMRs:'),
		caption = _('Text search across all EMRs'),
		style = wx.OK | wx.CANCEL | wx.CENTRE
	)
	result = search_term_dlg.ShowModal()

	if result != wx.ID_OK:
		return

	wx.BeginBusyCursor()
	search_term = search_term_dlg.GetValue()
	search_term_dlg.DestroyLater()
	results = gmClinNarrative.search_text_across_emrs(search_term = search_term)
	wx.EndBusyCursor()

	if len(results) == 0:
		gmGuiHelpers.gm_show_info (
			_(
			'Nothing found for search term:\n'
			' "%s"'
			) % search_term,
			_('Search results')
		)
		return

	items = [ [
		gmPerson.cPerson(aPK_obj = r['pk_patient'])['description_gender'],
		r['narrative'],
		r['src_table']
	] for r in results ]

	selected_patient = gmListWidgets.get_choices_from_list (
		parent = parent,
		caption = _('Search results for [%s]') % search_term,
		choices = items,
		columns = [_('Patient'), _('Match'), _('Match location')],
		data = [ r['pk_patient'] for r in results ],
		single_selection = True,
		can_return_empty = False
	)

	if selected_patient is None:
		return

	wx.CallAfter(set_active_patient, patient = gmPerson.cPerson(aPK_obj = selected_patient))
示例#37
0
def manage_addresses(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#------------------------------------------------------------
	def calculate_tooltip(address):
		return '\n'.join(address.format())
	#------------------------------------------------------------
	def delete(address):
		return gmDemographicRecord.delete_address(pk_address = address['pk_address'])
	#------------------------------------------------------------
	def refresh(lctrl):
		adrs = gmDemographicRecord.get_addresses(order_by = 'l10n_country, urb, street, number, subunit')
		items = [ [
				a['street'],
				gmTools.coalesce(a['notes_street'], ''),
				a['number'],
				gmTools.coalesce(a['subunit'], ''),
				a['postcode'],
				a['urb'],
				gmTools.coalesce(a['suburb'], ''),
				a['l10n_region'],
				a['l10n_country'],
				gmTools.coalesce(a['notes_subunit'], '')
			] for a in adrs
		]
		lctrl.set_string_items(items)
		lctrl.set_data(adrs)

	#------------------------------------------------------------
	cols = [
		_('Street'),
		_('Street info'),
		_('Number'),
		_('Subunit'),
		_('Postal code'),
		_('Community'),
		_('Suburb'),
		_('Region'),
		_('Country'),
		_('Comment')
	]
	return gmListWidgets.get_choices_from_list (
		parent = parent,
		caption = _('Showing addresses registered in GNUmed.'),
		columns = cols,
		single_selection = True,
		refresh_callback = refresh,
		delete_callback = delete,
		list_tooltip_callback = calculate_tooltip
	)
示例#38
0
def search_narrative_across_emrs(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	search_term_dlg = wx.TextEntryDialog (
		parent,
		_('Enter (regex) term to search for across all EMRs:'),
		caption = _('Text search across all EMRs'),
		style = wx.OK | wx.CANCEL | wx.CENTRE
	)
	result = search_term_dlg.ShowModal()

	if result != wx.ID_OK:
		return

	wx.BeginBusyCursor()
	search_term = search_term_dlg.GetValue()
	search_term_dlg.DestroyLater()
	results = gmClinNarrative.search_text_across_emrs(search_term = search_term)
	wx.EndBusyCursor()

	if len(results) == 0:
		gmGuiHelpers.gm_show_info (
			_(
			'Nothing found for search term:\n'
			' "%s"'
			) % search_term,
			_('Search results')
		)
		return

	items = [ [
		gmPerson.cPerson(aPK_obj = r['pk_patient']).description_gender,
		r['narrative'],
		r['src_table']
	] for r in results ]

	selected_patient = gmListWidgets.get_choices_from_list (
		parent = parent,
		caption = _('Search results for [%s]') % search_term,
		choices = items,
		columns = [_('Patient'), _('Match'), _('Match location')],
		data = [ r['pk_patient'] for r in results ],
		single_selection = True,
		can_return_empty = False
	)

	if selected_patient is None:
		return

	wx.CallAfter(set_active_patient, patient = gmPerson.cPerson(aPK_obj = selected_patient))
示例#39
0
def configure_string_from_list_option(parent=None, message=None, option=None, bias='user', default_value='', choices=None, columns=None, data=None, caption=None):

	dbcfg = gmCfg.cCfgSQL()

	current_value = dbcfg.get2 (
		option = option,
		workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
		bias = bias,
		default = default_value
	)

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if caption is None:
		caption = _('Configuration')

	selections = None
	if current_value is not None:
		try:
			selections = [choices.index(current_value)]
		except ValueError:
			pass

	choice = gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = message,
		caption = caption,
		choices = choices,
		columns = columns,
		data = data,
		selections = selections,
		single_selection = True,
		can_return_empty = False
	)

	# aborted
	if choice is None:
		return

	# same value selected again
	if choice == current_value:
		return

	dbcfg = gmCfg.cCfgSQL()
	dbcfg.set (
		workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
		option = option,
		value = choice
	)

	return
示例#40
0
def manage_addresses(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#------------------------------------------------------------
	def calculate_tooltip(address):
		return '\n'.join(address.format())
	#------------------------------------------------------------
	def delete(address):
		return gmDemographicRecord.delete_address(pk_address = address['pk_address'])
	#------------------------------------------------------------
	def refresh(lctrl):
		adrs = gmDemographicRecord.get_addresses(order_by = 'l10n_country, urb, street, number, subunit')
		items = [ [
				a['street'],
				gmTools.coalesce(a['notes_street'], ''),
				a['number'],
				gmTools.coalesce(a['subunit'], ''),
				a['postcode'],
				a['urb'],
				gmTools.coalesce(a['suburb'], ''),
				a['l10n_region'],
				a['l10n_country'],
				gmTools.coalesce(a['notes_subunit'], '')
			] for a in adrs
		]
		lctrl.set_string_items(items)
		lctrl.set_data(adrs)

	#------------------------------------------------------------
	cols = [
		_('Street'),
		_('Street info'),
		_('Number'),
		_('Subunit'),
		_('Postal code'),
		_('Community'),
		_('Suburb'),
		_('Region'),
		_('Country'),
		_('Comment')
	]
	return gmListWidgets.get_choices_from_list (
		parent = parent,
		caption = _('Showing addresses registered in GNUmed.'),
		columns = cols,
		single_selection = True,
		refresh_callback = refresh,
		delete_callback = delete,
		list_tooltip_callback = calculate_tooltip
	)
示例#41
0
	def __replace_keyword_with_expansion(self, keyword=None, position=None, show_list_if_needed=False):

		expansion = expand_keyword(parent = self, keyword = keyword, show_list_if_needed = show_list_if_needed)
		if expansion is None:
			return
		if expansion == '':
			return

		if not self.IsMultiLine():
			expansion_lines = gmTools.strip_leading_empty_lines (
				lines = gmTools.strip_trailing_empty_lines (
					text = expansion,
					return_list = True
				),
				return_list = True
			)
			if len(expansion_lines) == 0:
				return
			if len(expansion_lines) == 1:
				expansion = expansion_lines[0]
			else:
				msg = _(
					'The fragment <%s> expands to multiple lines !\n'
					'\n'
					'This text field can hold one line only, hwoever.\n'
					'\n'
					'Please select the line you want to insert:'
				) % keyword
				expansion = gmListWidgets.get_choices_from_list (
					parent = self,
					msg = msg,
					caption = _('Adapting multi-line expansion to single-line text field'),
					choices = expansion_lines,
					selections = [0],
					columns = [_('Keyword expansion lines')],
					single_selection = True,
					can_return_empty = False
				)
				if expansion is None:
					return

		self.Replace (
			position,
			position + len(keyword),
			expansion
		)

		self.SetInsertionPoint(position + len(expansion) + 1)
		self.ShowPosition(position + len(expansion) + 1)

		return
示例#42
0
def select_narrative(parent=None, soap_cats=None, msg=None):

    pat = gmPerson.gmCurrentPatient()
    emr = pat.emr

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    if soap_cats is None:
        soap_cats = 'soapu'
    soap_cats = list(soap_cats)
    i18n_soap_cats = [
        gmSoapDefs.soap_cat2l10n[cat].upper() for cat in soap_cats
    ]

    if msg is None:
        msg = _('Pick the [%s] narrative you want to use.') % '/'.join(
            i18n_soap_cats)

    #-----------------------------------------------
    def get_tooltip(soap):
        return soap.format(fancy=True, width=60)

    #-----------------------------------------------
    def refresh(lctrl):
        lctrl.secondary_sort_column = 0
        soap = emr.get_clin_narrative(soap_cats=soap_cats)
        lctrl.set_string_items([[
            gmDateTime.pydt_strftime(s['date'], '%Y %m %d'), s['modified_by'],
            gmSoapDefs.soap_cat2l10n[s['soap_cat']], s['narrative'],
            s['episode'], s['health_issue']
        ] for s in soap])
        lctrl.set_data(soap)

    #-----------------------------------------------
    return gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Picking [%s] narrative') % ('/'.join(i18n_soap_cats)),
        columns=[
            _('When'),
            _('Who'),
            _('Type'),
            _('Entry'),
            _('Episode'),
            _('Issue')
        ],
        single_selection=False,
        can_return_empty=False,
        refresh_callback=refresh,
        list_tooltip_callback=get_tooltip)
示例#43
0
def browse_coded_terms(parent=None, coding_systems=None, languages=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def refresh(lctrl):
		coded_terms = gmCoding.get_coded_terms (
			coding_systems = coding_systems,
			languages = languages,
			order_by = 'term, coding_system, code'
		)
		items = [ [
			ct['term'],
			ct['code'],
			ct['coding_system'],
			gmTools.coalesce(ct['lang'], ''),
			ct['version'],
			ct['coding_system_long']
		] for ct in coded_terms ]
		lctrl.set_string_items(items)
		lctrl.set_data(coded_terms)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('Coded terms known to GNUmed (may take a while to load).'),
		caption = _('Showing coded terms.'),
		columns = [ _('Term'), _('Code'), _('System'), _('Language'), _('Version'), _('Coding system details') ],
		single_selection = True,
		can_return_empty = True,
		ignore_OK_button = True,
		refresh_callback = refresh
#		edit_callback=None,
#		new_callback=None,
#		delete_callback=None,
#		left_extra_button=None,
#		middle_extra_button=None,
#		right_extra_button=None
	)
示例#44
0
def browse_data_sources(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
    #------------------------------------------------------------
    def refresh(lctrl):
        srcs = gmCoding.get_data_sources()
        items = [[
            '%s (%s): %s' %
            (s['name_short'], gmTools.coalesce(s['lang'], '?'), s['version']),
            s['name_long'].split('\n')[0].split('\r')[0],
            s['source'].split('\n')[0].split('\r')[0],
            gmTools.coalesce(s['description'],
                             '').split('\n')[0].split('\r')[0], s['pk']
        ] for s in srcs]
        lctrl.set_string_items(items)
        lctrl.set_data(srcs)

    #------------------------------------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('Sources of reference data registered in GNUmed.'),
        caption=_('Showing data sources'),
        columns=[_('System'),
                 _('Name'),
                 _('Source'),
                 _('Description'), '#'],
        single_selection=True,
        can_return_empty=False,
        ignore_OK_button=True,
        refresh_callback=refresh
        #		edit_callback=None,
        #		new_callback=None,
        #		delete_callback=None,
        #		left_extra_button=None,
        #		middle_extra_button=None,
        #		right_extra_button=None
    )
示例#45
0
def manage_regions(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#------------------------------------------------------------
	def delete(region=None):
		return delete_region(parent = parent, region = region['pk_region'])
	#------------------------------------------------------------
	def edit(region=None):
		return edit_region(parent = parent, region = region)
	#------------------------------------------------------------
	def refresh(lctrl):
		wx.BeginBusyCursor()
		provinces = gmDemographicRecord.get_regions()
		lctrl.set_string_items([ (p['l10n_country'], p['l10n_region']) for p in provinces ])
		lctrl.set_data(provinces)
		wx.EndBusyCursor()
	#------------------------------------------------------------
	msg = _(
		'This list shows the regions known to GNUmed.\n'
		'\n'
		'In your jurisdiction "region" may correspond to either of "state",\n'
		'"county", "province", "territory", "arrondissement", "department,"\n'
		'"prefecture", "kanton", or some such term.\n'
	)

	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Editing regions ...'),
		columns = [_('Country'), _('Region')],
		single_selection = True,
		new_callback = edit,
		#edit_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh
	)
示例#46
0
def browse_data_sources(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()
	#------------------------------------------------------------
	def refresh(lctrl):
		srcs = gmCoding.get_data_sources()
		items = [ [
			'%s (%s): %s' % (
				s['name_short'],
				gmTools.coalesce(s['lang'], '?'),
				s['version']
			),
			s['name_long'].split('\n')[0].split('\r')[0],
			s['source'].split('\n')[0].split('\r')[0],
			gmTools.coalesce(s['description'], '').split('\n')[0].split('\r')[0],
			s['pk']
		] for s in srcs ]
		lctrl.set_string_items(items)
		lctrl.set_data(srcs)
	#------------------------------------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('Sources of reference data registered in GNUmed.'),
		caption = _('Showing data sources'),
		columns = [ _('System'), _('Name'), _('Source'), _('Description'), '#' ],
		single_selection = True,
		can_return_empty = False,
		ignore_OK_button = True,
		refresh_callback = refresh
#		edit_callback=None,
#		new_callback=None,
#		delete_callback=None,
#		left_extra_button=None,
#		middle_extra_button=None,
#		right_extra_button=None
	)
示例#47
0
def show_audit_trail(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	conn = gmAuthWidgets.get_dbowner_connection(procedure = _('showing audit trail'))
	if conn is None:
		return False

	#-----------------------------------
	def refresh(lctrl):
		cmd = u'SELECT * FROM audit.v_audit_trail ORDER BY audit_when_ts'
		rows, idx = gmPG2.run_ro_queries(link_obj = conn, queries = [{'cmd': cmd}], get_col_idx = False)
		lctrl.set_string_items (
			[ [
				r['event_when'],
				r['event_by'],
				u'%s %s %s' % (
					gmTools.coalesce(r['row_version_before'], gmTools.u_diameter),
					gmTools.u_right_arrow,
					gmTools.coalesce(r['row_version_after'], gmTools.u_diameter)
				),
				r['event_table'],
				r['event'],
				r['pk_audit']
			] for r in rows ]
		)
	#-----------------------------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = u'',
		caption = _('GNUmed database audit log ...'),
		columns = [ _('When'), _('Who'), _('Revisions'), _('Table'), _('Event'), '#' ],
		single_selection = True,
		refresh_callback = refresh
	)
示例#48
0
def manage_form_templates(parent=None, template_types=None, active_only=False, excluded_types=None, msg=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#-------------------------
	def edit(template=None):
		return edit_template(parent = parent, template = template)
	#-------------------------
	def delete(template):
		delete = gmGuiHelpers.gm_show_question (
			aTitle = _('Deleting form template.'),
			aMessage = _(
				'Are you sure you want to delete\n'
				'the following form template ?\n\n'
				' "%s (%s)"\n\n'
				'You can only delete templates which\n'
				'have not yet been used to generate\n'
				'any forms from.'
			) % (template['name_long'], template['external_version'])
		)
		if delete:
			# FIXME: make this a priviledged operation ?
			gmForms.delete_form_template(template = template)
			return True
		return False
	#-------------------------
	def refresh(lctrl):
		templates = gmForms.get_form_templates(active_only = active_only, template_types = template_types, excluded_types = excluded_types)
		lctrl.set_string_items(items = [ [t['name_long'], t['external_version'], gmForms.form_engine_names[t['engine']]] for t in templates ])
		lctrl.set_data(data = templates)
	#-------------------------
	template = gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Select letter or form template.'),
		columns = [_('Template'), _('Version'), _('Type')],
		edit_callback = edit,
		new_callback = edit,
		delete_callback = delete,
		refresh_callback = refresh,
		single_selection = True
	)

	return template
示例#49
0
    def pick_soap_from_episode(episode):

        if episode is None:
            return False

        narr_for_epi = emr.get_clin_narrative(episodes=[episode['pk_episode']],
                                              soap_cats=soap_cats)

        if len(narr_for_epi) == 0:
            gmDispatcher.send(
                signal='statustext',
                msg=_('No narrative available for selected episode.'))
            return True

        selected_narr = gmListWidgets.get_choices_from_list(
            parent=parent,
            msg=_('Pick the [%s] narrative you want to include in the report.')
            % '/'.join(i18n_soap_cats),
            caption=_('Picking [%s] from %s%s%s') %
            ('/'.join(i18n_soap_cats), gmTools.u_left_double_angle_quote,
             episode['description'], gmTools.u_right_double_angle_quote),
            columns=[_('When'), _('Who'),
                     _('Type'), _('Entry')],
            choices=[[
                gmDateTime.pydt_strftime(narr['date'],
                                         '%Y %b %d  %H:%M',
                                         accuracy=gmDateTime.acc_minutes),
                narr['modified_by'],
                gmSoapDefs.soap_cat2l10n[narr['soap_cat']],
                narr['narrative'].replace('\n', '//').replace('\r', '//')
            ] for narr in narr_for_epi],
            data=narr_for_epi,
            #selections=None,
            #edit_callback=None,
            single_selection=False,
            can_return_empty=False,
            list_tooltip_callback=get_soap_tooltip)

        if selected_narr is None:
            return True

        for narr in selected_narr:
            selected_soap[narr['pk_narrative']] = narr

        return True
示例#50
0
def select_narrative(parent=None, soap_cats=None, msg=None):

	pat = gmPerson.gmCurrentPatient()
	emr = pat.emr

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if soap_cats is None:
		soap_cats = 'soapu'
	soap_cats = list(soap_cats)
	i18n_soap_cats = [ gmSoapDefs.soap_cat2l10n[cat].upper() for cat in soap_cats ]

	if msg is None:
		msg = _('Pick the [%s] narrative you want to use.') % '/'.join(i18n_soap_cats)

	#-----------------------------------------------
	def get_tooltip(soap):
		return soap.format(fancy = True, width = 60)
	#-----------------------------------------------
	def refresh(lctrl):
		lctrl.secondary_sort_column = 0
		soap = emr.get_clin_narrative(soap_cats = soap_cats)
		lctrl.set_string_items ([ [
			gmDateTime.pydt_strftime(s['date'], '%Y %m %d'),
			s['modified_by'],
			gmSoapDefs.soap_cat2l10n[s['soap_cat']],
			s['narrative'],
			s['episode'],
			s['health_issue']
		] for s in soap ])
		lctrl.set_data(soap)
	#-----------------------------------------------
	return gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Picking [%s] narrative') % ('/'.join(i18n_soap_cats)),
		columns = [_('When'), _('Who'), _('Type'), _('Entry'), _('Episode'), _('Issue')],
		single_selection = False,
		can_return_empty = False,
		refresh_callback = refresh,
		list_tooltip_callback = get_tooltip
	)
示例#51
0
	def pick_soap_from_episode(episode):

		if episode is None:
			return False

		narr_for_epi = emr.get_clin_narrative(episodes = [episode['pk_episode']], soap_cats = soap_cats)

		if len(narr_for_epi) == 0:
			gmDispatcher.send(signal = 'statustext', msg = _('No narrative available for selected episode.'))
			return True

		selected_narr = gmListWidgets.get_choices_from_list (
			parent = parent,
			msg = _('Pick the [%s] narrative you want to include in the report.') % '/'.join(i18n_soap_cats),
			caption = _('Picking [%s] from %s%s%s') % (
				'/'.join(i18n_soap_cats),
				gmTools.u_left_double_angle_quote,
				episode['description'],
				gmTools.u_right_double_angle_quote
			),
			columns = [_('When'), _('Who'), _('Type'), _('Entry')],
			choices = [ [
				gmDateTime.pydt_strftime(narr['date'], '%Y %b %d  %H:%M', accuracy = gmDateTime.acc_minutes),
				narr['modified_by'],
				gmSoapDefs.soap_cat2l10n[narr['soap_cat']],
				narr['narrative'].replace('\n', '//').replace('\r', '//')
			] for narr in narr_for_epi ],
			data = narr_for_epi,
			#selections=None,
			#edit_callback=None,
			single_selection = False,
			can_return_empty = False,
			list_tooltip_callback = get_soap_tooltip
		)

		if selected_narr is None:
			return True

		for narr in selected_narr:
			selected_soap[narr['pk_narrative']] = narr

		return True
示例#52
0
def select_org_unit(parent=None, msg=None, no_parent=False):

    if no_parent:
        parent = None
    else:
        if parent is None:
            parent = wx.GetApp().GetTopWindow()

    #--------------------
    def new():
        manage_orgs(parent=parent, no_parent=no_parent)
        return True

    #--------------------
    def refresh(lctrl):
        units = gmOrganization.get_org_units(
            order_by='organization, unit, l10n_unit_category')
        items = [[
            u['organization'], u['unit'],
            gmTools.coalesce(u['l10n_unit_category'], ''), u['pk_org_unit']
        ] for u in units]

        lctrl.set_string_items(items=items)
        lctrl.set_data(data=units)

    #--------------------
    if msg is None:
        msg = _("Organizations and units thereof.\n")

    return gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=msg,
        caption=_('Unit selection ...'),
        columns=[_('Organization'),
                 _('Unit'), _('Unit type'), '#'],
        can_return_empty=False,
        single_selection=True,
        refresh_callback=refresh,
        new_callback=new)
示例#53
0
def select_org_unit(parent=None, msg=None, no_parent=False):

	if no_parent:
		parent = None
	else:
		if parent is None:
			parent = wx.GetApp().GetTopWindow()

	#--------------------
	def new():
		manage_orgs(parent = parent, no_parent = no_parent)
		return True
	#--------------------
	def refresh(lctrl):
		units = gmOrganization.get_org_units(order_by = 'organization, unit, l10n_unit_category')
		items = [ [
			u['organization'],
			u['unit'],
			gmTools.coalesce(u['l10n_unit_category'], u''),
			u['pk_org_unit']
		] for u in units ]

		lctrl.set_string_items(items = items)
		lctrl.set_data(data = units)
	#--------------------
	if msg is None:
		msg = _("Organizations and units thereof.\n")

	return gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = msg,
		caption = _('Unit selection ...'),
		columns = [_('Organization'), _('Unit'), _('Unit type'), '#'],
		can_return_empty = False,
		single_selection = True,
		refresh_callback = refresh,
		new_callback = new
	)
示例#54
0
def select_address(missing=None, person=None):

	#--------------------------
	def calculate_tooltip(adr):
		return '\n'.join(adr.format())
	#--------------------------
	addresses = person.get_addresses()
	if len(addresses) == 0:
		return None

	msg = _(
		'There is no [%s] address registered with this patient.\n\n'
		'Please select the address you would like to use instead:'
	) % missing
	choices = [
		[
			a['l10n_address_type'],
			'%s %s%s, %s %s, %s' % (
				a['street'],
				a['number'],
				gmTools.coalesce(a['subunit'], '', '/%s'),
				a['postcode'],
				a['urb'],
				a['l10n_country']
			)
		]
	for a in addresses ]

	return gmListWidgets.get_choices_from_list (
		msg = msg,
		caption = _('Selecting address by type'),
		columns = [_('Type'), _('Address')],
		choices = choices,
		data = addresses,
		single_selection = True,
		list_tooltip_callback = calculate_tooltip
	)
示例#55
0
def manage_dynamic_hints(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
        # ------------------------------------------------------------

    def get_tooltip(item):
        if item is None:
            return None
        return item.format()
        # ------------------------------------------------------------

    def manage_data_packs(item):
        gmDataPackWidgets.manage_data_packs(parent=parent)
        return True
        # ------------------------------------------------------------

    def edit_hint(hint=None):
        return edit_dynamic_hint(parent=parent, hint=hint, single_entry=(hint is not None))
        # ------------------------------------------------------------

    def del_hint(hint=None):
        if hint is None:
            return False
        really_delete = gmGuiHelpers.gm_show_question(
            title=_("Deleting automatic dynamic hint"),
            question=_("Really delete this dynamic hint ?\n\n [%s]") % hint["title"],
        )
        if not really_delete:
            return False

        conn = gmAuthWidgets.get_dbowner_connection(procedure=_("deleting a dynamic hint"))
        if conn is None:
            return False
        gmAutoHints.delete_dynamic_hint(link_obj=conn, pk_hint=hint["pk_auto_hint"])
        conn.commit()
        conn.close()
        return True
        # ------------------------------------------------------------

    def refresh(lctrl):
        hints = gmAutoHints.get_dynamic_hints(order_by=u"is_active DESC, source, hint")
        items = [
            [
                gmTools.bool2subst(h["is_active"], gmTools.u_checkmark_thin, u""),
                h["title"],
                h["source"][:30],
                h["hint"][:60],
                gmTools.coalesce(h["url"], u"")[:60],
                h["lang"],
                h["pk_auto_hint"],
            ]
            for h in hints
        ]
        lctrl.set_string_items(items)
        lctrl.set_data(hints)
        # ------------------------------------------------------------

    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_("\nDynamic hints registered with GNUmed.\n"),
        caption=_("Showing dynamic hints."),
        columns=[_("Active"), _("Title"), _("Source"), _("Hint"), u"URL", _("Language"), u"#"],
        single_selection=True,
        refresh_callback=refresh,
        edit_callback=edit_hint,
        new_callback=edit_hint,
        delete_callback=del_hint,
        # 		left_extra_button = (
        # 			_('(De)-Activate'),
        # 			_('Toggle activation of the selected hint'),
        # 			toggle_activation
        # 		),
        # button to show DB schema
        right_extra_button=(
            _("Data packs"),
            _("Browse and install automatic dynamic hints data packs"),
            manage_data_packs,
        ),
        list_tooltip_callback=get_tooltip,
    )
示例#56
0
def manage_suppressed_hints(parent=None, pk_identity=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()
        # ------------------------------------------------------------

    def get_tooltip(item):
        if item is None:
            return None
        return item.format()
        # ------------------------------------------------------------

    def manage_hints(item):
        manage_dynamic_hints(parent=parent)
        return True
        # ------------------------------------------------------------

    def del_hint(hint=None):
        if hint is None:
            return False
        really_delete = gmGuiHelpers.gm_show_question(
            title=_("Deleting suppressed dynamic hint"),
            question=_("Really delete the suppression of this dynamic hint ?\n\n [%s]") % hint["title"],
        )
        if not really_delete:
            return False
        gmAutoHints.delete_suppressed_hint(pk_suppressed_hint=hint["pk_suppressed_hint"])
        return True
        # ------------------------------------------------------------

    def refresh(lctrl):
        hints = gmAutoHints.get_suppressed_hints(pk_identity=pk_identity, order_by=u"title")
        items = [
            [
                h["title"],
                gmDateTime.pydt_strftime(h["suppressed_when"], "%Y %b %d"),
                h["suppressed_by"],
                h["rationale"],
                gmTools.bool2subst(h["is_active"], gmTools.u_checkmark_thin, u""),
                h["source"][:30],
                gmTools.coalesce(h["url"], u"")[:60],
                h["pk_hint"],
            ]
            for h in hints
        ]
        lctrl.set_string_items(items)
        lctrl.set_data(hints)
        # ------------------------------------------------------------

    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_("\nDynamic hints suppressed in this patient.\n"),
        caption=_("Showing suppressed dynamic hints."),
        columns=[_("Title"), _("When"), _("By"), _("Rationale"), _("Active"), _("Source"), u"URL", u"Hint #"],
        single_selection=True,
        ignore_OK_button=True,
        refresh_callback=refresh,
        delete_callback=del_hint,
        right_extra_button=(_("Manage hints"), _("Manage automatic dynamic hints"), manage_hints),
        list_tooltip_callback=get_tooltip,
    )
示例#57
0
def set_active_praxis_branch(parent=None, no_parent=False):

    if no_parent:
        parent = None
    else:
        if parent is None:
            parent = wx.GetApp().GetTopWindow()

    branches = gmPraxis.get_praxis_branches()

    if len(branches) == 1:
        _log.debug('only one praxis branch configured')
        gmPraxis.gmCurrentPraxisBranch(branches[0])
        return True

    if len(branches) == 0:
        orgs = gmOrganization.get_orgs()
        if len(orgs) == 0:
            pk_cat = gmOrganization.create_org_category(category=u'Praxis')
            org = gmOrganization.create_org(_('Your praxis'), pk_cat)
            unit = org.add_unit(_('Your branch'))
            branch = gmPraxis.create_praxis_branch(
                pk_org_unit=unit['pk_org_unit'])
            _log.debug(
                'auto-created praxis branch because no organizations existed: %s',
                branch)
            gmPraxis.gmCurrentPraxisBranch(branch)
            gmGuiHelpers.gm_show_info(
                title=_('Praxis configuration ...'),
                info=_('GNUmed has auto-created the following\n'
                       'praxis branch for you (which you can\n'
                       'later configure as needed):\n'
                       '\n'
                       '%s') % branch.format())
            return True

        if len(orgs) == 1:
            units = orgs[0].units
            if len(units) == 1:
                branch = gmPraxis.create_praxis_branch(
                    pk_org_unit=units[0]['pk_org_unit'])
                _log.debug(
                    'auto-selected praxis branch because only one organization with only one unit existed: %s',
                    branch)
                gmPraxis.gmCurrentPraxisBranch(branch)
                gmGuiHelpers.gm_show_info(
                    title=_('Praxis configuration ...'),
                    info=_('GNUmed has auto-selected the following\n'
                           'praxis branch for you (which you can\n'
                           'later configure as needed):\n'
                           '\n'
                           '%s') % branch.format())
                return True

        _log.debug(
            'no praxis branches configured, selecting from organization units')
        msg = _(
            'No praxis branches configured currently.\n'
            '\n'
            'You MUST select one unit of an organization to be the initial\n'
            'branch (site, office) which you are logging in from.')
        unit = gmOrganizationWidgets.select_org_unit(msg=msg, no_parent=True)
        if unit is None:
            _log.warning('no organization unit selected, aborting')
            return False
        _log.debug('org unit selected as praxis branch: %s', unit)
        branch = gmPraxis.create_praxis_branch(pk_org_unit=unit['pk_org_unit'])
        _log.debug('created praxis branch: %s', branch)
        gmPraxis.gmCurrentPraxisBranch(branch)
        return True

    #--------------------
    def refresh(lctrl):
        branches = gmPraxis.get_praxis_branches()
        items = [[b['branch'],
                  gmTools.coalesce(b['l10n_unit_category'], u'')]
                 for b in branches]
        lctrl.set_string_items(items=items)
        lctrl.set_data(data=branches)

    #--------------------
    branch = gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_(
            "Select the branch of praxis [%s] which you are logging in from.\n"
        ) % branches[0]['praxis'],
        caption=_('Praxis branch selection ...'),
        columns=[_('Branch'), _('Branch type')],
        can_return_empty=False,
        single_selection=True,
        refresh_callback=refresh)
    if branch is None:
        _log.warning('no praxis branch selected, aborting')
        return False
    gmPraxis.gmCurrentPraxisBranch(branch)
    return True
示例#58
0
def configure_workplace_plugins(parent=None):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    #-----------------------------------
    def delete(workplace):

        curr_workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace
        if workplace == curr_workplace:
            gmDispatcher.send(signal='statustext',
                              msg=_('Cannot delete the active workplace.'),
                              beep=True)
            return False

        dlg = gmGuiHelpers.c2ButtonQuestionDlg(
            parent,
            -1,
            caption=_('Deleting workplace ...'),
            question=_(
                'Are you sure you want to delete this workplace ?\n\n "%s"\n')
            % workplace,
            show_checkbox=True,
            checkbox_msg=_('delete configuration, too'),
            checkbox_tooltip=_(
                'Check this if you want to delete all configuration items\n'
                'for this workplace along with the workplace itself.'),
            button_defs=[{
                'label': _('Delete'),
                'tooltip': _('Yes, delete this workplace.'),
                'default': True
            }, {
                'label': _('Do NOT delete'),
                'tooltip': _('No, do NOT delete this workplace'),
                'default': False
            }])

        decision = dlg.ShowModal()
        if decision != wx.ID_YES:
            dlg.Destroy()
            return False

        include_cfg = dlg.checkbox_is_checked()
        dlg.Destroy()

        dbo_conn = gmAuthWidgets.get_dbowner_connection(
            procedure=_('delete workplace'))
        if not dbo_conn:
            return False

        gmPraxis.delete_workplace(workplace=workplace,
                                  conn=dbo_conn,
                                  delete_config=include_cfg)
        return True

    #-----------------------------------
    def edit(workplace=None):

        dbcfg = gmCfg.cCfgSQL()

        if workplace is None:
            dlg = wx.TextEntryDialog(
                parent=parent,
                message=_('Enter a descriptive name for the new workplace:'),
                caption=_('Configuring GNUmed workplaces ...'),
                defaultValue=u'',
                style=wx.OK | wx.CENTRE)
            dlg.ShowModal()
            workplace = dlg.GetValue().strip()
            if workplace == u'':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new workplace without a name.'),
                    _('Configuring GNUmed workplaces ...'))
                return False
            curr_plugins = []
        else:
            curr_plugins = gmTools.coalesce(
                dbcfg.get2(option=u'horstspace.notebook.plugin_load_order',
                           workplace=workplace,
                           bias='workplace'), [])

        msg = _(
            'Pick the plugin(s) to be loaded the next time the client is restarted under the workplace:\n'
            '\n'
            '    [%s]\n') % workplace

        picker = gmListWidgets.cItemPickerDlg(
            parent, -1, title=_('Configuring workplace plugins ...'), msg=msg)
        picker.set_columns(['Available plugins'], ['Active plugins'])
        available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui')
        picker.set_choices(available_plugins)
        picker.set_picks(picks=curr_plugins[:])
        btn_pressed = picker.ShowModal()
        if btn_pressed != wx.ID_OK:
            picker.Destroy()
            return False

        new_plugins = picker.get_picks()
        picker.Destroy()
        if new_plugins == curr_plugins:
            return True

        if new_plugins is None:
            return True

        dbcfg.set(option=u'horstspace.notebook.plugin_load_order',
                  value=new_plugins,
                  workplace=workplace)

        return True

    #-----------------------------------
    def edit_old(workplace=None):

        available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui')

        dbcfg = gmCfg.cCfgSQL()

        if workplace is None:
            dlg = wx.TextEntryDialog(
                parent=parent,
                message=_('Enter a descriptive name for the new workplace:'),
                caption=_('Configuring GNUmed workplaces ...'),
                defaultValue=u'',
                style=wx.OK | wx.CENTRE)
            dlg.ShowModal()
            workplace = dlg.GetValue().strip()
            if workplace == u'':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new workplace without a name.'),
                    _('Configuring GNUmed workplaces ...'))
                return False
            curr_plugins = []
            choices = available_plugins
        else:
            curr_plugins = gmTools.coalesce(
                dbcfg.get2(option=u'horstspace.notebook.plugin_load_order',
                           workplace=workplace,
                           bias='workplace'), [])
            choices = curr_plugins[:]
            for p in available_plugins:
                if p not in choices:
                    choices.append(p)

        sels = range(len(curr_plugins))
        new_plugins = gmListWidgets.get_choices_from_list(
            parent=parent,
            msg=_('\n'
                  'Select the plugin(s) to be loaded the next time\n'
                  'the client is restarted under the workplace:\n'
                  '\n'
                  ' [%s]'
                  '\n') % workplace,
            caption=_('Configuring GNUmed workplaces ...'),
            choices=choices,
            selections=sels,
            columns=[_('Plugins')],
            single_selection=False)

        if new_plugins == curr_plugins:
            return True

        if new_plugins is None:
            return True

        dbcfg.set(option=u'horstspace.notebook.plugin_load_order',
                  value=new_plugins,
                  workplace=workplace)

        return True

    #-----------------------------------
    def clone(workplace=None):
        if workplace is None:
            return False

        new_name = wx.GetTextFromUser(
            message=_('Enter a name for the new workplace !'),
            caption=_('Cloning workplace'),
            default_value=u'%s-2' % workplace,
            parent=parent).strip()

        if new_name == u'':
            return False

        dbcfg = gmCfg.cCfgSQL()
        opt = u'horstspace.notebook.plugin_load_order'

        plugins = dbcfg.get2(option=opt, workplace=workplace, bias='workplace')

        dbcfg.set(option=opt, value=plugins, workplace=new_name)

        # FIXME: clone cfg, too

        return True

    #-----------------------------------
    def refresh(lctrl):
        workplaces = gmPraxis.gmCurrentPraxisBranch().workplaces
        curr_workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace
        try:
            sels = [workplaces.index(curr_workplace)]
        except ValueError:
            sels = []

        lctrl.set_string_items(workplaces)
        lctrl.set_selections(selections=sels)

    #-----------------------------------
    gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('\nSelect the workplace to configure below.\n'
              '\n'
              'The currently active workplace is preselected.\n'),
        caption=_('Configuring GNUmed workplaces ...'),
        columns=[_('Workplace')],
        single_selection=True,
        refresh_callback=refresh,
        edit_callback=edit,
        new_callback=edit,
        delete_callback=delete,
        left_extra_button=(_('Clone'), _('Clone the selected workplace'),
                           clone))
示例#59
0
def select_narrative_by_episode(parent=None, soap_cats=None):

    pat = gmPerson.gmCurrentPatient()
    emr = pat.emr

    all_epis = [
        epi for epi in emr.get_episodes(order_by='description')
        if epi.has_narrative
    ]
    if len(all_epis) == 0:
        gmDispatcher.send(signal='statustext',
                          msg=_('No episodes with progress notes found.'))
        return []

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    if soap_cats is None:
        soap_cats = 'soapu'
    soap_cats = list(soap_cats)
    i18n_soap_cats = [
        gmSoapDefs.soap_cat2l10n[cat].upper() for cat in soap_cats
    ]

    selected_soap = {}

    #selected_narrative_pks = []

    #-----------------------------------------------
    def get_soap_tooltip(soap):
        return soap.format(fancy=True, width=60)

    #-----------------------------------------------
    def pick_soap_from_episode(episode):

        if episode is None:
            return False

        narr_for_epi = emr.get_clin_narrative(episodes=[episode['pk_episode']],
                                              soap_cats=soap_cats)

        if len(narr_for_epi) == 0:
            gmDispatcher.send(
                signal='statustext',
                msg=_('No narrative available for selected episode.'))
            return True

        selected_narr = gmListWidgets.get_choices_from_list(
            parent=parent,
            msg=_('Pick the [%s] narrative you want to include in the report.')
            % '/'.join(i18n_soap_cats),
            caption=_('Picking [%s] from %s%s%s') %
            ('/'.join(i18n_soap_cats), gmTools.u_left_double_angle_quote,
             episode['description'], gmTools.u_right_double_angle_quote),
            columns=[_('When'), _('Who'),
                     _('Type'), _('Entry')],
            choices=[[
                gmDateTime.pydt_strftime(narr['date'],
                                         '%Y %b %d  %H:%M',
                                         accuracy=gmDateTime.acc_minutes),
                narr['modified_by'],
                gmSoapDefs.soap_cat2l10n[narr['soap_cat']],
                narr['narrative'].replace('\n', '//').replace('\r', '//')
            ] for narr in narr_for_epi],
            data=narr_for_epi,
            #selections=None,
            #edit_callback=None,
            single_selection=False,
            can_return_empty=False,
            list_tooltip_callback=get_soap_tooltip)

        if selected_narr is None:
            return True

        for narr in selected_narr:
            selected_soap[narr['pk_narrative']] = narr

        return True

#		selection_idxs = []
#		for idx in range(len(narr_for_epi)):
#			if narr_for_epi[idx]['pk_narrative'] in selected_narrative_pks:
#				selection_idxs.append(idx)
#		if len(selection_idxs) != 0:
#			dlg.set_selections(selections = selection_idxs)

#		selected_narrative_pks = [ i['pk_narrative'] for i in selected_narr ]
#		for narr in selected_narr:
#			selected_soap[narr['pk_narrative']] = narr
#
#		print "before returning from picking soap"
#
#		return True
#	#-----------------------------------------------

    def edit_episode(episode):
        return gmEMRStructWidgets.edit_episode(parent=parent, episode=episode)

    #-----------------------------------------------
    def refresh_episodes(lctrl):
        all_epis = [
            epi for epi in emr.get_episodes(order_by='description')
            if epi.has_narrative
        ]
        lctrl.set_string_items([[
            '%s%s' % (e['description'],
                      gmTools.coalesce(e['health_issue'], '', ' (%s)')),
            gmTools.bool2subst(e['episode_open'], _('open'), _('closed'))
        ] for e in all_epis])
        lctrl.set_data(all_epis)

    #-----------------------------------------------
    def get_episode_tooltip(episode):
        return episode.format(patient=pat,
                              with_encounters=False,
                              with_documents=False,
                              with_hospital_stays=False,
                              with_procedures=False,
                              with_family_history=False,
                              with_tests=False,
                              with_vaccinations=False)

    #-----------------------------------------------
    #selected_episode_pks = []

    epis_picked_from = gmListWidgets.get_choices_from_list(
        parent=parent,
        msg=_('\n Select the episode you want to report on.'),
        caption=_('Picking [%s] from episodes') % '/'.join(i18n_soap_cats),
        columns=[_('Episode'), _('Status')],
        edit_callback=edit_episode,
        refresh_callback=refresh_episodes,
        single_selection=True,
        can_return_empty=True,
        ignore_OK_button=False,
        left_extra_button=(_('&Pick notes'),
                           _('Pick [%s] entries from selected episode') %
                           '/'.join(i18n_soap_cats), pick_soap_from_episode),
        list_tooltip_callback=get_episode_tooltip)

    if epis_picked_from is None:
        return []

    return selected_soap.values()
示例#60
0
def list_configuration(parent=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	#---------------
	def refresh(lctrl):
		opts = gmCfg.get_all_options(order_by = 'owner, workplace, option')

		items = [ [
			o['owner'],
			o['workplace'],
			o['option'],
			o['value'],
			o['type'],
			gmTools.coalesce(o['description'], '')
		] for o in opts ]
		lctrl.set_string_items(items)
		lctrl.set_data(opts)
	#---------------
	def tooltip(item):
		return (
			'%s %s (#%s) %s\n'
			'\n'
			' %s @ %s\n'
			'\n'
			' %s: %s\n'
			'%s'
		) % (
			gmTools.u_box_horiz_single * 3,
			item['option'],
			item['pk_cfg_item'],
			gmTools.u_box_horiz_single * 3,
			item['owner'],
			item['workplace'],
			item['type'],
			gmTools.wrap(
				text = item['value'],
				width = 40,
				subsequent_indent = ' ' * 8
			),
			gmTools.wrap (
				text = gmTools.coalesce(item['description'], '', '\n%s'),
				width = 40,
				initial_indent = ' ',
				subsequent_indent = ' '
			)
		)
	#---------------
	def delete(item):
		delete_it = gmGuiHelpers.gm_show_question (
			aTitle = _('Deleting option'),
			aMessage = '%s\n\n%s %s (#%s) %s\n\n%s\n\n%s' % (
				tooltip(item),
				gmTools.u_box_horiz_single * 3,
				item['option'],
				item['pk_cfg_item'],
				gmTools.u_box_horiz_single * 3,
				_('Do you really want to delete this option ?'),
				_('(GNUmed will re-create options as needed.)')
			)
		)
		if not delete_it:
			return False

		from Gnumed.wxpython.gmAuthWidgets import get_dbowner_connection
		conn = get_dbowner_connection(procedure = _('Deleting option'))
		if conn is None:
			gmDispatcher.send(signal = 'statustext', msg = _('Cannot connect as database owner. Unable to delete option.'))
			return False

		cfg = gmCfg.cCfgSQL()
		cfg.delete(conn = conn, pk_option = item['pk_cfg_item'])
		return True
	#---------------
	gmListWidgets.get_choices_from_list (
		parent = parent,
		msg = _('All configured options currently in the database.'),
		caption = _('All configured options'),
		columns = [ _('User'), _('Workplace'), _('Option'), _('Value'), _('Type'), _('Description') ],
		refresh_callback = refresh,
		delete_callback = delete,
		ignore_OK_button = True,
		list_tooltip_callback = tooltip
	)