Skip to content

Commit ec9ba2d

Browse files
Merge pull request #5894 from nhsuk/alistair/imms-api-mmrv-search
Add MMRV to imms API searches
2 parents 9bc43dc + 8585fdc commit ec9ba2d

7 files changed

Lines changed: 381 additions & 2 deletions

File tree

app/jobs/search_vaccination_records_in_nhs_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def perform(patient_id)
1717
SemanticLogger.tagged(tx_id:, job_id:) do
1818
Sentry.set_tags(tx_id:, job_id:)
1919

20-
programmes = Programme.all.to_a
20+
programmes = Programme.all_as_variants
2121

2222
feature_flag_enabled =
2323
programmes.any? do |programme|

app/lib/nhs/immunisations_api.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ def search_immunisations(patient, programmes:, date_from: nil, date_to: nil)
288288
"patient.identifier" =>
289289
"https://fhir.nhs.uk/Id/nhs-number|#{patient.nhs_number}",
290290
"-immunization.target" =>
291-
programmes.map(&:snomed_target_disease_name).sort.join(","),
291+
programmes
292+
.flat_map { it.variants.map(&:snomed_target_disease_name) }
293+
.sort
294+
.join(","),
292295
"-date.from" => date_from&.strftime("%F"),
293296
"-date.to" => date_to&.strftime("%F")
294297
}.compact

app/models/programme.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def find_all(types, disease_types: nil, patient: nil)
8888
types.map { |type| find(type, patient:, disease_types:) }
8989
end
9090

91+
def all_as_variants
92+
all.flat_map(&:variants)
93+
end
94+
9195
def find(type, disease_types: nil, patient: nil)
9296
validate_type!(type)
9397

@@ -162,6 +166,25 @@ def variant_for(disease_types: nil, patient: nil)
162166
Programme::Variant.new(self, variant_type:)
163167
end
164168

169+
def variants
170+
if mmr?
171+
[
172+
variant_for(
173+
disease_types: Programme::Variant::DISEASE_TYPES.fetch("mmr")
174+
),
175+
(
176+
if Flipper.enabled?(:mmrv)
177+
variant_for(
178+
disease_types: Programme::Variant::DISEASE_TYPES.fetch("mmrv")
179+
)
180+
end
181+
)
182+
].compact
183+
else
184+
[self]
185+
end
186+
end
187+
165188
def disease_types = DISEASE_TYPES.fetch(type)
166189

167190
def doubles? = menacwy? || td_ipv?

app/models/programme/variant.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def disease_types = DISEASE_TYPES.fetch(variant_type)
4141

4242
def import_names = IMPORT_NAMES.fetch(variant_type)
4343

