def __init_ui(self): # FIXME: include more sources: coding systems/other database columns mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = ["SELECT DISTINCT ON (description) description, description FROM clin.health_issue WHERE description %(fragment_condition)s LIMIT 50"] ) mp.setThresholds(1, 3, 5) self._PRW_condition.matcher = mp mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [""" SELECT DISTINCT ON (grouping) grouping, grouping from ( SELECT rank, grouping from (( SELECT grouping, 1 as rank from clin.health_issue where grouping %%(fragment_condition)s and (SELECT True from clin.encounter where fk_patient = %s and pk = clin.health_issue.fk_encounter) ) union ( SELECT grouping, 2 as rank from clin.health_issue where grouping %%(fragment_condition)s )) as union_result order by rank ) as order_result limit 50""" % gmPerson.gmCurrentPatient().ID ] ) mp.setThresholds(1, 3, 5) self._PRW_grouping.matcher = mp self._PRW_age_noted.add_callback_on_lose_focus(self._on_leave_age_noted) self._PRW_year_noted.add_callback_on_lose_focus(self._on_leave_year_noted) # self._PRW_age_noted.add_callback_on_modified(self._on_modified_age_noted) # self._PRW_year_noted.add_callback_on_modified(self._on_modified_year_noted) self._PRW_year_noted.Enable(True) self._PRW_codes.add_callback_on_lose_focus(self._on_leave_codes)
def __init__(self, *args, **kwargs): wxgAllergyEditAreaPnl.wxgAllergyEditAreaPnl.__init__(self, *args, **kwargs) try: self.__allergy = kwargs['allergy'] except KeyError: self.__allergy = None mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [""" select substance, substance from clin.allergy where substance %(fragment_condition)s union select generics, generics from clin.allergy where generics %(fragment_condition)s union select allergene, allergene from clin.allergy where allergene %(fragment_condition)s union select atc_code, atc_code from clin.allergy where atc_code %(fragment_condition)s """ ] ) mp.setThresholds(2, 3, 5) self._PRW_trigger.matcher = mp mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [""" select narrative, narrative from clin.allergy where narrative %(fragment_condition)s """] ) mp.setThresholds(2, 3, 5) self._PRW_reaction.matcher = mp self._PRW_reaction.enable_default_spellchecker() # self._RBTN_type_sensitivity.MoveAfterInTabOrder(self._RBTN_type_allergy) # self._ChBOX_definite.MoveAfterInTabOrder(self._RBTN_type_sensitivity) self.refresh()
def __init__(self, *args, **kwargs): wxgAllergyEditAreaPnl.wxgAllergyEditAreaPnl.__init__( self, *args, **kwargs) try: self.__allergy = kwargs['allergy'] except KeyError: self.__allergy = None mp = gmMatchProvider.cMatchProvider_SQL2(queries=[ u""" select substance, substance from clin.allergy where substance %(fragment_condition)s union select generics, generics from clin.allergy where generics %(fragment_condition)s union select allergene, allergene from clin.allergy where allergene %(fragment_condition)s union select atc_code, atc_code from clin.allergy where atc_code %(fragment_condition)s """ ]) mp.setThresholds(2, 3, 5) self._PRW_trigger.matcher = mp mp = gmMatchProvider.cMatchProvider_SQL2(queries=[ u""" select narrative, narrative from clin.allergy where narrative %(fragment_condition)s """ ]) mp.setThresholds(2, 3, 5) self._PRW_reaction.matcher = mp self._PRW_reaction.enable_default_spellchecker() # self._RBTN_type_sensitivity.MoveAfterInTabOrder(self._RBTN_type_allergy) # self._ChBOX_definite.MoveAfterInTabOrder(self._RBTN_type_sensitivity) self.refresh()
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = """ SELECT DISTINCT ON (list_label) pk AS data, name_short || ' (' || version || ')' AS field_label, name_short || ' ' || version || ' (' || name_long || ')' AS list_label FROM ref.data_source WHERE name_short %(fragment_condition)s OR name_long %(fragment_condition)s ORDER BY list_label LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 4) # mp.word_separators = '[ \t=+&:@]+' self.SetToolTip(_('Select a data source / coding system.')) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = """ SELECT DISTINCT ON (list_label) pk AS data, name_short || ' (' || version || ')' AS field_label, name_short || ' ' || version || ' (' || name_long || ')' AS list_label FROM ref.data_source WHERE name_short %(fragment_condition)s OR name_long %(fragment_condition)s ORDER BY list_label LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) # mp.word_separators = '[ \t=+&:@]+' self.SetToolTip(_('Select a data source / coding system.')) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): query = u""" SELECT DISTINCT ON (data) * FROM ( SELECT pk AS data, _(description) || ' (' || description || ')' AS list_label, _(description) AS field_label FROM dem.org_category WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString(_("Select an organizational category.")) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [ """ SELECT DISTINCT ON (description) description AS data, description AS field_label, description || ' (' || CASE WHEN is_open IS TRUE THEN _('ongoing') ELSE _('closed') END || ')' AS list_label FROM clin.episode WHERE description %(fragment_condition)s ORDER BY description LIMIT 30 """ ] ) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.matcher = mp
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = u""" SELECT DISTINCT ON (label) pk_type, (l10n_type || ' (' || l10n_category || ')') AS label FROM dem.v_inbox_item_type WHERE l10n_type %(fragment_condition)s OR type %(fragment_condition)s OR l10n_category %(fragment_condition)s OR category %(fragment_condition)s ORDER BY label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) self.matcher = mp self.SetToolTipString(_('Select a message type.'))
def __init__(self, *args, **kwargs): query = """ SELECT DISTINCT ON (data) * FROM ( SELECT pk AS data, _(description) || ' (' || description || ')' AS list_label, _(description) AS field_label FROM dem.org_category WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTip(_("Select an organizational category.")) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = u""" SELECT pk AS data, name_short AS list_label, name_sort AS field_label FROM ref.paperwork_templates WHERE fk_template_type = (SELECT pk FROM ref.form_types WHERE name = '%s') AND ( name_long %%(fragment_condition)s OR name_short %%(fragment_condition)s ) ORDER BY list_label LIMIT 15 """ % gmDocuments.DOCUMENT_TYPE_VISUAL_PROGRESS_NOTE mp = gmMatchProvider.cMatchProvider_SQL2(queries=[query]) mp.setThresholds(2, 3, 5) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): query = u""" SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (field_label) pk AS data, _(description) AS field_label, (_(description) || ' (' || description || ')') AS list_label FROM dem.enum_comm_types WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ) AS ur ORDER BY ur.list_label """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) mp.word_separators = u'[ \t]+' gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.matcher = mp self.SetToolTipString(_('Select the type of communications channel.')) self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = u""" SELECT DISTINCT ON (label) pk_type, (l10n_type || ' (' || l10n_category || ')') AS label FROM dem.v_inbox_item_type WHERE l10n_type %(fragment_condition)s OR type %(fragment_condition)s OR l10n_category %(fragment_condition)s OR category %(fragment_condition)s ORDER BY label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 4) self.matcher = mp self.SetToolTipString(_('Select a message type.'))
def __init__(self, *args, **kwargs): query = """ SELECT id, type FROM (( SELECT id, _(name) AS type, 1 AS rank FROM dem.address_type WHERE _(name) %(fragment_condition)s ) UNION ( SELECT id, name AS type, 2 AS rank FROM dem.address_type WHERE name %(fragment_condition)s )) AS ur order by ur.rank, ur.type """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) mp.word_separators = '[ \t]+' gmPhraseWheel.cPhraseWheel.__init__ ( self, *args, **kwargs ) self.matcher = mp self.SetToolTip(_('Select the type of address.')) # self.capitalisation_mode = gmTools.CAPS_FIRST self.selection_only = True
def __init__(self, *args, **kwargs): # FIXME: add possible context query = """( SELECT DISTINCT ON (list_label) postcode AS data, postcode || ' (' || name || ')' AS list_label, postcode AS field_label FROM dem.street WHERE postcode %(fragment_condition)s ORDER BY list_label LIMIT 20 ) UNION ( SELECT DISTINCT ON (list_label) postcode AS data, postcode || ' (' || name || ')' AS list_label, postcode AS field_label FROM dem.urb WHERE postcode %(fragment_condition)s ORDER BY list_label LIMIT 20 )""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(2, 3, 15) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTip(_("Type or select a zip code (postcode).\n\nUse e.g. '?' if unknown.")) self.matcher = mp
def __init__(self, *args, **kwargs): query = """ SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (field_label) pk AS data, _(description) AS field_label, (_(description) || ' (' || description || ')') AS list_label FROM dem.enum_comm_types WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ) AS ur ORDER BY ur.list_label """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) mp.word_separators = '[ \t]+' gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.matcher = mp self.SetToolTip(_('Select the type of communications channel.')) self.selection_only = True
def __init__(self, *args, **kwargs): # FIXME: add possible context query = u"""( SELECT DISTINCT ON (list_label) postcode AS data, postcode || ' (' || name || ')' AS list_label, postcode AS field_label FROM dem.street WHERE postcode %(fragment_condition)s ORDER BY list_label LIMIT 20 ) UNION ( SELECT DISTINCT ON (list_label) postcode AS data, postcode || ' (' || name || ')' AS list_label, postcode AS field_label FROM dem.urb WHERE postcode %(fragment_condition)s ORDER BY list_label LIMIT 20 )""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(2, 3, 15) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString( _("Type or select a zip code (postcode).\n\nUse e.g. '?' if unknown." )) self.matcher = mp
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = """ SELECT DISTINCT ON (data) data, field_label, list_label FROM ( ( SELECT code AS data, (code || ': ' || term) AS list_label, (code || ' (' || term || ')') AS field_label FROM ref.atc WHERE term %(fragment_condition)s OR code %(fragment_condition)s ) UNION ALL ( SELECT atc as data, (atc || ': ' || description) AS list_label, (atc || ' (' || description || ')') AS field_label FROM ref.substance WHERE description %(fragment_condition)s OR atc %(fragment_condition)s ) UNION ALL ( SELECT atc_code AS data, (atc_code || ': ' || description || ' (' || preparation || ')') AS list_label, (atc_code || ': ' || description) AS field_label FROM ref.drug_product WHERE description %(fragment_condition)s OR atc_code %(fragment_condition)s ) -- it would be nice to be able to include ref.vacc_indication but that's hard to do in SQL ) AS candidates WHERE data IS NOT NULL ORDER BY data, list_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) # mp.word_separators = '[ \t=+&:@]+' self.SetToolTip( _('Select an ATC (Anatomical-Therapeutic-Chemical) code.')) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) # consider ATCs in ref.branded_drug and vacc_indication query = u""" SELECT data, list_label, field_label FROM ( SELECT DISTINCT ON (data) data, list_label, field_label FROM (( -- fragment -> vaccine SELECT pk_vaccine AS data, vaccine || ' (' || array_to_string(l10n_indications, ', ') || ')' AS list_label, vaccine AS field_label FROM clin.v_vaccines WHERE vaccine %(fragment_condition)s ) union all ( -- fragment -> localized indication -> vaccines SELECT pk_vaccine AS data, vaccine || ' (' || array_to_string(l10n_indications, ', ') || ')' AS list_label, vaccine AS field_label FROM clin.v_indications4vaccine WHERE l10n_indication %(fragment_condition)s ) union all ( -- fragment -> indication -> vaccines SELECT pk_vaccine AS data, vaccine || ' (' || array_to_string(indications, ', ') || ')' AS list_label, vaccine AS field_label FROM clin.v_indications4vaccine WHERE indication %(fragment_condition)s ) ) AS distinct_total ) AS total ORDER by list_label LIMIT 25 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 3) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): query = """ SELECT DISTINCT ON (data) * FROM ( SELECT * FROM (( SELECT pk_org_unit AS data, unit || coalesce(' (' || l10n_unit_category || ')', '') || ': ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE unit %(fragment_condition)s ) UNION ALL ( SELECT pk_org_unit AS data, coalesce(l10n_unit_category || ' ', '') || '"' || unit || '": ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE l10n_unit_category %(fragment_condition)s OR unit_category %(fragment_condition)s ) UNION ALL ( SELECT pk_org_unit AS data, organization || ': ' || unit || coalesce(' (' || l10n_unit_category || ')', '') AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE organization %(fragment_condition)s )) AS all_matches ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTip(_("Select an organizational unit.")) self.matcher = mp self.picklist_delay = 300
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { 'ctxt_vaccine': { 'where_part': 'AND pk_vaccine = %(pk_vaccine)s', 'placeholder': 'pk_vaccine' } } query = """ SELECT data, field_label, list_label FROM ( SELECT distinct on (field_label) data, field_label, list_label, rank FROM (( -- batch_no by vaccine SELECT batch_no AS data, batch_no AS field_label, batch_no || ' (' || vaccine || ')' AS list_label, 1 as rank FROM clin.v_vaccinations WHERE batch_no %(fragment_condition)s %(ctxt_vaccine)s ) UNION ALL ( -- batch_no for any vaccine SELECT batch_no AS data, batch_no AS field_label, batch_no || ' (' || vaccine || ')' AS list_label, 2 AS rank FROM clin.v_vaccinations WHERE batch_no %(fragment_condition)s ) ) AS matching_batch_nos ) as unique_matches ORDER BY rank, list_label LIMIT 25 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = context) mp.setThresholds(1, 2, 3) self.matcher = mp self.unset_context(context = 'pk_vaccine') self.SetToolTip(_('Enter or select the batch/lot number of the vaccine used.')) self.selection_only = False
def __init__(self, *args, **kwargs): query = u""" SELECT DISTINCT ON (data) * FROM ( SELECT * FROM (( SELECT pk_org_unit AS data, unit || coalesce(' (' || l10n_unit_category || ')', '') || ': ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE unit %(fragment_condition)s ) UNION ALL ( SELECT pk_org_unit AS data, coalesce(l10n_unit_category || ' ', '') || '"' || unit || '": ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE l10n_unit_category %(fragment_condition)s OR unit_category %(fragment_condition)s ) UNION ALL ( SELECT pk_org_unit AS data, organization || ': ' || unit || coalesce(' (' || l10n_unit_category || ')', '') AS list_label, unit || ' (' || organization || ')' AS field_label FROM dem.v_org_units WHERE organization %(fragment_condition)s )) AS all_matches ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString(_("Select an organizational unit.")) self.matcher = mp self.picklist_delay = 300
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { u'ctxt_vaccine': { u'where_part': u'AND pk_vaccine = %(pk_vaccine)s', u'placeholder': u'pk_vaccine' } } query = u""" SELECT data, field_label, list_label FROM ( SELECT distinct on (field_label) data, field_label, list_label, rank FROM (( -- batch_no by vaccine SELECT batch_no AS data, batch_no AS field_label, batch_no || ' (' || vaccine || ')' AS list_label, 1 as rank FROM clin.v_pat_vaccinations WHERE batch_no %(fragment_condition)s %(ctxt_vaccine)s ) UNION ALL ( -- batch_no for any vaccine SELECT batch_no AS data, batch_no AS field_label, batch_no || ' (' || vaccine || ')' AS list_label, 2 AS rank FROM clin.v_pat_vaccinations WHERE batch_no %(fragment_condition)s ) ) AS matching_batch_nos ) as unique_matches ORDER BY rank, list_label LIMIT 25 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = context) mp.setThresholds(1, 2, 3) self.matcher = mp self.unset_context(context = u'pk_vaccine') self.SetToolTipString(_('Enter or select the batch/lot number of the vaccine used.')) self.selection_only = False
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) query = """ SELECT DISTINCT ON (data) data, field_label, list_label FROM ( ( SELECT code AS data, (code || ': ' || term) AS list_label, (code || ' (' || term || ')') AS field_label FROM ref.atc WHERE term %(fragment_condition)s OR code %(fragment_condition)s ) UNION ALL ( SELECT atc as data, (atc || ': ' || description) AS list_label, (atc || ' (' || description || ')') AS field_label FROM ref.substance WHERE description %(fragment_condition)s OR atc %(fragment_condition)s ) UNION ALL ( SELECT atc_code AS data, (atc_code || ': ' || description || ' (' || preparation || ')') AS list_label, (atc_code || ': ' || description) AS field_label FROM ref.drug_product WHERE description %(fragment_condition)s OR atc_code %(fragment_condition)s ) -- it would be nice to be able to include ref.vacc_indication but that's hard to do in SQL ) AS candidates WHERE data IS NOT NULL ORDER BY data, list_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 4) # mp.word_separators = '[ \t=+&:@]+' self.SetToolTip(_('Select an ATC (Anatomical-Therapeutic-Chemical) code.')) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): super(cGenericCodesPhraseWheel, self).__init__(*args, **kwargs) query = """ SELECT -- DISTINCT ON (list_label) data, list_label, field_label FROM ( SELECT pk_generic_code AS data, (code || ' (' || coding_system || '): ' || term || ' (' || version || coalesce(' - ' || lang, '') || ')') AS list_label, code AS field_label FROM ref.v_coded_terms WHERE term %(fragment_condition)s OR code %(fragment_condition)s %(ctxt_system)s %(ctxt_lang)s ) AS applicable_codes ORDER BY list_label LIMIT 30 """ ctxt = { 'ctxt_system': { # must be a TUPLE ! 'where_part': 'AND coding_system IN %(system)s', 'placeholder': 'system' }, 'ctxt_lang': { 'where_part': 'AND lang = %(lang)s', 'placeholder': 'lang' } } mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=ctxt) mp.setThresholds(2, 4, 5) mp.word_separators = '[ \t=+&/:-]+' #mp.print_queries = True self.phrase_separators = ';' self.selection_only = False # not sure yet how this fares with multi-phrase input self.SetToolTip(_('Select one or more codes that apply.')) self.matcher = mp self.add_callback_on_lose_focus(callback=self.__on_losing_focus)
def __init__(self, *args, **kwargs): super(cGenericCodesPhraseWheel, self).__init__(*args, **kwargs) query = """ SELECT -- DISTINCT ON (list_label) data, list_label, field_label FROM ( SELECT pk_generic_code AS data, (code || ' (' || coding_system || '): ' || term || ' (' || version || coalesce(' - ' || lang, '') || ')') AS list_label, code AS field_label FROM ref.v_coded_terms WHERE term %(fragment_condition)s OR code %(fragment_condition)s %(ctxt_system)s %(ctxt_lang)s ) AS applicable_codes ORDER BY list_label LIMIT 30 """ ctxt = { 'ctxt_system': { # must be a TUPLE ! 'where_part': 'AND coding_system IN %(system)s', 'placeholder': 'system' }, 'ctxt_lang': { 'where_part': 'AND lang = %(lang)s', 'placeholder': 'lang' } } mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = ctxt) mp.setThresholds(2, 4, 5) mp.word_separators = '[ \t=+&/:-]+' #mp.print_queries = True self.phrase_separators = ';' self.selection_only = False # not sure yet how this fares with multi-phrase input self.SetToolTip(_('Select one or more codes that apply.')) self.matcher = mp self.add_callback_on_lose_focus(callback = self.__on_losing_focus)
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) cmd = """ SELECT DISTINCT ON (list_label) pk_encounter AS data, to_char(started, 'YYYY Mon DD (HH24:MI)') || ': ' || l10n_type || ' [#' || pk_encounter || ']' AS list_label, to_char(started, 'YYYY Mon DD') || ': ' || l10n_type AS field_label FROM clin.v_pat_encounters WHERE ( to_char(started, 'YYYY-MM-DD') %(fragment_condition)s OR l10n_type %(fragment_condition)s OR type %(fragment_condition)s ) %(ctxt_patient)s ORDER BY list_label LIMIT 30 """ context = { 'ctxt_patient': { 'where_part': 'AND pk_patient = %(patient)s', 'placeholder': 'patient' } } self.matcher = gmMatchProvider.cMatchProvider_SQL2(queries=[cmd], context=context) self.matcher._SQL_data2match = """ SELECT pk_encounter AS data, to_char(started, 'YYYY Mon DD (HH24:MI)') || ': ' || l10n_type AS list_label, to_char(started, 'YYYY Mon DD') || ': ' || l10n_type AS field_label FROM clin.v_pat_encounters WHERE pk_encounter = %(pk)s """ self.matcher.setThresholds(1, 3, 5) #self.matcher.print_queries = True self.selection_only = True # outside code MUST bind this to a patient self.set_context(context='patient', val=None)
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) ctxt = { 'ctxt_pat': { 'where_part': u'(pk_patient = %(pat)s) AND', 'placeholder': u'pat' } } mp = gmMatchProvider.cMatchProvider_SQL2(queries=[ u""" SELECT pk_hospital_stay, descr FROM ( SELECT DISTINCT ON (pk_hospital_stay) pk_hospital_stay, descr FROM (SELECT pk_hospital_stay, ( to_char(admission, 'YYYY-Mon-DD') || ' (' || ward || ' @ ' || hospital || '):' || episode || coalesce((' (' || health_issue || ')'), '') ) AS descr FROM clin.v_hospital_stays WHERE %(ctxt_pat)s ( hospital %(fragment_condition)s OR ward %(fragment_condition)s OR episode %(fragment_condition)s OR health_issue %(fragment_condition)s ) ) AS the_stays ) AS distinct_stays ORDER BY descr LIMIT 25 """ ], context=ctxt) mp.setThresholds(3, 4, 6) mp.set_context('pat', gmPerson.gmCurrentPatient().ID) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): context = { 'ctxt_zip': { 'where_part': 'and zip ilike %(zip)s', 'placeholder': 'zip' } } query = """ SELECT DISTINCT ON (rank, data) data, field_label, list_label FROM ( SELECT urb AS data, urb AS field_label, urb || ' (' || zip || ', ' || region || ', ' || l10n_country || ')' AS list_label, 1 AS rank FROM dem.v_zip2data WHERE urb %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT name AS data, name AS field_label, name || ' (' || postcode ||')' AS list_label, 2 AS rank FROM dem.urb WHERE name %(fragment_condition)s ) AS matching_urbs ORDER BY rank, data LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp.setThresholds(3, 5, 7) gmPhraseWheel.cPhraseWheel.__init__ ( self, *args, **kwargs ) self.unset_context(context = 'zip') self.SetToolTip(_('Type or select a city/town/village/dwelling.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.matcher = mp
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__ (self, *args, **kwargs) cmd = u""" SELECT DISTINCT ON (list_label) pk_encounter AS data, to_char(started, 'YYYY Mon DD (HH24:MI)') || ': ' || l10n_type || ' [#' || pk_encounter || ']' AS list_label, to_char(started, 'YYYY Mon DD') || ': ' || l10n_type AS field_label FROM clin.v_pat_encounters WHERE ( to_char(started, 'YYYY-MM-DD') %(fragment_condition)s OR l10n_type %(fragment_condition)s OR type %(fragment_condition)s ) %(ctxt_patient)s ORDER BY list_label LIMIT 30 """ context = {'ctxt_patient': { 'where_part': u'AND pk_patient = %(patient)s', 'placeholder': u'patient' }} self.matcher = gmMatchProvider.cMatchProvider_SQL2(queries = [cmd], context = context) self.matcher._SQL_data2match = u""" SELECT pk_encounter AS data, to_char(started, 'YYYY Mon DD (HH24:MI)') || ': ' || l10n_type AS list_label, to_char(started, 'YYYY Mon DD') || ': ' || l10n_type AS field_label FROM clin.v_pat_encounters WHERE pk_encounter = %(pk)s """ self.matcher.setThresholds(1, 3, 5) #self.matcher.print_queries = True self.selection_only = True # outside code MUST bind this to a patient self.set_context(context = 'patient', val = None)
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__ (self, *args, **kwargs) ctxt = {'ctxt_pat': {'where_part': '(pk_patient = %(pat)s) AND', 'placeholder': 'pat'}} mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [ """ SELECT pk_hospital_stay, descr FROM ( SELECT DISTINCT ON (pk_hospital_stay) pk_hospital_stay, descr FROM (SELECT pk_hospital_stay, ( to_char(admission, 'YYYY-Mon-DD') || ' (' || ward || ' @ ' || hospital || '):' || episode || coalesce((' (' || health_issue || ')'), '') ) AS descr FROM clin.v_hospital_stays WHERE %(ctxt_pat)s ( hospital %(fragment_condition)s OR ward %(fragment_condition)s OR episode %(fragment_condition)s OR health_issue %(fragment_condition)s ) ) AS the_stays ) AS distinct_stays ORDER BY descr LIMIT 25 """ ], context = ctxt ) mp.setThresholds(3, 4, 6) mp.set_context('pat', gmPerson.gmCurrentPatient().ID) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): query = """ SELECT DISTINCT ON (suburb) suburb, suburb FROM dem.street WHERE suburb %(fragment_condition)s ORDER BY suburb LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(2, 3, 6) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString(_('Type or select the suburb.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.matcher = mp
def __init__(self, parent): query = """ select pk, internal_OBSOLETE_name from test_org """ mp = gmMatchProvider.cMatchProvider_SQL2([query]) mp.setThresholds(aWord=2, aSubstring=4) gmPhraseWheel.cPhraseWheel.__init__(self, parent=parent, id=-1, size=wx.DefaultSize, pos=wx.DefaultPosition) self.SetToolTip( _('choose which lab will process the probe with the specified ID')) self.matcher = mp
def __init__(self, *args, **kwargs): context = { u'ctxt_zip': { u'where_part': u'AND zip ILIKE %(zip)s', u'placeholder': u'zip' } } query = u""" SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) street AS data, street AS field_label, street || ' (' || zip || ', ' || urb || coalesce(', ' || suburb, '') || ', ' || l10n_country || ')' AS list_label, 1 AS rank FROM dem.v_zip2data WHERE street %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT DISTINCT ON (data) name AS data, name AS field_label, name || ' (' || coalesce(postcode, '') || coalesce(', ' || suburb, '') || ')' AS list_label, 2 AS rank FROM dem.street WHERE name %(fragment_condition)s ) AS matching_streets ORDER BY rank, field_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp.setThresholds(3, 5, 8) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.unset_context(context=u'zip') self.SetToolTipString(_('Type or select a street.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.matcher = mp
def __init_ui(self): mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [""" SELECT DISTINCT ON (label) cmd, label FROM cfg.report_query WHERE label %(fragment_condition)s OR cmd %(fragment_condition)s """] ) mp.setThresholds(2,3,5) self._PRW_report_name.matcher = mp self._PRW_report_name.add_callback_on_selection(callback = self._on_report_selected) self._PRW_report_name.add_callback_on_lose_focus(callback = self._auto_load_report)
def __init_ui(self): mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [u""" SELECT DISTINCT ON (label) cmd, label FROM cfg.report_query WHERE label %(fragment_condition)s OR cmd %(fragment_condition)s """] ) mp.setThresholds(2,3,5) self._PRW_report_name.matcher = mp self._PRW_report_name.add_callback_on_selection(callback = self._on_report_selected) self._PRW_report_name.add_callback_on_lose_focus(callback = self._auto_load_report)
def __init__(self, *args, **kwargs): context = { 'ctxt_zip': { 'where_part': 'AND zip ILIKE %(zip)s', 'placeholder': 'zip' } } query = """ SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) street AS data, street AS field_label, street || ' (' || zip || ', ' || urb || coalesce(', ' || suburb, '') || ', ' || l10n_country || ')' AS list_label, 1 AS rank FROM dem.v_zip2data WHERE street %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT DISTINCT ON (data) name AS data, name AS field_label, name || ' (' || coalesce(postcode, '') || coalesce(', ' || suburb, '') || ')' AS list_label, 2 AS rank FROM dem.street WHERE name %(fragment_condition)s ) AS matching_streets ORDER BY rank, field_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp.setThresholds(3, 5, 8) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.unset_context(context = 'zip') self.SetToolTip(_('Type or select a street.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.matcher = mp
def __init__(self, parent): query = """ select pk, internal_OBSOLETE_name from test_org """ mp = gmMatchProvider.cMatchProvider_SQL2([query]) mp.setThresholds(aWord=2, aSubstring=4) gmPhraseWheel.cPhraseWheel.__init__( self, parent = parent, id = -1, size = wx.DefaultSize, pos = wx.DefaultPosition ) self.SetToolTipString(_('choose which lab will process the probe with the specified ID')) self.matcher = mp
def __init__(self, *args, **kwargs): query = """ SELECT DISTINCT ON (data) * FROM ( SELECT * FROM (( SELECT pk_org AS data, organization || ' (' || l10n_category || ')' AS list_label, organization || ' (' || l10n_category || ')' AS field_label FROM dem.v_orgs WHERE organization %(fragment_condition)s ) UNION ALL ( SELECT pk_org AS data, l10n_category || ': ' || organization AS list_label, organization || ' (' || l10n_category || ')' AS field_label FROM dem.v_orgs WHERE l10n_category %(fragment_condition)s OR category %(fragment_condition)s )) AS all_matches ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTip(_("Select an organization.")) self.matcher = mp self.picklist_delay = 300 self.selection_only = True
def __init__(self, *args, **kwargs): query = u""" SELECT DISTINCT ON (data) * FROM ( SELECT * FROM (( SELECT pk_org AS data, organization || ' (' || l10n_category || ')' AS list_label, organization || ' (' || l10n_category || ')' AS field_label FROM dem.v_orgs WHERE organization %(fragment_condition)s ) UNION ALL ( SELECT pk_org AS data, l10n_category || ': ' || organization AS list_label, organization || ' (' || l10n_category || ')' AS field_label FROM dem.v_orgs WHERE l10n_category %(fragment_condition)s OR category %(fragment_condition)s )) AS all_matches ORDER BY list_label ) AS ordered_matches LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 3, 5) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString(_("Select an organization.")) self.matcher = mp self.picklist_delay = 300 self.selection_only = True
def __init__(self, *args, **kwargs): query = """( SELECT pk_praxis_branch AS data, branch || ' (' || praxis || ')' AS field_label, branch || coalesce(' (' || l10n_unit_category || ')', '') || ' of ' || l10n_organization_category || ' "' || praxis || '"' AS list_label FROM dem.v_praxis_branches WHERE branch %(fragment_condition)s ) UNION ( SELECT pk_praxis_branch AS data, branch || ' (' || praxis || ')' AS field_label, branch || coalesce(' (' || l10n_unit_category || ')', '') || ' of ' || l10n_organization_category || ' "' || praxis || '"' AS list_label FROM dem.v_praxis_branches WHERE praxis %(fragment_condition)s ) UNION ( SELECT pk_praxis_branch AS data, branch || ' (' || praxis || ')' AS field_label, branch || coalesce(' (' || l10n_unit_category || ')', '') || ' of ' || l10n_organization_category || ' "' || praxis || '"' AS list_label FROM dem.v_praxis_branches WHERE l10n_unit_category %(fragment_condition)s ) ORDER BY list_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(1, 2, 4) gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) self.SetToolTipString(_("Select a praxis branch.")) self.matcher = mp self.selection_only = True self.picklist_delay = 300
def test_prw_sql2(): print "Do you want to test the database connected phrase wheel ?" yes_no = raw_input('y/n: ') if yes_no != 'y': return True gmPG2.get_connection() query = u"""SELECT code, code || ': ' || _(name), _(name) FROM dem.country WHERE _(name) %(fragment_condition)s""" mp = gmMatchProvider.cMatchProvider_SQL2(queries = [query]) app = wx.PyWidgetTester(size = (400, 50)) global prw #prw = cPhraseWheel(parent = app.frame, id = -1) prw = cMultiPhraseWheel(parent = app.frame, id = -1) prw.matcher = mp app.frame.Show(True) app.MainLoop() return True
def __init__(self, *args, **kwargs): query = """ SELECT DISTINCT ON (suburb) suburb, suburb FROM dem.street WHERE suburb %(fragment_condition)s ORDER BY suburb LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) mp.setThresholds(2, 3, 6) gmPhraseWheel.cPhraseWheel.__init__ ( self, *args, **kwargs ) self.SetToolTip(_('Type or select the suburb.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.matcher = mp
def __init_ui(self): self._PRW_hospital_stay.add_callback_on_lose_focus(callback = self._on_hospital_stay_lost_focus) self._PRW_hospital_stay.set_context(context = 'pat', val = gmPerson.gmCurrentPatient().ID) self._PRW_location.add_callback_on_lose_focus(callback = self._on_location_lost_focus) self._DPRW_date.add_callback_on_lose_focus(callback = self._on_start_lost_focus) self._DPRW_end.add_callback_on_lose_focus(callback = self._on_end_lost_focus) # procedure mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [ """ select distinct on (narrative) narrative, narrative from clin.procedure where narrative %(fragment_condition)s order by narrative limit 25 """ ] ) mp.setThresholds(2, 4, 6) self._PRW_procedure.matcher = mp
def __init__(self, *args, **kwargs): super(cRelationshipTypePhraseWheel, self).__init__(*args, **kwargs) query = """ SELECT DISTINCT ON (list_label) pk as data, _(description) as field_label, _(description) as list_label FROM clin.fhx_relation_type WHERE description %(fragment_condition)s OR _(description) %(fragment_condition)s ORDER BY list_label LIMIT 30""" mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 3) self.matcher = mp
def __init__(self, *args, **kwargs): super(cRelationshipTypePhraseWheel, self).__init__(*args, **kwargs) query = u""" SELECT DISTINCT ON (list_label) pk as data, _(description) as field_label, _(description) as list_label FROM clin.fhx_relation_type WHERE description %(fragment_condition)s OR _(description) %(fragment_condition)s ORDER BY list_label LIMIT 30""" mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 3) self.matcher = mp
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__ (self, *args, **kwargs) mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [ """ SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) * FROM ( SELECT pk AS data, _(description) AS field_label, case when _(description) = description then _(description) else _(description) || ' (' || description || ')' end AS list_label FROM clin.encounter_type WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ) AS q_distinct_pk ) AS q_ordered ORDER BY list_label """ ] ) mp.setThresholds(2, 4, 6) self.matcher = mp self.selection_only = True self.picklist_delay = 50
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__ (self, *args, **kwargs) mp = gmMatchProvider.cMatchProvider_SQL2 ( queries = [ u""" SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) * FROM ( SELECT pk AS data, _(description) AS field_label, case when _(description) = description then _(description) else _(description) || ' (' || description || ')' end AS list_label FROM clin.encounter_type WHERE _(description) %(fragment_condition)s OR description %(fragment_condition)s ) AS q_distinct_pk ) AS q_ordered ORDER BY list_label """ ] ) mp.setThresholds(2, 4, 6) self.matcher = mp self.selection_only = True self.picklist_delay = 50
def test_prw_patients(): gmPG2.get_connection() query = u""" select pk_identity, firstnames || ' ' || lastnames || ', ' || to_char(dob, 'YYYY-MM-DD'), firstnames || ' ' || lastnames from dem.v_active_persons where firstnames || lastnames %(fragment_condition)s """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = [query]) app = wx.PyWidgetTester(size = (500, 50)) global prw prw = cPhraseWheel(parent = app.frame, id = -1) prw.matcher = mp prw.selection_only = True app.frame.Show(True) app.MainLoop() return True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__ (self, *args, **kwargs) query = """ SELECT data, list_label, field_label FROM ( SELECT DISTINCT ON (data) * FROM (( -- already-used org_units SELECT pk_org_unit AS data, ward || ' @ ' || hospital AS list_label, ward || ' @ ' || hospital AS field_label, 1 AS rank FROM clin.v_hospital_stays WHERE ward %(fragment_condition)s OR hospital %(fragment_condition)s ) UNION ALL ( -- wards SELECT pk_org_unit AS data, unit || ' (' || l10n_unit_category || ') @ ' || organization AS list_label, unit || ' @ ' || organization AS field_label, 2 AS rank FROM dem.v_org_units WHERE unit_category = 'Ward' AND unit %(fragment_condition)s AND NOT EXISTS ( SELECT 1 FROM clin.v_hospital_stays WHERE clin.v_hospital_stays.pk_org_unit = dem.v_org_units.pk_org_unit ) ) UNION ALL ( -- hospital units SELECT pk_org_unit AS data, unit || coalesce(' (' || l10n_unit_category || ')', '') || ' @ ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' @ ' || organization AS field_label, 3 AS rank FROM dem.v_org_units WHERE unit_category <> 'Ward' AND organization_category = 'Hospital' AND unit %(fragment_condition)s AND NOT EXISTS ( SELECT 1 FROM clin.v_hospital_stays WHERE clin.v_hospital_stays.pk_org_unit = dem.v_org_units.pk_org_unit ) ) UNION ALL ( -- any other units SELECT pk_org_unit AS data, unit || coalesce(' (' || l10n_unit_category || ')', '') || ' @ ' || organization || ' (' || l10n_organization_category || ')' AS list_label, unit || ' @ ' || organization AS field_label, 3 AS rank FROM dem.v_org_units WHERE unit_category <> 'Ward' AND organization_category <> 'Hospital' AND unit %(fragment_condition)s AND NOT EXISTS ( SELECT 1 FROM clin.v_hospital_stays WHERE clin.v_hospital_stays.pk_org_unit = dem.v_org_units.pk_org_unit ) )) AS all_matches ORDER BY data, rank ) AS distinct_matches ORDER BY rank, list_label LIMIT 50 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = [query]) mp.setThresholds(2, 4, 6) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) # consider ATCs in ref.drug_product and ref.vacc_indication query = """ SELECT data, list_label, field_label FROM ( SELECT DISTINCT ON (data) data, list_label, field_label FROM (( -- fragment -> vaccine SELECT r_v_v.pk_vaccine AS data, r_v_v.vaccine || ' (' || (SELECT string_agg(l10n_inds.ind_desc::text, ', ') FROM ( SELECT unnest(r_v_v.indications)->>'l10n_indication' AS ind_desc ) AS l10n_inds) || ')' AS list_label, r_v_v.vaccine AS field_label FROM ref.v_vaccines r_v_v WHERE r_v_v.vaccine %(fragment_condition)s ) union all ( -- fragment -> localized indication -> vaccines SELECT r_vi4v.pk_vaccine AS data, r_vi4v.vaccine || ' (' || (SELECT string_agg(l10n_inds.ind_desc::text, ', ') FROM ( SELECT unnest(r_vi4v.indications)->>'l10n_indication' AS ind_desc ) AS l10n_inds) || ')' AS list_label, r_vi4v.vaccine AS field_label FROM ref.v_indications4vaccine r_vi4v WHERE r_vi4v.l10n_indication %(fragment_condition)s ) union all ( -- fragment -> indication -> vaccines SELECT r_vi4v.pk_vaccine AS data, r_vi4v.vaccine || ' (' || (SELECT string_agg(l10n_inds.ind_desc::text, ', ') FROM ( SELECT unnest(r_vi4v.indications)->>'l10n_indication' AS ind_desc ) AS l10n_inds) || ')' AS list_label, r_vi4v.vaccine AS field_label FROM ref.v_indications4vaccine r_vi4v WHERE r_vi4v.indication %(fragment_condition)s ) ) AS distinct_total ) AS total ORDER by list_label LIMIT 25 """ mp = gmMatchProvider.cMatchProvider_SQL2(queries = query) mp.setThresholds(1, 2, 3) self.matcher = mp self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { 'ctxt_country_name': { 'where_part': 'AND l10n_country ILIKE %(country_name)s OR country ILIKE %(country_name)s', 'placeholder': 'country_name' }, 'ctxt_zip': { 'where_part': 'AND zip ilike %(zip)s', 'placeholder': 'zip' }, 'ctxt_country_code': { 'where_part': 'AND country IN (SELECT code FROM dem.country WHERE _(name) ILIKE %(country_name)s OR name ILIKE %(country_name)s)', 'placeholder': 'country_name' } } query = """ SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (field_label) data, field_label, list_label, rank FROM ( -- 1: find regions based on name, context: zip and country name SELECT code_region AS data, region AS field_label, region || ' (' || code_region || '), ' || l10n_country || ' (' || code_country || ')' AS list_label, 1 AS rank FROM dem.v_zip2data WHERE region %(fragment_condition)s %(ctxt_country_name)s %(ctxt_zip)s UNION ALL -- 2: find regions based on code, context: zip and country name SELECT code_region AS data, region AS field_label, code_region || ': ' || region || ' (' || l10n_country || ', ' || code_country || ')' AS list_label, 2 AS rank FROM dem.v_zip2data WHERE code_region %(fragment_condition)s %(ctxt_country_name)s %(ctxt_zip)s UNION ALL -- 3: find regions based on name, context: country SELECT code AS data, name AS field_label, name || ' (' || code || '), ' || country AS list_label, 3 AS rank FROM dem.region WHERE name %(fragment_condition)s %(ctxt_country_code)s UNION ALL -- 4: find regions based on code, context: country SELECT code AS data, name AS field_label, code || ': ' || name || ', ' || country AS list_label, 3 AS rank FROM dem.region WHERE code %(fragment_condition)s %(ctxt_country_code)s ) AS candidate_regions ) AS distinct_matches ORDER BY rank, list_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp.setThresholds(2, 5, 6) mp.word_separators = '[ \t]+' self.matcher = mp self.unset_context(context = 'zip') self.unset_context(context = 'country_name') self.SetToolTip(_('Type or select a region (state/province/county/territory/arrondissement/prefecture/department/kanton/...).')) self.capitalisation_mode = gmTools.CAPS_FIRST self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { 'ctxt_zip': { 'where_part': 'and zip ilike %(zip)s', 'placeholder': 'zip' } } query = """ SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) data, field_label, list_label, rank FROM ( -- localized to user SELECT code_country AS data, l10n_country AS field_label, l10n_country || ' (' || code_country || '): ' || country AS list_label, 1 AS rank FROM dem.v_zip2data WHERE l10n_country %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT code AS data, _(name) AS field_label, _(name) || ' (' || code || '): ' || name AS list_label, 2 AS rank FROM dem.country WHERE _(name) %(fragment_condition)s UNION ALL -- non-localized SELECT code_country AS data, l10n_country AS field_label, country || ' (' || code_country || '): ' || l10n_country AS list_label, 3 AS rank FROM dem.v_zip2data WHERE country %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT code AS data, _(name) AS field_label, name || ' (' || code || '): ' || _(name) AS list_label, 4 AS rank FROM dem.country WHERE name %(fragment_condition)s UNION ALL -- abbreviation SELECT code AS data, _(name) AS field_label, code || ': ' || _(name) || ' (' || name || ')' AS list_label, 5 AS rank FROM dem.country WHERE code %(fragment_condition)s ) AS candidates ) AS distint_candidates ORDER BY rank, list_label LIMIT 25""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp._SQL_data2match = """ SELECT code AS data, _(name) AS field_label, code || ': ' || _(name) || ' (' || name || ')' AS list_label, 5 AS rank FROM dem.country WHERE code = %(pk)s """ mp.setThresholds(2, 5, 9) self.matcher = mp self.unset_context(context = 'zip') self.SetToolTip(_('Type or select a country.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { u'ctxt_country_name': { u'where_part': u'AND l10n_country ILIKE %(country_name)s OR country ILIKE %(country_name)s', u'placeholder': u'country_name' }, u'ctxt_zip': { u'where_part': u'AND zip ilike %(zip)s', u'placeholder': u'zip' }, u'ctxt_country_code': { u'where_part': u'AND country IN (SELECT code FROM dem.country WHERE _(name) ILIKE %(country_name)s OR name ILIKE %(country_name)s)', u'placeholder': u'country_name' } } query = u""" SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (field_label) data, field_label, list_label, rank FROM ( -- 1: find regions based on name, context: zip and country name SELECT code_region AS data, region AS field_label, region || ' (' || code_region || '), ' || l10n_country || ' (' || code_country || ')' AS list_label, 1 AS rank FROM dem.v_zip2data WHERE region %(fragment_condition)s %(ctxt_country_name)s %(ctxt_zip)s UNION ALL -- 2: find regions based on code, context: zip and country name SELECT code_region AS data, region AS field_label, code_region || ': ' || region || ' (' || l10n_country || ', ' || code_country || ')' AS list_label, 2 AS rank FROM dem.v_zip2data WHERE code_region %(fragment_condition)s %(ctxt_country_name)s %(ctxt_zip)s UNION ALL -- 3: find regions based on name, context: country SELECT code AS data, name AS field_label, name || ' (' || code || '), ' || country AS list_label, 3 AS rank FROM dem.region WHERE name %(fragment_condition)s %(ctxt_country_code)s UNION ALL -- 4: find regions based on code, context: country SELECT code AS data, name AS field_label, code || ': ' || name || ', ' || country AS list_label, 3 AS rank FROM dem.region WHERE code %(fragment_condition)s %(ctxt_country_code)s ) AS candidate_regions ) AS distinct_matches ORDER BY rank, list_label LIMIT 50""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp.setThresholds(2, 5, 6) mp.word_separators = u'[ \t]+' self.matcher = mp self.unset_context(context=u'zip') self.unset_context(context=u'country_name') self.SetToolTipString( _('Type or select a region (state/province/county/territory/arrondissement/prefecture/department/kanton/...).' )) self.capitalisation_mode = gmTools.CAPS_FIRST self.selection_only = True
def __init__(self, *args, **kwargs): gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) context = { u'ctxt_zip': { u'where_part': u'and zip ilike %(zip)s', u'placeholder': u'zip' } } query = u""" SELECT data, field_label, list_label FROM ( SELECT DISTINCT ON (data) data, field_label, list_label, rank FROM ( -- localized to user SELECT code_country AS data, l10n_country AS field_label, l10n_country || ' (' || code_country || '): ' || country AS list_label, 1 AS rank FROM dem.v_zip2data WHERE l10n_country %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT code AS data, _(name) AS field_label, _(name) || ' (' || code || '): ' || name AS list_label, 2 AS rank FROM dem.country WHERE _(name) %(fragment_condition)s UNION ALL -- non-localized SELECT code_country AS data, l10n_country AS field_label, country || ' (' || code_country || '): ' || l10n_country AS list_label, 3 AS rank FROM dem.v_zip2data WHERE country %(fragment_condition)s %(ctxt_zip)s UNION ALL SELECT code AS data, _(name) AS field_label, name || ' (' || code || '): ' || _(name) AS list_label, 4 AS rank FROM dem.country WHERE name %(fragment_condition)s UNION ALL -- abbreviation SELECT code AS data, _(name) AS field_label, code || ': ' || _(name) || ' (' || name || ')' AS list_label, 5 AS rank FROM dem.country WHERE code %(fragment_condition)s ) AS candidates ) AS distint_candidates ORDER BY rank, list_label LIMIT 25""" mp = gmMatchProvider.cMatchProvider_SQL2(queries=query, context=context) mp._SQL_data2match = u""" SELECT code AS data, _(name) AS field_label, code || ': ' || _(name) || ' (' || name || ')' AS list_label, 5 AS rank FROM dem.country WHERE code = %(pk)s """ mp.setThresholds(2, 5, 9) self.matcher = mp self.unset_context(context=u'zip') self.SetToolTipString(_('Type or select a country.')) self.capitalisation_mode = gmTools.CAPS_FIRST self.selection_only = True