Class: Renalware::Surveys::EQ5DSummaryPart

Inherits:
Renalware::SummaryPart show all
Defined in:
app/models/renalware/surveys/eq5d_summary_part.rb

Constant Summary

Constants inherited from Renalware::SummaryPart

Renalware::SummaryPart::DATE_FORMAT

Instance Method Summary collapse

Methods inherited from Renalware::SummaryPart

#cache?, #cache_key, #render?

Instance Method Details

#column_headingsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 27

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



20
21
22
23
24
25
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 20

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



12
13
14
15
16
17
18
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 12

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

#rowsObject



8
9
10
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 8

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

#surveyObject



46
47
48
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 46

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

#to_partial_pathObject



42
43
44
# File 'app/models/renalware/surveys/eq5d_summary_part.rb', line 42

def to_partial_path
  "renalware/surveys/eq5d_summary_part"
end