If it's necessary to bulk remove patients from sessions (i.e. more than a few usages of "Remove from cohort" required), the following commands can be used in a Rails console:
org = Organisation.find_by(ods_code: "")
team = org.teams.find_by(name: "")
location = org.schools.find_by(name: "School name")
session = org.sessions.find_by(location:)
session.patients.count # get the number of patients
# check all the patients can be safely removed from the session
session.patient_locations.all?(&:safe_to_destroy?)
# update all the patients to unknown school
session.patients.update_all(
cohort_id: nil,
home_educated: false,
school_id: nil
)
# remove all patients from the session
session.patient_locations.destroy_all
# update all the patient-team associations
PatientTeamUpdater.call(team:)We've had patients who have somehow ended up in only the community clinic instead of a session, even though they are associated with the correct school. This command will assign them to the session at their school:
patient = Patient.find(...)
SchoolMove.new(patient:, school: patient.school).confirm!Normally patients are added to a location on import. However, their may be cases when they need to be added to a location after they've been imported, for example if their school was not added to the team at the time the patients were imported. At the time of writing, re-importing the patients does not add them to the location's session or to the team's cohorts.
To fix this, ensure the location has been added to the school using the bin/mavis schools add-to-team command line tool.
The following console commands will manually add an existing patient to the location's session and the team's cohorts by using the logic in SchoolMove.
# Find the location
school = Location.find_by_urn_and_site("...")
# The location should only have one session with no patients:
school.sessions.first.patients.count
=> 0
# Use the logic in SchoolMove to associate each patient with the location session
academic_year = AcademicYear.current
school.patients.each { SchoolMove.new(patient: _1, school:, academic_year:).confirm! }
# Confirm that the patients have been added
school.sessions.first.patients.count
=> 294Consent.where(notify_parents_on_vaccination: false).pluck(:patient_id)org = Organisation.find_by(ods_code: "...")
team = org.teams.find_by(name: "")
dates = {}
sessions = team.sessions
sessions
.eager_load(:location)
.each do |session|
Consent
.where(team:, patient: session.patients)
.each do |consent|
dates[consent.responded_at.to_date] ||= {}
dates[consent.responded_at.to_date][session.location] ||= 0
dates[consent.responded_at.to_date][session.location] += 1
end
end
str =
CSV.generate do |csv|
csv << [""] + sessions.map { _1.location.name }
csv << ["Cohort"] + sessions.map { _1.patients.count }
dates.keys.sort.each do |date|
csv << [date.iso8601] + sessions.map { dates[date].fetch(_1.location, 0) }
end
end
puts strTo quickly take the service offline (for client users) there is a basic_auth feature flag which can be added and enabled. In production the credentials for this are secret and therefore this acts as a quick way of preventing users from accessing the service.
- Visit https://manage-vaccinations-in-schools.nhs.uk/flipper
- Add the
basic_authfeature flag if it doesn't exist already - Enable the
basic_authfeature flag
Flipper.enable(:basic_auth)patient = Patient.find(_)
# Find the parent you need to remove from the patient.
patient.parents.pluck(:id, :full_name, :email, :phone)
parent = patient.parents.find(_)
# Remove the parent relationship
patient.parent_relationships.find_by(parent:).destroy
# Check that the parent has other patients or any consents linked to them
parent.patients
parent.consents
# If the parent doesn't have any more patients or consents they can removed.
# Check with the original request to see if this is appropriate.
parent.destroyThis can be done manually, and doesn't need a SchoolMove:
# Check if the patient session in question is safe to be destroyed.
patient.patient_locations.first.safe_to_destroy?
patient.patient_locations.first.destroy
patient.sessions << clinic_session