Class: ConceptQL::Operators::TemporalOperator
Overview
Base class for all temporal operators
Subclasses must implement the where_clause method which should probably return a Sequel expression to use for filtering.
Direct Known Subclasses
After, AnyOverlap, Before, Contains, During, Equal, OverlappedBy, Overlaps, StartedBy, TrimDateEnd, TrimDateStart
Instance Attribute Summary
#left
Attributes inherited from Operator
#arguments, #errors, #nodifier, #options, #upstreams, #values
Class Method Summary
collapse
Instance Method Summary
collapse
#code_list, #display_name, #upstreams
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, #unionable?, #upstreams_valid?, #valid?
#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
Class Method Details
.within_skip(type) ⇒ Object
22
23
24
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 22
def self.within_skip(type)
define_method(:"within_check_#{type}?"){false}
end
|
Instance Method Details
#add_occurrences_condition(ds, occurrences) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 62
def add_occurrences_condition(ds, occurrences)
occurrences_col = occurrences_column
ds.distinct.from_self
.select_append{row_number{}.over(:partition => :person_id, :order => occurrences_col).as(:occurrence)}
.from_self
.select(*query_columns(ds))
.where{occurrence > occurrences.to_i}
end
|
#add_option_conditions(ds) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 36
def add_option_conditions(ds)
if within = options[:within]
ds = add_within_condition(ds, within)
end
if at_least = options[:at_least]
ds = add_within_condition(ds, at_least, :exclude)
end
if occurrences = options[:occurrences]
ds = add_occurrences_condition(ds, occurrences)
end
ds
end
|
#add_within_condition(ds, within, meth = :where) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 52
def add_within_condition(ds, within, meth=:where)
within = DateAdjuster.new(within)
after = within.adjust(:r__start_date, true)
before = within.adjust(:r__end_date)
within_col = Sequel.expr(within_column)
ds = ds.send(meth){within_col >= after} if within_check_after?
ds = ds.send(meth){within_col <= before} if within_check_before?
ds.distinct
end
|
#inclusive? ⇒ Boolean
87
88
89
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 87
def inclusive?
options[:inclusive]
end
|
#left_stream(db) ⇒ Object
91
92
93
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 91
def left_stream(db)
Sequel.expr(left.evaluate(db).from_self).as(:l)
end
|
#occurrences_column ⇒ Object
75
76
77
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 75
def occurrences_column
:start_date
end
|
#query(db) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 26
def query(db)
ds = db.from(left_stream(db))
.join(right_stream(db), l__person_id: :r__person_id)
.where(where_clause)
.select_all(:l)
ds = add_option_conditions(ds)
ds.from_self
end
|
#right_stream(db) ⇒ Object
95
96
97
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 95
def right_stream(db)
Sequel.expr(right.evaluate(db).from_self).as(:r)
end
|
#within_check_after? ⇒ Boolean
79
80
81
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 79
def within_check_after?
true
end
|
#within_check_before? ⇒ Boolean
83
84
85
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 83
def within_check_before?
true
end
|
#within_column ⇒ Object
71
72
73
|
# File 'lib/conceptql/operators/temporal_operator.rb', line 71
def within_column
:l__start_date
end
|