Class: PhqAssessment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/phq_assessment.rb

Overview

Collected responses from one Participant PHQ-9 assessment session.

Constant Summary collapse

MIN_QUESTION_SCORE =
0
MAX_QUESTION_SCORE =
3
QUESTION_ATTRIBUTES =

rubocop:disable Style/MutableConstant

:q1, :q2, :q3, :q4, :q5, :q6, :q7, :q8, :q9
SUICIDAL_SCORE =

rubocop:enable Style/MutableConstant

3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.most_recentObject



19
20
21
# File 'app/models/phq_assessment.rb', line 19

def self.most_recent
  recenty_released.first
end

Instance Method Details

#answered_questionsObject



23
24
25
# File 'app/models/phq_assessment.rb', line 23

def answered_questions
  @answered_questions ||= remove_nils
end

#completed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/phq_assessment.rb', line 27

def completed?
  number_answered == QUESTION_ATTRIBUTES.count
end

#number_answeredObject



31
32
33
# File 'app/models/phq_assessment.rb', line 31

def number_answered
  answered_questions.count
end

#scoreObject



35
36
37
# File 'app/models/phq_assessment.rb', line 35

def score
  answered_questions.inject(:+)
end

#suicidal?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/phq_assessment.rb', line 39

def suicidal?
  q9 == SUICIDAL_SCORE
end