Skip to content

Commit 8a97e7c

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 38a0dc0 commit 8a97e7c

7 files changed

Lines changed: 212 additions & 142 deletions

File tree

app/components/app_activity_log_component.rb

Lines changed: 186 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -41,147 +41,12 @@ class AppActivityLogComponent < ViewComponent::Base
4141

4242
def initialize(team:, patient:, programme_type: nil, session: nil)
4343
@patient = patient
44-
45-
@archive_reasons =
46-
@patient.archive_reasons.where(team:).includes(:created_by)
47-
48-
@attendance_records =
49-
patient
50-
.attendance_records
51-
.includes(:location)
52-
.then do |scope|
53-
session ? scope.where(location: session.location) : scope
54-
end
55-
56-
@consents =
57-
@patient
58-
.consents
59-
.includes(
60-
:consent_form,
61-
:parent,
62-
:recorded_by,
63-
patient: :parent_relationships
64-
)
65-
.then do |scope|
66-
if programme_type
67-
scope.where(programme_type:)
68-
elsif session
69-
scope.for_session(session)
70-
else
71-
scope
72-
end
73-
end
74-
75-
@gillick_assessments =
76-
@patient
77-
.gillick_assessments
78-
.includes(:performed_by)
79-
.order(:created_at)
80-
.then do |scope|
81-
if programme_type
82-
scope.where(programme_type:)
83-
elsif session
84-
scope.for_session(session)
85-
else
86-
scope
87-
end
88-
end
89-
90-
@notes =
91-
@patient
92-
.notes
93-
.includes(:created_by, :patient, :session)
94-
.then { |scope| session ? scope.where(session:) : scope }
95-
96-
@notify_log_entries =
97-
@patient
98-
.notify_log_entries
99-
.includes(:sent_by)
100-
.preload(:notify_log_entry_programmes)
101-
.then do |scope|
102-
if programme_type
103-
scope.for_programme_type(programme_type)
104-
elsif session
105-
scope.for_session(session)
106-
else
107-
scope
108-
end
109-
end
110-
111-
@patient_locations =
112-
@patient
113-
.patient_locations
114-
.includes(:location)
115-
.then do |scope|
116-
session ? scope.where(location: session.location) : scope
117-
end
118-
119-
@patient_merge_log_entries =
120-
@patient.patient_merge_log_entries.includes(:user)
121-
122-
@patient_specific_directions =
123-
@patient
124-
.patient_specific_directions
125-
.includes(:created_by)
126-
.then do |scope|
127-
if programme_type
128-
scope.where(programme_type:)
129-
elsif session
130-
scope.for_session(session)
131-
else
132-
scope
133-
end
134-
end
135-
136-
@pre_screenings =
137-
@patient
138-
.pre_screenings
139-
.includes(:performed_by)
140-
.then do |scope|
141-
if programme_type
142-
scope.where(programme_type:)
143-
elsif session
144-
scope.for_session(session)
145-
else
146-
scope
147-
end
148-
end
149-
150-
@triages =
151-
@patient
152-
.triages
153-
.includes(:performed_by)
154-
.then do |scope|
155-
if programme_type
156-
scope.where(programme_type:)
157-
elsif session
158-
scope.for_session(session)
159-
else
160-
scope
161-
end
162-
end
163-
164-
@vaccination_records =
165-
@patient
166-
.vaccination_records
167-
.with_discarded
168-
.includes(:performed_by_user, :vaccine)
169-
.then { |scope| programme_type ? scope.where(programme_type:) : scope }
44+
@team = team
45+
@programme_type = programme_type
46+
@session = session
17047
end
17148

172-
attr_reader :archive_reasons,
173-
:consents,
174-
:gillick_assessments,
175-
:notes,
176-
:notify_log_entries,
177-
:patient,
178-
:patient_locations,
179-
:patient_merge_log_entries,
180-
:patient_specific_directions,
181-
:pre_screenings,
182-
:attendance_records,
183-
:triages,
184-
:vaccination_records
49+
attr_reader :patient
18550

