conceptql 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +226 -117
- data/LICENSE +21 -0
- data/README.md +35 -83
- data/bin/conceptql +2 -1
- data/bin/conceptql_utils +6 -0
- data/config/multiple_vocabularies.csv +4 -0
- data/config/provenance.yml +489 -0
- data/config/race.yml +50 -0
- data/config/vocabularies.csv +87 -0
- data/lib/conceptql/behaviors/code_lister.rb +23 -0
- data/lib/conceptql/behaviors/drugish.rb +17 -0
- data/lib/conceptql/behaviors/labish.rb +19 -0
- data/lib/conceptql/behaviors/metadatable.rb +226 -73
- data/lib/conceptql/behaviors/provenanceable.rb +26 -0
- data/lib/conceptql/behaviors/single_event.rb +11 -0
- data/lib/conceptql/behaviors/timeless.rb +11 -0
- data/lib/conceptql/behaviors/utilizable.rb +206 -0
- data/lib/conceptql/behaviors/windowable.rb +27 -0
- data/lib/conceptql/cli.rb +117 -108
- data/lib/conceptql/columnizer.rb +75 -0
- data/lib/conceptql/data_model/base.rb +462 -0
- data/lib/conceptql/data_model/gdm.rb +155 -0
- data/lib/conceptql/data_model/gdm_wide.rb +42 -0
- data/lib/conceptql/data_model/omopv4_plus.rb +12 -0
- data/lib/conceptql/data_model.rb +30 -0
- data/lib/conceptql/database.rb +214 -0
- data/lib/conceptql/date_adjuster.rb +66 -18
- data/lib/conceptql/diagram.rb +243 -0
- data/lib/conceptql/lexicon/lexicon_gdm.rb +47 -0
- data/lib/conceptql/lexicon/lexicon_no_db.rb +49 -0
- data/lib/conceptql/lexicon/lexicon_ohdsi.rb +63 -0
- data/lib/conceptql/lexicon/lexicon_strategy.rb +116 -0
- data/lib/conceptql/lexicon.rb +111 -0
- data/lib/conceptql/nodifier.rb +65 -24
- data/lib/conceptql/operators/after.rb +34 -14
- data/lib/conceptql/operators/any_overlap.rb +8 -6
- data/lib/conceptql/operators/before.rb +34 -10
- data/lib/conceptql/operators/binary_operator_operator.rb +66 -23
- data/lib/conceptql/operators/casting_operator.rb +51 -36
- data/lib/conceptql/operators/co_reported.rb +111 -0
- data/lib/conceptql/operators/concurrent_within.rb +69 -0
- data/lib/conceptql/operators/contains.rb +12 -8
- data/lib/conceptql/operators/count.rb +17 -9
- data/lib/conceptql/operators/date_range.rb +48 -14
- data/lib/conceptql/operators/death.rb +14 -4
- data/lib/conceptql/operators/dedup.rb +31 -0
- data/lib/conceptql/operators/during.rb +7 -12
- data/lib/conceptql/operators/episode.rb +146 -0
- data/lib/conceptql/operators/equal.rb +9 -3
- data/lib/conceptql/operators/ethnicity.rb +49 -0
- data/lib/conceptql/operators/except.rb +19 -12
- data/lib/conceptql/operators/filter.rb +23 -8
- data/lib/conceptql/operators/first.rb +16 -3
- data/lib/conceptql/operators/from.rb +52 -4
- data/lib/conceptql/operators/gender.rb +34 -11
- data/lib/conceptql/operators/hospice.rb +19 -0
- data/lib/conceptql/operators/hospitalization.rb +19 -0
- data/lib/conceptql/operators/information_periods.rb +36 -0
- data/lib/conceptql/operators/invalid.rb +35 -0
- data/lib/conceptql/operators/last.rb +16 -3
- data/lib/conceptql/operators/match.rb +91 -0
- data/lib/conceptql/operators/multiple_vocabularies.rb +172 -0
- data/lib/conceptql/operators/numeric.rb +65 -23
- data/lib/conceptql/operators/numeric_filter.rb +68 -0
- data/lib/conceptql/operators/occurrence.rb +153 -32
- data/lib/conceptql/operators/one_in_two_out.rb +237 -38
- data/lib/conceptql/operators/operator.rb +624 -178
- data/lib/conceptql/operators/pass_thru.rb +17 -3
- data/lib/conceptql/operators/person.rb +18 -6
- data/lib/conceptql/operators/person_filter.rb +9 -3
- data/lib/conceptql/operators/place_of_service_filter.rb +43 -0
- data/lib/conceptql/operators/provenance.rb +55 -0
- data/lib/conceptql/operators/provider_filter.rb +62 -0
- data/lib/conceptql/operators/race.rb +55 -7
- data/lib/conceptql/operators/read.rb +168 -0
- data/lib/conceptql/operators/recall.rb +49 -14
- data/lib/conceptql/operators/snf.rb +19 -0
- data/lib/conceptql/operators/sum.rb +29 -12
- data/lib/conceptql/operators/temporal_operator.rb +108 -16
- data/lib/conceptql/operators/time_window.rb +20 -32
- data/lib/conceptql/operators/trim_date.rb +71 -0
- data/lib/conceptql/operators/trim_date_end.rb +28 -40
- data/lib/conceptql/operators/trim_date_start.rb +28 -41
- data/lib/conceptql/operators/union.rb +67 -6
- data/lib/conceptql/operators/vocabulary.rb +151 -0
- data/lib/conceptql/paths.rb +41 -0
- data/lib/conceptql/query.rb +191 -26
- data/lib/conceptql/query_modifiers/gdm/admission_date_query_modifier.rb +46 -0
- data/lib/conceptql/query_modifiers/gdm/drug_query_modifier.rb +54 -0
- data/lib/conceptql/query_modifiers/gdm/lab_query_modifier.rb +57 -0
- data/lib/conceptql/query_modifiers/gdm/pos_query_modifier.rb +46 -0
- data/lib/conceptql/query_modifiers/gdm/provenance_query_modifier.rb +45 -0
- data/lib/conceptql/query_modifiers/gdm/provider_query_modifier.rb +53 -0
- data/lib/conceptql/query_modifiers/gdm_wide/admission_date_query_modifier.rb +42 -0
- data/lib/conceptql/query_modifiers/gdm_wide/drug_query_modifier.rb +52 -0
- data/lib/conceptql/query_modifiers/gdm_wide/lab_query_modifier.rb +55 -0
- data/lib/conceptql/query_modifiers/gdm_wide/pos_query_modifier.rb +37 -0
- data/lib/conceptql/query_modifiers/gdm_wide/provenance_query_modifier.rb +38 -0
- data/lib/conceptql/query_modifiers/omopv4_plus/admission_date_query_modifier.rb +45 -0
- data/lib/conceptql/query_modifiers/omopv4_plus/drug_query_modifier.rb +80 -0
- data/lib/conceptql/query_modifiers/omopv4_plus/pos_query_modifier.rb +47 -0
- data/lib/conceptql/query_modifiers/omopv4_plus/provenance_query_modifier.rb +45 -0
- data/lib/conceptql/query_modifiers/omopv4_plus/provider_query_modifier.rb +26 -0
- data/lib/conceptql/query_modifiers/query_modifier.rb +20 -0
- data/lib/conceptql/rdbms/duckdb.rb +25 -0
- data/lib/conceptql/rdbms/generic.rb +120 -0
- data/lib/conceptql/rdbms/postgres.rb +51 -0
- data/lib/conceptql/rdbms/spark.rb +22 -0
- data/lib/conceptql/rdbms.rb +22 -0
- data/lib/conceptql/scope.rb +481 -31
- data/lib/conceptql/sql_formatters/formatter.rb +25 -0
- data/lib/conceptql/sql_formatters.rb +22 -0
- data/lib/conceptql/utils.rb +113 -0
- data/lib/conceptql/utils_cli.rb +17 -0
- data/lib/conceptql/version.rb +3 -1
- data/lib/conceptql/visitors/metadata_extractor.rb +54 -0
- data/lib/conceptql/vocabularies/behaviors/costish.rb +24 -0
- data/lib/conceptql/vocabularies/behaviors/gdmish.rb +19 -0
- data/lib/conceptql/vocabularies/behaviors/omopish.rb +32 -0
- data/lib/conceptql/vocabularies/dynamic_vocabularies.rb +63 -0
- data/lib/conceptql/vocabularies/entry.rb +138 -0
- data/lib/conceptql/vocabularies/vocabulary_class_factory.rb +85 -0
- data/lib/conceptql/window/base.rb +26 -0
- data/lib/conceptql/window/date_range.rb +25 -0
- data/lib/conceptql/window/table.rb +116 -0
- data/lib/conceptql/window.rb +72 -0
- data/lib/conceptql.rb +65 -2
- data/lib/sequel/extensions/pg_ctas_explain.rb +22 -0
- data/lib/sequel/extensions/pg_vacuum_table.rb +23 -0
- data/schemas/gdm.yml +882 -0
- data/schemas/gdm_wide.yml +757 -0
- data/schemas/ohdsi_vocabs.yml +143 -0
- data/schemas/omopv4_plus.yml +729 -0
- data/schemas/omopv4_plus_more_ignorables.tsv +13 -0
- metadata +267 -207
- data/.gitignore +0 -23
- data/Gemfile +0 -4
- data/Guardfile +0 -56
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -1
- data/conceptql.gemspec +0 -32
- data/doc/ConceptQL Specification (alpha).pdf +0 -0
- data/doc/diagram_0.png +0 -0
- data/doc/implementation_notes.md +0 -39
- data/doc/spec.md +0 -1344
- data/lib/conceptql/behaviors/debuggable.rb +0 -70
- data/lib/conceptql/behaviors/dottable.rb +0 -103
- data/lib/conceptql/behaviors/preppable.rb +0 -20
- data/lib/conceptql/converter.rb +0 -65
- data/lib/conceptql/debugger.rb +0 -48
- data/lib/conceptql/fake_grapher.rb +0 -20
- data/lib/conceptql/graph.rb +0 -52
- data/lib/conceptql/graph_nodifier.rb +0 -203
- data/lib/conceptql/logger.rb +0 -10
- data/lib/conceptql/operators/complement.rb +0 -38
- data/lib/conceptql/operators/concept.rb +0 -70
- data/lib/conceptql/operators/condition_type.rb +0 -71
- data/lib/conceptql/operators/cpt.rb +0 -25
- data/lib/conceptql/operators/drug_type_concept.rb +0 -21
- data/lib/conceptql/operators/from_seer_visits.rb +0 -23
- data/lib/conceptql/operators/hcpcs.rb +0 -25
- data/lib/conceptql/operators/icd10.rb +0 -28
- data/lib/conceptql/operators/icd9.rb +0 -28
- data/lib/conceptql/operators/icd9_procedure.rb +0 -25
- data/lib/conceptql/operators/intersect.rb +0 -34
- data/lib/conceptql/operators/loinc.rb +0 -25
- data/lib/conceptql/operators/medcode.rb +0 -28
- data/lib/conceptql/operators/medcode_procedure.rb +0 -27
- data/lib/conceptql/operators/ndc.rb +0 -29
- data/lib/conceptql/operators/observation_by_enttype.rb +0 -29
- data/lib/conceptql/operators/observation_period.rb +0 -30
- data/lib/conceptql/operators/overlapped_by.rb +0 -23
- data/lib/conceptql/operators/overlaps.rb +0 -19
- data/lib/conceptql/operators/place_of_service_code.rb +0 -24
- data/lib/conceptql/operators/procedure_occurrence.rb +0 -25
- data/lib/conceptql/operators/prodcode.rb +0 -29
- data/lib/conceptql/operators/rxnorm.rb +0 -24
- data/lib/conceptql/operators/snomed.rb +0 -24
- data/lib/conceptql/operators/snomed_condition.rb +0 -26
- data/lib/conceptql/operators/source_vocabulary_operator.rb +0 -58
- data/lib/conceptql/operators/standard_vocabulary_operator.rb +0 -45
- data/lib/conceptql/operators/started_by.rb +0 -22
- data/lib/conceptql/operators/to_seer_visits.rb +0 -24
- data/lib/conceptql/operators/visit.rb +0 -15
- data/lib/conceptql/operators/visit_occurrence.rb +0 -30
- data/lib/conceptql/tree.rb +0 -53
- data/lib/conceptql/utils/temp_table.rb +0 -72
- data/spec/conceptql/behaviors/dottable_spec.rb +0 -99
- data/spec/conceptql/converter_spec.rb +0 -51
- data/spec/conceptql/date_adjuster_spec.rb +0 -68
- data/spec/conceptql/operators/after_spec.rb +0 -16
- data/spec/conceptql/operators/before_spec.rb +0 -16
- data/spec/conceptql/operators/casting_operator_spec.rb +0 -68
- data/spec/conceptql/operators/complement_spec.rb +0 -15
- data/spec/conceptql/operators/concept_spec.rb +0 -40
- data/spec/conceptql/operators/condition_type_spec.rb +0 -128
- data/spec/conceptql/operators/contains_spec.rb +0 -19
- data/spec/conceptql/operators/cpt_spec.rb +0 -29
- data/spec/conceptql/operators/date_range_spec.rb +0 -33
- data/spec/conceptql/operators/death_spec.rb +0 -10
- data/spec/conceptql/operators/during_spec.rb +0 -30
- data/spec/conceptql/operators/except_spec.rb +0 -15
- data/spec/conceptql/operators/first_spec.rb +0 -35
- data/spec/conceptql/operators/from_spec.rb +0 -13
- data/spec/conceptql/operators/gender_spec.rb +0 -27
- data/spec/conceptql/operators/hcpcs_spec.rb +0 -29
- data/spec/conceptql/operators/icd10_spec.rb +0 -34
- data/spec/conceptql/operators/icd9_procedure_spec.rb +0 -29
- data/spec/conceptql/operators/icd9_spec.rb +0 -34
- data/spec/conceptql/operators/intersect_spec.rb +0 -28
- data/spec/conceptql/operators/last_spec.rb +0 -36
- data/spec/conceptql/operators/loinc_spec.rb +0 -29
- data/spec/conceptql/operators/medcode_procedure_spec.rb +0 -34
- data/spec/conceptql/operators/medcode_spec.rb +0 -34
- data/spec/conceptql/operators/observation_period_spec.rb +0 -10
- data/spec/conceptql/operators/occurrence_spec.rb +0 -87
- data/spec/conceptql/operators/overlapped_by_spec.rb +0 -32
- data/spec/conceptql/operators/overlaps_spec.rb +0 -21
- data/spec/conceptql/operators/person_filter_spec.rb +0 -15
- data/spec/conceptql/operators/person_spec.rb +0 -10
- data/spec/conceptql/operators/place_of_service_code_spec.rb +0 -24
- data/spec/conceptql/operators/procedure_occurrence_spec.rb +0 -10
- data/spec/conceptql/operators/prodcode_spec.rb +0 -35
- data/spec/conceptql/operators/query_double.rb +0 -20
- data/spec/conceptql/operators/query_double_spec.rb +0 -7
- data/spec/conceptql/operators/race_spec.rb +0 -21
- data/spec/conceptql/operators/rxnorm_spec.rb +0 -29
- data/spec/conceptql/operators/snomed_spec.rb +0 -29
- data/spec/conceptql/operators/source_vocabulary_operator_spec.rb +0 -35
- data/spec/conceptql/operators/standard_vocabulary_operator_spec.rb +0 -35
- data/spec/conceptql/operators/started_by_spec.rb +0 -22
- data/spec/conceptql/operators/temporal_operator_spec.rb +0 -51
- data/spec/conceptql/operators/time_window_spec.rb +0 -77
- data/spec/conceptql/operators/union_spec.rb +0 -21
- data/spec/conceptql/operators/visit_occurrence_spec.rb +0 -10
- data/spec/conceptql/query_spec.rb +0 -22
- data/spec/conceptql/tree_spec.rb +0 -50
- data/spec/doubles/stream_for_casting_double.rb +0 -9
- data/spec/doubles/stream_for_occurrence_double.rb +0 -25
- data/spec/doubles/stream_for_temporal_double.rb +0 -6
- data/spec/spec_helper.rb +0 -102
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ConceptQL
|
|
6
|
+
module Window
|
|
7
|
+
# Provides a scope window based on the ConceptQL result set of another table
|
|
8
|
+
class Table < Base
|
|
9
|
+
def call(op, query, options = {})
|
|
10
|
+
l_table = Sequel[:l]
|
|
11
|
+
r_table = Sequel[:r]
|
|
12
|
+
r_start_date = apply_adjustments(op, r_table[:start_date], adjust_start)
|
|
13
|
+
r_end_date = apply_adjustments(op, r_table[:end_date], adjust_end)
|
|
14
|
+
|
|
15
|
+
exprs = []
|
|
16
|
+
exprs << Sequel.expr(l_table[:person_id] => r_table[:person_id])
|
|
17
|
+
|
|
18
|
+
query = Sequel[query] if query.is_a?(Symbol)
|
|
19
|
+
|
|
20
|
+
unless options[:timeless]
|
|
21
|
+
exprs << (r_start_date <= l_table[event_start_date_column])
|
|
22
|
+
exprs << (l_table[event_end_date_column] <= r_end_date)
|
|
23
|
+
end
|
|
24
|
+
expr = exprs.inject(&:&)
|
|
25
|
+
|
|
26
|
+
rhs = query.db[get_table_window(query)]
|
|
27
|
+
|
|
28
|
+
unless opts[:precalculated_window_id]
|
|
29
|
+
rhs = remove_window_id(rhs)
|
|
30
|
+
rhs = rhs
|
|
31
|
+
.select_group(:person_id, :start_date, :end_date)
|
|
32
|
+
.select_append do
|
|
33
|
+
row_number.function.over(order: %i[person_id start_date end_date])
|
|
34
|
+
.as(:window_id)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
rhs = rhs.as(:r)
|
|
39
|
+
|
|
40
|
+
remove_window_id(query)
|
|
41
|
+
.from_self(alias: :l)
|
|
42
|
+
.join(rhs, expr)
|
|
43
|
+
.select_all(:l)
|
|
44
|
+
.select_append(r_table[:window_id])
|
|
45
|
+
.from_self
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The persons this window covers. An operator that runs a window
|
|
49
|
+
# function over a whole table filters on this first, because a database
|
|
50
|
+
# cannot push the window join (#call) below that function.
|
|
51
|
+
def person_ids(db)
|
|
52
|
+
db[get_table_window(nil)].select(:person_id)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def remove_window_id(ds)
|
|
56
|
+
cols = ds.opts[:select]
|
|
57
|
+
if cols && !cols.empty? && cols.any? { |c| !c.is_a?(Symbol) }
|
|
58
|
+
# When select has non-symbol expressions (e.g. CAST...AS),
|
|
59
|
+
# select_remove can't match them by symbol name, so filter manually
|
|
60
|
+
ds.select(*cols.reject { |c| window_id_column?(c) })
|
|
61
|
+
else
|
|
62
|
+
ds.select_remove(:window_id)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def window_id_column?(col)
|
|
67
|
+
case col
|
|
68
|
+
when Symbol
|
|
69
|
+
col == :window_id
|
|
70
|
+
when Sequel::SQL::AliasedExpression
|
|
71
|
+
col.alias == :window_id
|
|
72
|
+
when Sequel::SQL::QualifiedIdentifier
|
|
73
|
+
col.column == :window_id
|
|
74
|
+
else
|
|
75
|
+
false
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def get_table_window(_query)
|
|
80
|
+
case table_window
|
|
81
|
+
when Array
|
|
82
|
+
cdb.query(table_window).query(force_temp_tables: false)
|
|
83
|
+
when String
|
|
84
|
+
tables = table_window.split(".")
|
|
85
|
+
tables.length == 2 ? Sequel.qualify(*tables) : Sequel.identifier(table_window)
|
|
86
|
+
when Symbol
|
|
87
|
+
Sequel[table_window]
|
|
88
|
+
else
|
|
89
|
+
table_window
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def apply_adjustments(op, column, adjustment)
|
|
94
|
+
return column unless adjustment
|
|
95
|
+
|
|
96
|
+
DateAdjuster.new(op, adjustment).adjust(column)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def table_window
|
|
100
|
+
opts[:window_table]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def cdb
|
|
104
|
+
opts[:cdb]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def adjust_start
|
|
108
|
+
opts[:adjust_window_start]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def adjust_end
|
|
112
|
+
opts[:adjust_window_end]
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "window/table"
|
|
4
|
+
require_relative "window/date_range"
|
|
5
|
+
|
|
6
|
+
module ConceptQL
|
|
7
|
+
# Provides a singleton method which will return a series of scope windows
|
|
8
|
+
# that should be applied to each selection operator in a ConceptQL statement
|
|
9
|
+
module Window
|
|
10
|
+
class << self
|
|
11
|
+
EVENT_DATE_COLUMNS = {
|
|
12
|
+
nil => %i[start_date start_date],
|
|
13
|
+
start_date: %i[start_date start_date],
|
|
14
|
+
end_date: %i[end_date end_date],
|
|
15
|
+
date_range: %i[start_date end_date]
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
def from(opts)
|
|
19
|
+
fetch_windows(prep_options(opts))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def fetch_windows(opts)
|
|
23
|
+
windows = []
|
|
24
|
+
|
|
25
|
+
windows << date_range_window(opts) if use_date_range?(opts)
|
|
26
|
+
|
|
27
|
+
windows << table_window(opts) if use_table_window?(opts)
|
|
28
|
+
|
|
29
|
+
windows << person_filter(opts) if use_person_filter?(opts)
|
|
30
|
+
|
|
31
|
+
windows
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def use_date_range?(opts)
|
|
35
|
+
opts[:start_date] && opts[:end_date]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def use_table_window?(opts)
|
|
39
|
+
opts[:window_table]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def use_person_filter?(opts)
|
|
43
|
+
opts[:person_ids]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def date_range_window(opts)
|
|
47
|
+
DateRange.new(opts)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def person_filter(opts)
|
|
51
|
+
lambda do |_, ds, _options = {}|
|
|
52
|
+
ds.where(person_id: opts[:person_ids])
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def table_window(opts)
|
|
57
|
+
Table.new(opts)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def prep_options(opts)
|
|
61
|
+
scope_by = opts.fetch(:scope_by, :start_date).to_sym
|
|
62
|
+
raise "Unknown scope_by value #{scope_by.inspect}" unless EVENT_DATE_COLUMNS.key?(scope_by)
|
|
63
|
+
|
|
64
|
+
start_col, end_col = *(EVENT_DATE_COLUMNS[scope_by])
|
|
65
|
+
opts.merge(
|
|
66
|
+
event_start_date_column: start_col,
|
|
67
|
+
event_end_date_column: end_col
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/conceptql.rb
CHANGED
|
@@ -1,7 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "conceptql/version"
|
|
2
|
-
require "conceptql/
|
|
4
|
+
require "conceptql/paths"
|
|
5
|
+
require "conceptql/utils"
|
|
6
|
+
require "conceptql/operators/operator"
|
|
7
|
+
require "conceptql/behaviors/code_lister"
|
|
8
|
+
require "conceptql/behaviors/timeless"
|
|
9
|
+
require "conceptql/behaviors/windowable"
|
|
10
|
+
require "conceptql/behaviors/utilizable"
|
|
11
|
+
require "conceptql/vocabularies/dynamic_vocabularies"
|
|
12
|
+
require "conceptql/visitors/metadata_extractor"
|
|
3
13
|
require "conceptql/query"
|
|
14
|
+
require "conceptql/database"
|
|
15
|
+
require "conceptql/data_model"
|
|
16
|
+
require "conceptql/columnizer"
|
|
17
|
+
require "conceptql/diagram"
|
|
18
|
+
|
|
19
|
+
# byebug is only required during development
|
|
20
|
+
begin
|
|
21
|
+
require "pry-byebug"
|
|
22
|
+
rescue LoadError
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Dir.glob("#{File.dirname(__FILE__)}/../lib/conceptql/query_modifiers/**/*.rb").sort.each do |file|
|
|
27
|
+
require_relative file
|
|
28
|
+
end
|
|
4
29
|
|
|
5
30
|
module ConceptQL
|
|
6
|
-
|
|
31
|
+
DEFAULT_DATA_MODEL = :gdm
|
|
32
|
+
|
|
33
|
+
def self.avoid_ctes?
|
|
34
|
+
ENV["CONCEPTQL_AVOID_CTES"] == "true"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.metadata(cdb, opts = {})
|
|
38
|
+
{
|
|
39
|
+
categories: categories,
|
|
40
|
+
operators: ConceptQL::Nodifier.new(cdb).to_metadata(opts)
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.categories
|
|
45
|
+
[
|
|
46
|
+
"Select by Clinical Codes",
|
|
47
|
+
"Select by Property",
|
|
48
|
+
"Get Related Data",
|
|
49
|
+
"Modify Data",
|
|
50
|
+
"Combine Streams",
|
|
51
|
+
"Filter by Comparing",
|
|
52
|
+
"Filter Single Stream"
|
|
53
|
+
].map.with_index do |name, priority|
|
|
54
|
+
{ name: name, priority: priority }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Require all built-in operator classes eagerly. Each registers itself in
|
|
60
|
+
# ConceptQL::Operators.static_operators as its file loads.
|
|
61
|
+
#
|
|
62
|
+
# Vocabulary operators are not built here: each ConceptQL::Database builds its
|
|
63
|
+
# own from config/vocabularies.csv and its own lexicon (Database#operators), so
|
|
64
|
+
# loading the library touches no database.
|
|
65
|
+
Dir.new("#{File.dirname(__FILE__)}/conceptql/operators")
|
|
66
|
+
.entries
|
|
67
|
+
.each do |filename|
|
|
68
|
+
require_relative "conceptql/operators/#{filename}" if filename =~ /\.rb\z/ && filename != File.basename(__FILE__)
|
|
7
69
|
end
|
|
70
|
+
ConceptQL::Operators.static_operators.each_value(&:freeze)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
# Allows for EXPLAIN ANALYZE to be run on a CTAS statement
|
|
4
|
+
module Sequel
|
|
5
|
+
# Module that overrides #create_table_as and #create_table_as_sql
|
|
6
|
+
module PgCtasExplain
|
|
7
|
+
def create_table_as(name, sql, options)
|
|
8
|
+
return super unless options[:explain]
|
|
9
|
+
|
|
10
|
+
sql = sql.sql if sql.is_a?(Sequel::Dataset)
|
|
11
|
+
explain(create_table_as_sql(name, sql, options), options)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def explain(sql, options = {})
|
|
15
|
+
operations = [ "EXPLAIN" ]
|
|
16
|
+
operations << "ANALYZE" if options[:analyze]
|
|
17
|
+
log_info(fetch("#{operations.join(' ')} #{sql}").map(:'QUERY PLAN').join("\r\n"))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Database.register_extension(:pg_ctas_explain, PgCtasExplain)
|
|
22
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
# Adds DB#vacuum_table method
|
|
4
|
+
module Sequel
|
|
5
|
+
# Adds DB#vacuum_table method
|
|
6
|
+
module PgVacuumTable
|
|
7
|
+
def vacuum_table(table_name, opts = {})
|
|
8
|
+
run(vacuum_table_sql(table_name, opts))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def vacuum_table_sql(table_name, opts)
|
|
12
|
+
dataset.with_sql(vacuum_operations(opts).join(" "), table_name).sql
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def vacuum_operations(opts)
|
|
16
|
+
operations = [ "VACUUM" ]
|
|
17
|
+
operations << "ANALYZE" if opts[:analyze]
|
|
18
|
+
operations << "?"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Database.register_extension(:pg_vacuum_table, PgVacuumTable)
|
|
23
|
+
end
|