<commit_before>require "active_support/concern"

module ConceptQL
  module Behaviors
    module Utilizable
      extend ActiveSupport::Concern
      include ConceptQL::Behaviors::Windowable

      included do
        domains :condition_occurrence
        category "Select by Property"
        basic_type :selection
        validate_no_upstreams
        validate_no_arguments

        require_column :length_of_stay
        require_column :admission_source
        require_column :discharge_location
      end

      def query(db)
        return db[:condition_occurrence].limit(1).nullify if omopv4_plus?
        return gdm_it(db)
      end

      def collection_type
        raise NotImplementedError
      end

      def gdm_it(db)
        ancestor_ids = lexicon.concepts("JIGSAW_FILE_PROVENANCE_TYPE", collection_type).select(:id)
        descendant_ids = lexicon.descendants_of(ancestor_ids).select_map(:descendant_id)
        primary_ids = lexicon.concepts("JIGSAW_CODE_PROVENANCE_TYPE", "primary").select_map(:id)

        primary_concepts = db[:clinical_codes].from_self(alias: :pcc)
          .join(:contexts, { Sequel[:pcn][:id] => Sequel[:pcc][:context_id] }, table_alias: :pcn)
          .join(:concepts, { Sequel[:pco][:id] => Sequel[:pcc][:clinical_code_concept_id] }, table_alias: :pco)
          .where(provenance_concept_id: primary_ids)
          .select(Sequel[:pcn][:collection_id], Sequel[:pco][:concept_code], Sequel[:pco][:vocabulary_id])


        db[:collections].from_self(alias: :cl)
          .join(:admission_details, { Sequel[:ad][:id] => Sequel[:cl][:admission_detail_id] }, table_alias: :ad)
          .left_join(:contexts, { Sequel[:cn][:collection_id] => Sequel[:cl][:id] }, table_alias: :cn)<commit_msg>Utilizable: fix issue bug where Lexicon bled into dataset<commit_after>require "active_support/concern"

module ConceptQL
  module Behaviors
    module Utilizable
      extend ActiveSupport::Concern
      include ConceptQL::Behaviors::Windowable

      included do
        domains :condition_occurrence
        category "Select by Property"
        basic_type :selection
        validate_no_upstreams
        validate_no_arguments

        require_column :length_of_stay
        require_column :admission_source
        require_column :discharge_location
      end

      def query(db)
        return db[:condition_occurrence].limit(1).nullify if omopv4_plus?
        return gdm_it(db)
      end

      def collection_type
        raise NotImplementedError
      end

      def gdm_it(db)
        ancestor_ids = lexicon.concepts("JIGSAW_FILE_PROVENANCE_TYPE", collection_type).select_map(:id)
        descendant_ids = lexicon.descendants_of(ancestor_ids).select_map(:descendant_id)
        primary_ids = lexicon.concepts("JIGSAW_CODE_PROVENANCE_TYPE", "primary").select_map(:id)

        primary_concepts = db[:clinical_codes].from_self(alias: :pcc)
          .join(:contexts, { Sequel[:pcn][:id] => Sequel[:pcc][:context_id] }, table_alias: :pcn)
          .join(:concepts, { Sequel[:pco][:id] => Sequel[:pcc][:clinical_code_concept_id] }, table_alias: :pco)
          .where(provenance_concept_id: primary_ids)
          .select(Sequel[:pcn][:collection_id], Sequel[:pco][:concept_code], Sequel[:pco][:vocabulary_id])


        db[:collections].from_self(alias: :cl)
          .join(:admission_details, { Sequel[:ad][:id] => Sequel[:cl][:admission_detail_id] }, table_alias: :ad)
          .left_join(:contexts, { Sequel[:cn][:collection_id] => Sequel[:cl][:id] }, table_alias: :cn)
{'fraction_non_alphanumeric': 0.11676136363636364, 'fraction_numerical': 0.0011363636363636363, 'mean_word_length': 3.651254953764861, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1993939', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1133, 'n_words': 177}