Class: Renalware::Surveys::POSSComponent

Inherits:
ApplicationComponent show all
Includes:
ToggleHelper
Defined in:
app/components/renalware/surveys/pos_s_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#policy, #renalware

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

#patientObject (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_headingsObject



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_labelsObject



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

#rowsObject

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

#surveyObject



54
55
56
# File 'app/components/renalware/surveys/pos_s_component.rb', line 54

def survey
  @survey ||= Renalware::Surveys::Survey.find_by!(code: "prom")
end