Skip to content

Commit

Permalink
Remove cohort reference
Browse files Browse the repository at this point in the history
This removes the cohort reference on patients, and removes any final
bits of code that rely on the cohort reference.
  • Loading branch information
thomasleese committed Jan 22, 2025
1 parent 91b3321 commit ae4d218
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 23 deletions.
1 change: 0 additions & 1 deletion app/controllers/dev_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def reset_organisation

patients.includes(:parents).destroy_all

Cohort.where(organisation:).destroy_all
Batch.where(organisation:).destroy_all

UnscheduledSessionsFactory.new.call
Expand Down
1 change: 0 additions & 1 deletion app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Organisation < ApplicationRecord

has_many :batches
has_many :cohort_imports
has_many :cohorts
has_many :consent_forms
has_many :consents
has_many :locations
Expand Down
11 changes: 2 additions & 9 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Patient < ApplicationRecord

audited

belongs_to :cohort, optional: true
belongs_to :gp_practice, class_name: "Location", optional: true
belongs_to :organisation, optional: true

Expand Down Expand Up @@ -353,24 +352,18 @@ def add_to_upcoming_sessions!
end

def self.from_consent_form(consent_form)
birth_academic_year = consent_form.date_of_birth.academic_year
organisation = consent_form.organisation

cohort = Cohort.find_or_create_by!(birth_academic_year:, organisation:)

new(
address_line_1: consent_form.address_line_1,
address_line_2: consent_form.address_line_2,
address_postcode: consent_form.address_postcode,
address_town: consent_form.address_town,
birth_academic_year:,
cohort:,
birth_academic_year: consent_form.date_of_birth.academic_year,
date_of_birth: consent_form.date_of_birth,
family_name: consent_form.family_name,
given_name: consent_form.given_name,
home_educated: consent_form.home_educated,
nhs_number: consent_form.nhs_number,
organisation:,
organisation: consent_form.organisation,
preferred_family_name: consent_form.preferred_family_name,
preferred_given_name: consent_form.preferred_given_name,
school: consent_form.school
Expand Down
5 changes: 0 additions & 5 deletions spec/factories/patients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
session&.organisation || school&.organisation ||
association(:organisation, programmes: [programme].compact)
end
cohort do
if organisation
Cohort.find_or_create_by!(birth_academic_year:, organisation:)
end
end

nhs_number do
# Prevents duplicate NHS numbers by sequencing and appending a check
Expand Down
1 change: 0 additions & 1 deletion spec/models/class_import_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@

it do
expect(patient).to have_attributes(
cohort: nil,
date_of_birth: Date.new(2010, 1, 1),
gender_code: "not_known",
home_educated: false,
Expand Down
1 change: 0 additions & 1 deletion spec/models/cohort_import_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@

it do
expect(patient).to have_attributes(
cohort: nil,
date_of_birth: Date.new(2010, 1, 1),
gender_code: "male",
home_educated: false,
Expand Down
10 changes: 5 additions & 5 deletions spec/models/immunisation_import_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,17 @@
end
end

describe "#cohort" do
subject(:cohort) { patient.cohort }
describe "#organisation" do
subject(:cohort) { patient.organisation }

let(:data) { valid_data }

it { should be_nil }

context "with an existing patient in a cohort" do
let(:patient) { create(:patient, nhs_number:, cohort: create(:cohort)) }
context "with an existing patient in the cohort" do
let(:patient) { create(:patient, nhs_number:) }

it { should eq(patient.cohort) }
it { should eq(patient.organisation) }
end
end
end
Expand Down

0 comments on commit ae4d218

Please sign in to comment.