11# frozen_string_literal: true
22
3- class AppConsentComponent < ViewComponent ::Base
3+ class AppConsentCardComponent < ViewComponent ::Base
44 def initialize ( patient_session :, programme :)
55 super
66
@@ -12,13 +12,12 @@ def initialize(patient_session:, programme:)
1212
1313 delegate :patient , :session , to : :patient_session
1414
15- def consents
16- @consents ||=
17- patient
18- . consents
19- . where ( programme :)
20- . includes ( :consent_form , :parent )
21- . order ( created_at : :desc )
15+ def colour
16+ I18n . t ( status , scope : %i[ status consent colour ] )
17+ end
18+
19+ def heading
20+ "#{ programme . name } : #{ I18n . t ( status , scope : %i[ status consent label ] ) } "
2221 end
2322
2423 def latest_consent_request
@@ -35,20 +34,24 @@ def consent_status
3534 @consent_status ||= patient . consent_status ( programme :)
3635 end
3736
37+ def vaccination_status
38+ @vaccination_status ||= patient . vaccination_status ( programme :)
39+ end
40+
3841 def can_send_consent_request?
3942 consent_status . no_response? && patient . send_notifications? &&
4043 session . open_for_consent? && patient . parents . any?
4144 end
4245
43- def status_colour ( consent )
44- if consent . invalidated? || consent . withdrawn?
45- "grey"
46- elsif consent . response_given?
47- "aqua-green"
48- elsif consent . response_refused?
49- "red"
50- else
51- "grey"
52- end
46+ def who_refused
47+ consents =
48+ patient . consents . where ( programme :) . not_invalidated . includes ( :parent )
49+
50+ ConsentGrouper
51+ . call ( consents , programme :)
52+ . find ( &:response_refused? )
53+ &.who_responded
5354 end
55+
56+ delegate :status , to : :consent_status
5457end
0 commit comments