Skip to content

Commit ab2487b

Browse files
Merge pull request #6524 from NHSDigital/alistair/imms-api-save-product-code
Save product code and term from Imms API records
2 parents facbf1c + 8d5e719 commit ab2487b

7 files changed

Lines changed: 160 additions & 22 deletions

File tree

app/lib/fhir_mapper/vaccination_record.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def self.from_fhir_record(fhir_record, patient:)
158158
attrs[:nhs_immunisations_api_snomed_reason_code] = reason_coding&.code
159159
attrs[:nhs_immunisations_api_snomed_reason_term] = reason_coding&.display
160160

161+
product_coding = vaccine_product_coding_from_fhir(fhir_record)
162+
attrs[:nhs_immunisations_api_snomed_product_code] = product_coding&.code
163+
attrs[
164+
:nhs_immunisations_api_snomed_product_term
165+
] = product_coding&.display
166+
161167
attrs[:vaccine] = Vaccine.from_fhir_record(fhir_record)
162168
attrs[:batch_number] = fhir_record.lotNumber&.to_s
163169

@@ -174,7 +180,6 @@ def self.from_fhir_record(fhir_record, patient:)
174180
)
175181
else
176182
attrs[:disease_types] = attrs[:programme].disease_types
177-
notes << vaccine_batch_notes_from_fhir(fhir_record)
178183
attrs[:full_dose] = true
179184
end
180185

@@ -313,21 +318,6 @@ def fhir_dose_quantity
313318
end
314319
end
315320