44+
def variants
45+
[self]
46+
end
47+
4448
def vaccines
4549
@vaccines ||= Vaccine.for_programme(self)
4650
end
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"type": "searchset",
3+
"total": 1,
4+
"link": [
5+
{
6+
"relation": "self",
7+
"url": "https://internal-dev.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization?immunization.target=MMRV%2CMMR%2C3IN1%2CMENACWY%2CFLU%2CHPV&-immunization.target=MMRV%2CMMR%2C3IN1%2CMENACWY%2CFLU%2CHPV&patient.identifier=https%3A%2F%2Ffhir.nhs.uk%2FId%2Fnhs-number%7C9990001855"
8+
}
9+
],
10+
"entry": [
11+
{
12+
"fullUrl": "https://internal-dev.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization/944d6fef-93b3-45e6-a34b-fe93861e57da",
13+
"resource": {
14+
"id": "944d6fef-93b3-45e6-a34b-fe93861e57da",
15+
"meta": {
16+
"versionId": "1"
17+
},
18+
"extension": [
19+
{
20+
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure",
21+
"valueCodeableConcept": {
22+
"coding": [
23+
{
24+
"system": "http://snomed.info/sct",
25+
"code": "432636005",
26+
"display": "Administration of vaccine product containing only Human alphaherpesvirus 3 and Measles morbillivirus and Mumps orthorubulavirus and Rubella virus antigens"
27+
}
28+
]
29+
}
30+
}
31+
],
32+
"identifier": [
33+
{
34+
"use": "official",
35+
"system": "http://manage-vaccinations-in-schools.nhs.uk/vaccination_records",
36+
"value": "fe2ff033-0be1-4619-8e3a-b75ca1be02e4"
37+
}
38+
],
39+
"status": "completed",
40+
"vaccineCode": {
41+
"coding": [
42+
{
43+
"system": "http://snomed.info/sct",
44+
"code": "45525711000001102",
45+
"display": "Priorix Tetra vaccine powder and solvent for solution for injection 0.5ml pre-filled syringes (GlaxoSmithKline UK Ltd) (product)"
46+
}
47+
]
48+
},
49+
"patient": {
50+
"reference": "urn:uuid:b98d36c9-acab-444e-b2e8-f92c59f2ee26",
51+
"type": "Patient",
52+
"identifier": {
53+
"system": "https://fhir.nhs.uk/Id/nhs-number",
54+
"value": "9990001855"
55+
}
56+
},
57+
"occurrenceDateTime": "2026-01-27T08:49:44+00:00",
58+
"recorded": "2026-01-27T08:50:53.257000+00:00",
59+
"primarySource": true,
60+
"location": {
61+
"identifier": {
62+
"system": "https://fhir.hl7.org.uk/Id/urn-school-number",
63+
"value": "100001"
64+
}
65+
},
66+
"manufacturer": {
67+
"display": "GlaxoSmithKline"
68+
},
69+
"lotNumber": "XKCD1234",
70+
"expirationDate": "2026-11-10",
71+
"site": {
72+
"coding": [
73+
{
74+
"system": "http://snomed.info/sct",
75+
"code": "368208006",
76+
"display": "Left upper arm structure"
77+
}
78+
]
79+
},
80+
"route": {
81+
"coding": [
82+
{
83+
"system": "http://snomed.info/sct",
84+
"code": "78421000",
85+
"display": "Intramuscular"
86+
}
87+
]
88+
},
89+
"doseQuantity": {
90+
"value": 0.5,
91+
"unit": "ml",
92+
"system": "http://snomed.info/sct",
93+
"code": "258773002"
94+
},
95+
"performer": [
96+
{
97+
"actor": {
98+
"type": "Organization",
99+
"identifier": {
100+
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
101+
"value": "R1L"
102+
}
103+
}
104+
}
105+
],
106+
"reasonCode": [
107+
{
108+
"coding": [
109+
{
110+
"system": "http://snomed.info/sct",
111+
"code": "723620004"
112+
}
113+
]
114+
}
115+
],
116+
"protocolApplied": [
117+
{
118+
"targetDisease": [
119+
{
120+
"coding": [
121+
{
122+
"system": "http://snomed.info/sct",
123+
"code": "14189004",
124+
"display": "Measles"
125+
}
126+
]
127+
},
128+
{
129+
"coding": [
130+
{
131+
"system": "http://snomed.info/sct",
132+
"code": "36989005",
133+
"display": "Mumps"
134+
}
135+
]
136+
},
137+
{
138+
"coding": [
139+
{
140+
"system": "http://snomed.info/sct",
141+
"code": "36653000",
142+
"display": "Rubella"
143+
}
144+
]
145+
},
146+
{
147+
"coding": [
148+
{
149+
"system": "http://snomed.info/sct",
150+
"code": "38907003",
151+
"display": "Varicella"
152+
}
153+
]
154+
}
155+
],
156+
"doseNumberString": "Unknown"
157+
}
158+
],
159+
"resourceType": "Immunization"
160+
},
161+
"search": {
162+
"mode": "match"
163+
}
164+
},
165+
{
166+
"fullUrl": "urn:uuid:b98d36c9-acab-444e-b2e8-f92c59f2ee26",
167+
"resource": {
168+
"id": "9990001855",
169+
"identifier": [
170+
{
171+
"system": "https://fhir.nhs.uk/Id/nhs-number",
172+
"value": "9990001855"
173+
}
174+
],
175+
"resourceType": "Patient"
176+
},
177+
"search": {
178+
"mode": "include"
179+
}
180+
}
181+
],
182+
"resourceType": "Bundle"
183+
}

spec/lib/nhs/immunisations_api_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,28 @@
11151115
include_examples "unexpected response status", 250, "searching"
11161116

11171117
include_examples "an imms_api_integration feature flag check"
1118+
1119+
context "with the mmrv feature flag enabled" do
1120+
before { Flipper.enable(:mmrv) }
1121+
1122+
let(:date_from) { nil }
1123+
let(:date_to) { nil }
1124+
1125+
let(:expected_query) do
1126+
{
1127+
"patient.identifier" =>
1128+
"https://fhir.nhs.uk/Id/nhs-number|#{patient.nhs_number}",
1129+
"-immunization.target" => "3IN1,FLU,HPV,MENACWY,MMR,MMRV"
1130+
}
1131+
end
1132+
1133+
let(:body) do
1134+
file_fixture("fhir/search_response_1_result_mmrv.json").read
1135+
end
1136+
1137+
it_behaves_like "continues the request and returns the bundle anyway",
1138+
1,
1139+
2
1140+
end
11181141
end
11191142
end

0 commit comments

Comments
 (0)