Skip to content

Commit 3de0776

Browse files
Don't show duplicate Imms API vaccs records in activity log
Some Imms API records have a `discarded_at` date, because they were deduplicated when they were ingested. These records should be suppressed all over the UI; the user shouldn't know that they ever existed. This fixes the bug that these records were showing two cards in the activity log: - "Vaccinated" - "Vaccination record archived" Jira-Issue: MAV-5895
1 parent d2f3795 commit 3de0776

2 files changed

Lines changed: 154 additions & 93 deletions

File tree

app/components/app_activity_log_component.rb

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -485,55 +485,63 @@ def triage_events
485485
end
486486

487487
def vaccination_events
488-
vaccination_records.flat_map do |vaccination_record|
489-
title =
490-
if vaccination_record.administered?
491-
if (vaccine = vaccination_record.vaccine)
492-
"Vaccinated with #{vaccine.brand}"
493-
elsif vaccination_record.sourced_from_manual_report?
494-
"Vaccination record added manually"
495-
elsif vaccination_record.sourced_from_historical_upload?
496-
"Vaccination record uploaded"
488+
events =
489+
vaccination_records.flat_map do |vaccination_record|
490+
if vaccination_record.sourced_from_nhs_immunisations_api? &&
491+
vaccination_record.discarded?
492+
next
493+
end
494+
495+
title =
496+
if vaccination_record.administered?
497+
if (vaccine = vaccination_record.vaccine)
498+
"Vaccinated with #{vaccine.brand}"
499+
elsif vaccination_record.sourced_from_manual_report?
500+
"Vaccination record added manually"
501+
elsif vaccination_record.sourced_from_historical_upload?
502+
"Vaccination record uploaded"
503+
else
504+
"Vaccinated"
505+
end
497506
else
498-
"Vaccinated"
507+
"Vaccination not given: #{vaccination_record.human_enum_name(:outcome)}"
499508
end
500-
else
501-
"Vaccination not given: #{vaccination_record.human_enum_name(:outcome)}"
502-
end
503509

504-
subtitle =
505-
if historical_vaccination_event?(vaccination_record)
506-
"Record added to Mavis #{vaccination_record.created_at.to_fs(:long)} · " \
507-
"Vaccination given #{vaccination_record.performed_at.to_date.to_fs(:long)}"
508-
end
510+
subtitle =
511+
if historical_vaccination_event?(vaccination_record)
512+
"Record added to Mavis #{vaccination_record.created_at.to_fs(:long)} · " \
513+
"Vaccination given #{vaccination_record.performed_at.to_date.to_fs(:long)}"
514+
end
509515

510-
at =
511-
if historical_vaccination_event?(vaccination_record)
512-
vaccination_record.created_at
513-
else
514-
vaccination_record.performed_at
515-
end
516+
at =
517+
if historical_vaccination_event?(vaccination_record)
518+
vaccination_record.created_at
519+
else
520+
vaccination_record.performed_at
521+
end
516522

517-
kept = {
518-
title:,
519-
body: vaccination_record.notes,
520-
at:,
521-
by: vaccination_record.performed_by,
522-
programmes: [vaccination_record.programme],
523-
subtitle:
524-
}
523+
kept = {
524+
title:,
525+
body: vaccination_record.notes,
526+
at:,
527+
by: vaccination_record.performed_by,
528+
programmes: [vaccination_record.programme],
529+
subtitle:
530+
}
525531

526-
discarded =
527-
if vaccination_record.discarded?
528-
{
529-
title: "Vaccination record archived",
530-
at: vaccination_record.discarded_at,
531-
programmes: [vaccination_record.programme]
532-
}
533-
end
532+
discarded =
533+
if vaccination_record.discarded?
534+
{
535+
title: "Vaccination record archived",
536+
at: vaccination_record.discarded_at,
537+
programmes: [vaccination_record.programme]
538+
}
539+
end
534540

535-
[kept, discarded].compact
536-
end
541+
[kept, discarded].compact
542+
end
543+
544+
events.compact
537545
end
538546

539547
def historical_vaccination_event?(vaccination_record)

spec/components/app_activity_log_component_spec.rb

Lines changed: 104 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,6 @@
347347
programme: "Flu"
348348
end
349349

350-
describe "vaccination not administered" do
351-
before do
352-
create(
353-
:vaccination_record,
354-
:not_administered,
355-
programme: programmes.first,
356-
patient:,
357-
session:,
358-
performed_at: Time.zone.local(2025, 5, 31, 13),
359-
performed_by: user,
360-
notes: "Some notes.",
361-
vaccine: programmes.first.vaccines.find_by!(upload_name: "Gardasil")
362-
)
363-
end
364-
365-
include_examples "card",
366-
title: "Vaccination not given: Unwell",
367-
date: "31 May 2025 at 1:00pm",
368-
notes: "Some notes.",
369-
by: "JOY, Nurse",
370-
programme: "HPV"
371-
end
372-
373350
describe "historical upload" do
374351
let(:date_and_time) { Time.zone.local(2026, 3, 4, 11, 30) }
375352

