Sha256: 3f76de9a012aa3dbad10a065c5ba773b49287eee6c7c7bf90f9db3116e7ff664

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

require_relative 'node'

module ConceptQL
  module Nodes
    # A StandardVocabularyNode is a superclass for a node 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, 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 CPT, this would be procedure_occurrence
    # * concept_column
    #   * Name of the column in the table that stores a concept_id related to the criterion
    #   * e.g. for CPT, this would be procedure_concept_id
    # * vocabulary_id
    #   * The vocabulary ID of the source vocabulary for the criterion
    #   * e.g. for CPT, a value of 4 (for CPT-4)
    class StandardVocabularyNode < Node
      def query(db)
        db.from(table_name)
          .join(:vocabulary__concept___c, c__concept_id: table_concept_column)
          .where(c__concept_code: values, c__vocabulary_id: vocabulary_id)
      end

      def type
        table
      end
      private

      def table_name
        @table_name ||= make_table_name(table)
      end

      def table_concept_column
        "tab__#{concept_column}".to_sym
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
conceptql-0.1.1 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.1.0 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.9 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.8 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.7 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.6 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.5 lib/conceptql/nodes/standard_vocabulary_node.rb
conceptql-0.0.4 lib/conceptql/nodes/standard_vocabulary_node.rb