Skip to content

Commit 2a60a22

Browse files
committed
Merge pull request #3784 from nhsuk/programme-specific-vaccines
Don't show vaccination records for the wrong programme
2 parents b4ba45e + 0df753c commit 2a60a22

4 files changed

Lines changed: 35 additions & 22 deletions

File tree

app/components/app_patient_session_outcome_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class AppPatientSessionOutcomeComponent < ViewComponent::Base
88
<% card.with_heading { heading } %>
99
<%= render AppPatientVaccinationTableComponent.new(
1010
patient,
11-
show_caption: true,
12-
show_programme: false,
11+
programme:,
12+
show_caption: true
1313
) %>
1414
<% end %>
1515
ERB

app/components/app_patient_vaccination_table_component.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# frozen_string_literal: true
22

33
class AppPatientVaccinationTableComponent < ViewComponent::Base
4-
def initialize(patient, show_caption:, show_programme:)
4+
def initialize(patient, programme: nil, show_caption: false)
55
super
66

77
@patient = patient
8+
@programme = programme
89
@show_caption = show_caption
9-
@show_programme = show_programme
1010
end
1111

1212
private
1313

14-
attr_reader :patient, :show_caption, :show_programme
14+
attr_reader :patient, :programme, :show_caption
15+
16+
def show_programme = programme.nil?
1517

1618
def vaccination_records
1719
patient
1820
.vaccination_records
21+
.then { programme ? it.where(programme:) : it }
1922
.includes(:location, :programme)
2023
.order(performed_at: :desc)
2124
end

app/views/patients/show.html.erb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,5 @@
3030

3131
<%= render AppCardComponent.new(section: true) do |card| %>
3232
<% card.with_heading { "Vaccinations" } %>
33-
<%= render AppPatientVaccinationTableComponent.new(
34-
@patient,
35-
show_caption: false,
36-
show_programme: true,
37-
) %>
33+
<%= render AppPatientVaccinationTableComponent.new(@patient, show_caption: false) %>
3834
<% end %>

spec/components/app_patient_vaccination_table_component_spec.rb

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
describe AppPatientVaccinationTableComponent do
44
subject { render_inline(component) }
55

6-
let(:component) do
7-
described_class.new(patient, show_caption:, show_programme:)
8-
end
6+
let(:component) { described_class.new(patient, programme:, show_caption:) }
97

108
let(:patient) { create(:patient) }
9+
let(:programme) { nil }
1110
let(:show_caption) { false }
12-
let(:show_programme) { false }
1311

1412
it { should have_content("No vaccinations") }
1513

1614
context "with a vaccination record" do
17-
let(:programme) { create(:programme, :hpv) }
18-
1915
let(:location) do
2016
create(
2117
:school,
@@ -26,12 +22,19 @@
2622
)
2723
end
2824

25+
let(:vaccination_record_programme) { create(:programme, :hpv) }
26+
2927
before do
3028
create(
3129
:vaccination_record,
3230
patient:,
33-
session: create(:session, location:, programmes: [programme]),
34-
programme:,
31+
session:
32+
create(
33+
:session,
34+
location:,
35+
programmes: [vaccination_record_programme]
36+
),
37+
programme: vaccination_record_programme,
3538
performed_at: Time.zone.local(2024, 1, 1)
3639
)
3740
end
@@ -40,12 +43,23 @@
4043
it { should have_content("Test School") }
4144
it { should have_content("Waterloo Road, London, SE1 8TY") }
4245
it { should have_content("Vaccinated") }
43-
it { should_not have_content("HPV") }
46+
it { should have_content("HPV") }
47+
48+
context "when showing records from a specific programme" do
49+
let(:programme) { vaccination_record_programme }
50+
51+
it { should_not have_content("HPV") }
52+
end
4453

45-
context "when showing the programme" do
46-
let(:show_programme) { true }
54+
context "with a vaccination record from a different programme" do
55+
let(:programme) { create(:programme, :hpv) }
56+
let(:vaccination_record_programme) { create(:programme, :flu) }
4757

48-
it { should have_content("HPV") }
58+
it { should_not have_link("1 January 2024") }
59+
it { should_not have_content("Test School") }
60+
it { should_not have_content("Waterloo Road, London, SE1 8TY") }
61+
it { should_not have_content("Vaccinated") }
62+
it { should_not have_content("HPV") }
4963
end
5064
end
5165
end

0 commit comments

Comments
 (0)