Skip to content

Commit

Permalink
[feature/PI-590-path_alias] fix-forward: resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jaklinger committed Nov 13, 2024
1 parent 63c9663 commit bda5169
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 110 deletions.
8 changes: 6 additions & 2 deletions src/api/createDeviceMessageHandlingSystem/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_index() -> None:
assert device.ods_code == ODS_CODE
assert device.created_on.date() == datetime.today().date()
assert device.updated_on.date() == datetime.today().date()
assert device.deleted_on is None
assert not device.deleted_on

questionnaire_responses = device.questionnaire_responses["spine_mhs/1"]
assert len(questionnaire_responses) == 1
Expand All @@ -147,7 +147,11 @@ def test_index() -> None:
repo = DeviceRepository(
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
)
created_device = repo.read(device.id)
created_device = repo.read(
product_team_id=device.product_team_id,
product_id=device.product_id,
id=device.id,
)

# Check party_key is added to tags in the created device
expected_party_key = (str(ProductKeyType.PARTY_KEY), "abc1234-987654")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_index_without_questionnaire() -> None:
created_device_reference_data = repo.read(
product_team_id=device_reference_data.product_team_id,
product_id=device_reference_data.product_id,
device_reference_data_id=device_reference_data.id,
id=device_reference_data.id,
)
assert created_device_reference_data == device_reference_data

Expand Down Expand Up @@ -155,6 +155,6 @@ def test_index_with_questionnaire() -> None:
created_device_reference_data = repo.read(
product_team_id=device_reference_data.product_team_id,
product_id=device_reference_data.product_id,
device_reference_data_id=device_reference_data.id,
id=device_reference_data.id,
)
assert created_device_reference_data == device_reference_data
15 changes: 8 additions & 7 deletions src/api/searchDeviceReferenceData/src/v1/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ def parse_incoming_path_parameters(data, cache) -> CpmProductPathParams:
return CpmProductPathParams(**event.path_parameters)


def validate_product_team(data, cache) -> ProductTeam:
def read_product_team(data, cache) -> ProductTeam:
product_team_repo = ProductTeamRepository(
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
)
path_params: CpmProductPathParams = data[parse_incoming_path_parameters]
return product_team_repo.read(id=path_params.product_team_id)


def validate_product(data, cache) -> CpmProduct:
def read_product(data, cache) -> CpmProduct:
cpm_product_repo = CpmProductRepository(
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
)
product_team: ProductTeam = data[read_product_team]
path_params: CpmProductPathParams = data[parse_incoming_path_parameters]
return cpm_product_repo.read(
product_team_id=path_params.product_team_id, product_id=path_params.product_id
product_team_id=product_team.id, id=path_params.product_id
)


def query_device_ref_data(data, cache) -> list[dict]:
product_team: ProductTeam = data[validate_product_team]
product: CpmProduct = data[validate_product]
product_team: ProductTeam = data[read_product_team]
product: CpmProduct = data[read_product]
drd_repo = DeviceReferenceDataRepository(
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
)
Expand All @@ -54,8 +55,8 @@ def return_device_ref_data(data, cache) -> tuple[HTTPStatus, dict]:

steps = [
parse_incoming_path_parameters,
validate_product_team,
validate_product,
read_product_team,
read_product,
query_device_ref_data,
return_device_ref_data,
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ Feature: Create MHS Device - success scenarios
| version | 1 |
| Authorization | letmein |

Scenario: Successfully create a MHS Device
Scenario Outline: Successfully create a MHS Device
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| keys.0.key_type | product_team_id_alias |
| keys.0.key_value | FOOBAR |
And I note the response field "$.id" as "product_team_id"
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
| 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"
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/MessageHandlingSystem" with body:
And I note the response field "$.keys.0.key_value" as "party_key"
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/Device/MessageHandlingSystem" with body:
| path | value |
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 |
Expand Down Expand Up @@ -68,10 +69,16 @@ Feature: Create MHS Device - success scenarios
| updated_on | << ignore >> |
| deleted_on | << ignore >> |
| keys | [] |
| tags.0.0.0 | ${ note(party_key_tag) } |
| tags.0.0.1 | ${ note(party_key_value) } |
| tags | << ignore >> |
| questionnaire_responses | << ignore >> |
And the response headers contain:
| name | value |
| Content-Type | application/json |
| Content-Length | 1147 |

Examples:
| product_team_id | product_id |
| ${ note(product_team_id) } | ${ note(product_id) } |
| ${ note(product_team_id) } | ${ note(party_key) } |
| FOOBAR | ${ note(product_id) } |
| FOOBAR | ${ note(party_key) } |
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
| version | 1 |
| Authorization | letmein |

Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses
Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| keys.0.key_type | product_team_id_alias |
| keys.0.key_value | FOOBAR |
And I note the response field "$.id" as "product_team_id"
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
| 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_value" as "party_key"
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions"
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/DeviceReferenceData/AccreditedSystemsAdditionalInteractions"
Then I receive a status code "201" with body
| path | value |
| id | << ignore >> |
Expand Down Expand Up @@ -52,18 +54,27 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
| Content-Type | application/json |
| Content-Length | 333 |

Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses
Examples:
| product_team_id | product_id |
| ${ note(product_team_id) } | ${ note(product_id) } |
| ${ note(product_team_id) } | ${ note(party_key) } |
| FOOBAR | ${ note(product_id) } |
| FOOBAR | ${ note(party_key) } |

Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| path | value |
| name | My Great Product Team |
| ods_code | F5H1R |
| keys.0.key_type | product_team_id_alias |
| keys.0.key_value | FOOBAR |
And I note the response field "$.id" as "product_team_id"
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
| 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_value" as "party_key"
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body:
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body:
| path | value |
| questionnaire_responses.spine_as_additional_interactions.0.Interaction ID | urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
| questionnaire_responses.spine_as_additional_interactions.1.Interaction ID | urn:nhs:names:services:ebs:PRSC_IN080000UK07 |
Expand Down Expand Up @@ -117,3 +128,10 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
| name | value |
| Content-Type | application/json |
| Content-Length | 938 |

Examples:
| product_team_id | product_id |
| ${ note(product_team_id) } | ${ note(product_id) } |
| ${ note(product_team_id) } | ${ note(party_key) } |
| FOOBAR | ${ note(product_id) } |
| FOOBAR | ${ note(party_key) } |
33 changes: 0 additions & 33 deletions src/layers/domain/core/device/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,39 +391,6 @@ def add_questionnaire_response(
},
)

