Skip to content

Commit ab91473

Browse files
authored
Merge pull request #6029 from nhsuk/already-vaccinated-mmr-status-updates
First dose of MMR shouldn't make programme status vaccinated
2 parents efab23a + 16f79c9 commit ab91473

9 files changed

Lines changed: 96 additions & 22 deletions

app/components/app_vaccination_record_summary_component.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def call
4545
row.with_value { programme_value }
4646
end
4747

48-
if @vaccination_record.administered?
48+
if @vaccination_record.administered? && !@vaccination_record.sourced_from_manual_report?
4949
summary_list.with_row do |row|
5050
row.with_key { "Vaccine" }
5151

@@ -351,12 +351,6 @@ def outcome_value
351351
outcome =
352352
VaccinationRecord.human_enum_name(:outcome, @vaccination_record.outcome)
353353

354-
if Flipper.enabled?(:already_vaccinated) &&
355-
@vaccination_record.already_had? &&
356-
@vaccination_record.reported_as_already_vaccinated?
357-
outcome = VaccinationRecord.human_enum_name(:outcome, "administered")
358-
end
359-
360354
highlight_if(outcome, @vaccination_record.outcome_changed?)
361355
end
362356

app/controllers/patient_sessions/programmes_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def record_already_vaccinated
3131
first_active_wizard_step:,
3232
location_id: nil,
3333
location_name: "Unknown",
34-
outcome: :already_had,
34+
outcome: (Flipper.enabled?(:already_vaccinated) ? :administered : :already_had),
3535
patient: @patient,
3636
performed_at: (Time.current unless Flipper.enabled?(:already_vaccinated)),
3737
performed_by_user_id:
@@ -42,7 +42,7 @@ def record_already_vaccinated
4242
(current_user.id if Flipper.enabled?(:already_vaccinated)),
4343
reported_at: (Time.current if Flipper.enabled?(:already_vaccinated)),
4444
session: @session,
45-
source: "service"
45+
source: (Flipper.enabled?(:already_vaccinated) ? :manual_report : :service)
4646
)
4747

4848
redirect_to draft_vaccination_record_path(

app/models/draft_vaccination_record.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def wizard_steps
7070
:date_and_time,
7171
(:outcome if can_change_outcome?),
7272
(:supplier if requires_supplied_by?),
73-
(:delivery if administered?),
74-
(:dose if administered? && can_be_half_dose?),
75-
(:batch if administered?),
73+
(:delivery if administered? && !reported_as_already_vaccinated?),
74+
(:dose if administered? && can_be_half_dose? && !reported_as_already_vaccinated?),
75+
(:batch if administered? && !reported_as_already_vaccinated?),
7676
(
77-
if !already_had? && (session&.generic_clinic? || national_reporting_user_and_record?)
77+
if !reported_as_already_vaccinated? && (session&.generic_clinic? || national_reporting_user_and_record?)
7878
:location
7979
end
8080
),
@@ -162,7 +162,7 @@ def wizard_steps
162162

163163
with_options on: :update,
164164
if: -> do
165-
required_for_step?(:confirm, exact: true) && administered?
165+
required_for_step?(:confirm, exact: true) && administered? && !reported_as_already_vaccinated?
166166
end do
167167
validates :delivery_method,
168168
:delivery_site,
@@ -191,8 +191,7 @@ def already_had?
191191
end
192192

193193
def reported_as_already_vaccinated?
194-
Flipper.enabled?(:already_vaccinated) && already_had? &&
195-
reported_by_id.present?
194+
Flipper.enabled?(:already_vaccinated) && administered? && sourced_from_manual_report?
196195
end
197196

198197
# So that a form error matches to a field in this model
@@ -381,6 +380,8 @@ def sourced_from_consent_refusal? = source == "consent_refusal"
381380

382381
def sourced_from_national_reporting? = source == "national_reporting"
383382

383+
def sourced_from_manual_report? = source == "manual_report"
384+
384385
def national_reporting_user_and_record?
385386
@current_user.selected_team.has_national_reporting_access? &&
386387
sourced_from_national_reporting?
@@ -487,7 +488,7 @@ def vaccine_method
487488
def can_be_half_dose? = vaccine_method == "nasal"
488489

489490
def can_change_outcome?
490-
(outcome != "already_had" || editing? || session.nil? || session.today?) &&
491+
((outcome != "already_had" && reported_at.nil?) || editing? || session.nil? || session.today?) &&
491492
!national_reporting_user_and_record?
492493
end
493494

app/models/vaccination_record.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class VaccinationRecord < ApplicationRecord
195195
historical_upload: 1,
196196
nhs_immunisations_api: 2,
197197
consent_refusal: 3,
198-
national_reporting: 4
198+
national_reporting: 4,
199+
manual_report: 5
199200
},
200201
prefix: "sourced_from",
201202
validate: true
@@ -272,7 +273,7 @@ class << self
272273
def not_administered? = !administered?
273274

