Module: Scat::Autocomplete
- Included in:
- App
- Defined in:
- lib/scat/autocomplete.rb
Overview
Auto-completion mix-in.
Instance Method Summary collapse
-
#autocomplete(attribute, text) ⇒ String
Fetches controlled caTissue values for the given attribute and value prefix.
Instance Method Details
#autocomplete(attribute, text) ⇒ String
Fetches controlled caTissue values for the given attribute and value prefix. The supported attributes include the following:
-
:clinical_diagnosis
(SpecimenCollectionGroup.clinical_diagnosis
) -
:tissue_site
(SpecimenCharacteristics.tissue_site
)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/scat/autocomplete.rb', line 16 def autocomplete(attribute, text) # Start up the cache if necessary @cache ||= Cache.new # Compare lower case. text_dc = text.downcase # The search term is the first word in the text. words = text_dc.split(' ') term = words.first logger.debug { "Scat is matching the cached #{attribute} values which contain #{term}..." } # The hash key, e.g. dx:lymphoma. key = KEY_PREFIX_HASH[attribute] + term # The CVs which match the term. cvs = @cache.get_all(key) # Load the CVs if necessary. cvs = load_controlled_values(attribute, term, key) if cvs.empty? # The CVs which match the entire target. matched = words.size == 1 ? cvs : cvs.select { |cv| cv.downcase[text_dc] } logger.debug { "#{matched.empty? ? 'No' : matched.size} #{attribute} values match '#{text}'." } matched.to_json end |