|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | class AppConsentCardComponent < ViewComponent::Base |
4 | | - def initialize(patient_session:, programme:) |
| 4 | + def initialize(consent, session:) |
5 | 5 | super |
6 | 6 |
|
7 | | - @patient_session = patient_session |
8 | | - @programme = programme |
| 7 | + @consent = consent |
| 8 | + @session = session |
9 | 9 | end |
10 | 10 |
|
11 | | - attr_reader :patient_session, :programme |
12 | | - |
13 | | - delegate :patient, :session, to: :patient_session |
14 | | - |
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])}" |
| 11 | + def call |
| 12 | + render AppCardComponent.new(**card_options) do |card| |
| 13 | + card.with_heading { heading } |
| 14 | + govuk_summary_list(rows:) |
| 15 | + end |
21 | 16 | end |
22 | 17 |
|
23 | | - def latest_consent_request |
24 | | - @latest_consent_request ||= |
25 | | - patient |
26 | | - .consent_notifications |
27 | | - .request |
28 | | - .has_programme(programme) |
29 | | - .order(sent_at: :desc) |
30 | | - .first |
31 | | - end |
| 18 | + private |
32 | 19 |
|
33 | | - def consent_status |
34 | | - @consent_status ||= patient.consent_status(programme:) |
35 | | - end |
| 20 | + attr_reader :consent, :session |
36 | 21 |
|
37 | | - def vaccination_status |
38 | | - @vaccination_status ||= patient.vaccination_status(programme:) |
39 | | - end |
| 22 | + delegate :patient, :programme, to: :consent |
40 | 23 |
|
41 | | - def can_send_consent_request? |
42 | | - consent_status.no_response? && patient.send_notifications? && |
43 | | - session.open_for_consent? && patient.parents.any? |
| 24 | + def link_to |
| 25 | + session_patient_programme_consent_path(session, patient, programme, consent) |
44 | 26 | end |
45 | 27 |
|
46 | | - def who_refused |
47 | | - consents = |
48 | | - patient.consents.where(programme:).not_invalidated.includes(:parent) |
| 28 | + def card_options = { link_to:, colour: "offset", compact: true } |
49 | 29 |
|
50 | | - ConsentGrouper |
51 | | - .call(consents, programme:) |
52 | | - .find(&:response_refused?) |
53 | | - &.who_responded |
| 30 | + def heading |
| 31 | + if consent.via_self_consent? |
| 32 | + consent.who_responded |
| 33 | + else |
| 34 | + "#{consent.name} (#{consent.who_responded})" |
| 35 | + end |
54 | 36 | end |
55 | 37 |
|
56 | | - delegate :status, to: :consent_status |
| 38 | + def rows |
| 39 | + [ |
| 40 | + if (phone = consent.parent&.phone).present? |
| 41 | + { key: { text: "Phone number" }, value: { text: phone } } |
| 42 | + end, |
| 43 | + if (email = consent.parent&.email).present? |
| 44 | + { key: { text: "Email address" }, value: { text: email } } |
| 45 | + end, |
| 46 | + { |
| 47 | + key: { |
| 48 | + text: "Date" |
| 49 | + }, |
| 50 | + value: { |
| 51 | + text: consent.responded_at.to_fs(:long) |
| 52 | + } |
| 53 | + }, |
| 54 | + { |
| 55 | + key: { |
| 56 | + text: "Decision" |
| 57 | + }, |
| 58 | + value: { |
| 59 | + text: helpers.consent_status_tag(consent) |
| 60 | + } |
| 61 | + } |
| 62 | + ].compact |
| 63 | + end |
57 | 64 | end |
0 commit comments