Skip to content

Commit f6d3838

Browse files
committed
Refactor patient session factory
This removes the traits from the patient session factory and moves them instead to the patient factory to make it easier to migrate away from the patient session factory in preparation for the removal of the model. Jira-Issue: MAV-1822
1 parent 57d0a43 commit f6d3838

30 files changed

+260
-670
lines changed

app/controllers/patients_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@ def set_patient
4646
:school,
4747
consents: %i[parent patient],
4848
parent_relationships: :parent,
49-
patient_sessions: :location,
49+
sessions: :location,
5050
vaccination_records: :programme
5151
).find(params[:id])
5252
end
5353

5454
def set_in_generic_clinic
5555
generic_clinic_session =
5656
current_team.generic_clinic_session(academic_year: AcademicYear.pending)
57-
@in_generic_clinic =
58-
@patient.patient_sessions.exists?(session: generic_clinic_session)
57+
@in_generic_clinic = @patient.sessions.include?(generic_clinic_session)
5958
end
6059

6160
def record_access_log_entry

db/seeds.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ def create_session(user, team, programmes:, completed: false, year_groups: nil)
9696
year_groups.each do |year_group|
9797
patients_without_consent =
9898
FactoryBot.create_list(
99-
:patient_session,
99+
:patient,
100100
2,
101101
programmes: [programme],
102102
session:,
103-
user:,
103+
performed_by: user,
104104
year_group:
105105
)
106-
unmatched_patients = patients_without_consent.sample(2).map(&:patient)
107-
unmatched_patients.each do |patient|
106+
107+
patients_without_consent.each do |patient|
108108
FactoryBot.create(
109109
:consent_form,
110110
:recorded,
@@ -126,14 +126,14 @@ def create_session(user, team, programmes:, completed: false, year_groups: nil)
126126
)
127127

128128
traits = %i[
129-
consent_given_triage_not_needed
129+
consent_conflicting
130130
consent_given_triage_needed
131-
triaged_ready_to_vaccinate
131+
consent_given_triage_not_needed
132132
consent_refused
133-
consent_conflicting
134-
vaccinated
135-
delay_vaccination
133+
triage_delay_vaccination
134+
triage_ready_to_vaccinate
136135
unable_to_vaccinate
136+
vaccinated
137137
]
138138

139139
if programme.vaccinated_dose_sequence != 1
@@ -142,12 +142,12 @@ def create_session(user, team, programmes:, completed: false, year_groups: nil)
142142

143143
traits.each do |trait|
144144
FactoryBot.create_list(
145-
:patient_session,
145+
:patient,
146146
1,
147147
trait,
148148
programmes: [programme],
149149
session:,
150-
user:,
150+
performed_by: user,
151151
year_group:
152152
)
153153
end

spec/components/app_programme_session_table_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
let(:patient) { create(:patient, session:) }
1717

1818
before do
19-
create_list(:patient_session, 4, :consent_no_response, session:)
19+
create_list(:patient, 4, :consent_no_response, session:)
2020

2121
create(:patient_consent_status, :given, programme:, patient:)
2222

spec/components/app_session_actions_component_spec.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,35 @@
1616

1717
before do
1818
create(
19-
:patient_session,
19+
:patient,
2020
:consent_no_response,
2121
:unknown_attendance,
2222
session:,
2323
year_group:
2424
)
2525
create(
26-
:patient_session,
26+
:patient,
2727
:consent_conflicting,
2828
:unknown_attendance,
2929
session:,
3030
year_group:
3131
)
3232
create(
33-
:patient_session,
33+
:patient,
3434
:consent_given_triage_needed,
3535
:unknown_attendance,
3636
session:,
3737
year_group:
3838
)
3939
create(
40-
:patient_session,
40+
:patient,
4141
:consent_given_triage_not_needed,
4242
:in_attendance,
4343
session:,
4444
year_group:
4545
)
46-
create(:patient_session, :vaccinated, :in_attendance, session:, year_group:)
47-
48-
create(
49-
:patient_session,
50-
patient: patient_without_nhs_number,
51-
session:,
52-
year_group:
53-
)
46+
create(:patient, :vaccinated, :in_attendance, session:, year_group:)
47+
create(:patient, nhs_number: nil, session:, year_group:)
5448
end
5549

5650
it { should have_text("No NHS number1 child") }

spec/components/app_session_details_summary_component_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
context "with activity" do
1616
before do
17-
create(:patient_session, session:)
18-
create(:patient_session, :consent_refused, session:)
19-
create(:patient_session, :vaccinated, session:)
17+
create(:patient, session:)
18+
create(:patient, :consent_refused, session:)
19+
create(:patient, :vaccinated, session:)
2020
end
2121

2222
it { should have_text("Cohort3 children") }
@@ -28,8 +28,8 @@
2828

2929
context "when the patients are not eligible for the programme" do
3030
before do
31-
create(:patient_session, session:, year_group: 7)
32-
create(:patient_session, :consent_refused, session:, year_group: 7)
31+
create(:patient, session:, year_group: 7)
32+
create(:patient, :consent_refused, session:, year_group: 7)
3333
end
3434

3535
it { should have_text("CohortNo children") }

spec/components/app_vaccinate_form_component_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616
create(
1717
:patient,
1818
:consent_given_triage_not_needed,
19-
programmes:,
19+
:in_attendance,
20+
session:,
2021
given_name: "Hari"
2122
)
2223
end
23-
let(:patient_session) do
24-
create(:patient_session, :in_attendance, programmes:, patient:, session:)
25-
end
2624

2725
let(:vaccinate_form) do
2826
VaccinateForm.new(current_user:, patient:, session_date:, programme:)
2927
end
3028

3129
let(:component) { described_class.new(vaccinate_form) }
3230

33-
before { patient_session.strict_loading!(false) }
34-
3531
it { should have_css(".nhsuk-card") }
3632

3733
context "with a flu programme and consent to nasal spray" do

0 commit comments

Comments
 (0)