Skip to content

Commit 7003530

Browse files
authored
Merge pull request #370 from NHSDigital/revert-353-VED-73-Read-S-flag-obfuscation
Revert "VED-73- drop obfuscation for s-flag-patient"
2 parents 55cbf76 + e40edd3 commit 7003530

File tree

12 files changed

+81
-109
lines changed

12 files changed

+81
-109
lines changed

backend/.envrc.default

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
layout pyenv 3.10.16
1+
layout pyenv 3.10.12
22

3-
dotenv
3+
dotenv

backend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build
2-
.venv
2+
.venv

backend/src/fhir_service.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,26 @@ def get_immunization_by_id(self, imms_id: str, imms_vax_type_perms: str) -> Opti
8585
if not (imms_resp := self.immunization_repo.get_immunization_by_id(imms_id, imms_vax_type_perms)):
8686
return None
8787

88-
# Returns the Immunisation full resource with no obfuscation
89-
resource = imms_resp.get("Resource", {})
90-
imms_filtered_for_read = Filter.read(resource) if resource else {}
88+
# Remove fields rom the imms resource which are not to be returned for read
89+
imms_filtered_for_read = Filter.read(imms_resp.get("Resource", {}))
9190

91+
# Handle s-flag filtering, where applicable
92+
if not (nhs_number := obtain_field_value(imms_filtered_for_read, FieldNames.patient_identifier_value)):
93+
imms_filtered_for_read_and_s_flag = imms_filtered_for_read
94+
else:
95+
if patient := self.pds_service.get_patient_details(nhs_number):
96+
imms_filtered_for_read_and_s_flag = handle_s_flag(imms_filtered_for_read, patient)
97+
else:
98+
raise UnhandledResponseError("unable to validate NHS number with downstream service")
9299

93100
return {
94101
"Version": imms_resp.get("Version", ""),
95-
"Resource": Immunization.parse_obj(imms_filtered_for_read),
102+
"Resource": Immunization.parse_obj(imms_filtered_for_read_and_s_flag),
96103
}
97104

98105
def get_immunization_by_id_all(self, imms_id: str, imms: dict) -> Optional[dict]:
99106
"""
100-
Get an Immunization by its ID. Return None if it is not found. If the patient doesn't have an NHS number,
107+
Get an Immunization by its ID. Return None if not found. If the patient doesn't have an NHS number,
101108
return the Immunization without calling PDS or checking S flag.
102109
"""
103110
imms["id"] = imms_id

backend/tests/test_fhir_service.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,23 @@ def test_get_immunization_by_id_patient_not_restricted(self):
204204

205205
# Then
206206
self.assertEqual(actual_output["Resource"], expected_output)
207-
207+
208+
def test_get_immunization_by_id_patient_restricted(self):
209+
"""it should return a filtered Immunization when patient is restricted"""
210+
imms_id = "restricted_id"
211+
immunization_data = load_json_data("completed_covid19_immunization_event.json")
212+
filtered_immunization = load_json_data("completed_covid19_immunization_event_filtered_for_s_flag_and_read.json")
213+
self.imms_repo.get_immunization_by_id.return_value = {"Resource": immunization_data}
214+
patient_data = {"meta": {"security": [{"code": "R"}]}}
215+
self.fhir_service.pds_service.get_patient_details.return_value = patient_data
216+
217+
# When
218+
resp_imms = self.fhir_service.get_immunization_by_id(imms_id, "COVID19:read")
219+
act_res = resp_imms["Resource"]
220+
filtered_immunization_res = Immunization.parse_obj(filtered_immunization)
221+
# Then
222+
self.assertEqual(act_res, filtered_immunization_res)
223+
208224
def test_pre_validation_failed(self):
209225
"""it should throw exception if Immunization is not valid"""
210226
imms_id = "an-id"

delta_backend/src/delta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def handler(event, context):
8484
"SupplierSystem": supplier_system,
8585
"DateTimeStamp": approximate_creation_time.isoformat(),
8686
"Source": delta_source,
87-
"Imms": flat_json,
87+
"Imms": str(flat_json),
8888
"ExpiresAt": expiry_time_epoch,
8989
}
9090
)

delta_backend/tests/test_convert_to_flat_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def assert_dynamodb_record(self, operation_flag, items, expected_values, expecte
8989
self.assertGreater(len(filtered_items), 0, f"No matching item found for {operation_flag}")
9090

9191
imms_data = filtered_items[0]["Imms"]
92-
self.assertIsInstance(imms_data, list)
92+
self.assertIsInstance(imms_data, str)
9393
self.assertGreater(len(imms_data), 0)
9494

9595
# Check Imms JSON structure matches exactly
96-
self.assertEqual(imms_data, expected_imms, "Imms data does not match expected JSON structure")
96+
self.assertEqual(imms_data, str(expected_imms), "Imms data does not match expected JSON structure")
9797

9898
for key, expected_value in expected_values.items():
9999
self.assertIn(key, filtered_items[0], f"{key} is missing")
@@ -1067,4 +1067,4 @@ def _run_test_practitioner_surname(self, expected_forename):
10671067
self.assertEqual(flat_json[0]["PERFORMING_PROFESSIONAL_SURNAME"], expected_forename)
10681068

10691069
if __name__ == "__main__":
1070-
unittest.main()
1070+
unittest.main()

delta_backend/tests/utils_for_converter_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def get_expected_imms(expected_action_flag):
187187
"PRIMARY_SOURCE": "true",
188188
"VACCINATION_PROCEDURE_CODE": "13246814444444",
189189
"VACCINATION_PROCEDURE_TERM": "Administration of first dose of severe acute respiratory syndrome coronavirus 2 vaccine (procedure)",
190-
"DOSE_SEQUENCE": Decimal("1"),
190+
"DOSE_SEQUENCE": 1,
191191
"VACCINE_PRODUCT_CODE": "39114911000001105",
192192
"VACCINE_PRODUCT_TERM": "COVID-19 Vaccine Vaxzevria (ChAdOx1 S [recombinant]) not less than 2.5x100,000,000 infectious units/0.5ml dose suspension for injection multidose vials (AstraZeneca UK Ltd) (product)",
193193
"VACCINE_MANUFACTURER": "AstraZeneca Ltd",
@@ -379,7 +379,7 @@ def get_expected_imms_error_output(expected_action_flag):
379379
"PRIMARY_SOURCE": "true",
380380
"VACCINATION_PROCEDURE_CODE": "13246814444444",
381381
"VACCINATION_PROCEDURE_TERM": "Administration of first dose of severe acute respiratory syndrome coronavirus 2 vaccine (procedure)",
382-
"DOSE_SEQUENCE": Decimal("1"),
382+
"DOSE_SEQUENCE": 1,
383383
"VACCINE_PRODUCT_CODE": "39114911000001105",
384384
"VACCINE_PRODUCT_TERM": "COVID-19 Vaccine Vaxzevria (ChAdOx1 S [recombinant]) not less than 2.5x100,000,000 infectious units/0.5ml dose suspension for injection multidose vials (AstraZeneca UK Ltd) (product)",
385385
"VACCINE_MANUFACTURER": "AstraZeneca Ltd",

devtools/.terraform.lock.hcl

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/poetry.lock

Lines changed: 7 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)