Skip to content

Commit aa48e80

Browse files
committed
Ensure incorrect vaccine given message isn't shown
Once a patient has been vaccinated, their list of approved vaccine methods is empty (they're not approved for any vaccines because they're already vaccinated), therefore we were always showing a message saying that the vaccine method recorded is not an approved vaccine method for this patient. It looks like this broken when we introduced a new consent status of not required (5eac3c4) although before that it would also have been showing if the approved method originally came from triage. Jira-Issue: MAV-1831
1 parent ca74c7e commit aa48e80

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

app/models/draft_vaccination_record.rb

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,43 @@ def identity_check=(identity_check)
261261
end
262262

263263
def vaccine_method_matches_consent_and_triage?
264-
return true if delivery_method.blank? || !administered?
264+
if delivery_method.blank? || !administered? || academic_year.nil?
265+
return true
266+
end
267+
268+
# We can't use `patient.approved_vaccine_methods` because once vaccinated
269+
# a patient no longer has an approved list of vaccine methods (they don't
270+
# need the vaccine).
271+
272+
consent_generator =
273+
StatusGenerator::Consent.new(
274+
programme:,
275+
academic_year:,
276+
patient:,
277+
consents: patient.consents,
278+
vaccination_records: []
279+
)
280+
281+
triage_generator =
282+
StatusGenerator::Triage.new(
283+
programme:,
284+
academic_year:,
285+
patient:,
286+
consents: patient.consents,
287+
triages: patient.triages,
288+
vaccination_records: []
289+
)
290+
291+
approved_vaccine_methods =
292+
if triage_generator.status == :not_required
293+
consent_generator.vaccine_methods
294+
else
295+
[triage_generator.vaccine_method].compact
296+
end
265297

266-
academic_year = session&.academic_year || performed_at.academic_year
267-
approved_methods =
268-
patient.approved_vaccine_methods(programme:, academic_year:)
269298
vaccine_method = Vaccine.delivery_method_to_vaccine_method(delivery_method)
270299

271-
approved_methods.include?(vaccine_method)
300+
approved_vaccine_methods.include?(vaccine_method)
272301
end
273302

274303
private
@@ -321,13 +350,15 @@ def reset_unused_attributes
321350
end
322351
end
323352

353+
def academic_year = session&.academic_year
354+
324355
def earliest_possible_value
325-
session.academic_year.to_academic_year_date_range.first.beginning_of_day
356+
academic_year.to_academic_year_date_range.first.beginning_of_day
326357
end
327358

328359
def latest_possible_value
329360
[
330-
session.academic_year.to_academic_year_date_range.last.end_of_day,
361+
academic_year.to_academic_year_date_range.last.end_of_day,
331362
Time.current
332363
].min
333364
end

spec/features/edit_vaccination_record_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ def when_i_click_on_edit_vaccination_record
346346

347347
def then_i_see_the_edit_vaccination_record_page
348348
expect(page).to have_content("Edit vaccination record")
349+
expect(page).not_to have_content(
350+
"The vaccine given does not match that determined by the child’s consent or triage outcome"
351+
)
349352
end
350353

351354
def when_i_click_back

0 commit comments

Comments
 (0)