18651
def all_events
18752
[
@@ -290,6 +155,8 @@ def consent_events
290155
end
291156

292157
def expiration_events
158+
return [] unless include_programme_specific_events?
159+
293160
all_programmes = Programme.all.to_a
294161

295162
AcademicYear.all.flat_map do |academic_year|
@@ -568,6 +435,186 @@ def attendance_events
568435

569436
private
570437

438+
def include_programme_specific_events?
439+
@programme_type.present? || @session.present?
440+
end
441+
442+
def archive_reasons
443+
return [] if include_programme_specific_events?
444+
445+
@archive_reasons ||=
446+
@patient.archive_reasons.where(team: @team).includes(:created_by)
447+
end
448+
449+
def patient_merge_log_entries
450+
return [] if include_programme_specific_events?
451+
452+
@patient_merge_log_entries ||=
453+
@patient.patient_merge_log_entries.includes(:user)
454+
end
455+
456+
def attendance_records
457+
return [] unless include_programme_specific_events?
458+
459+
@attendance_records ||=
460+
patient
461+
.attendance_records
462+
.includes(:location)
463+
.then do |scope|
464+
@session ? scope.where(location: @session.location) : scope
465+
end
466+
end
467+
468+
def consents
469+
return [] unless include_programme_specific_events?
470+
471+
@consents ||=
472+
@patient
473+
.consents
474+
.includes(
475+
:consent_form,
476+
:parent,
477+
:recorded_by,
478+
patient: :parent_relationships
479+
)
480+
.then do |scope|
481+
if @programme_type
482+
scope.where(programme_type: @programme_type)
483+
elsif @session
484+
scope.for_session(@session)
485+
else
486+
scope
487+
end
488+
end
489+
end
490+
491+
def gillick_assessments
492+
return [] unless include_programme_specific_events?
493+
494+
@gillick_assessments ||=
495+
@patient
496+
.gillick_assessments
497+
.includes(:performed_by)
498+
.order(:created_at)
499+
.then do |scope|
500+
if @programme_type
501+
scope.where(programme_type: @programme_type)
502+
elsif @session
503+
scope.for_session(@session)
504+
else
505+
scope
506+
end
507+
end
508+
end
509+
510+
def notes
511+
return [] unless include_programme_specific_events?
512+
513+
@notes ||=
514+
@patient
515+
.notes
516+
.includes(:created_by, :patient, :session)
517+
.then { |scope| @session ? scope.where(session: @session) : scope }
518+
end
519+
520+
def notify_log_entries
521+
return [] unless include_programme_specific_events?
522+
523+
@notify_log_entries ||=
524+
@patient
525+
.notify_log_entries
526+
.includes(:sent_by)
527+
.preload(:notify_log_entry_programmes)
528+
.then do |scope|
529+
if @programme_type
530+
scope.for_programme_type(@programme_type)
531+
elsif @session
532+
scope.for_session(@session)
533+
else
534+
scope
535+
end
536+
end
537+
end
538+
539+
def patient_locations
540+
return [] unless include_programme_specific_events?
541+
542+
@patient_locations ||=
543+
@patient
544+
.patient_locations
545+
.includes(:location)
546+
.then do |scope|
547+
@session ? scope.where(location: @session.location) : scope
548+
end
549+
end
550+
551+
def patient_specific_directions
552+
return [] unless include_programme_specific_events?
553+
554+
@patient_specific_directions ||=
555+
@patient
556+
.patient_specific_directions
557+
.includes(:created_by)
558+
.then do |scope|
559+
if @programme_type
560+
scope.where(programme_type: @programme_type)
561+
elsif @session
562+
scope.for_session(@session)
563+
else
564+
scope
565+
end
566+
end
567+
end
568+
569+
def pre_screenings
570+
return [] unless include_programme_specific_events?
571+
572+
@pre_screenings ||=
573+
@patient
574+
.pre_screenings
575+
.includes(:performed_by)
576+
.then do |scope|
577+
if @programme_type
578+
scope.where(programme_type: @programme_type)
579+
elsif @session
580+
scope.for_session(@session)
581+
else
582+
scope
583+
end
584+
end
585+
end
586+
587+
def triages
588+
return [] unless include_programme_specific_events?
589+
590+
@triages ||=
591+
@patient
592+
.triages
593+
.includes(:performed_by)
594+
.then do |scope|
595+
if @programme_type
596+
scope.where(programme_type: @programme_type)
597+
elsif @session
598+
scope.for_session(@session)
599+
else
600+
scope
601+
end
602+
end
603+
end
604+
605+
def vaccination_records
606+
return [] unless include_programme_specific_events?
607+
608+
@vaccination_records ||=
609+
@patient
610+
.vaccination_records
611+
.with_discarded
612+
.includes(:performed_by_user, :vaccine)
613+
.then do |scope|
614+
@programme_type ? scope.where(programme_type: @programme_type) : scope
615+
end
616+
end
617+
571618
def expired_items_for(academic_year:, programmes:)
572619
{
573620
consents:,
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

0 commit comments

Comments
 (0)