Skip to content

Commit 0c8f5e9

Browse files
committed
Merge branch 'feature/PI-605-bulk_etl_transform' into release/2024-11-27
2 parents 32f233e + 8dd6c05 commit 0c8f5e9

File tree

52 files changed

+2975
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2975
-521
lines changed

infrastructure/terraform/per_workspace/vars.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "api_lambda_layers" {
4040
default = [
4141
"domain",
4242
"event",
43-
"api_utils"
43+
"api_utils",
44+
"sds"
4445
]
4546
}
4647

src/api/createDeviceMessageHandlingSystem/src/v1/steps.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
)
1010
from domain.core.cpm_product import CpmProduct
1111
from domain.core.device import (
12-
MHS_DEVICE_NAME,
1312
Device,
1413
DeviceKeyAddedEvent,
1514
DeviceReferenceDataIdAddedEvent,
@@ -31,6 +30,7 @@
3130
)
3231
from domain.request_models import CpmProductPathParams, CreateMhsDeviceIncomingParams
3332
from domain.response.validation_errors import mark_validation_errors_as_inbound
33+
from sds.epr.constants import EprNameTemplate, SdsDeviceReferenceDataPath, SdsFieldName
3434

3535

3636
@mark_validation_errors_as_inbound
@@ -42,13 +42,17 @@ def parse_mhs_device_payload(data, cache) -> CreateMhsDeviceIncomingParams:
4242
def check_for_existing_mhs(data, cache):
4343
product_team: ProductTeam = data[read_product_team]
4444
product: CpmProduct = data[read_product]
45+
party_key: str = data[get_party_key]
4546

4647
device_repo = DeviceRepository(
4748
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
4849
)
4950

5051
devices = device_repo.search(product_team_id=product_team.id, product_id=product.id)
51-
if any(device.name == MHS_DEVICE_NAME for device in devices):
52+
if any(
53+
device.name == EprNameTemplate.MHS_DEVICE.format(party_key=party_key)
54+
for device in devices
55+
):
5256
raise ConfigurationError(
5357
"There is already an existing MHS Device for this Product"
5458
)
@@ -65,12 +69,11 @@ def read_device_reference_data(data, cache) -> DeviceReferenceData:
6569
)
6670

6771
party_key: str = data[get_party_key]
68-
# use {QuestionnaireInstance.SPINE_MHS_MESSAGE_SETS}
69-
mhs_message_set_drd_name = f"{party_key} - MHS Message Set"
70-
7172
try:
7273
(device_reference_data,) = filter(
73-
lambda drd: drd.name == mhs_message_set_drd_name, device_reference_datas
74+
lambda drd: drd.name
75+
== EprNameTemplate.MESSAGE_SETS.format(party_key=party_key),
76+
device_reference_datas,
7477
)
7578
except ValueError:
7679
raise ConfigurationError(
@@ -98,11 +101,14 @@ def validate_spine_mhs_questionnaire_response(data, cache) -> QuestionnaireRespo
98101

99102
def create_mhs_device(data, cache) -> Device:
100103
product: CpmProduct = data[read_product]
104+
party_key: str = data[get_party_key]
101105
payload: CreateMhsDeviceIncomingParams = data[parse_mhs_device_payload]
102106

103107
# Create a new Device dictionary excluding 'questionnaire_responses'
104108
device_payload = payload.dict(exclude={"questionnaire_responses"})
105-
return product.create_device(**device_payload)
109+
return product.create_device(
110+
name=EprNameTemplate.MHS_DEVICE.format(party_key=party_key), **device_payload
111+
)
106112

107113

108114
def create_party_key_tag(data, cache) -> DeviceTagAddedEvent:
@@ -114,20 +120,18 @@ def create_cpa_id_keys(data, cache) -> DeviceKeyAddedEvent:
114120
mhs_device: Device = data[create_mhs_device]
115121
party_key = data[get_party_key]
116122
drd: DeviceReferenceData = data[read_device_reference_data]
117-
interaction_ids = []
118123

119-
# Extract Interaction IDs from questionnaire responses
120124
questionnaire_responses = drd.questionnaire_responses.get(
121125
f"{QuestionnaireInstance.SPINE_MHS_MESSAGE_SETS}/1", []
122126
)
123-
for response in questionnaire_responses:
124-
interaction_ids.append(response.data.get("Interaction ID"))
125127

126-
# Use cpa_id in furture
128+
interaction_ids = [
129+
response.data.get(SdsFieldName.INTERACTION_ID)
130+
for response in questionnaire_responses
131+
]
132+
127133
for id in interaction_ids:
128-
mhs_device.add_key(
129-
key_type=DeviceKeyType.INTERACTION_ID, key_value=f"{party_key}:{id}"
130-
)
134+
mhs_device.add_key(key_type=DeviceKeyType.CPA_ID, key_value=f"{party_key}:{id}")
131135

132136
return mhs_device
133137

@@ -136,7 +140,8 @@ def add_device_reference_data_id(data, cache) -> DeviceReferenceDataIdAddedEvent
136140
mhs_device: Device = data[create_mhs_device]
137141
drd: DeviceReferenceData = data[read_device_reference_data]
138142
return mhs_device.add_device_reference_data_id(
139-
device_reference_data_id=str(drd.id), path_to_data=["*"]
143+
device_reference_data_id=str(drd.id),
144+
path_to_data=[SdsDeviceReferenceDataPath.ALL],
140145
)
141146

142147

src/api/createDeviceMessageHandlingSystem/tests/test_index.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
QuestionnaireRepository,
2424
)
2525
from event.json import json_loads
26+
from sds.epr.constants import MHS_DEVICE_SUFFIX, EprNameTemplate
2627

