Skip to content

Commit

Permalink
Don't add deceased patients to sessions
Browse files Browse the repository at this point in the history
If a patient is marked as deceased we shouldn't be adding them to any
sessions.
  • Loading branch information
thomasleese committed Oct 17, 2024
1 parent 2aaf323 commit 6ed18e8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/consent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def match_with_patient!(patient)
.has_programme(programme)
.find_by(team:, location: school)

if upcoming_session
if upcoming_session && patient.date_of_death.nil?
patient.patient_sessions.find_or_create_by!(session: upcoming_session)
end
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ def create_patient_sessions!
cohorts = team.cohorts.for_year_groups(year_groups, academic_year:)

patients_in_cohorts =
Patient.where(cohort: cohorts, school: location).includes(
:upcoming_sessions,
vaccination_records: :programme
)
Patient.where(
cohort: cohorts,
school: location,
date_of_death: nil
).includes(:upcoming_sessions, vaccination_records: :programme)

required_programmes = Set.new(programmes)

Expand Down
4 changes: 4 additions & 0 deletions spec/factories/patients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
home_educated { true }
end

trait :deceased do
date_of_death { Date.current }
end

trait :consent_request_sent do
after(:create) do |patient, context|
create(
Expand Down
8 changes: 8 additions & 0 deletions spec/models/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@
programme: hpv_programme,
patient: both_vaccinated_teen
)

create(
:patient,
:deceased,
date_of_birth: 9.years.ago.to_date,
team:,
school:
)
end

context "with a Flu session" do
Expand Down

0 comments on commit 6ed18e8

Please sign in to comment.