Skip to content

Commit 99311fc

Browse files
committed
Refactor duplicate patient summary to component
Also make it display highlighted attributes if they are dirty.
1 parent 3b05a9c commit 99311fc

File tree

3 files changed

+148
-52
lines changed

3 files changed

+148
-52
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientSummaryComponent < ViewComponent::Base
4+
def initialize(patient:)
5+
super
6+
7+
@patient = patient
8+
end
9+
10+
def call
11+
govuk_summary_list do |summary_list|
12+
summary_list.with_row do |row|
13+
row.with_key { "NHS number" }
14+
row.with_value { format_nhs_number }
15+
end
16+
summary_list.with_row do |row|
17+
row.with_key { "Full name" }
18+
row.with_value { format_full_name }
19+
end
20+
summary_list.with_row do |row|
21+
row.with_key { "Date of birth" }
22+
row.with_value { format_date_of_birth }
23+
end
24+
summary_list.with_row do |row|
25+
row.with_key { "Sex" }
26+
row.with_value { format_gender_code }
27+
end
28+
summary_list.with_row do |row|
29+
row.with_key { "Postcode" }
30+
row.with_value { format_postcode }
31+
end
32+
summary_list.with_row do |row|
33+
row.with_key { "School" }
34+
row.with_value { format_school }
35+
end
36+
end
37+
end
38+
39+
private
40+
41+
def format_nhs_number
42+
highlight_if(
43+
helpers.format_nhs_number(@patient.nhs_number),
44+
@patient.nhs_number_changed?
45+
)
46+
end
47+
48+
def format_full_name
49+
highlight_if(
50+
@patient.full_name,
51+
@patient.first_name_changed? || @patient.last_name_changed?
52+
)
53+
end
54+
55+
def format_date_of_birth
56+
highlight_if(
57+
@patient.date_of_birth.to_date.to_fs(:long),
58+
@patient.date_of_birth_changed?
59+
)
60+
end
61+
62+
def format_gender_code
63+
highlight_if(
64+
@patient.gender_code.to_s.humanize,
65+
@patient.gender_code_changed?
66+
)
67+
end
68+
69+
def format_postcode
70+
highlight_if(@patient.address_postcode, @patient.address_postcode_changed?)
71+
end
72+
73+
def format_school
74+
highlight_if(@patient.school.name, @patient.school_id_changed?)
75+
end
76+
77+
def highlight_if(value, condition)
78+
condition ? tag.span(value, class: "app-highlight") : value
79+
end
80+
end

app/views/immunisation_imports/patients/show.html.erb

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,19 @@
2727
<%= render AppCardComponent.new(colour: "blue") do |c| %>
2828
<% c.with_heading { "Duplicate record" } %>
2929
<h3 class="nhsuk-heading-s">Duplicate child record</h3>
30-
<%= govuk_summary_list do |summary_list| %>
31-
<% summary_list.with_row do |row| %>
32-
<% row.with_key { "NHS number" } %>
33-
<% row.with_value { format_nhs_number(@patient.nhs_number) } %>
34-
<% end %>
35-
<% summary_list.with_row do |row| %>
36-
<% row.with_key { "Full name" } %>
37-
<% row.with_value { @patient.full_name } %>
38-
<% end %>
39-
<% summary_list.with_row do |row| %>
40-
<% row.with_key { "Date of birth" } %>
41-
<% row.with_value { @patient.date_of_birth.to_fs(:long) } %>
42-
<% end %>
43-
<% summary_list.with_row do |row| %>
44-
<% row.with_key { "Sex" } %>
45-
<% row.with_value { @patient.gender_code.humanize } %>
46-
<% end %>
47-
<% summary_list.with_row do |row| %>
48-
<% row.with_key { "Postcode" } %>
49-
<% row.with_value { @patient.address_postcode } %>
50-
<% end %>
51-
<% summary_list.with_row do |row| %>
52-
<% row.with_key { "School" } %>
53-
<% row.with_value { @patient.school&.name } %>
54-
<% end %>
55-
<% end %>
30+
<%= render AppPatientSummaryComponent.new(
31+
patient: @patient.with_pending_changes,
32+
) %>
5633
<% end %>
5734
</div>
5835

