Skip to content

Commit afb976e

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 1cc2fb9 commit afb976e

File tree

4 files changed

+80
-59
lines changed

4 files changed

+80
-59
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/factories/patients.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,6 @@
234234
end
235235
end
236236

237-
trait :triage_safe_to_vaccinate_nasal do
238-
triage_statuses do
239-
programmes.map do |programme|
240-
association(
241-
:patient_triage_status,
242-
:safe_to_vaccinate_nasal,
243-
patient: instance,
244-
programme:
245-
)
246-
end
247-
end
248-
end
249-
250237
trait :triage_required do
251238
triage_statuses do
252239
programmes.map do |programme|

spec/features/edit_vaccination_record_spec.rb

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

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

352355
def when_i_click_back

spec/models/draft_vaccination_record_spec.rb

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@
358358
context "when vaccination is not administered" do
359359
let(:attributes) { valid_not_administered_attributes }
360360

361-
it { should be true }
361+
it { should be(true) }
362362
end
363363

364364
context "when delivery method is nasal_spray" do
@@ -367,41 +367,39 @@
367367
end
368368

369369
context "when consent is given for nasal" do
370-
let(:patient) do
371-
create(
372-
:patient,
373-
:consent_given_nasal_only_triage_not_needed,
374-
session:
375-
)
376-
end
370+
before { create(:consent, :given_nasal, patient:, programme:) }
377371

378-
it { should be true }
372+
it { should be(true) }
379373
end
380374

381375
context "when consent is given for injection" do
382-
let(:patient) do
383-
create(
384-
:patient,
385-
:consent_given_injection_only_triage_needed,
386-
session:
387-
)
388-
end
376+
before { create(:consent, :given_injection, patient:, programme:) }
389377

390-
it { should be false }
378+
it { should be(false) }
391379
end
392380

393381
context "when triage is safe for nasal" do
394-
let(:patient) do
395-
create(:patient, :triage_safe_to_vaccinate_nasal, session:)
382+
before do
383+
create(:consent, :given_nasal, patient:, programme:)
384+
create(
385+
:triage,
386+
:ready_to_vaccinate,
387+
patient:,
388+
programme:,
389+
vaccine_method: "nasal"
390+
)
396391
end
397392

398-
it { should be true }
393+
it { should be(true) }
399394
end
400395

401396
context "when triage is safe for injection" do
402-
let(:patient) { create(:patient, :triage_safe_to_vaccinate, session:) }
397+
before do
398+
create(:consent, :given_injection, patient:, programme:)
399+
create(:triage, :ready_to_vaccinate, patient:, programme:)
400+
end
403401

404-
it { should be false }
402+
it { should be(false) }
405403
end
406404
end
407405

@@ -411,37 +409,39 @@
411409
end
412410

413411
context "when consent is given for injection" do
414-
let(:patient) do
415-
create(
416-
:patient,
417-
:consent_given_injection_only_triage_not_needed,
418-
session:
419-
)
420-
end
412+
before { create(:consent, :given_injection, patient:, programme:) }
421413

422-
it { should be true }
414+
it { should be(true) }
423415
end
424416

425417
context "when consent is given for nasal" do
426-
let(:patient) do
427-
create(:patient, :consent_given_nasal_only_triage_needed, session:)
428-
end
418+
before { create(:consent, :given_nasal, patient:, programme:) }
429419

430-
it { should be false }
420+
it { should be(false) }
431421
end
432422

433423
context "when triage is safe for injection" do
434-
let(:patient) { create(:patient, :triage_safe_to_vaccinate, session:) }
424+
before do
425+
create(:consent, :given_injection, patient:, programme:)
426+
create(:triage, :ready_to_vaccinate, patient:, programme:)
427+
end
435428

436-
it { should be true }
429+
it { should be(true) }
437430
end
438431

439432
context "when triage is safe for nasal" do
440-
let(:patient) do
441-
create(:patient, :triage_safe_to_vaccinate_nasal, session:)
433+
before do
434+
create(:consent, :given_nasal, patient:, programme:)
435+
create(
436+
:triage,
437+
:ready_to_vaccinate,
438+
patient:,
439+
programme:,
440+
vaccine_method: "nasal"
441+
)
442442
end
443443

444-
it { should be false }
444+
it { should be(false) }
445445
end
446446
end
447447
end

0 commit comments

Comments
 (0)