Skip to content

Commit 8d62e29

Browse files
authored
[PRMP-908] Refactor MNS document review logic and handling (#933)
1 parent 7233ab2 commit 8d62e29

16 files changed

+1035
-241
lines changed

.github/workflows/base-e2e-mns.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "Z-BASE E2e Test: MNS E2E Tests"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
build_branch:
7+
description: "Branch with e2e tests."
8+
required: true
9+
type: "string"
10+
environment:
11+
description: "Which Environment type are we using"
12+
required: true
13+
type: "string"
14+
sandbox:
15+
description: "Sandbox to run the smoke tests on."
16+
required: true
17+
type: "string"
18+
secrets:
19+
AWS_ASSUME_ROLE:
20+
required: true
21+
22+
permissions:
23+
pull-requests: write
24+
id-token: write
25+
contents: read
26+
27+
jobs:
28+
mns-e2e-test:
29+
runs-on: ubuntu-latest
30+
environment: ${{ inputs.environment }}
31+
strategy:
32+
matrix:
33+
test-file:
34+
- test_mns_process.py
35+
- test_mns_death.py
36+
fail-fast: false
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v6
40+
with:
41+
repository: "NHSDigital/national-document-repository"
42+
ref: ${{ inputs.build_branch }}
43+
44+
- name: AWS Role
45+
uses: aws-actions/configure-aws-credentials@v5
46+
with:
47+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
48+
role-skip-session-tagging: true
49+
mask-aws-account-id: true
50+
aws-region: ${{ vars.AWS_REGION }}
51+
52+
- name: Set up Python 3.11
53+
uses: actions/setup-python@v6
54+
with:
55+
python-version: 3.11
56+
57+
- name: Make virtual environment
58+
run: |
59+
make env
60+
61+
- name: Start virtual environment
62+
run: |
63+
source ./lambdas/venv/bin/activate
64+
echo PATH=$PATH >> $GITHUB_ENV
65+
66+
67+
- name: Set E2e Test Variables
68+
run: |
69+
AWS_WORKSPACE="${SANDBOX}"
70+
AWS_DEFAULT_REGION=${{ vars.AWS_REGION }}
71+
echo "AWS_WORKSPACE=$AWS_WORKSPACE" >> $GITHUB_ENV
72+
echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION" >> $GITHUB_ENV
73+
env:
74+
SANDBOX: ${{ inputs.sandbox }}
75+
76+
- name: Run MNS E2E Test - ${{ matrix.test-file }}
77+
run: |
78+
cd ./lambdas && ./venv/bin/python3 -m pytest tests/e2e/mns/${{ matrix.test-file }} -vv

.github/workflows/full-deploy-to-sandbox.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ jobs:
138138
secrets:
139139
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
140140

141+
run_mns_e2etest:
142+
uses: ./.github/workflows/base-e2e-mns.yml
143+
needs: ["disable_fhir_stub"]
144+
with:
145+
build_branch: ${{ inputs.build_branch }}
146+
environment: development
147+
sandbox: ${{ inputs.sandbox }}
148+
secrets:
149+
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
150+
141151
deploy_ui:
142152
name: Deploy UI
143153
uses: ./.github/workflows/base-deploy-ui.yml

.github/workflows/lambdas-deploy-feature-to-sandbox.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,13 @@ jobs:
119119
sandbox: ${{ inputs.sandbox }}
120120
secrets:
121121
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
122+
123+
run_mns_e2etest:
124+
uses: ./.github/workflows/base-e2e-mns.yml
125+
needs: ["deploy_all_lambdas", "disable_fhir_stub"]
126+
with:
127+
build_branch: ${{ inputs.build_branch }}
128+
environment: development
129+
sandbox: ${{ inputs.sandbox }}
130+
secrets:
131+
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

.github/workflows/ndr-e2e-test-sandbox.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ jobs:
5757
sandbox: ${{ inputs.sandbox }}
5858
secrets:
5959
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
60+
61+
services-mns-e2etest:
62+
uses: ./.github/workflows/base-e2e-mns.yml
63+
with:
64+
build_branch: ${{ inputs.build_branch }}
65+
environment: ${{ inputs.environment }}
66+
sandbox: ${{ inputs.sandbox }}
67+
secrets:
68+
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

lambdas/enums/lambda_error.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
from enum import Enum
1+
from enum import Enum, StrEnum
22
from typing import Optional
33

44
from enums.fhir.fhir_issue_type import FhirIssueCoding, UKCoreSpineError
55
from utils.error_response import ErrorResponse
66
from utils.request_context import request_context
77

8-
9-
class LambdaError(Enum):
8+
class ErrorMessage(StrEnum):
109
MISSING_POST = "Missing POST request body"
1110
MISSING_KEY = "An error occurred due to missing key"
1211
RETRIEVE_DOCUMENTS = "Unable to retrieve documents for patient"
12+
FAILED_TO_QUERY_DYNAMO = "Failed to query DynamoDB"
13+
FAILED_TO_VALIDATE = "Failed to validate data"
14+
FAILED_TO_UPDATE_DYNAMO = "Failed to update DynamoDB"
15+
FAILED_TO_CREATE_TRANSACTION = "Failed to create transaction"
16+
17+
class LambdaError(Enum):
1318

1419
def create_error_response(
1520
self, params: Optional[dict] = None, **kwargs
@@ -240,15 +245,15 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
240245
}
241246
ManifestMissingBody = {
242247
"err_code": "DMS_4002",
243-
"message": MISSING_POST,
248+
"message": ErrorMessage.MISSING_POST,
244249
}
245250
ManifestFilterDocumentReferences = {
246251
"err_code": "DMS_4003",
247252
"message": "Selected document references do not match any documents stored for this patient",
248253
}
249254
ManifestMissingJobId = {
250255
"err_code": "DMS_4004",
251-
"message": MISSING_KEY,
256+
"message": ErrorMessage.MISSING_KEY,
252257
}
253258
ManifestMissingJob = {
254259
"err_code": "DMS_4005",
@@ -272,19 +277,19 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
272277
}
273278
StitchNoService = {
274279
"err_code": "LGS_5001",
275-
"message": RETRIEVE_DOCUMENTS,
280+
"message": ErrorMessage.RETRIEVE_DOCUMENTS,
276281
}
277282
StitchClient = {
278283
"err_code": "LGS_5002",
279284
"message": "Unable to return stitched pdf file due to internal error",
280285
}
281286
StitchDB = {
282287
"err_code": "LGS_5003",
283-
"message": RETRIEVE_DOCUMENTS,
288+
"message": ErrorMessage.RETRIEVE_DOCUMENTS,
284289
}
285290
StitchValidation = {
286291
"err_code": "LGS_5004",
287-
"message": RETRIEVE_DOCUMENTS,
292+
"message": ErrorMessage.RETRIEVE_DOCUMENTS,
288293
}
289294
StitchCloudFront = {
290295
"err_code": "LGS_5005",
@@ -325,7 +330,7 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
325330
"""
326331
FeedbackMissingBody = {
327332
"err_code": "SFB_4001",
328-
"message": MISSING_POST,
333+
"message": ErrorMessage.MISSING_POST,
329334
}
330335

331336
FeedbackInvalidBody = {
@@ -612,7 +617,7 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
612617
}
613618
DocTypeKey = {
614619
"err_code": "VDT_4003",
615-
"message": MISSING_KEY,
620+
"message": ErrorMessage.MISSING_KEY,
616621
}
617622
PatientIdInvalid = {
618623
"err_code": "PN_4001",
@@ -621,7 +626,7 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
621626
}
622627
PatientIdNoKey = {
623628
"err_code": "PN_4002",
624-
"message": MISSING_KEY,
629+
"message": ErrorMessage.MISSING_KEY,
625630
"fhir_coding": UKCoreSpineError.MISSING_VALUE,
626631
}
627632
PatientIdMismatch = {
@@ -671,7 +676,7 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
671676
"""
672677
DocumentReviewDB = {
673678
"err_code": "UDR_5001",
674-
"message": RETRIEVE_DOCUMENTS,
679+
"message": ErrorMessage.RETRIEVE_DOCUMENTS,
675680
}
676681

677682
DocumentReviewValidation = {

lambdas/services/document_service.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def fetch_documents_from_table(
109109
def get_item(
110110
self,
111111
document_id: str,
112-
sort_key: dict = None,
112+
sort_key: dict | None = None,
113113
table_name: str = None,
114114
model_class: type[BaseModel] = None,
115115
) -> Optional[BaseModel]:
@@ -218,7 +218,7 @@ def update_document(
218218
update_fields_name: set[str] | None = None,
219219
condition_expression: str | Attr | ConditionBase = None,
220220
expression_attribute_values: dict = None,
221-
key_pair: dict | None = None
221+
key_pair: dict | None = None,
222222
):
223223
"""Update document in specified or configured table."""
224224
table_name = table_name or self.table_name
@@ -228,13 +228,9 @@ def update_document(
228228
"updated_fields": document.model_dump(
229229
exclude_none=True, by_alias=True, include=update_fields_name
230230
),
231+
"key_pair": key_pair
232+
or {DocumentReferenceMetadataFields.ID.value: document.id},
231233
}
232-
if key_pair:
233-
update_kwargs["key_pair"] = key_pair
234-
else:
235-
update_kwargs["key_pair"] = {
236-
DocumentReferenceMetadataFields.ID.value: document.id
237-
}
238234

239235
if condition_expression:
240236
update_kwargs["condition_expression"] = condition_expression

0 commit comments

Comments
 (0)