Skip to content

Commit 6f0fb34

Browse files
committed
Update actual_upcoming_session logic
This defaults to the organisation's generic clinic session if no upcoming session is found.
1 parent c9652d8 commit 6f0fb34

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

app/controllers/concerns/consent_form_mailer_concern.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def send_consent_form_confirmation(consent_form)
1616
)
1717
elsif consent_form.needs_triage?
1818
mailer.confirmation_triage.deliver_later
19-
elsif consent_form.actual_upcoming_session.nil? ||
19+
elsif consent_form.actual_upcoming_session ==
20+
consent_form.organisation.generic_clinic_session ||
2021
consent_form.actual_upcoming_session.completed? ||
2122
consent_form.actual_upcoming_session.closed?
2223
mailer.confirmation_clinic.deliver_later

app/models/consent_form.rb

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,22 @@ def actual_upcoming_session
348348
Session.upcoming.has_programme(programme).where(organisation:)
349349

350350
if location.clinic?
351-
# If they've been booked in to a clinic we don't move them to a school
352-
# session as it's likely they're in a clinic for a reason.
351+
# If they've been booked in to a clinic we don't move them to a
352+
# school session as it's likely they're in a clinic for a reason.
353353
session_scope.find_by(location:)
354354
elsif school
355355
session_scope.find_by(location: school)
356356
elsif education_setting_home?
357357
session_scope.find_by(location: organisation.generic_clinic)
358358
else
359359
session_scope.find_by(location:)
360-
end
360+
end => upcoming_session
361+
362+
# There are no upcoming sessions available for their chosen location,
363+
# either the original session or a different school or a clinic if
364+
# home educated. This can happen if the parent fills out the form
365+
# late.
366+
upcoming_session || organisation.generic_clinic_session
361367
end
362368
end
363369

@@ -424,24 +430,14 @@ def match_with_patient!(patient)
424430
if patient.changed?
425431
patient.save!
426432

427-
unless patient.deceased? || patient.invalidated?
428-
move_patient_to_session =
429-
if actual_upcoming_session.nil?
430-
# There are no upcoming sessions available for their chosen location,
431-
# either the original session or a different school or a clinic if
432-
# home educated. This can happen if the parent fills out the form
433-
# late.
434-
organisation.generic_clinic_session
435-
elsif original_session != actual_upcoming_session
436-
actual_upcoming_session
437-
end
433+
patient_can_move =
434+
!patient.deceased? && !patient.invalidated? && actual_upcoming_session
438435

439-
if move_patient_to_session
440-
patient.move_to_session!(
441-
move_patient_to_session,
442-
from: original_session
443-
)
444-
end
436+
if patient_can_move
437+
patient.move_to_session!(
438+
actual_upcoming_session,
439+
from: original_session
440+
)
445441
end
446442
end
447443

0 commit comments

Comments
 (0)