Skip to content

Commit 13d49df

Browse files
committed
Add logic to uplift legacy identifiers
1 parent 574518e commit 13d49df

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

lambdas/recordforwarder/src/service/fhir_batch_service.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
IMMUNIZATION_VALIDATOR = ImmunizationValidator()
66

7+
TPP_V2_SUPPLIER_IDENTIFIER_SYSTEM = "YGA"
8+
TPP_V5_SUPPLIER_IDENTIFIER_SYSTEM = "https://tpp-uk.com/Id/ve/vacc"
9+
EMIS_V2_SUPPLIER_IDENTIFIER_SYSTEM = "YGJ"
10+
EMIS_V5_SUPPLIER_IDENTIFIER_SYSTEM = "https://emishealth.com/identifiers/vacc"
11+
12+
13+
def _uplift_legacy_identifier(immunization: dict):
14+
# This code the above constants can be safely removed once DPS carries out it's data migration to update legacy
15+
# identifiers as it will become redundant. Please see issue VED-904 for more information.
16+
identifier_system = immunization["identifier"][0]["system"]
17+
18+
if identifier_system == TPP_V2_SUPPLIER_IDENTIFIER_SYSTEM:
19+
immunization["identifier"][0]["system"] = TPP_V5_SUPPLIER_IDENTIFIER_SYSTEM
20+
21+
if identifier_system == EMIS_V2_SUPPLIER_IDENTIFIER_SYSTEM:
22+
immunization["identifier"][0]["system"] = EMIS_V5_SUPPLIER_IDENTIFIER_SYSTEM
23+
724

