Class: Renalware::Surveys::POSSSummaryPart

Inherits:
Renalware::SummaryPart show all
Defined in:
app/models/renalware/surveys/pos_s_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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/renalware/surveys/pos_s_summary_part.rb', line 31

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



24
25
26
27
28
29
# File 'app/models/renalware/surveys/pos_s_summary_part.rb', line 24

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



13
14
15
16
17
18
19
20
21
# File 'app/models/renalware/surveys/pos_s_summary_part.rb', line 13

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

#rowsObject

Backed by a SQL view



9
10
11
# File 'app/models/renalware/surveys/pos_s_summary_part.rb', line 9

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

#surveyObject



50
51
52
# File 'app/models/renalware/surveys/pos_s_summary_part.rb', line 50

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

#to_partial_pathObject



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

def to_partial_path
  "renalware/surveys/pos_s_summary_part"
end