Skip to content

Commit 5c99e16

Browse files
authored
Merge pull request #6583 from NHSDigital/add-programme-status-card
Add programme status card
2 parents d965a82 + 940bdd2 commit 5c99e16

15 files changed

Lines changed: 389 additions & 130 deletions
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientSessionProgrammeComponent < ViewComponent::Base
4+
erb_template <<-ERB
5+
<%= render AppCardComponent.new(feature: true) do |card| %>
6+
<% card.with_heading(level: 4, colour:) { heading } %>
7+
<% if details.present? %>
8+
<p><%= details %></p>
9+
<% end %>
10+
<% if programme_status.vaccinated? || programme_status.cannot_vaccinate? %>
11+
<%= render AppPatientVaccinationTableComponent.new(
12+
patient,
13+
programme:,
14+
academic_year:,
15+
show_caption: true,
16+
show_details: false
17+
) %>
18+
<% end %>
19+
<%= render AppActionLinkComponent.new(
20+
text: action_link_text,
21+
href: patient_programme_path(patient, programme.type)
22+
) %>
23+
<% end %>
24+
ERB
25+
26+
def initialize(patient:, session:, programme:)
27+
@patient = patient
28+
@session = session
29+
@programme = programme
30+
end
31+
32+
private
33+
34+
attr_reader :patient, :session, :programme
35+
36+
delegate :academic_year, to: :session
37+
delegate :triage_summary, to: :helpers
38+
39+
def heading
40+
"#{resolver[:prefix]}: #{resolver[:text]}"
41+
end
42+
43+
def colour
44+
resolver[:colour]
45+
end
46+
47+
def details
48+
if latest_triage
49+
triage_summary(latest_triage)
50+
elsif programme_status.due?
51+
criteria_label =
52+
I18n.t(
53+
programme_status.vaccine_criteria.to_param,
54+
scope: :vaccine_criteria
55+
)
56+
if criteria_label.present?
57+
"#{patient.given_name} is ready to vaccinate (#{criteria_label.downcase})."
58+
else
59+
"#{patient.given_name} is ready to vaccinate."
60+
end
61+
elsif programme_status.vaccinated?
62+
record =
63+
patient
64+
.vaccination_records
65+
.for_programme(programme)
66+
.order_by_performed_at
67+
.first
68+
nurse = [
69+
record&.performed_by_given_name,
70+
record&.performed_by_family_name
71+
].compact_blank.join(" ")
72+
if nurse.present?
73+
"#{patient.given_name} was vaccinated by #{nurse} on #{record&.performed_at&.to_fs(:long)}."
74+
else
75+
"#{patient.given_name} was vaccinated on #{record&.performed_at&.to_fs(:long)}."
76+
end
77+
elsif programme_status.needs_triage?
78+
"You need to decide if it’s safe to vaccinate #{patient.given_name}."
79+
else
80+
resolver[:details_text]
81+
end
82+
end
83+
84+
def latest_triage
85+
@latest_triage ||=
86+
TriageFinder.call(
87+
patient.triages.includes(:performed_by),
88+
programme_type: programme.type,
89+
academic_year:
90+
)
91+
end
92+
93+
def programme_status
94+
@programme_status ||= patient.programme_status(programme, academic_year:)
95+
end
96+
97+
def action_link_text
98+
"View child’s #{programme.name} record"
99+
end
100+
101+
def resolver
102+
@resolver ||=
103+
PatientProgrammeStatusResolver.call(
104+
patient,
105+
programme_type: programme.type,
106+
academic_year:
107+
)
108+
end
109+
end

app/components/app_patient_session_vaccination_component.rb

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/components/app_patient_vaccination_table_component.html.erb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<% if vaccination_records.present? %>
22
<%= govuk_table(html_attributes: { class: "nhsuk-table-responsive" }) do |table| %>
3-
<% table.with_caption(text: "Vaccination records", size: "s") if show_caption %>
3+
<% table.with_caption(text: "Vaccination outcomes", size: "s") if show_caption %>
44

55
<% table.with_head do |head| %>
66
<% head.with_row do |row| %>
77
<% row.with_cell(text: "Date") %>
8-
<% row.with_cell(text: "Location") %>
8+
<% row.with_cell(text: "Location") if show_details %>
99
<% row.with_cell(text: "Programme") if show_programme %>
10-
<% row.with_cell(text: "Source") %>
10+
<% row.with_cell(text: "Source") if show_details %>
1111
<% row.with_cell(text: "Outcome") %>
1212
<% end %>
1313
<% end %>
@@ -17,19 +17,21 @@
1717
<% body.with_row do |row| %>
1818
<% row.with_cell do %>
1919
<span class="nhsuk-table-responsive__heading">Date</span>
20-
<%= link_to vaccination_record.performed_at.to_date.to_fs(:long),
20+
<%= link_to vaccination_record.performed_at.to_fs(:long),
2121
vaccination_record_path(vaccination_record) %>
2222
<% end %>
2323