5936
<div class="nhsuk-grid-column-one-half">
6037
<%= render AppCardComponent.new(colour: "blue") do |c| %>
6138
<% c.with_heading { "Previously uploaded record" } %>
6239
<h3 class="nhsuk-heading-s">Previously uploaded child record</h3>
63-
<%= govuk_summary_list do |summary_list| %>
64-
<% summary_list.with_row do |row| %>
65-
<% row.with_key { "NHS number" } %>
66-
<% row.with_value { format_nhs_number(@patient.nhs_number) } %>
67-
<% end %>
68-
<% summary_list.with_row do |row| %>
69-
<% row.with_key { "Full name" } %>
70-
<% row.with_value { @patient.full_name } %>
71-
<% end %>
72-
<% summary_list.with_row do |row| %>
73-
<% row.with_key { "Date of birth" } %>
74-
<% row.with_value { @patient.date_of_birth.to_fs(:long) } %>
75-
<% end %>
76-
<% summary_list.with_row do |row| %>
77-
<% row.with_key { "Sex" } %>
78-
<% row.with_value { @patient.gender_code.humanize } %>
79-
<% end %>
80-
<% summary_list.with_row do |row| %>
81-
<% row.with_key { "Postcode" } %>
82-
<% row.with_value { @patient.address_postcode } %>
83-
<% end %>
84-
<% summary_list.with_row do |row| %>
85-
<% row.with_key { "School" } %>
86-
<% row.with_value { @patient.school&.name } %>
87-
<% end %>
88-
<% end %>
40+
<%= render AppPatientSummaryComponent.new(
41+
patient: @patient,
42+
) %>
8943
<% end %>
9044
</div>
9145
</div>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# frozen_string_literal: true
2+
3+
describe AppPatientSummaryComponent, type: :component do
4+
subject { page }
5+
6+
before { render_inline(component) }
7+
8+
let(:component) { described_class.new(patient:) }
9+
let(:school) { create(:location, :school, name: "Test School") }
10+
let(:other_school) { create(:location, :school, name: "Other School") }
11+
let(:patient) do
12+
create(
13+
:patient,
14+
nhs_number: "1234567890",
15+
first_name: "John",
16+
last_name: "Doe",
17+
date_of_birth: Date.new(2000, 1, 1),
18+
gender_code: "male",
19+
address_postcode: "SW1A 1AA",
20+
school:,
21+
pending_changes: {
22+
first_name: "Jane",
23+
date_of_birth: Date.new(2001, 1, 1),
24+
address_postcode: "SW1A 2AA",
25+
school_id: other_school.id
26+
}
27+
)
28+
end
29+
30+
it { should have_content("NHS number") }
31+
it { should have_content("123\u00A0\u200D456\u00A0\u200D7890") }
32+
33+
it { should have_content("Full name") }
34+
it { should have_content("John Doe") }
35+
36+
it { should have_content("Date of birth") }
37+
it { should have_content("1 January 2000") }
38+
39+
it { should have_content("Sex") }
40+
it { should have_content("Male") }
41+
42+
it { should have_content("Postcode") }
43+
it { should have_content("SW1A 1AA") }
44+
45+
it { should have_content("School") }
46+
it { should have_content("Test School") }
47+
48+
it { should_not have_css(".app-highlight") }
49+
50+
context "with pending changes" do
51+
let(:component) do
52+
described_class.new(patient: patient.with_pending_changes)
53+
end
54+
55+
it { should have_css(".app-highlight", text: "Jane Doe") }
56+
it { should have_css(".app-highlight", text: "1 January 2001") }
57+
it { should have_css(".app-highlight", text: "SW1A 2AA") }
58+
it { should_not have_css(".app-highlight", text: "Male") }
59+
it { should_not have_css(".app-highlight", text: "Test School") }
60+
it { should have_css(".app-highlight", text: "Other School") }
61+
end
62+
end

0 commit comments

Comments
 (0)