274275
def reported_as_already_vaccinated?
275-
already_had? && reported_by_id.present?
276+
administered? && sourced_from_manual_report?
276277
end
277278

278279
def show_in_academic_year?(current_academic_year)

app/policies/vaccination_record_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def update?
2727
(
2828
record.performed_by_user_id == user.id || user.is_nurse? ||
2929
user.is_prescriber?
30-
) && record.sourced_from_service? &&
30+
) && (record.sourced_from_service? || record.sourced_from_manual_report?) &&
3131
record.performed_ods_code == user.selected_organisation.ods_code
3232
elsif team.has_national_reporting_access?
3333
record.sourced_from_national_reporting? &&
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ChangeVaccinationRecordsSourceCheckConstraint < ActiveRecord::Migration[8.1]
2+
def up
3+
remove_check_constraint :vaccination_records, name: "source_check"
4+
5+
add_check_constraint :vaccination_records,
6+
"(session_id IS NULL AND source != 0 AND source != 5) OR " \
7+
"(session_id IS NOT NULL AND (source = 0 OR source = 5))",
8+
name: "source_check",
9+
validate: false
10+
end
11+
12+
def down
13+
remove_check_constraint :vaccination_records, name: "source_check"
14+
15+
add_check_constraint :vaccination_records,
16+
"(session_id IS NULL AND source != 0) OR " \
17+
"(session_id IS NOT NULL AND source = 0)",
18+
name: "source_check",
19+
validate: false
20+
end
21+
end

db/schema.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2026_02_09_161431) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_02_17_111256) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pg_trgm"
@@ -994,9 +994,10 @@
994994
t.index ["supplied_by_user_id"], name: "index_vaccination_records_on_supplied_by_user_id"
995995
t.index ["uuid"], name: "index_vaccination_records_on_uuid", unique: true
996996
t.index ["vaccine_id"], name: "index_vaccination_records_on_vaccine_id"
997-
t.check_constraint "session_id IS NULL AND source <> 0 OR session_id IS NOT NULL AND source = 0", name: "source_check"
998997
end
999998

999+
add_check_constraint "vaccination_records", "session_id IS NULL AND source <> 0 AND source <> 5 OR session_id IS NOT NULL AND (source = 0 OR source = 5)", name: "source_check", validate: false
1000+
10001001
create_table "vaccines", force: :cascade do |t|
10011002
t.text "brand", null: false
10021003
t.boolean "contains_gelatine", null: false

spec/components/app_vaccination_record_summary_component_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797

9898
it { should_not have_css(".nhsuk-summary-list__row", text: "Vaccine") }
9999
end
100+
101+
context "when manually reported that vaccination was already had" do
102+
let(:source) { "manual_report" }
103+
104+
it { should_not have_css(".nhsuk-summary-list__row", text: "Vaccine") }
105+
end
100106
end
101107

102108
describe "method row" do
@@ -106,6 +112,12 @@
106112
text: "MethodIntramuscular"
107113
)
108114
end
115+
116+
context "when manually reported that vaccination was already had" do
117+
let(:source) { "manual_report" }
118+
119+
it { should_not have_css(".nhsuk-summary-list__row", text: "MethodIntramuscular") }
120+
end
109121
end
110122

