Class: ConceptQL::Operators::SourceVocabularyOperator

Inherits:
VocabularyOperator show all
Defined in:
lib/conceptql/operators/source_vocabulary_operator.rb

Overview

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

If that seems confusing, then think of ICD-9 or NDC criteria. That type of criterion takes a set of values that are mapped via the source_to_concept_map table into a standard vocabulary.

This kind of criterion can have some interesting issues when we are searching for rows that match. Let’s take ICD-9 286.53 for example. That code maps to concept_id 0, so if we try to pull all conditions that match just the concept_id of 0 we’ll pull all condtions that have no match in the SNOMED standard vocabulary. That’s not what we want! So we need to search the condition_source_value field for matches on this code instead.

But there’s another, more complicated problem. Say we’re looking for ICD-9 289.81. OMOP maps this to concept_id 432585. OMOP also maps 20 other conditions, 6 of which are other ICD-9 codes, to this same concept_id. So if we look for ICD-9s that have a non-zero condition_condept_id, we might pull up conditions that match on concept_id, but aren’t the same exact code as the one we’re looking for.

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

Subclasses must provide the following methods:

  • table

    • The CDM table name where the criterion will fetch its rows

    • e.g. for ICD-9, this would be condition_occurrence

  • concept_column

    • Name of the column in the table that stores a concept_id related to the criterion

    • e.g. for ICD-9, this would be condition_concept_id

  • source_column

    • Name of the column in the table that stores the “raw” value related to the criterion

    • e.g. for ICD-9, this would be condition_source_value

  • vocabulary_id

    • The vocabulary ID of the source vocabulary for the criterion

    • e.g. for ICD-9, a value of 2 (for ICD-9-CM)

Instance Attribute Summary

Attributes inherited from Operator

#arguments, #errors, #nodifier, #options, #upstreams, #values

Instance Method Summary collapse

Methods inherited from VocabularyOperator

#code_list, #domain

Methods inherited from Operator

#annotate, #cast_column, #code_list, codes_should_match, #columns, #create_upstreams, #data_model, #database_type, default_query_columns, #domains, #dup_values, #dynamic_columns, #evaluate, inherited, #initialize, #inspect, #label, new, #operator_name, #optimized, query_columns, register, require_column, #required_columns, #scope, #select_it, #setup_select, #sql, #stream, #to_op, #upstreams_valid?, #valid?

Methods included from Metadatable

#allows_many_upstreams, #allows_one_upstream, #argument, #auto_label, #basic_type, #category, #derive_metadata_from_validations, #desc, #domains, #get_desc, #humanized_class_name, #inherited, #just_class_name, #no_desc, #option, #predominant_domains, #pref_name, #preferred_name, #reset_categories, #standard_description, #to_metadata, #validate_at_least_one_upstream_to_metadata, #validate_at_most_one_upstream_to_metadata, #validate_no_arguments_to_metadata, #validate_no_upstreams_to_metadata, #validate_one_upstream_to_metadata, #validate_required_options_to_metadata, #warn_about_missing_metadata

Constructor Details

This class inherits a constructor from ConceptQL::Operators::Operator

Instance Method Details

#conditions(db) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 54

def conditions(db)
  if omopv4?
    [[:scm__source_code, arguments_fix(db)], [:scm__source_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) ⇒ Object



64
65
66
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 64

def describe_code(db, code)
  db[:source_to_concept_map].filter(:source_vocabulary_id => vocabulary_id).filter(:source_code => code).map(:source_code_description)[0]
end

#query(db) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 30

def query(db)
  ds = db.from(table_name).where(conditions(db))
  if omopv4?
    ds = ds.join(:source_to_concept_map___scm, [[:scm__target_concept_id, table_concept_column], [:scm__source_code, table_source_column]])
  end
  ds
end

#query_colsObject



38
39
40
41
42
43
44
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 38

def query_cols
  if omopv4?
    table_columns(table_name, :source_to_concept_map)
  else
    table_columns(table_name)
  end
end

#union(other) ⇒ Object



50
51
52
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 50

def union(other)
  dup_values(values + other.values)
end

#unionable?(other) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/conceptql/operators/source_vocabulary_operator.rb', line 46

def unionable?(other)
  other.is_a?(self.class)
end