Skip to content

Commit 9d4bbc3

Browse files
committed
Remove PatientSession#todays_attendance
It's specific to the session so we need to move it out of this model so it can be used when we no longer have an explicit link to the session. Jira-Issue: MAV-1938
1 parent 583e107 commit 9d4bbc3

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

app/controllers/sessions/register_controller.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class Sessions::RegisterController < ApplicationController
55

66
before_action :set_session
77
before_action :set_patient_search_form, only: :show
8+
before_action :set_session_date, only: :create
89
before_action :set_patient, only: :create
9-
before_action :set_patient_session, only: :create
1010

1111
layout "full"
1212

@@ -27,13 +27,17 @@ def show
2727
def create
2828
attendance_record =
2929
ActiveRecord::Base.transaction do
30-
record = authorize @patient_session.todays_attendance
30+
record =
31+
authorize @patient
32+
.attendance_records
33+
.includes(:session_date)
34+
.find_or_initialize_by(session_date: @session_date)
3135
record.update!(attending: params[:status] == "present")
32-
StatusUpdater.call(patient: @patient_session.patient)
36+
StatusUpdater.call(patient: @patient)
3337
record
3438
end
3539

36-
name = @patient_session.patient.full_name
40+
name = @patient.full_name
3741

3842
flash[:info] = if attendance_record.attending?
3943
t("attendance_flash.present", name:)
@@ -50,12 +54,11 @@ def set_session
5054
@session = policy_scope(Session).find_by!(slug: params[:session_slug])
5155
end
5256

53-
def set_patient
54-
@patient = policy_scope(Patient).find(params[:patient_id])
57+
def set_session_date
58+
@session_date = @session.session_dates.find_by!(value: Date.current)
5559
end
5660

57-
def set_patient_session
58-
@patient_session =
59-
PatientSession.find_by!(patient: @patient, session: @session)
61+
def set_patient
62+
@patient = policy_scope(Patient).find(params[:patient_id])
6063
end
6164
end

app/models/patient_session.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,6 @@ def destroy_if_safe!
321321

322322
def programmes = session.programmes_for(patient:, academic_year:)
323323

324-
def todays_attendance
325-
if (session_date = session.session_dates.today.first)
326-
patient
327-
.attendance_records
328-
.includes(:patient, session_date: { session: :programmes })
329-
.find_or_initialize_by(session_date:)
330-
end
331-
end
332-
333324
def next_activity(programme:)
334325
if patient.vaccination_status(programme:, academic_year:).vaccinated?
335326
return nil

app/views/patient_sessions/_header.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
</li>
3939
<% end %>
4040

41-
<% if @session.requires_registration? && (attendance_record = @patient_session.todays_attendance) %>
41+
<% if @session.requires_registration? && (session_date = @session.session_dates.today.first) %>
42+
<% attendance_record = @patient.attendance_records.includes(:session_date).find_or_initialize_by(session_date:) %>
43+
4244
<li class="app-action-list__item">
4345
<%= render AppStatusTagComponent.new(@patient_session.registration_status&.status || "unknown", context: :register) %>
4446
</li>

0 commit comments

Comments
 (0)