316-
private_class_method def self.vaccine_batch_notes_from_fhir(fhir_record)
317-
fhir_vaccine =
318-
fhir_record.vaccineCode&.coding&.find do
319-
it.system == "http://snomed.info/sct"
320-
end
321-
322-
vaccine_snomed_code = fhir_vaccine&.code
323-
vaccine_description = fhir_vaccine&.display.presence
324-
325-
[
326-
("SNOMED product code: #{vaccine_snomed_code}" if vaccine_snomed_code),
327-
("SNOMED description: #{vaccine_description}" if vaccine_description)
328-
].compact.join("\n").presence
329-
end
330-
331321
def fhir_user_performer(reference_id:)
332322
FHIR::Immunization::Performer.new(
333323
actor: FHIR::Reference.new(reference: "##{reference_id}")
@@ -376,6 +366,12 @@ def fhir_org_performer
376366
end
377367
end
378368

369+
private_class_method def self.vaccine_product_coding_from_fhir(fhir_record)
370+
fhir_record.vaccineCode&.coding&.find do
371+
it.system == "http://snomed.info/sct"
372+
end
373+
end
374+
379375
def fhir_reason_code
380376
FHIR::CodeableConcept.new(
381377
coding: [

app/models/vaccination_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# nhs_immunisations_api_recorded_at :datetime
2424
# nhs_immunisations_api_snomed_procedure_code :string
2525
# nhs_immunisations_api_snomed_procedure_term :string
26+
# nhs_immunisations_api_snomed_product_code :string
27+
# nhs_immunisations_api_snomed_product_term :string
2628
# nhs_immunisations_api_snomed_reason_code :string
2729
# nhs_immunisations_api_snomed_reason_term :string
2830
# nhs_immunisations_api_sync_pending_at :datetime
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
class AddNHSImmunisationsAPISnomedProductToVaccinationRecords < ActiveRecord::Migration[
4+
8.1
5+
]
6+
def change
7+
change_table :vaccination_records, bulk: true do |t|
8+
t.string :nhs_immunisations_api_snomed_product_code
9+
t.string :nhs_immunisations_api_snomed_product_term
10+
end
11+
end
12+
end

db/schema.rb

Lines changed: 3 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: 2026_03_31_110000) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_04_07_120000) 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"
@@ -1007,6 +1007,8 @@
10071007
t.datetime "nhs_immunisations_api_recorded_at"
10081008
t.string "nhs_immunisations_api_snomed_procedure_code"
10091009
t.string "nhs_immunisations_api_snomed_procedure_term"
1010+
t.string "nhs_immunisations_api_snomed_product_code"
1011+
t.string "nhs_immunisations_api_snomed_product_term"
10101012
t.string "nhs_immunisations_api_snomed_reason_code"
10111013
t.string "nhs_immunisations_api_snomed_reason_term"
10121014
t.datetime "nhs_immunisations_api_sync_pending_at"

spec/factories/vaccination_records.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# nhs_immunisations_api_recorded_at :datetime
2424
# nhs_immunisations_api_snomed_procedure_code :string
2525
# nhs_immunisations_api_snomed_procedure_term :string
26+
# nhs_immunisations_api_snomed_product_code :string
27+
# nhs_immunisations_api_snomed_product_term :string
2628
# nhs_immunisations_api_snomed_reason_code :string
2729
# nhs_immunisations_api_snomed_reason_term :string
2830
# nhs_immunisations_api_sync_pending_at :datetime

spec/lib/fhir_mapper/vaccination_record_spec.rb

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,15 @@
722722
its(:nhs_immunisations_api_snomed_reason_term) do
723723
should eq "Disease outbreak (event)"
724724
end
725+
726+
its(:nhs_immunisations_api_snomed_product_code) do
727+
should eq "43207411000001105"
728+
end
729+
730+
its(:nhs_immunisations_api_snomed_product_term) do
731+
should eq "Cell-based trivalent influenza vaccine (surface antigen, inactivated) suspension for injection " \
732+
"0.5ml pre-filled syringes (Seqirus UK Ltd)"
733+
end
725734
end
726735

727736
context "with a record with not full dose" do
@@ -772,6 +781,14 @@
772781
should eq "Disease outbreak (event)"
773782
end
774783

784+
its(:nhs_immunisations_api_snomed_product_code) do
785+
should eq "43208811000001106"
786+
end
787+
788+
its(:nhs_immunisations_api_snomed_product_term) do
789+
should eq "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd) (product)"
790+
end
791+
775792
its(:notes) do
776793
should eq "Performing organisation display name: Acme Healthcare"
777794
end
@@ -826,6 +843,14 @@
826843
should eq "Disease outbreak (event)"
827844
end
828845

846+
its(:nhs_immunisations_api_snomed_product_code) do
847+
should eq "43208811000001106"
848+
end
849+
850+
its(:nhs_immunisations_api_snomed_product_term) do
851+
should eq "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd) (product)"
852+
end
853+
829854
its(:notes) do
830855
should eq "Performing organisation display name: Acme Healthcare"
831856
end
@@ -886,6 +911,14 @@
886911
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
887912
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
888913

914+
its(:nhs_immunisations_api_snomed_product_code) do
915+
should eq "43208811000001106"
916+
end
917+
918+
its(:nhs_immunisations_api_snomed_product_term) do
919+
should eq "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd)"
920+
end
921+
889922
its(:notes) { should be_nil }
890923
end
891924

@@ -941,11 +974,13 @@
941974
should eq "Disease outbreak (event)"
942975
end
943976

944-
its(:notes) do
945-
should include(
946-
"SNOMED product code: 43207411000001106",
947-
"SNOMED description: Cell-based trivalent influenza vaccine"
948-
)
977+
its(:nhs_immunisations_api_snomed_product_code) do
978+
should eq "43207411000001106"
979+
end
980+
981+
its(:nhs_immunisations_api_snomed_product_term) do
982+
should eq "Cell-based trivalent influenza vaccine (surface antigen, inactivated) suspension for injection " \
983+
"0.5ml pre-filled syringes (Seqirus UK Ltd)"
949984
end
950985
end
951986

@@ -994,6 +1029,9 @@
9941029
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
9951030
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
9961031

1032+
its(:nhs_immunisations_api_snomed_product_code) { should be_nil }
1033+
its(:nhs_immunisations_api_snomed_product_term) { should be_nil }
1034+
9971035
its(:notes) do
9981036
should include(
9991037
"Reported dose number string: Dose sequence not recorded"
@@ -1043,6 +1081,14 @@
10431081
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
10441082
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
10451083

1084+
its(:nhs_immunisations_api_snomed_product_code) do
1085+
should eq "43208811000001106"
1086+
end
1087+
1088+
its(:nhs_immunisations_api_snomed_product_term) do
1089+
should eq "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd)"
1090+
end
1091+
10461092
its(:notes) { should be_nil }
10471093
end
10481094

@@ -1086,6 +1132,15 @@
10861132
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
10871133
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
10881134

1135+
its(:nhs_immunisations_api_snomed_product_code) do
1136+
should eq "43207411000001105"
1137+
end
1138+
1139+
its(:nhs_immunisations_api_snomed_product_term) do
1140+
should eq "Cell-based trivalent influenza vaccine (surface antigen, inactivated) suspension for injection " \
1141+
"0.5ml pre-filled syringes (Seqirus UK Ltd)"
1142+
end
1143+
10891144
its(:notes) { should be_nil }
10901145
end
10911146

@@ -1133,6 +1188,15 @@
11331188
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
11341189
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
11351190

1191+
its(:nhs_immunisations_api_snomed_product_code) do
1192+
should eq "43207411000001105"
1193+
end
1194+
1195+
its(:nhs_immunisations_api_snomed_product_term) do
1196+
should eq "Cell-based trivalent influenza vaccine (surface antigen, inactivated) suspension for injection " \
1197+
"0.5ml pre-filled syringes (Seqirus UK Ltd)"
1198+
end
1199+
11361200
its(:notes) { should be_nil }
11371201
end
11381202

@@ -1185,6 +1249,14 @@
11851249
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
11861250
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
11871251

1252+
its(:nhs_immunisations_api_snomed_product_code) do
1253+
should eq "43208811000001106"
1254+
end
1255+
1256+
its(:nhs_immunisations_api_snomed_product_term) do
1257+
should eq "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd) (product)"
1258+
end
1259+
11881260
its(:notes) { should be_nil }
11891261
end
11901262

@@ -1237,6 +1309,9 @@
12371309
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
12381310
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
12391311

1312+
its(:nhs_immunisations_api_snomed_product_code) { should be_nil }
1313+
its(:nhs_immunisations_api_snomed_product_term) { should be_nil }
1314+
12401315
its(:notes) { should be_nil }
12411316
end
12421317

@@ -1281,6 +1356,9 @@
12811356
its(:nhs_immunisations_api_snomed_reason_code) { should be_nil }
12821357
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
12831358

1359+
its(:nhs_immunisations_api_snomed_product_code) { should be_nil }
1360+
its(:nhs_immunisations_api_snomed_product_term) { should be_nil }
1361+
12841362
its(:notes) do
12851363
should include(
12861364
"Reported dose number string: Dose sequence not recorded"
@@ -1345,6 +1423,15 @@
13451423
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
13461424
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
13471425

1426+
its(:nhs_immunisations_api_snomed_product_code) do
1427+
should eq "33493111000001108"
1428+
end
1429+
1430+
its(:nhs_immunisations_api_snomed_product_term) do
1431+
should eq "Gardasil 9 vaccine suspension for injection 0.5ml pre-filled syringes " \
1432+
"(Merck Sharp & Dohme (UK) Ltd) (product)"
1433+
end
1434+
13481435
its(:notes) { should be_nil }
13491436
end
13501437
end
@@ -1407,6 +1494,14 @@
14071494
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
14081495
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
14091496

1497+
its(:nhs_immunisations_api_snomed_product_code) do
1498+
should eq "39779611000001104"
1499+
end
1500+
1501+
its(:nhs_immunisations_api_snomed_product_term) do
1502+
should eq "MenQuadfi vaccine solution for injection 0.5ml vials (Sanofi) (product)"
1503+
end
1504+
14101505
its(:notes) { should include("Reported dose number string: Unknown") }
14111506
end
14121507
end
@@ -1469,6 +1564,15 @@
14691564
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
14701565
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
14711566

1567+
its(:nhs_immunisations_api_snomed_product_code) do
1568+
should eq "7374511000001107"
1569+
end
1570+
1571+
its(:nhs_immunisations_api_snomed_product_term) do
1572+
should eq "Revaxis vaccine suspension for injection 0.5ml pre-filled syringes (Sanofi) " \
1573+
"1 pre-filled disposable injection (product)"
1574+
end
1575+
14721576
its(:notes) { should include("Reported dose number string: Unknown") }
14731577
end
14741578
end
@@ -1535,6 +1639,15 @@
15351639
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
15361640
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
15371641

1642+
its(:nhs_immunisations_api_snomed_product_code) do
1643+
should eq "13968211000001108"
1644+
end
1645+
1646+
its(:nhs_immunisations_api_snomed_product_term) do
1647+
should eq "M-M-RVAXPRO vaccine powder and solvent for suspension for injection 0.5ml pre-filled syringes " \
1648+
"(Merck Sharp & Dohme (UK) Ltd) (product)"
1649+
end
1650+
15381651
its(:notes) { should include("Reported dose number string: Unknown") }
15391652
end
15401653
end
@@ -1601,6 +1714,15 @@
16011714
its(:nhs_immunisations_api_snomed_reason_code) { should eq "723620004" }
16021715
its(:nhs_immunisations_api_snomed_reason_term) { should be_nil }
16031716

1717+
its(:nhs_immunisations_api_snomed_product_code) do
1718+
should eq "45525711000001102"
1719+
end
1720+
1721+
its(:nhs_immunisations_api_snomed_product_term) do
1722+
should eq "Priorix Tetra vaccine powder and solvent for solution for injection 0.5ml pre-filled syringes " \
1723+
"(GlaxoSmithKline UK Ltd) (product)"
1724+
end
1725+
16041726
its(:notes) { should include("Reported dose number string: Unknown") }
16051727
end
16061728
end

spec/models/vaccination_record_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# nhs_immunisations_api_recorded_at :datetime
2424
# nhs_immunisations_api_snomed_procedure_code :string
2525
# nhs_immunisations_api_snomed_procedure_term :string
26+
# nhs_immunisations_api_snomed_product_code :string
27+
# nhs_immunisations_api_snomed_product_term :string
2628
# nhs_immunisations_api_snomed_reason_code :string
2729
# nhs_immunisations_api_snomed_reason_term :string
2830
# nhs_immunisations_api_sync_pending_at :datetime

0 commit comments

Comments
 (0)