Skip to content

Commit

Permalink
Ensure patient sessions are active
Browse files Browse the repository at this point in the history
When moving a patient between schools we need to ensure the patient
session is active so that the patient appears in the list for any
scheduled sessions.

I think we might be able to remove the concept of active/inactive
patient sessions as nurses aren't creating these manually anymore, but
we can fix that separately.
  • Loading branch information
thomasleese committed Oct 8, 2024
1 parent 346208d commit ef63558
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def handle_school_changed
.or(Session.unscheduled)

new_sessions.find_each do |session|
patient_sessions.find_or_create_by!(session:)
patient_sessions
.find_or_initialize_by(session:)
.tap { |patient_session| patient_session.update!(active: true) }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/models/class_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
session.location
)
expect(patient.upcoming_sessions).to contain_exactly(session)
expect(patient.patient_sessions.find_by(session:)).to be_active
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/models/patient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@
it "adds the patient to the session" do
match_consent_form!
expect(new_session.reload.patients).to include(patient)
expect(
patient.patient_sessions.find_by(session: new_session)
).to be_active
end
end
end
Expand Down

0 comments on commit ef63558

Please sign in to comment.