2728
from test_helpers.dynamodb import mock_table
2829
from test_helpers.uuid import consistent_uuid
2930

3031
TABLE_NAME = "hiya"
31-
DEVICE_NAME = "Product-MHS"
32+
DEVICE_NAME = "ABC1234-987654 - Message Handling System"
3233
ODS_CODE = "AAA"
3334
PRODUCT_ID = ProductId.create()
3435
PRODUCT_TEAM_NAME = "My Product Team"
@@ -52,6 +53,7 @@
5253
"MHS Is Authenticated": "PERSISTENT",
5354
"Product Key": "product-key-001",
5455
"Requestor URP": "requestor-789",
56+
"MHS Manufacturer Organisation": "AAA",
5557
}
5658

5759

@@ -102,7 +104,7 @@ def mock_epr_product_with_message_set_drd() -> (
102104

103105
# Set up DeviceReferenceData in DB
104106
device_reference_data = product.create_device_reference_data(
105-
name="ABC1234-987654 - MHS Message Set"
107+
name=EprNameTemplate.MESSAGE_SETS.format(party_key="ABC1234-987654")
106108
)
107109
device_reference_data.add_questionnaire_response(questionnaire_response)
108110
device_reference_data.add_questionnaire_response(questionnaire_response_2)
@@ -204,7 +206,7 @@ def test_index() -> None:
204206
device = Device(**_device)
205207
assert device.product_team_id == product.product_team_id
206208
assert device.product_id == product.id
207-
assert device.name == DEVICE_NAME
209+
assert device.name.endswith(MHS_DEVICE_SUFFIX)
208210
assert device.ods_code == ODS_CODE
209211
assert device.created_on.date() == datetime.today().date()
210212
assert device.updated_on.date() == datetime.today().date()
@@ -301,7 +303,7 @@ def test_incoming_errors(body, path_parameters, error_code, status_code):
301303
}
302304
},
303305
"MISSING_VALUE",
304-
"Failed to validate data against 'spine_mhs/1': 'Unique Identifier' is a required property",
306+
"Failed to validate data against 'spine_mhs/1': 'MHS Manufacturer Organisation' is a required property",
305307
400,
306308
),
307309
],

src/api/createDeviceReferenceDataASActions/src/v1/steps.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
)
2222
from domain.request_models import CreateDeviceReferenceAdditionalInteractionsDataParams
2323
from domain.response.validation_errors import mark_validation_errors_as_inbound
24-
25-
DEVICE_NAME_MARKER = "AS Additional Interactions"
24+
from sds.epr.constants import ADDITIONAL_INTERACTIONS_SUFFIX, EprNameTemplate
2625

2726

