class ConceptQL::Operators::StandardVocabularyOperator

A StandardVocabularyOperator is a superclass for a operator that represents a criterion whose column stores information associated with a standard vocabulary.

If that seems confusing, then think of CPT or SNOMED criteria. That type of criterion takes a set of values that live in the OMOP concept table.

My coworker came up with a nice, generalized query that checks for matching concept_ids and matching source_code values. This class encapsulates that query.

Subclasses must provide the following methods:

Public Instance Methods

conditions(db) click to toggle source
# File lib/conceptql/operators/standard_vocabulary_operator.rb, line 36
def conditions(db)
  if omopv4?
    {c__concept_code: arguments_fix(db), c__vocabulary_id: vocabulary_id}
  else
    conditions = { code_column => arguments_fix(db) }
    conditions[vocabulary_id_column] = vocabulary_id if vocabulary_id_column
    conditions
  end
end
describe_code(db, code) click to toggle source
# File lib/conceptql/operators/standard_vocabulary_operator.rb, line 46
def describe_code(db, code)
  db[:concept].filter(:vocabulary_id => vocabulary_id).filter(:concept_code => code).map(:concept_name)[0]
end
query(db) click to toggle source
# File lib/conceptql/operators/standard_vocabulary_operator.rb, line 23
def query(db)
  ds = db.from(table_name)
    .where(conditions(db))
  if omopv4?
    ds = ds.join(:concept___c, c__concept_id: table_concept_column)
  end
  ds
end
query_cols() click to toggle source
# File lib/conceptql/operators/standard_vocabulary_operator.rb, line 32
def query_cols
  table_columns(table_name, :concept)
end

Private Instance Methods

validate(db, opts = {}) click to toggle source
Calls superclass method
# File lib/conceptql/operators/standard_vocabulary_operator.rb, line 52
def validate(db, opts = {})
  super
  if add_warnings?(db, opts)
    args = arguments.dup
    args -= bad_arguments
    missing_args = args - db[:concept].where(:vocabulary_id=>vocabulary_id, :concept_code=>arguments_fix(db, args)).select_map(:concept_code)
    unless missing_args.empty?
      add_warning("unknown concept code", *missing_args)
    end
  end
end