111123
describe "site row" do
@@ -115,6 +127,12 @@
115127
text: "SiteLeft arm (upper position)"
116128
)
117129
end
130+
131+
context "when manually reported that vaccination was already had" do
132+
let(:source) { "manual_report" }
133+
134+
it { should_not have_css(".nhsuk-summary-list__row", text: "MethodIntramuscular") }
135+
end
118136
end
119137

120138
describe "dose volume row" do
@@ -193,6 +211,12 @@
193211
before { vaccination_record.dose_sequence = 2 }
194212

195213
it { should have_content("Dose number2nd") }
214+
215+
context "when manually reported that vaccination was already had" do
216+
let(:source) { "manual_report" }
217+
218+
it { should have_content("Dose number2nd") }
219+
end
196220
end
197221
end
198222
end

spec/features/mmr_already_had_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@
5757
and_i_see_that_the_vaccinator_is_unknown
5858
and_i_see_that_the_location_is_unknown
5959
and_i_see_that_the_reporter_is_set
60+
and_i_see_that_there_are_no_vaccine_batch_details
6061
expect(page).to have_content("LocationUnknown")
6162
and_had_been_vaccinated_with_mmr
6263
and_the_dose_number_is_first
6364
and_the_consent_requests_are_sent
6465
then_the_parent_doesnt_receive_a_consent_request
66+
67+
when_the_status_updater_runs
68+
and_i_navigate_to_the_patient_record
69+
then_i_see_that_the_vaccination_record_has_outcome_vaccinated
6570
end
6671

6772
scenario "record a patient as already had their 1st MMR dose and then edit dates" do
@@ -132,10 +137,15 @@
132137
and_i_see_that_the_vaccinator_is_unknown
133138
and_i_see_that_the_location_is_unknown
134139
and_i_see_that_the_reporter_is_set
140+
and_i_see_that_there_are_no_vaccine_batch_details
135141
and_had_been_vaccinated_with_mmrv
136142
and_the_dose_number_is_second
137143
and_the_consent_requests_are_sent
138144
then_the_parent_doesnt_receive_a_consent_request
145+
146+
when_the_status_updater_runs
147+
and_i_navigate_to_the_patient_record
148+
then_i_see_that_the_vaccination_record_has_outcome_vaccinated
139149
end
140150
end
141151

@@ -317,6 +327,12 @@ def and_i_see_that_the_reporter_is_set
317327
expect(page).to have_content("Reported by#{@nurse.full_name}")
318328
end
319329

330+
def and_i_see_that_there_are_no_vaccine_batch_details
331+
expect(page).not_to have_content("Batch number")
332+
expect(page).not_to have_content("Batch expiry date")
333+
expect(page).not_to have_content("Site")
334+
end
335+
320336
def and_had_been_vaccinated_with_mmr
321337
vaccination_record = @patient.vaccination_records.last
322338
expect(vaccination_record.programme_type).to eq("mmr")
@@ -390,4 +406,20 @@ def and_i_see_the_updated_date_in_the_summary
390406
"Date#{@vaccination_date.strftime("%-d %B %Y")}"
391407
)
392408
end
409+
410+
def when_the_status_updater_runs
411+
PatientStatusUpdaterJob.perform_inline(@patient.id)
412+
end
413+
414+
def and_i_navigate_to_the_patient_record
415+
visit patient_path(@patient)
416+
end
417+
418+
def then_i_see_that_the_vaccination_record_has_outcome_vaccinated
419+
expect(page).to have_content("Vaccination date #{@vaccination_date.strftime("%-d %B %Y")}")
420+
expect(page).to have_content("Location Unknown")
421+
expect(page).to have_content("Programme MMR")
422+
expect(page).to have_content("Source Manual report")
423+
expect(page).to have_content("Outcome Vaccinated")
424+
end
393425
end

0 commit comments

Comments
 (0)