Skip to content

Commit 1288b96

Browse files
committed
Triage from vaccination history requires consent
This fixes a bug where for a patient to be triaged based on their vaccination history, they should receive have received consent. This is logic that we used to have (https://github.com/nhsuk/manage-vaccinations-in-schools/blob/a3c88d2900b11ae7aea67d6655046ef4a6d2233d/app/models/patient/triage_outcome.rb#L94) but was inadvertantly removed in version 2.1.2 with the performance improvements that stored the patient statuses in the database.
1 parent ee6ff7b commit 1288b96

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

app/models/patient/triage_status.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def assign_status
6262
end
6363

6464
def consent_requires_triage?
65-
ConsentGrouper.call(consents, programme_id:).any?(&:triage_needed?)
65+
latest_consents.any?(&:triage_needed?)
6666
end
6767

6868
def vaccination_history_requires_triage?
@@ -88,9 +88,24 @@ def status_should_be_delay_vaccination?
8888
def status_should_be_required?
8989
return true if latest_triage&.needs_follow_up?
9090

91+
return false if latest_consents.empty?
92+
93+
consent_given =
94+
if (self_consents = latest_consents.select(&:via_self_consent?)).any?
95+
self_consents.all?(&:response_given?)
96+
else
97+
latest_consents.all?(&:response_given?)
98+
end
99+
100+
return false unless consent_given
101+
91102
consent_requires_triage? || vaccination_history_requires_triage?
92103
end
93104

105+
def latest_consents
106+
@latest_consents ||= ConsentGrouper.call(consents, programme_id:)
107+
end
108+
94109
def latest_triage
95110
@latest_triage ||= triages.find { it.programme_id == programme_id }
96111
end

spec/features/triage_partially_vaccinated_spec.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
when_i_go_the_session
1717
then_i_see_one_patient_needing_consent
18+
and_i_see_no_patients_needing_triage
1819

19-
when_the_parent_gives_consent
20+
when_i_go_the_session
21+
and_the_parent_gives_consent
2022
and_i_click_on_triage
2123
then_i_see_one_patient_needing_triage
2224
and_i_click_on_the_patient
@@ -67,7 +69,7 @@ def then_i_see_the_completed_upload
6769
end
6870

6971
def when_i_go_the_session
70-
click_on "Sessions"
72+
click_on "Sessions", match: :first
7173
click_on "Scheduled"
7274
click_on @session.location.name
7375
end
@@ -89,12 +91,21 @@ def then_i_see_one_patient_needing_consent
8991
click_on "Update results"
9092

9193
expect(page).to have_content("Showing 1 to 1 of 1 children")
94+
end
9295

93-
click_on @session.location.name
96+
def and_i_see_no_patients_needing_triage
97+
click_on "Triage"
98+
99+
choose "Needs triage"
100+
click_on "Update results"
101+
102+
expect(page).to have_content("No children matching search criteria found")
94103
end
95104

96-
def when_the_parent_gives_consent
97-
Patient.first.consent_status(programme: @programme).given!
105+
def and_the_parent_gives_consent
106+
create(:consent, :given, patient: Patient.first, programme: @programme)
107+
StatusUpdater.call(patient: @patient)
108+
98109
page.refresh
99110
end
100111

spec/models/patient/triage_status_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@
5757
it { should be(:required) }
5858
end
5959

60+
context "with a historical vaccination that needs triage" do
61+
let(:programme) { create(:programme, :td_ipv) }
62+
63+
before do
64+
create(:vaccination_record, patient:, programme:, dose_sequence: 1)
65+
end
66+
67+
it { should be(:not_required) }
68+
69+
context "when consent is given" do
70+
before { create(:consent, :given, patient:, programme:) }
71+
72+
it { should be(:required) }
73+
end
74+
75+
context "when consent is refused" do
76+
before { create(:consent, :refused, patient:, programme:) }
77+
78+
it { should be(:not_required) }
79+
end
80+
end
81+
6082
context "with a safe to vaccinate triage" do
6183
before { create(:triage, :ready_to_vaccinate, patient:, programme:) }
6284

0 commit comments

Comments
 (0)