Skip to content

Commit ca17962

Browse files
authored
Merge pull request #5535 from nhsuk/add-disease-types-to-vaccination-records
Add disease types to vaccination records
2 parents c0a912f + d904188 commit ca17962

13 files changed

Lines changed: 68 additions & 3 deletions

app/jobs/patients_refused_consent_already_vaccinated_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def record_already_vaccinated!(patient, programme:, consents:)
5656
performed_at = consents.map(&:submitted_at).min
5757

5858
VaccinationRecord.create!(
59+
# TODO: Change this to `consent.disease_types` when available.
60+
disease_types: programme.disease_types,
5961
location_name: "Unknown",
6062
notes:,
6163
outcome: "already_had",

app/lib/fhir_mapper/vaccination_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ def self.from_fhir_record(fhir_record, patient:)
105105
attrs[:vaccine] = Vaccine.from_fhir_record(fhir_record)
106106

107107
if attrs[:vaccine]
108+
attrs[:disease_types] = attrs[:vaccine].disease_types
108109
attrs[:batch] = batch_from_fhir(fhir_record, vaccine: attrs[:vaccine])
109110
attrs[:full_dose] = full_dose_from_fhir(
110111
fhir_record,
111112
vaccine: attrs[:vaccine]
112113
)
113114
else
115+
attrs[:disease_types] = attrs[:programme].disease_types
114116
attrs[:notes] = vaccine_batch_notes_from_fhir(fhir_record)
115117
attrs[:full_dose] = true
116118
end

app/models/draft_vaccination_record.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DraftVaccinationRecord
1010
attribute :batch_id, :integer
1111
attribute :delivery_method, :string
1212
attribute :delivery_site, :string
13+
attribute :disease_types, array: true
1314
attribute :dose_sequence, :integer
1415
attribute :first_active_wizard_step, :string
1516
attribute :full_dose, :boolean
@@ -25,9 +26,9 @@ class DraftVaccinationRecord
2526
attribute :performed_by_family_name, :string
2627
attribute :performed_by_given_name, :string
2728
attribute :performed_by_user_id, :integer
28-
attribute :protocol, :string
2929
attribute :performed_ods_code, :string
3030
attribute :programme_type, :string
31+
attribute :protocol, :string
3132
attribute :session_id, :integer
3233
attribute :supplied_by_user_id, :integer
3334

@@ -299,6 +300,7 @@ def writable_attribute_names
299300
batch_id
300301
delivery_method
301302
delivery_site
303+
disease_types
302304
dose_sequence
303305
full_dose
304306
identity_check
@@ -336,6 +338,8 @@ def reset_unused_attributes
336338
self.identity_check_confirmed_by_other_name = ""
337339
self.identity_check_confirmed_by_other_relationship = ""
338340
end
341+
342+
self.disease_types = vaccine&.disease_types || programme.disease_types
339343
end
340344

341345
def academic_year = session&.academic_year

app/models/immunisation_import_row.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def to_vaccination_record
126126
end
127127

128128
attributes = {
129+
disease_types:,
129130
dose_sequence: dose_sequence_value,
130131
full_dose: true,
131132
outcome:,
@@ -138,8 +139,8 @@ def to_vaccination_record
138139
session:,
139140
supplied_by:
140141
}
141-
attributes.merge!(location:, location_name:) unless imms_api_record?
142142

143+
attributes.merge!(location:, location_name:) unless imms_api_record?
143144
attributes.merge!(notify_parents: true) if session
144145

145146
if performed_by_user.nil? &&
@@ -498,6 +499,8 @@ def delivery_method_value
498499
end
499500
end
500501

502+
def disease_types = vaccine&.disease_types || programme.disease_types
503+
501504
def dose_sequence_value
502505
value =
503506
parsed_vaccination_description_string&.dig(:dose_sequence) ||

app/models/vaccination_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# delivery_method :integer
1010
# delivery_site :integer
1111
# discarded_at :datetime
12+
# disease_types :enum is an Array
1213
# dose_sequence :integer
1314
# full_dose :boolean
1415
# local_patient_id_uri :string
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class AddDiseaseTypesToVaccinationRecords < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :vaccination_records,
6+
:disease_types,
7+
:enum,
8+
enum_type: :disease_type,
9+
array: true
10+
end
11+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
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: 2025_12_15_103351) do
13+
ActiveRecord::Schema[8.1].define(version: 2025_12_15_114448) 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"
@@ -932,6 +932,7 @@
932932
t.integer "delivery_method"
933933
t.integer "delivery_site"
934934
t.datetime "discarded_at"
935+
t.enum "disease_types", array: true, enum_type: "disease_type"
935936
t.integer "dose_sequence"
936937
t.boolean "full_dose"
937938
t.string "local_patient_id"

lib/tasks/data_migration.rake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ namespace :data_migration do
55
task create_clinic_notifications: :environment do
66
DataMigration::CreateClinicNotifications.call
77
end
8+
9+
desc "Set disease types on vaccination records."
10+
task set_disease_types: :environment do
11+
VaccinationRecord
12+
.includes(:vaccine)
13+
.find_each do |vaccination_record|
14+
disease_types =
15+
vaccination_record.vaccine&.disease_types ||
16+
vaccination_record.programme.disease_types
17+
vaccination_record.update_columns(disease_types:)
18+
end
19+
end
820
end

spec/factories/vaccination_records.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# delivery_method :integer
1010
# delivery_site :integer
1111
# discarded_at :datetime
12+
# disease_types :enum is an Array
1213
# dose_sequence :integer
1314
# full_dose :boolean
1415
# local_patient_id_uri :string
@@ -95,6 +96,7 @@
9596
delivery_method { "intramuscular" }
9697

9798
vaccine { programme.vaccines.active.sample if session }
99+
disease_types { vaccine&.disease_types || programme.disease_types }
98100

99101
batch do
100102
if vaccine

spec/features/hpv_vaccination_administered_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
when_i_confirm_the_details
4848
then_i_see_a_success_message
49+
and_the_disease_types_are_set_on_the_record
4950
and_i_can_no_longer_vaccinate_the_patient
5051
and_i_no_longer_see_the_patient_in_the_record_tab
5152
and_i_no_longer_see_the_patient_in_the_consent_tab
@@ -238,6 +239,12 @@ def then_i_see_a_success_message
238239
expect(page).to have_content("Vaccination outcome recorded for HPV")
239240
end
240241

242+
def and_the_disease_types_are_set_on_the_record
243+
expect(VaccinationRecord.last.disease_types).to contain_exactly(
244+
"human_papillomavirus"
245+
)
246+
end
247+
241248
def and_i_can_no_longer_vaccinate_the_patient
242249
expect(page).not_to have_content("You still need to record an outcome")
243250
expect(page).not_to have_content("ready for their HPV vaccination?")

0 commit comments

Comments
 (0)