Skip to content

Commit 54f7ae7

Browse files
Akol125RobertNovac
authored andcommitted
parent 0719a0d
author Akol125 <akinola.olutola1@nhs.net> 1741732167 +0000 committer Robert Novac <robert.novac@airelogic.com> 1742314388 +0000 READ request- drop obfuscation for s-flag patient
1 parent 837cac1 commit 54f7ae7

File tree

12 files changed

+194
-60
lines changed

12 files changed

+194
-60
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.12
1+
layout pyenv 3.10.16
22

3-
dotenv
3+
dotenv

backend/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
build
22
.venv
3+
.direnv
4+
.env
5+
.envrc
6+
terraform.tfstate
7+
.python-version

backend/src/fhir_service.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_immunization_by_identifier(
7676
base_url = f"{get_service_url()}/Immunization"
7777
response = form_json(imms_resp, element, identifier, base_url)
7878
return response
79-
79+
8080
def get_immunization_by_id(self, imms_id: str, imms_vax_type_perms: str) -> Optional[dict]:
8181
"""
8282
Get an Immunization by its ID. Return None if not found. If the patient doesn't have an NHS number,
@@ -85,26 +85,19 @@ 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-
# 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", {}))
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 {}
9091

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")
9992

10093
return {
10194
"Version": imms_resp.get("Version", ""),
102-
"Resource": Immunization.parse_obj(imms_filtered_for_read_and_s_flag),
95+
"Resource": Immunization.parse_obj(imms_filtered_for_read),
10396
}
10497

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

backend/src/filter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def add_use_to_identifier(imms: dict) -> dict:
9494

9595
class Filter:
9696
"""Functions for filtering a FHIR Immunization Resource"""
97-
9897
@staticmethod
9998
def read(imms: dict) -> dict:
10099
"""Apply filtering for READ request"""

backend/src/get_imms_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_imms_handler(event, context):
1616

1717
def get_immunization_by_id(event, controller: FhirController):
1818
try:
19-
return controller.get_immunization_by_id(event)
19+
return controller.get_immunization_by_id(event)
2020
except Exception: # pylint: disable = broad-exception-caught
2121
exp_error = create_operation_outcome(
2222
resource_id=str(uuid.uuid4()),

backend/tests/test_fhir_service.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def setUp(self):
157157
self.pds_service = create_autospec(PdsService)
158158
self.validator = create_autospec(ImmunizationValidator)
159159
self.fhir_service = FhirService(self.imms_repo, self.pds_service, self.validator)
160-
160+
161161
def test_get_immunization_by_id(self):
162162
"""it should find an Immunization by id"""
163163
imms_id = "an-id"
@@ -204,23 +204,7 @@ def test_get_immunization_by_id_patient_not_restricted(self):
204204

205205
# Then
206206
self.assertEqual(actual_output["Resource"], expected_output)
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-
207+
224208
def test_pre_validation_failed(self):
225209
"""it should throw exception if Immunization is not valid"""
226210
imms_id = "an-id"

devtools/.terraform.lock.hcl

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

e2e/clear_dynamodb.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import boto3
2+
3+
# Get the DynamoDB table name
4+
TABLE_NAME = "imms-internal-dev-imms-events"
5+
6+
if not TABLE_NAME:
7+
raise ValueError("DYNAMODB_TABLE_NAME environment variable is not set")
8+
9+
# Initialize DynamoDB client
10+
dynamodb = boto3.resource("dynamodb")
11+
table = dynamodb.Table(TABLE_NAME)
12+
13+
def get_primary_keys():
14+
"""Retrieve the primary key schema of the table."""
15+
response = table.key_schema
16+
return [key["AttributeName"] for key in response]
17+
18+
<<<<<<< HEAD
19+
=======
20+
def get_total_count():
21+
"""Get the total count of items in the table, handling pagination."""
22+
total_count = 0
23+
last_evaluated_key = None
24+
25+
while True:
26+
if last_evaluated_key:
27+
response = table.scan(Select='COUNT', ExclusiveStartKey=last_evaluated_key)
28+
else:
29+
response = table.scan(Select='COUNT')
30+
31+
total_count += response.get("Count", 0)
32+
last_evaluated_key = response.get("LastEvaluatedKey")
33+
34+
if not last_evaluated_key:
35+
break
36+
37+
return total_count
38+
39+
>>>>>>> 6caf6a5f (added)
40+
def clear_dynamodb():
41+
"""Deletes all items from the DynamoDB table, handling pagination."""
42+
print(f"Clearing DynamoDB table: {TABLE_NAME}")
43+
44+
primary_keys = get_primary_keys()
45+
if not primary_keys:
46+
raise ValueError("Unable to retrieve primary key schema")
47+
48+
<<<<<<< HEAD
49+
=======
50+
total_count = get_total_count()
51+
print(f"Total items before deletion: {total_count}")
52+
53+
>>>>>>> 6caf6a5f (added)
54+
deleted_count = 0
55+
56+
while True:
57+
scan = table.scan()
58+
items = scan.get("Items", [])
59+
60+
if not items:
61+
break
62+
63+
with table.batch_writer() as batch:
64+
for item in items:
65+
key = {pk: item[pk] for pk in primary_keys}
66+
batch.delete_item(Key=key)
67+
deleted_count += 1
68+
69+
print(f"Deleted {len(items)} items...")
70+
71+
print(f"Total {deleted_count} items deleted from DynamoDB")
72+
73+
if __name__ == "__main__":
74+
<<<<<<< HEAD
75+
clear_dynamodb()
76+
=======
77+
clear_dynamodb()
78+
>>>>>>> 6caf6a5f (added)

0 commit comments

Comments
 (0)