Skip to content

Commit e847da6

Browse files
authored
Merge branch 'master' into APM-000-AMP-3654-removed-interactive-product-backlog
2 parents 239d079 + a20bdcf commit e847da6

File tree

9 files changed

+144
-50
lines changed

9 files changed

+144
-50
lines changed

redis_sync/src/event_read.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import redis
22

33

4+
# Reads a Redis hash using the 'read' key from the event payload.
45
def read_event(redis_client: redis.Redis, event: dict, logger) -> dict:
56
try:
67
read_key = event["read"]

redis_sync/src/s3_event.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
class S3EventRecord:
2+
"""
3+
S3 Event Parsing Utilities
4+
This module defines helper classes for extracting relevant information from
5+
AWS S3 event records, such as the bucket name and object key.
6+
- `S3EventRecord` provides access to individual record fields.
7+
- `S3Event` wraps the event and extracts a list of `S3EventRecord` objects.
8+
"""
29
def __init__(self, s3_record):
310
self.s3_record = s3_record
411

redis_sync/src/s3_reader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
"Upload the content from a config file in S3 to ElastiCache (Redis)"
2-
31
from clients import s3_client
42
from clients import logger
53

64

75
class S3Reader:
86

7+
"""
8+
Fetch the file from S3 using the specified bucket and key.
9+
The file is expected to be a UTF-8 encoded text file (e.g., JSON or plain text).
10+
We read the file content from the response body and decode it into a string.
11+
This string can then be passed to json.loads() or other parsers as needed.
12+
"""
13+
914
@staticmethod
1015
def read(bucket_name, file_key):
1116
try:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ def transform_vaccine_map(map):
1313
"vacc_to_diseases": vacc_to_diseases,
1414
"diseases_to_vacc": diseases_to_vacc
1515
}
16+
17+
18+
def transform_supplier_permissions(supplier):
19+
"""
20+
Transform a supplier-permission
21+
"""
22+
logger.info("Transforming supplier permissions data")
23+
logger.info("source data: %s", supplier)
24+
25+
supplier_permissions = {
26+
entry["supplier"]: entry["permissions"] for entry in supplier
27+
}
28+
29+
return {"supplier_permissions": supplier_permissions}

redis_sync/src/transform_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from constants import RedisCacheKey
22
from clients import logger
3-
from transform_vaccine_map import transform_vaccine_map
3+
from src.transform_configs import transform_vaccine_map, transform_supplier_permissions
44
'''
55
Transform config file to format required in REDIS cache.
66
'''
@@ -10,7 +10,7 @@ def transform_map(data, file_type):
1010
# Transform the vaccine map data as needed
1111
logger.info("Transforming data for file type: %s", file_type)
1212
if file_type == RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY:
13-
return data
13+
return transform_supplier_permissions(data)
1414
if file_type == RedisCacheKey.DISEASE_MAPPING_FILE_KEY:
1515
return transform_vaccine_map(data)
1616
logger.info("No specific transformation defined for file type: %s", file_type)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"supplier_permissions": {
3+
"DPSFULL": ["COVID19_FULL", "FLU_FULL", "MMR_FULL", "RSV_FULL"],
4+
"DPSREDUCED": ["COVID19_FULL", "FLU_FULL", "MMR_FULL", "RSV_FULL"],
5+
"EMIS": ["RSV_UPDATE"],
6+
"PINNACLE": [""],
7+
"SONAR": ["FLU_CREATE", "FLU_DELETE"],
8+
"TPP": [""],
9+
"AGEM-NIVS": [""],
10+
"NIMS": [""],
11+
"EVA": ["COVID19_CREATE", "COVID19_DELETE", "COVID19_UPDATE"],
12+
"RAVS": [""],
13+
"MEDICAL_DIRECTOR": [""],
14+
"COVID19_VACCINE_RESOLUTION_SERVICEDESK": [""]
15+
}
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"supplier": "DPSFULL",
4+
"permissions": ["COVID19_FULL", "FLU_FULL", "MMR_FULL", "RSV_FULL"]
5+
},
6+
{
7+
"supplier": "DPSREDUCED",
8+
"permissions": ["COVID19_FULL", "FLU_FULL", "MMR_FULL", "RSV_FULL"]
9+
},
10+
{
11+
"supplier": "EMIS",
12+
"permissions": ["RSV_UPDATE"]
13+
},
14+
{
15+
"supplier": "PINNACLE",
16+
"permissions": [""]
17+
},
18+
{
19+
"supplier": "SONAR",
20+
"permissions": ["FLU_CREATE", "FLU_DELETE"]
21+
},
22+
{
23+
"supplier": "TPP",
24+
"permissions": [""]
25+
},
26+
{
27+
"supplier": "AGEM-NIVS",
28+
"permissions": [""]
29+
},
30+
{
31+
"supplier": "NIMS",
32+
"permissions": [""]
33+
},
34+
{
35+
"supplier": "EVA",
36+
"permissions": ["COVID19_CREATE", "COVID19_DELETE", "COVID19_UPDATE"]
37+
},
38+
{
39+
"supplier": "RAVS",
40+
"permissions": [""]
41+
},
42+
{
43+
"supplier": "MEDICAL_DIRECTOR",
44+
"permissions": [""]
45+
},
46+
{
47+
"supplier": "COVID19_VACCINE_RESOLUTION_SERVICEDESK",
48+
"permissions": [""]
49+
}
50+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import unittest
3+
import json
4+
from unittest.mock import patch
5+
from transform_configs import transform_vaccine_map, transform_supplier_permissions
6+
7+
8+
class TestTransformConfigs(unittest.TestCase):
9+
def setUp(self):
10+
self.logger_info_patcher = patch("transform_configs.logger.info")
11+
self.mock_logger_info = self.logger_info_patcher.start()
12+
13+
with open("./tests/test_data/disease_mapping.json") as mapping_data:
14+
self.sample_map = json.load(mapping_data)
15+
16+
with open("./tests/test_data/permissions_config.json") as permissions_data:
17+
self.supplier_data = json.load(permissions_data)
18+
19+
def tearDown(self):
20+
self.logger_info_patcher.stop()
21+
22+
def test_disease_to_vacc(self):
23+
with open("./tests/test_data/expected_disease_to_vacc.json") as f:
24+
expected = json.load(f)
25+
result = transform_vaccine_map(self.sample_map)
26+
self.assertEqual(result["diseases_to_vacc"], expected)
27+
28+
def test_vacc_to_diseases(self):
29+
with open("./tests/test_data/expected_vacc_to_diseases.json") as f:
30+
expected = json.load(f)
31+
result = transform_vaccine_map(self.sample_map)
32+
self.assertEqual(result["vacc_to_diseases"], expected)
33+
34+
def test_transform_supplier_permissions_against_expected_file(self):
35+
with open("./tests/test_data/expected_perms.json") as f:
36+
expected = json.load(f)
37+
result = transform_supplier_permissions(self.supplier_data)
38+
self.assertEqual(result, expected)
39+
40+
def test_empty_input(self):
41+
result = transform_supplier_permissions([])
42+
self.assertEqual(result, {"supplier_permissions": {}})
43+
44+
def test_missing_keys_raises_error(self):
45+
broken_input = [{"supplier": "X"}, {"permissions": ["read:vaccine"]}]
46+
with self.assertRaises(KeyError):
47+
transform_supplier_permissions(broken_input)

redis_sync/tests/test_transform_vaccine_map.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)