Class: Renalware::Surveys::EQ5DComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/renalware/surveys/eq5d_component.rb

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#policy, #renalware

Instance Method Details

#column_headingsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/renalware/surveys/eq5d_component.rb', line 29

def column_headings
  @column_headings ||= begin
    headings = ["Date"]

    headings.concat(
      Renalware::Survey
      .find_by!(code: "eq5d")
      .questions
      .order(:position)
      .pluck(:label)
    )
    headings
  end
end

#data_for_question_code(_code) ⇒ Object



22
23
24
25
26
27
# File 'app/components/renalware/surveys/eq5d_component.rb', line 22

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



14
15
16
17
18
19
20
# File 'app/components/renalware/surveys/eq5d_component.rb', line 14

def question_labels
  survey
    .questions
    .order(:position)
    .select(:code, :label)
    .each_with_object({}) { |q, hash| hash[q.code] = q.label }
end

#rowsObject



10
11
12
# File 'app/components/renalware/surveys/eq5d_component.rb', line 10

def rows
  @rows ||= EQ5DPivotedResponse.where(patient_id: patient.id)
end

#surveyObject



44
45
46
# File 'app/components/renalware/surveys/eq5d_component.rb', line 44

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