Package Gnumed :: Package pycommon :: Module gmMatchProvider :: Class cMatchProvider_SQL2 |
[frames] | no frames]

# Class cMatchProvider_SQL2

source code

        object --+
                 |
    cMatchProvider --+
                     |
                    cMatchProvider_SQL2

Known Subclasses:
  - wxpython.gmAddressWidgets.cAddressMatchProvider

    Match provider which searches matches
       in possibly several database tables.

    queries:
            - a list of unicode strings
            - each string is a query
            - each string must contain: "... WHERE <column> %(fragment_condition)s ..."
            - each string can contain in the where clause: "... %(<ctxt_key1>)s ..."
            - each query must return (data, list_label, field_label)

    context definitions to be used in the queries, example:
            {'ctxt_key1': {'where_part': 'AND country = %(country)s', 'placeholder': 'country'}}

    client code using .set_context() must use the 'placeholder':
            <phrasewheel>/<match provider>.set_context('country', 'Germany')

    full example query:

            query = 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
                            (
                                    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 = %(PLACEHOLDER)s',
                    'placeholder': u'PLACEHOLDER'
            }}
            self.mp = gmMatchProvider.cMatchProvider_SQL2(queries = query, context = context)
            self.set_context(context = 'PLACEHOLDER', val = '<THE VALUE>')

    _SQL_data2match:
            SQL to retrieve a match by, say, primary key
            wherein the only keyword argument is 'pk'

Instance Methods
__init__(self, queries=None, context=None) x.__init__(...) initializes x; see x.__class__.__doc__ for signature | source code
getAllMatches(self) Return all items. | source code
getMatchesByPhrase(self, aFragment) Return matches for aFragment at start of phrases. | source code
getMatchesBySubstr(self, aFragment) Return matches for aFragment as a true substring. | source code
getMatchesByWord(self, aFragment) Return matches for aFragment at start of words inside phrases. | source code
get_match_by_data(self, data=None) | source code
Inherited from `cMatchProvider`: `getMatches`, `setThresholds`, `set_context`, `unset_context` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables
Inherited from `cMatchProvider`: `print_queries`

Properties
Inherited from `cMatchProvider`: `ignored_chars`, `word_separators` Inherited from `object`: `__class__`

Method Details

### __init__(self, queries=None, context=None) (Constructor) | source code
x.__init__(...) initializes x; see x.__class__.__doc__ for signature Overrides: object.__init__ (inherited documentation)

### getAllMatches(self) | source code
Return all items. Overrides: cMatchProvider.getAllMatches

### getMatchesByPhrase(self, aFragment) | source code
Return matches for aFragment at start of phrases. Overrides: cMatchProvider.getMatchesByPhrase

### getMatchesBySubstr(self, aFragment) | source code
Return matches for aFragment as a true substring. Overrides: cMatchProvider.getMatchesBySubstr

### getMatchesByWord(self, aFragment) | source code
Return matches for aFragment at start of words inside phrases. Overrides: cMatchProvider.getMatchesByWord

### get_match_by_data(self, data=None) | source code
Overrides: cMatchProvider.get_match_by_data