825
class ImmunizationBatchService:
926
def __init__(
@@ -27,6 +44,10 @@ def create_immunization(
2744
Exception will be raised if resource exits. Multiple calls to this method won't change
2845
the record in the database.
2946
"""
47+
48+
# TODO: Remove after DPS data migration to new identifiers
49+
_uplift_legacy_identifier(immunization)
50+
3051
try:
3152
self.validator.validate(immunization)
3253
except (ValueError, MandatoryError) as error:
@@ -47,6 +68,10 @@ def update_immunization(
4768
Exception will be raised if resource didn't exist.Multiple calls to this method won't change
4869
the record in the database.
4970
"""
71+
72+
# TODO: Remove after DPS data migration to new identifiers
73+
_uplift_legacy_identifier(immunization)
74+
5075
try:
5176
self.validator.validate(immunization)
5277
except (ValueError, MandatoryError) as error:
@@ -67,4 +92,8 @@ def delete_immunization(
6792
Exception will be raised if resource didn't exist.Multiple calls to this method won't change
6893
the record in the database.
6994
"""
95+
96+
# TODO: Remove after DPS data migration to new identifiers
97+
_uplift_legacy_identifier(immunization)
98+
7099
return self.immunization_repo.delete_immunization(immunization, supplier_system, vax_type, table, is_present)

lambdas/recordforwarder/tests/service/test_fhir_batch_service.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,38 @@ def test_create_immunization_post_validation_error(self):
9797
self.assertTrue(expected_msg in error.exception.message)
9898
self.mock_repo.create_immunization.assert_not_called()
9999

100+
def test_create_immunization_uplifts_legacy_identifier_system_tpp(self):
101+
"""it should recognise a legacy TPP identifier system and use the new style identifier"""
102+
103+
immunisation = create_covid_immunization_dict_no_id()
104+
immunisation["identifier"][0]["system"] = "YGA"
105+
106+
_ = self.service.create_immunization(
107+
immunization=immunisation,
108+
supplier_system="test_supplier",
109+
vax_type="test_vax",
110+
table=self.mock_table,
111+
is_present=True,
112+
)
113+
114+
self.assertEqual(immunisation["identifier"][0]["system"], "https://tpp-uk.com/Id/ve/vacc")
115+
116+
def test_create_immunization_uplifts_legacy_identifier_system_emis(self):
117+
"""it should recognise a legacy EMIS identifier system and use the new style identifier"""
118+
119+
immunisation = create_covid_immunization_dict_no_id()
120+
immunisation["identifier"][0]["system"] = "YGJ"
121+
122+
_ = self.service.create_immunization(
123+
immunization=immunisation,
124+
supplier_system="test_supplier",
125+
vax_type="test_vax",
126+
table=self.mock_table,
127+
is_present=True,
128+
)
129+
130+
self.assertEqual(immunisation["identifier"][0]["system"], "https://emishealth.com/identifiers/vacc")
131+
100132

101133
class TestUpdateImmunizationBatchService(TestFhirBatchServiceBase):
102134
def setUp(self):
@@ -169,6 +201,38 @@ def test_update_immunization_post_validation_error(self):
169201
self.assertTrue(expected_msg in error.exception.message)
170202
self.mock_repo.update_immunization.assert_not_called()
171203

204+
def test_update_immunization_uplifts_legacy_identifier_system_tpp(self):
205+
"""it should recognise a legacy TPP identifier system and use the new style identifier"""
206+
207+
immunisation = create_covid_immunization_dict_no_id()
208+
immunisation["identifier"][0]["system"] = "YGA"
209+
210+
_ = self.service.update_immunization(
211+
immunization=immunisation,
212+
supplier_system="test_supplier",
213+
vax_type="test_vax",
214+
table=self.mock_table,
215+
is_present=True,
216+
)
217+
218+
self.assertEqual(immunisation["identifier"][0]["system"], "https://tpp-uk.com/Id/ve/vacc")
219+
220+
def test_update_immunization_uplifts_legacy_identifier_system_emis(self):
221+
"""it should recognise a legacy EMIS identifier system and use the new style identifier"""
222+
223+
immunisation = create_covid_immunization_dict_no_id()
224+
immunisation["identifier"][0]["system"] = "YGJ"
225+
226+
_ = self.service.update_immunization(
227+
immunization=immunisation,
228+
supplier_system="test_supplier",
229+
vax_type="test_vax",
230+
table=self.mock_table,
231+
is_present=True,
232+
)
233+
234+
self.assertEqual(immunisation["identifier"][0]["system"], "https://emishealth.com/identifiers/vacc")
235+
172236

173237
class TestDeleteImmunizationBatchService(unittest.TestCase):
174238
def setUp(self):
@@ -194,6 +258,38 @@ def test_delete_immunization_valid(self):
194258
)
195259
self.assertEqual(result, imms_id)
196260

261+
def test_delete_immunization_uplifts_legacy_identifier_system_tpp(self):
262+
"""it should recognise a legacy TPP identifier system and use the new style identifier"""
263+
264+
immunisation = create_covid_immunization_dict_no_id()
265+
immunisation["identifier"][0]["system"] = "YGA"
266+
267+
_ = self.service.delete_immunization(
268+
immunization=immunisation,
269+
supplier_system="test_supplier",
270+
vax_type="test_vax",
271+
table=self.mock_table,
272+
is_present=True,
273+
)
274+
275+
self.assertEqual(immunisation["identifier"][0]["system"], "https://tpp-uk.com/Id/ve/vacc")
276+
277+
def test_delete_immunization_uplifts_legacy_identifier_system_emis(self):
278+
"""it should recognise a legacy EMIS identifier system and use the new style identifier"""
279+
280+
immunisation = create_covid_immunization_dict_no_id()
281+
immunisation["identifier"][0]["system"] = "YGJ"
282+
283+
_ = self.service.delete_immunization(
284+
immunization=immunisation,
285+
supplier_system="test_supplier",
286+
vax_type="test_vax",
287+
table=self.mock_table,
288+
is_present=True,
289+
)
290+
291+
self.assertEqual(immunisation["identifier"][0]["system"], "https://emishealth.com/identifiers/vacc")
292+
197293

198294
if __name__ == "__main__":
199295
unittest.main()

0 commit comments

Comments
 (0)