Skip to content

Commit 8ef4a48

Browse files
fix: use cached vaccination status
We also need to add StatusUpdater.call(patient: @patient) to a lot of the tests so that the vaccination status is not nil.
1 parent 249c363 commit 8ef4a48

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

app/components/app_patient_programmes_table_component.rb

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,47 @@ def seasonal_programme_rows(programme:)
4545

4646
vaccination_records = vaccination_records_for(programme:, academic_year:)
4747

48-
if vaccination_records.count.positive?
49-
(1..vaccination_records.count).to_a.map do |i|
48+
rows =
49+
(1..vaccination_records.count - 1).to_a.map do |i|
5050
build_row(
5151
programme:,
5252
academic_year:,
5353
vaccination_records: vaccination_records.slice(0, i)
5454
)
5555
end
56-
else
57-
[build_row(programme:, academic_year:, vaccination_records: [])]
58-
end
56+
57+
rows +
58+
[
59+
build_row_from_cache(
60+
programme:,
61+
academic_year:,
62+
last_vaccination_record: vaccination_records.last
63+
)
64+
]
5965
end
6066
end
6167

6268
def non_seasonal_programme_rows(programme:)
6369
academic_year = AcademicYear.pending
6470
vaccination_records = vaccination_records_for(programme:)
6571

66-
if vaccination_records.count.positive?
67-
(1..vaccination_records.count).to_a.map do |i|
72+
rows =
73+
(1..vaccination_records.count - 1).to_a.map do |i|
6874
build_row(
6975
programme:,
7076
academic_year:,
7177
vaccination_records: vaccination_records.slice(0, i)
7278
)
7379
end
74-
else
75-
[build_row(programme:, academic_year:, vaccination_records: [])]
76-
end
80+
81+
rows +
82+
[
83+
build_row_from_cache(
84+
programme:,
85+
academic_year:,
86+
last_vaccination_record: vaccination_records.last
87+
)
88+
]
7789
end
7890

7991
def build_row(programme:, academic_year:, vaccination_records: nil)
@@ -98,7 +110,33 @@ def build_row(programme:, academic_year:, vaccination_records: nil)
98110
vaccination_status:,
99111
programme:,
100112
academic_year:,
101-
latest_vaccination_record: vaccination_records.last
113+
latest_vaccination_record: vaccination_records&.last
114+
)
115+
]
116+
end
117+
118+
def build_row_from_cache(programme:, academic_year:, last_vaccination_record:)
119+
cached_vaccination_status =
120+
@patient.vaccination_status(programme:, academic_year:)
121+
122+
vaccination_status = {
123+
status: cached_vaccination_status.status.to_sym,
124+
latest_session_status:
125+
cached_vaccination_status.latest_session_status.to_sym
126+
}
127+
128+
[
129+
name_for_programme(
130+
programme:,
131+
academic_year:,
132+
dose_sequence: last_vaccination_record&.dose_sequence
133+
),
134+
status_for_programme(vaccination_status:, programme:, academic_year:),
135+
notes_for_programme(
136+
vaccination_status:,
137+
programme:,
138+
academic_year:,
139+
latest_vaccination_record: last_vaccination_record
102140
)
103141
]
104142
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@
256256
t.boolean "notify_parents_on_vaccination"
257257
t.datetime "submitted_at", null: false
258258
t.integer "vaccine_methods", default: [], null: false, array: true
259-
t.integer "academic_year", null: false
260259
t.boolean "notify_parent_on_refusal"
260+
t.integer "academic_year", null: false
261261
t.index ["academic_year"], name: "index_consents_on_academic_year"
262262
t.index ["parent_id"], name: "index_consents_on_parent_id"
263263
t.index ["patient_id"], name: "index_consents_on_patient_id"

spec/features/vaccination_programmes_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def then_the_table_has_a_row_showing_hpv_vaccinated
110110
end
111111

112112
def and_the_table_has_a_row_showing_second_hpv_vaccinated
113+
puts page.html
114+
113115
expect(page).to have_selector(
114116
"table.nhsuk-table tbody tr",
115117
text: "HPV (2nd dose)"
@@ -183,6 +185,8 @@ def and_the_patient_is_vaccinated_for_hpv
183185
session: @session,
184186
performed_at: 6.months.ago
185187
)
188+
189+
StatusUpdater.call(patient: @patient)
186190
end
187191

188192
def and_the_patient_has_a_second_dose_of_hpv
@@ -193,6 +197,8 @@ def and_the_patient_has_a_second_dose_of_hpv
193197
programme: @hpv_programme,
194198
session: @session
195199
)
200+
201+
StatusUpdater.call(patient: @patient)
196202
end
197203

198204
def and_the_patient_had_two_flu_doses_last_year

0 commit comments

Comments
 (0)