Skip to content

Commit a24bb38

Browse files
committed
wip
1 parent 501a36a commit a24bb38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+316
-294
lines changed

app/components/app_activity_log_component.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def initialize(team:, patient:, session: nil)
6666
@patient_locations =
6767
@patient
6868
.patient_locations
69-
.includes_programmes
70-
.includes(session: :location)
71-
.then { |scope| session ? scope.where(session:) : scope }
69+
.includes(:location)
70+
.then do |scope|
71+
session ? scope.where(location: session.location) : scope
72+
end
7273

7374
@patient_specific_directions =
7475
@patient
@@ -347,14 +348,10 @@ def pre_screening_events
347348

348349
def session_events
349350
patient_locations.map do |patient_location|
350-
patient = patient_location.patient
351-
session = patient_location.session
352-
353351
[
354352
{
355-
title: "Added to the session at #{session.location.name}",
356-
at: patient_location.created_at,
357-
programmes: session.programmes_for(patient:)
353+
title: "Added to the session at #{patient_location.location.name}",
354+
at: patient_location.created_at
358355
}
359356
]
360357
end

app/components/app_patient_programmes_table_component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ def vaccination_records_for(programme:, academic_year: nil)
258258
end
259259

260260
def eligible_year_groups_for(programme:)
261-
location_ids =
262-
patient.patient_locations.joins(:session).select(:location_id)
261+
location_ids = patient.patient_locations.select(:location_id)
263262

264263
LocationProgrammeYearGroup
265264
.where(location_id: location_ids)

app/components/app_programme_session_table_component.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def vaccinated_percentage(session:)
5353
end
5454

5555
def patient_locations(session:)
56-
session
57-
.patient_locations
58-
.joins(:patient, :session)
59-
.appear_in_programmes([programme])
56+
session.patient_locations.joins(:patient).appear_in_programmes([programme])
6057
end
6158

6259
def format_number(count) = count.to_s

app/components/app_session_actions_component.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ def render? = rows.any?
2020
delegate :academic_year, :programmes, to: :session
2121

2222
def patient_locations
23-
session
24-
.patient_locations
25-
.joins(:patient, :session)
26-
.appear_in_programmes(programmes)
23+
session.patient_locations.joins(:patient).appear_in_programmes(programmes)
2724
end
2825

2926
def rows
@@ -80,7 +77,7 @@ def register_attendance_row
8077
return nil unless session.requires_registration? && session.today?
8178

8279
status = "unknown"
83-
count = patient_locations.has_registration_status(status).count
80+
count = patient_locations.has_registration_status(status, session:).count
8481
href = session_register_path(session, register_status: status)
8582

8683
generate_row(:children_to_register, count:, href:)
@@ -92,7 +89,7 @@ def ready_for_vaccinator_row
9289
counts_by_programme =
9390
session.programmes.index_with do |programme|
9491
patient_locations
95-
.has_registration_status(%w[attending completed])
92+
.has_registration_status(%w[attending completed], session:)
9693
.includes(
9794
patient: %i[consent_statuses triage_statuses vaccination_statuses]
9895
)

app/components/app_session_details_summary_component.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ def call
1717
delegate :programmes, to: :session
1818

1919
def patient_locations
20-
session
21-
.patient_locations
22-
.joins(:patient, :session)
23-
.appear_in_programmes(programmes)
20+
session.patient_locations.joins(:patient).appear_in_programmes(programmes)
2421
end
2522

2623
def cohort_row

app/components/app_session_needs_review_warning_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def make_row_from_warning(warning)
4545
def patient_locations
4646
@session
4747
.patient_locations
48-
.joins(:patient, :session)
48+
.joins(:patient)
4949
.appear_in_programmes(@session.programmes)
5050
end
5151
end

app/controllers/consent_forms_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def set_patient
136136
@patient =
137137
policy_scope(Patient).includes(
138138
parent_relationships: :parent,
139-
pending_sessions: :programmes,
140139
vaccination_records: :programme
141140
).find(params[:patient_id])
142141
end

app/controllers/imports/issues_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def set_import_issues
4040
@patients =
4141
policy_scope(Patient).with_pending_changes.includes(
4242
:gp_practice,
43-
:pending_sessions,
4443
:school,
4544
:school_moves
4645
)

app/controllers/patient_sessions/base_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def set_patient
3636

3737
def set_patient_location
3838
@patient_location =
39-
PatientLocation.find_by!(patient: @patient, session: @session)
39+
PatientLocation.find_by!(
40+
patient: @patient,
41+
location: @session.location,
42+
academic_year: @session.academic_year
43+
)
4044
end
4145

4246
def set_programme

app/controllers/patients_controller.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def edit
2626
end
2727

2828
def invite_to_clinic
29-
session =
30-
current_team.generic_clinic_session(academic_year: AcademicYear.pending)
31-
32-
PatientLocation.find_or_create_by!(patient: @patient, session:)
29+
PatientLocation.find_or_create_by!(
30+
patient: @patient,
31+
location: current_team.generic_clinic,
32+
academic_year: AcademicYear.pending
33+
)
3334

3435
redirect_to patient_path(@patient),
3536
flash: {
@@ -46,15 +47,16 @@ def set_patient
4647
:school,
4748
consents: %i[parent patient],
4849
parent_relationships: :parent,
49-
sessions: :location,
5050
vaccination_records: :programme
5151
).find(params[:id])
5252
end
5353

5454
def set_in_generic_clinic
55-
generic_clinic_session =
56-
current_team.generic_clinic_session(academic_year: AcademicYear.pending)
57-
@in_generic_clinic = @patient.sessions.include?(generic_clinic_session)
55+
@in_generic_clinic =
56+
@patient.patient_locations.exists?(
57+
location: current_team.generic_clinic,
58+
academic_year: AcademicYear.pending
59+
)
5860
end
5961

6062
def record_access_log_entry

0 commit comments

Comments
 (0)