@@ -394,32 +371,6 @@
394371
programme: "HPV"
395372
end
396373

397-
describe "discarded vaccination" do
398-
before do
399-
create(
400-
:vaccination_record,
401-
:discarded,
402-
programme: programmes.first,
403-
patient:,
404-
session:,
405-
performed_at: Time.zone.local(2025, 5, 31, 13),
406-
discarded_at: Time.zone.local(2025, 5, 31, 14),
407-
performed_by: user
408-
)
409-
end
410-
411-
include_examples "card",
412-
title: "Vaccinated with Gardasil 9",
413-
date: "31 May 2025 at 1:00pm",
414-
by: "JOY, Nurse",
415-
programme: "HPV"
416-
417-
include_examples "card",
418-
title: "Vaccination record archived",
419-
date: "31 May 2025 at 2:00pm",
420-
programme: "HPV"
421-
end
422-
423374
describe "self-consent" do
424375
before do
425376
create(
@@ -708,11 +659,34 @@
708659
end
709660

710661
describe "vaccination records" do
711-
context "for the MMRV variant" do
662+
let(:programme) { Programme.hpv }
663+
664+
context "for an administered vaccination record" do
665+
before do
666+
create(
667+
:vaccination_record,
668+
programme:,
669+
patient:,
670+
session:,
671+
performed_at: Time.zone.local(2025, 5, 31, 13),
672+
performed_by: user,
673+
notes: "Some notes.",
674+
vaccine: programme.vaccines.find_by!(upload_name: "Gardasil9")
675+
)
676+
end
677+
678+
include_examples "card",
679+
title: "Vaccinated with Gardasil 9",
680+
date: "31 May 2025 at 1:00pm",
681+
notes: "Some notes.",
682+
by: "JOY, Nurse",
683+
programme: "HPV"
684+
end
685+
686+
context "for an MMRV variant record" do
712687
let(:programme) do
713688
Programme::Variant.new(Programme.mmr, variant_type: "mmrv")
714689
end
715-
let(:programmes) { [programme] }
716690

717691
before do
718692
create(
@@ -729,6 +703,85 @@
729703
date: "31 May 2025 at 1:00pm",
730704
programme: "MMRV"
731705
end
706+
707+
context "for a not administered record" do
708+
before do
709+
create(
710+
:vaccination_record,
711+
:not_administered,
712+
programme:,
713+
patient:,
714+
session:,
715+
performed_at: Time.zone.local(2025, 5, 31, 13),
716+
performed_by: user,
717+
notes: "Some notes.",
718+
vaccine: programmes.first.vaccines.find_by!(upload_name: "Gardasil")
719+
)
720+
end
721+
722+
include_examples "card",
723+
title: "Vaccination not given: Unwell",
724+
date: "31 May 2025 at 1:00pm",
725+
notes: "Some notes.",
726+
by: "JOY, Nurse",
727+
programme: "HPV"
728+
end
729+
730+
context "for a discarded record" do
731+
before do
732+
create(
733+
:vaccination_record,
734+
:discarded,
735+
programme:,
736+
patient:,
737+
session:,
738+
performed_at: Time.zone.local(2025, 5, 31, 13),
739+
discarded_at: Time.zone.local(2025, 5, 31, 14),
740+
performed_by: user
741+
)
742+
end
743+
744+
include_examples "card",
745+
title: "Vaccinated with Gardasil 9",
746+
date: "31 May 2025 at 1:00pm",
747+
by: "JOY, Nurse",
748+
programme: "HPV"
749+
750+
include_examples "card",
751+
title: "Vaccination record archived",
752+
date: "31 May 2025 at 2:00pm",
753+
programme: "HPV"
754+
end
755+
756+
context "for a discarded Imms API record" do
757+
before do
758+
create(
759+
:vaccination_record,
760+
:discarded,
761+
:sourced_from_nhs_immunisations_api,
762+
programme:,
763+
patient:,
764+
session:,
765+
performed_at: Time.zone.local(2025, 5, 31, 13),
766+
discarded_at: Time.zone.local(2025, 5, 31, 14),
767+
performed_by: user
768+
)
769+
end
770+
771+
it "doesn't render card 'vaccinated'" do
772+
expect(rendered).not_to have_css(
773+
".app-timeline__header",
774+
text: "Vaccinated with"
775+
)
776+
end
777+
778+
it "doesn't render card 'archived'" do
779+
expect(rendered).not_to have_css(
780+
".app-timeline__header",
781+
text: "Vaccination record archived"
782+
)
783+
end
784+
end
732785
end
733786

734787
describe "patient merge events" do

0 commit comments

Comments
 (0)