Class: ConceptQL::Operators::OneInTwoOut
- Defined in:
- lib/conceptql/operators/one_in_two_out.rb
Defined Under Namespace
Classes: FakeOperator
Constant Summary
Constants inherited from Operator
ConceptQL::Operators::Operator::COLUMNS
Instance Attribute Summary
Attributes inherited from Operator
#arguments, #options, #upstreams, #values
Instance Method Summary collapse
Methods inherited from Operator
#columns, #evaluate, #initialize, #label, #select_it, #set_values, #sql, #stream
Methods included from Metadatable
#allows_many_upstreams, #allows_one_upstream, #argument, #category, #desc, #humanized_class_name, #inherited, #just_class_name, #option, #predominant_types, #preferred_name, #reset_categories, #to_metadata
Constructor Details
This class inherits a constructor from ConceptQL::Operators::Operator
Instance Method Details
#query(db) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/conceptql/operators/one_in_two_out.rb', line 19 def query(db) inpatient = select_it(visit_query(db).where(place_of_service_concept_id: 8717), :visit_occurrence).from_self outpatient = select_it(visit_query(db).exclude(place_of_service_concept_id: 8717), :visit_occurrence).from_self gap = [:gap] || 30 valid_outpatient_people = outpatient .group_by(:person_id) .select(:person_id) .select_append(Sequel.expr(Sequel.function(:max, :start_date) - Sequel.function(:min, :end_date)).as(:date_diff)) .from_self .where{ date_diff >= gap} relevant_outpatient = outpatient.where(person_id: valid_outpatient_people.select(:person_id)) earliest(db, inpatient.union(relevant_outpatient)) end |
#types ⇒ Object
15 16 17 |
# File 'lib/conceptql/operators/one_in_two_out.rb', line 15 def types [:visit_occurrence] end |