Class: Renalware::Surveys::EQ5DComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#policy, #renalware

Constructor Details

#initialize(patient:) ⇒ EQ5DComponent

Returns a new instance of EQ5DComponent.



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

def initialize(patient:)
  @patient = patient
end

Instance Attribute Details

#patientObject (readonly)

Returns the value of attribute patient.



8
9
10
# File 'app/components/renalware/surveys/eq5d_component.rb', line 8

def patient
  @patient
end

Instance Method Details

#column_headingsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/renalware/surveys/eq5d_component.rb', line 33

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



26
27
28
29
30
31
# File 'app/components/renalware/surveys/eq5d_component.rb', line 26

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



18
19
20
21
22
23
24
# File 'app/components/renalware/surveys/eq5d_component.rb', line 18

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

#rowsObject



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

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

#surveyObject



48
49
50
# File 'app/components/renalware/surveys/eq5d_component.rb', line 48

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