Class: Renalware::Surveys::POSSComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Renalware::Surveys::POSSComponent
- Includes:
- ToggleHelper
- Defined in:
- app/components/renalware/surveys/pos_s_component.rb
Instance Attribute Summary collapse
-
#patient ⇒ Object
readonly
Returns the value of attribute patient.
Instance Method Summary collapse
- #column_headings ⇒ Object
-
#data_for_question_code(_code) ⇒ Object
Return data for charting.
-
#initialize(patient:) ⇒ POSSComponent
constructor
A new instance of POSSComponent.
- #question_labels ⇒ Object
-
#rows ⇒ Object
Backed by a SQL view.
- #survey ⇒ Object
Methods included from ToggleHelper
#css_toggle_link_to, #row_toggler, #rows_toggler, #table_toggler, #td_toggle_row, #th_toggle_all_rows, #toggler
Methods inherited from ApplicationComponent
Constructor Details
#initialize(patient:) ⇒ POSSComponent
Returns a new instance of POSSComponent.
12 13 14 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 12 def initialize(patient:) @patient = patient end |
Instance Attribute Details
#patient ⇒ Object (readonly)
Returns the value of attribute patient.
10 11 12 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 10 def patient @patient end |
Instance Method Details
#column_headings ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 39 def column_headings @column_headings ||= begin headings = ["Date"] headings.concat( Renalware::Survey .find_by!(code: "prom") .questions .order(:position) .pluck(:label) ) headings end end |
#data_for_question_code(_code) ⇒ Object
Return data for charting
32 33 34 35 36 37 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 32 def data_for_question_code(_code) Renalware::Surveys::Response .where(patient_id: patient.id, question_id: 1) .pluck(:answered_on, :value) .to_h end |
#question_labels ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 21 def question_labels @question_labels ||= begin survey .questions .order(:position) .select(:code, :label, :label_abbrv) .each_with_object({}) { |q, hash| hash[q.code] = q.admin_label } end end |
#rows ⇒ Object
Backed by a SQL view
17 18 19 |
# File 'app/components/renalware/surveys/pos_s_component.rb', line 17 def rows @rows ||= POSSPivotedResponse.where(patient_id: patient.id) end |