2827
@mark_validation_errors_as_inbound
@@ -60,7 +59,7 @@ def require_no_existing_additional_interactions_device_reference_data(
6059
product_team_id=product.product_team_id, product_id=product.id
6160
)
6261
if any(
63-
device_reference_data.name.endswith(DEVICE_NAME_MARKER)
62+
device_reference_data.name.endswith(ADDITIONAL_INTERACTIONS_SUFFIX)
6463
for device_reference_data in results
6564
):
6665
raise AlreadyExistsError(
@@ -91,7 +90,7 @@ def create_additional_interactions_device_reference_data(
9190
product: CpmProduct = data[read_product]
9291
party_key: str = data[get_party_key]
9392
return product.create_device_reference_data(
94-
name=f"{party_key} - {DEVICE_NAME_MARKER}"
93+
name=EprNameTemplate.ADDITIONAL_INTERACTIONS.format(party_key=party_key)
9594
)
9695

9796

src/api/createDeviceReferenceDataMessageSet/src/v1/steps.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
)
2121
from domain.request_models import CreateDeviceReferenceMessageSetsDataParams
2222
from domain.response.validation_errors import mark_validation_errors_as_inbound
23-
24-
DEVICE_NAME_MARKER = "MHS Message Set"
23+
from sds.epr.constants import MESSAGE_SETS_SUFFIX, EprNameTemplate
2524

2625

2726
@mark_validation_errors_as_inbound
@@ -43,11 +42,11 @@ def require_no_existing_message_sets_device_reference_data(
4342
product_team_id=product.product_team_id, product_id=product.id
4443
)
4544
if any(
46-
device_reference_data.name.endswith(DEVICE_NAME_MARKER)
45+
device_reference_data.name.endswith(MESSAGE_SETS_SUFFIX)
4746
for device_reference_data in results
4847
):
4948
raise AlreadyExistsError(
50-
"This product already has a 'Message Set' DeviceReferenceData. "
49+
"This product already has a 'Message Sets' DeviceReferenceData. "
5150
"Please update, or delete and recreate if you wish to make changes."
5251
)
5352

@@ -71,7 +70,7 @@ def create_message_set_device_reference_data(data, cache) -> DeviceReferenceData
7170
product: CpmProduct = data[read_product]
7271
party_key: str = data[get_party_key]
7372
return product.create_device_reference_data(
74-
name=f"{party_key} - {DEVICE_NAME_MARKER}"
73+
name=EprNameTemplate.MESSAGE_SETS.format(party_key=party_key)
7574
)
7675

7776

src/api/createDeviceReferenceDataMessageSet/tests/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_index_without_questionnaire() -> None:
8383
device_reference_data = DeviceReferenceData(**_device_reference_data)
8484
assert device_reference_data.product_id == product.id
8585
assert device_reference_data.product_team_id == product.product_team_id
86-
assert device_reference_data.name == "AAA-100001 - MHS Message Set"
86+
assert device_reference_data.name == "AAA-100001 - MHS Message Sets"
8787
assert device_reference_data.ods_code == ODS_CODE
8888
assert device_reference_data.created_on.date() == datetime.today().date()
8989
assert device_reference_data.updated_on is None
@@ -136,7 +136,7 @@ def test_index_with_questionnaire() -> None:
136136
device_reference_data = DeviceReferenceData(**_device_reference_data)
137137
assert device_reference_data.product_id == product.id
138138
assert device_reference_data.product_team_id == product.product_team_id
139-
assert device_reference_data.name == "AAA-100001 - MHS Message Set"
139+
assert device_reference_data.name == "AAA-100001 - MHS Message Sets"
140140
assert device_reference_data.ods_code == ODS_CODE
141141
assert device_reference_data.created_on.date() == datetime.today().date()
142142
assert device_reference_data.updated_on.date() == datetime.today().date()

src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.failure.feature

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ Feature: Create MHS Device - failure scenarios
237237
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
238238
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 |
239239
Then I receive a status code "400" with body
240-
| path | value |
241-
| errors.0.code | MISSING_VALUE |
242-
| errors.0.message | Failed to validate data against 'spine_mhs/1': 'Managing Organization' is a required property |
240+
| path | value |
241+
| errors.0.code | MISSING_VALUE |
242+
| errors.0.message | Failed to validate data against 'spine_mhs/1': 'MHS Manufacturer Organisation' is a required property |
243243
And the response headers contain:
244244
| name | value |
245245
| Content-Type | application/json |
246-
| Content-Length | 147 |
246+
| Content-Length | 155 |
247247

248248
Scenario: Cannot create a MHS Device with a Product that already has an MHS Device
249249
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
@@ -272,6 +272,7 @@ Feature: Create MHS Device - failure scenarios
272272
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
273273
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 |
274274
| questionnaire_responses.spine_mhs.0.Managing Organization | Example Org |
275+
| questionnaire_responses.spine_mhs.0.MHS Manufacturer Organisation | AAA |
275276
| questionnaire_responses.spine_mhs.0.MHS Party key | party-key-001 |
276277
| questionnaire_responses.spine_mhs.0.MHS CPA ID | cpa-id-001 |
277278
| questionnaire_responses.spine_mhs.0.Approver URP | approver-123 |
@@ -291,6 +292,7 @@ Feature: Create MHS Device - failure scenarios
291292
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
292293
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123457 |
293294
| questionnaire_responses.spine_mhs.0.Managing Organization | Example Org |
295+
| questionnaire_responses.spine_mhs.0.MHS Manufacturer Organisation | AAA |
294296
| questionnaire_responses.spine_mhs.0.MHS Party key | party-key-003 |
295297
| questionnaire_responses.spine_mhs.0.MHS CPA ID | cpa-id-001 |
296298
| questionnaire_responses.spine_mhs.0.Approver URP | approver-123 |

src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.success.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Feature: Create MHS Device - success scenarios
3232
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
3333
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 |
3434
| questionnaire_responses.spine_mhs.0.Managing Organization | Example Org |
35+
| questionnaire_responses.spine_mhs.0.MHS Manufacturer Organisation | AAA |
3536
| questionnaire_responses.spine_mhs.0.MHS Party key | party-key-001 |
3637
| questionnaire_responses.spine_mhs.0.MHS CPA ID | cpa-id-001 |
3738
| questionnaire_responses.spine_mhs.0.Approver URP | approver-123 |
@@ -48,22 +49,22 @@ Feature: Create MHS Device - success scenarios
4849
Then I receive a status code "201" with body
4950
| path | value |
5051
| id | << ignore >> |
51-
| name | Product-MHS |
52+
| name | F5H1R-850000 - Message Handling System |
5253
| status | active |
5354
| product_id | ${ note(product_id) } |
5455
| product_team_id | ${ note(product_team_id) } |
5556
| ods_code | F5H1R |
5657
| created_on | << ignore >> |
5758
| updated_on | << ignore >> |
5859
| deleted_on | << ignore >> |
59-
| keys.0.key_type | interaction_id |
60+
| keys.0.key_type | cpa_id |
6061
| keys.0.key_value | F5H1R-850000:urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
6162
| questionnaire_responses | << ignore >> |
6263
| device_reference_data | << ignore >> |
6364
And the response headers contain:
6465
| name | value |
6566
| Content-Type | application/json |
66-
| Content-Length | 1295 |
67+
| Content-Length | 1354 |
6768
And I note the response field "$.id" as "device_id"
6869
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/${ note(device_id) }"
6970
Then I receive a status code "200" with body
@@ -112,7 +113,7 @@ Feature: Create MHS Device - success scenarios
112113
And the response headers contain:
113114
| name | value |
114115
| Content-Type | application/json |
115-
| Content-Length | 1717 |
116+
| Content-Length | 1736 |
116117

117118
Examples:
118119
| product_team_id | product_id |

src/api/tests/feature_tests/features/createDeviceReferenceDataMessageSet.failure.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ Feature: Create "Message Set" Device Reference Data - failure scenarios
115115
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/MhsMessageSet"
116116
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/MhsMessageSet"
117117
Then I receive a status code "400" with body
118-
| path | value |
119-
| errors.0.code | VALIDATION_ERROR |
120-
| errors.0.message | This product already has a 'Message Set' DeviceReferenceData. Please update, or delete and recreate if you wish to make changes. |
118+
| path | value |
119+
| errors.0.code | VALIDATION_ERROR |
120+
| errors.0.message | This product already has a 'Message Sets' DeviceReferenceData. Please update, or delete and recreate if you wish to make changes. |
121121
And the response headers contain:
122122
| name | value |
123123
| Content-Type | application/json |
124-
| Content-Length | 185 |
124+
| Content-Length | 186 |
125125

126126
Scenario: Fail to create an "MHS Message Set" Device Reference Data in non-EPR product
127127
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:

0 commit comments

Comments
 (0)