Skip to content

Commit 2d67a9b

Browse files
committed
Move archive and merge activity to the child record tab
Archive and patient merge events are not specific to any programme, so they shouldn't appear on every programme tab. Extract them into a new AppPatientActivityComponent ("Activity log" card) rendered on the Child record tab instead.
1 parent 4204198 commit 2d67a9b

7 files changed

Lines changed: 53 additions & 23 deletions

File tree

app/components/app_activity_log_component.rb

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ class AppActivityLogComponent < ViewComponent::Base
4141

4242
def initialize(team:, patient:, programme_type: nil, session: nil)
4343
@patient = patient
44+
@patient_level = programme_type.nil? && session.nil?
4445

45-
@archive_reasons =
46-
@patient.archive_reasons.where(team:).includes(:created_by)
46+
if @patient_level
47+
@archive_reasons =
48+
@patient.archive_reasons.where(team:).includes(:created_by)
49+
50+
@patient_merge_log_entries =
51+
@patient.patient_merge_log_entries.includes(:user)
52+
53+
return
54+
end
4755

4856
@attendance_records =
4957
patient
@@ -116,9 +124,6 @@ def initialize(team:, patient:, programme_type: nil, session: nil)
116124
session ? scope.where(location: session.location) : scope
117125
end
118126

119-
@patient_merge_log_entries =
120-
@patient.patient_merge_log_entries.includes(:user)
121-
122127
@patient_specific_directions =
123128
@patient
124129
.patient_specific_directions
@@ -184,21 +189,23 @@ def initialize(team:, patient:, programme_type: nil, session: nil)
184189
:vaccination_records
185190

186191
def all_events
187-
[
188-
archive_events,
189-
attendance_events,
190-
consent_events,
191-
expiration_events,
192-
gillick_assessment_events,
193-
note_events,
194-
notify_events,
195-
patient_merge_events,
196-
patient_specific_direction_events,
197-
pre_screening_events,
198-
session_events,
199-
triage_events,
200-
vaccination_events
201-
].flatten.sort_by { it[:at] }.reverse
192+
if @patient_level
193+
[archive_events, patient_merge_events]
194+
else
195+
[
196+
attendance_events,
197+
consent_events,
198+
expiration_events,
199+
gillick_assessment_events,
200+
note_events,
201+
notify_events,
202+
patient_specific_direction_events,
203+
pre_screening_events,
204+
session_events,
205+
triage_events,
206+
vaccination_events
207+
]
208+
end.flatten.sort_by { it[:at] }.reverse
202209
end
203210

204211
def archive_events
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientActivityComponent < ViewComponent::Base
4+
def initialize(patient, team:)
5+
@patient = patient
6+
@team = team
7+
end
8+
9+
def call
10+
render AppCardComponent.new(section: true) do |card|
11+
card.with_heading { "Activity log" }
12+
render AppActivityLogComponent.new(patient:, team:)
13+
end
14+
end
15+
16+
private
17+
18+
attr_reader :patient, :team
19+
end

app/views/patients/show.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@
3838
) %>
3939
<% end %>
4040
<% end %>
41+
42+
<%= render AppPatientActivityComponent.new(@patient, team: current_team) %>

spec/components/app_activity_log_component_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
end
7777

7878
describe "archive reasons" do
79+
let(:component) { described_class.new(patient:, team:) }
80+
7981
before do
8082
create(
8183
:archive_reason,
@@ -787,6 +789,8 @@
787789
end
788790

789791
describe "patient merge events" do
792+
let(:component) { described_class.new(patient:, team:) }
793+
790794
before do
791795
create(
792796
:patient_merge_log_entry,

spec/features/archive_children_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ def and_i_see_an_archived_tag
224224
end
225225

226226
def and_i_see_an_activity_log_entry
227-
within(".app-secondary-navigation") { click_on "HPV" }
228227
expect(page).to have_content("Record archived:")
229228
end
230229

spec/features/manage_children_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
and_the_vaccination_record_is_updated_with_the_nhs
7676

7777
when_i_go_back_to_the_patient_page
78-
and_i_click_on_a_programme
7978
then_i_see_the_patient_merge_in_the_activity_log
8079
end
8180

spec/features/national_reporting_team_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def then_i_should_see_the_childs_card
182182

183183
def then_i_should_see_vaccinations_then_child_details
184184
app_cards = page.all(".app-card")
185-
expect(app_cards.count).to eq(2)
185+
expect(app_cards.count).to eq(3)
186186
expect(app_cards[0]).to have_content("Vaccinations")
187187
expect(app_cards[1]).to have_content("Child record")
188188
end

0 commit comments

Comments
 (0)