Skip to content

Commit

Permalink
feature/PI-582-modify_read_device Read mhs device with drds
Browse files Browse the repository at this point in the history
  • Loading branch information
megan-bower4 committed Nov 19, 2024
1 parent 1c27bbc commit ae2a978
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 71 deletions.
42 changes: 42 additions & 0 deletions src/api/readDevice/src/v1/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
from domain.core.cpm_product.v1 import CpmProduct
from domain.core.device.v3 import Device
from domain.core.device_reference_data.v1 import DeviceReferenceData
from domain.core.product_team.v3 import ProductTeam
from domain.repository.cpm_product_repository.v3 import CpmProductRepository
from domain.repository.device_reference_data_repository.v1 import (
DeviceReferenceDataRepository,
)
from domain.repository.device_repository.v3 import DeviceRepository
from domain.repository.product_team_repository.v2 import ProductTeamRepository
from domain.request_models.v1 import DevicePathParams
Expand Down Expand Up @@ -54,6 +58,42 @@ def read_device(data, cache) -> Device:
)


def read_device_reference_data(data, cache) -> list[DeviceReferenceData]:
product_team: ProductTeam = data[read_product_team]
product: CpmProduct = data[read_product]
device: Device = data[read_device]

drds = []
device_reference_data_repo = DeviceReferenceDataRepository(
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
)
for id in device.device_reference_data:
drd = device_reference_data_repo.read(
product_team_id=product_team.id,
product_id=product.id,
id=id,
)
drds.append(drd)

return drds


def update_device_with_device_reference_data(data, cache) -> Device:
device: Device = data[read_device]
device_reference_datas = data[read_device_reference_data]

for drd in device_reference_datas:
for key, responses in drd.questionnaire_responses.items():
if key not in device.questionnaire_responses:
# If the key doesn't exist, initialize it with the responses
device.questionnaire_responses[key] = responses
else:
# If the key exists, extend the list with new responses
device.questionnaire_responses[key].extend(responses)

return device


def device_to_dict(data, cache) -> tuple[str, dict]:
device: Device = data[read_device]
return HTTPStatus.OK, device.state()
Expand All @@ -64,5 +104,7 @@ def device_to_dict(data, cache) -> tuple[str, dict]:
read_product_team,
read_product,
read_device,
read_device_reference_data,
update_device_with_device_reference_data,
device_to_dict,
]
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ Feature: Create MHS Device - failure scenarios
| path | value |
| name | My Great Product |
And I note the response field "$.id" as "product_id"
And I note the response field "$.keys.0.key_type" as "party_key_tag"
And I note the response field "$.keys.0.key_value" as "party_key_value"
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/MhsMessageSet"
And I note the response field "$.id" as "message_set_drd_id"
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/MessageHandlingSystem" with body:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Create MHS Device - success scenarios
| name | My Great Product |
And I note the response field "$.id" as "product_id"
And I note the response field "$.keys.0.key_type" as "party_key_tag"
And I note the response field "$.keys.0.key_value" as "party_key_value"
And I note the response field "$.keys.0.key_value" as "party_key_tag_value"
And I have already made a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/${ note(product_id) }/DeviceReferenceData/MhsMessageSet" with body:
| path | value |
| questionnaire_responses.spine_mhs_message_sets.0.Interaction ID | urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
Expand Down Expand Up @@ -67,26 +67,34 @@ Feature: Create MHS Device - success scenarios
And I note the response field "$.id" as "device_id"
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/${ note(device_id) }"
Then I receive a status code "200" with body
| path | value |
| id | ${ note(device_id) } |
| name | Product-MHS |
| status | active |
| product_id | ${ note(product_id) } |
| product_team_id | ${ note(product_team_id) } |
| ods_code | F5H1R |
| created_on | << ignore >> |
| updated_on | << ignore >> |
| deleted_on | << ignore >> |
| keys.0.key_type | interaction_id |
| keys.0.key_value | F5H1R-850000:urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
| tags.0.0.0 | ${ note(party_key_tag) } |
| tags.0.0.1 | ${ note(party_key_value) } |
| questionnaire_responses | << ignore >> |
| device_reference_data | << ignore >> |
| path | value |
| id | ${ note(device_id) } |
| name | Product-MHS |
| status | active |
| product_id | ${ note(product_id) } |
| product_team_id | ${ note(product_team_id) } |
| ods_code | F5H1R |
| created_on | << ignore >> |
| updated_on | << ignore >> |
| deleted_on | << ignore >> |
| keys.0.key_type | interaction_id |
| keys.0.key_value | F5H1R-850000:urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
| tags.0.0.0 | ${ note(party_key_tag) } |
<<<<<<< HEAD
| tags.0.0.1 | ${ note(party_key_value) } |
=======
| tags.0.0.1 | ${ note(party_key_tag_value) } |
>>>>>>> 894cef9 (feature/PI-582-modify_read_device Read mhs device with drds)
| questionnaire_responses | << ignore >> |
| device_reference_data | << ignore >> |
And the response headers contain:
| name | value |
| Content-Type | application/json |
| Content-Length | 1338 |
| name | value |
| Content-Type | application/json |
<<<<<<< HEAD
| Content-Length | 1338 |
=======
| Content-Length | 1717 |
>>>>>>> 894cef9 (feature/PI-582-modify_read_device Read mhs device with drds)

Examples:
| product_team_id | product_id |
Expand Down
Loading

0 comments on commit ae2a978

Please sign in to comment.