24-
<% row.with_cell do %>
25-
<span class="nhsuk-table-responsive__heading">Location</span>
26-
<%= helpers.vaccination_record_location(vaccination_record) %>
24+
<% if show_details %>
25+
<% row.with_cell do %>
26+
<span class="nhsuk-table-responsive__heading">Location</span>
27+
<%= helpers.vaccination_record_location(vaccination_record) %>
2728

28-
<% if (location = vaccination_record.location) && location.has_address? %>
29-
<br />
30-
<span class="nhsuk-u-secondary-text-colour">
31-
<%= helpers.format_address_single_line(location) %>
32-
</span>
29+
<% if (location = vaccination_record.location) && location.has_address? %>
30+
<br />
31+
<span class="nhsuk-u-secondary-text-colour">
32+
<%= helpers.format_address_single_line(location) %>
33+
</span>
34+
<% end %>
3335
<% end %>
3436
<% end %>
3537

@@ -40,9 +42,11 @@
4042
<% end %>
4143
<% end %>
4244

43-
<% row.with_cell do %>
44-
<span class="nhsuk-table-responsive__heading">Source</span>
45-
<%= vaccination_record_source(vaccination_record) %>
45+
<% if show_details %>
46+
<% row.with_cell do %>
47+
<span class="nhsuk-table-responsive__heading">Source</span>
48+
<%= vaccination_record_source(vaccination_record) %>
49+
<% end %>
4650
<% end %>
4751

4852
<% row.with_cell do %>

app/components/app_patient_vaccination_table_component.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
# frozen_string_literal: true
22

33
class AppPatientVaccinationTableComponent < ViewComponent::Base
4-
def initialize(patient, academic_year:, programme: nil, show_caption: false)
4+
def initialize(
5+
patient,
6+
academic_year:,
7+
programme: nil,
8+
show_caption: false,
9+
show_details: true
10+
)
511
@patient = patient
612
@academic_year = academic_year
713
@programme = programme
814
@show_caption = show_caption
15+
@show_details = show_details
916
end
1017

1118
private
1219

1320
delegate :govuk_table, :vaccination_record_source, to: :helpers
1421

15-
attr_reader :patient, :academic_year, :programme, :show_caption
22+
attr_reader :patient, :academic_year, :programme, :show_caption, :show_details
1623

1724
def show_programme = programme.nil?
1825

app/helpers/triages_helper.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,22 @@ def triage_summary(triage)
6161
triage.programme.has_multiple_vaccine_methods?
6262
vaccination_method =
6363
Vaccine.human_enum_name(:method_prefix, triage.vaccine_method)
64-
"is safe to vaccinate using the #{vaccination_method} vaccine only."
64+
" is safe to vaccinate using the #{vaccination_method} vaccine only."
6565
else
66-
"is safe to vaccinate."
66+
" is safe to vaccinate."
6767
end
6868
elsif triage.do_not_vaccinate?
69-
"should not be vaccinated."
69+
" should not be vaccinated."
7070
elsif triage.delay_vaccination?
71-
"’s vaccination should be delayed."
71+
if triage.delay_vaccination_until.present?
72+
"’s vaccination should be delayed until #{triage.delay_vaccination_until.to_fs(:long)}."
73+
else
74+
"’s vaccination should be delayed."
75+
end
76+
elsif triage.invite_to_clinic?
77+
"’s vaccination should take place at a clinic."
7278
end
7379

74-
"#{prefix}#{triage.patient.full_name} #{suffix}" if suffix
80+
"#{prefix}#{triage.patient.given_name}#{suffix}" if suffix
7581
end
7682
end

app/models/patient/programme_status.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def has_refusal? = status.in?(HAS_REFUSAL_STATUSES.keys)
154154

155155
def cannot_vaccinate? = status.in?(CANNOT_VACCINATE_STATUSES.keys)
156156

157+
def needs_triage? = status.in?(NEEDS_TRIAGE_STATUSES.keys)
158+
159+
def due? = status.in?(DUE_STATUSES.keys)
160+
157161
def vaccinated? = status.in?(VACCINATED_STATUSES.keys)
158162

159163
def group = GROUPS.find { status.starts_with?(it) }

app/views/patient_sessions/programmes/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
</div>
77

88
<div class="app-grid-column-patient-session">
9+
<%= render AppPatientSessionProgrammeComponent.new(patient: @patient, session: @session, programme: @programme) %>
10+
911
<%= render AppPatientSessionConsentComponent.new(patient: @patient, session: @session, programme: @programme) %>
1012

1113
<%= render AppPatientSessionTriageComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, triage_form: @triage_form) %>
1214

1315
<%= render AppPatientSessionRecordComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, vaccinate_form: @vaccinate_form) %>
14-
15-
<%= render AppPatientSessionVaccinationComponent.new(patient: @patient, session: @session, programme: @programme) %>
1616
</div>
1717
</div>

0 commit comments

Comments
 (0)