@event
def update_questionnaire_response(
self,
questionnaire_response: QuestionnaireResponse,
) -> QuestionnaireResponseUpdatedEvent:
questionnaire_id = questionnaire_response.questionnaire_id
questionnaire_responses = self.questionnaire_responses.get(questionnaire_id)
created_on = questionnaire_response.created_on

if questionnaire_responses is None:
raise QuestionnaireNotFoundError(
"This device does not contain a Questionnaire "
f"with id '{questionnaire_id}'"
)

current_created_ons = [qr.created_on for qr in questionnaire_responses]
if created_on in current_created_ons:
raise QuestionnaireResponseNotFoundError(
"This device does not contain a Questionnaire with a "
f"response created on '{created_on.isoformat()}'"
)
questionnaire_responses.append(questionnaire_response)

return QuestionnaireResponseUpdatedEvent(
id=self.id,
keys=[k.dict() for k in self.keys],
tags=[t.value for t in self.tags],
questionnaire_responses={
q_name: [qr.dict() for qr in qrs]
for q_name, qrs in self.questionnaire_responses.items()
},
)

def is_active(self):
return self.status is Status.ACTIVE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json

from domain.repository.device_repository.tests.utils import devices_exactly_equal
import pytest
from domain.core.device.v3 import Device
from domain.core.questionnaire.v3 import Questionnaire
Expand Down Expand Up @@ -105,47 +104,3 @@ def test__device_repository__with_questionnaires_and_tags(
)
== device
)


@pytest.mark.integration
def test__device_repository__modify_questionnaire_response_that_has_been_persisted(
device: Device, repository: DeviceRepository, shoe_questionnaire: Questionnaire
):
# Persist model before updating model
repository.write(device)
intermediate_device = repository.read(
product_team_id=device.product_team_id,
product_id=device.product_id,
id=device.id,
)

# Update the model
questionnaire_responses = intermediate_device.questionnaire_responses
assert len(questionnaire_responses["shoe/1"]) == 2
(_questionnaire_response, _) = questionnaire_responses["shoe/1"]

questionnaire_response = shoe_questionnaire.validate(
{"foot": "R", "shoe-size": 789}
)
questionnaire_response.created_on = _questionnaire_response.created_on

intermediate_device.update_questionnaire_response(
questionnaire_response=questionnaire_response
)

# Persist and verify consistency
repository.write(intermediate_device)
device_from_db = repository.read(
product_team_id=intermediate_device.product_team_id,
product_id=intermediate_device.product_id,
id=intermediate_device.id,
)
assert devices_exactly_equal(device_from_db, intermediate_device)
assert not devices_exactly_equal(device_from_db, device)
assert device_from_db.questionnaire_responses["shoe/1"][-1].data == {
"foot": ["R"],
"shoe-size": [789],
}

assert device_from_db.created_on == device.created_on
assert device_from_db.updated_on > device.updated_on
3 changes: 1 addition & 2 deletions src/layers/domain/repository/device_repository/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,10 @@ def handle_QuestionnaireResponseUpdatedEvent(
)

# Update "questionnaire_responses" on the tag-indexed Devices
tag_values = {DeviceTag(__root__=tag) for tag in event.tags}
update_tag_transactions = update_tag_indexes(
table_name=self.table_name,
device_id=event.id,
tag_values=tag_values,
tag_values=event.tags,
data=data,
)
return update_root_and_key_transactions + update_tag_transactions
Expand Down

0 comments on commit bda5169

Please sign in to comment.