Skip to content

Commit 0db9d07

Browse files
authored
Merge pull request #762 from NHSDigital/feature/eema1-NRL-477-validateDocStatusAndDailyBuildAndFormatCode
NRL-477, NRL-502, NRL-1137 validate doc status and daily build and format code
2 parents 8215abe + 99d43c1 commit 0db9d07

File tree

13 files changed

+507
-151
lines changed

13 files changed

+507
-151
lines changed

.github/workflows/daily-build.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build NRL Project on Environment
2+
run-name: Build NRL Project on ${{ inputs.environment || 'dev' }}
3+
permissions:
4+
id-token: write
5+
contents: read
6+
actions: write
7+
8+
on:
9+
schedule:
10+
- cron: "0 1 * * *"
11+
workflow_dispatch:
12+
inputs:
13+
environment:
14+
type: environment
15+
description: "The environment to deploy changes to"
16+
default: "dev"
17+
required: true
18+
19+
jobs:
20+
build:
21+
name: Build - develop
22+
runs-on: [self-hosted, ci]
23+
24+
steps:
25+
- name: Git clone - develop
26+
uses: actions/checkout@v4
27+
with:
28+
ref: develop
29+
30+
- name: Setup asdf cache
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.asdf
34+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
35+
restore-keys: |
36+
${{ runner.os }}-asdf-
37+
38+
- name: Install asdf
39+
uses: asdf-vm/actions/[email protected]
40+
with:
41+
asdf_branch: v0.13.1
42+
43+
- name: Install zip
44+
run: sudo apt-get install zip
45+
46+
- name: Setup Python environment
47+
run: |
48+
poetry install --no-root
49+
source $(poetry env info --path)/bin/activate
50+
51+
- name: Run Linting
52+
run: make lint
53+
54+
- name: Run Unit Tests
55+
run: make test
56+
57+
- name: Build Project
58+
run: make build
59+
60+
- name: Configure Management Credentials
61+
uses: aws-actions/configure-aws-credentials@v4
62+
with:
63+
aws-region: eu-west-2
64+
role-to-assume: ${{ secrets.MGMT_ROLE_ARN }}
65+
role-session-name: github-actions-ci-${{ inputs.environment || 'dev' }}-${{ github.run_id }}
66+
67+
- name: Add S3 Permissions to Lambda
68+
run: |
69+
account=$(echo '${{ inputs.environment || 'dev' }}' | cut -d '-' -f1)
70+
inactive_stack=$(poetry run python ./scripts/get_env_config.py inactive-stack ${{ inputs.environment || 'dev' }})
71+
make get-s3-perms ENV=${account} TF_WORKSPACE_NAME=${inactive_stack}
72+
73+
- name: Save Build Artifacts
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: build-artifacts
77+
path: |
78+
dist/*.zip
79+
!dist/nrlf_permissions.zip
80+
81+
- name: Save NRLF Permissions cache
82+
uses: actions/cache/save@v4
83+
with:
84+
key: ${{ github.run_id }}-nrlf-permissions
85+
path: dist/nrlf_permissions.zip

api/consumer/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ components:
788788
description: The status of this document reference.
789789
docStatus:
790790
type: string
791-
pattern: "[^\\s]+(\\s[^\\s]+)*"
791+
enum: ["entered-in-error", "amended", "preliminary", "final"]
792792
description: The status of the underlying document.
793793
type:
794794
$ref: "#/components/schemas/CodeableConcept"

api/producer/createDocumentReference/tests/test_create_document_reference.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,47 @@ def test_create_document_reference_with_no_practiceSetting():
411411
}
412412

413413

414+
def test_create_document_reference_with_invalid_docStatus():
415+
doc_ref = load_document_reference("Y05868-736253002-Valid")
416+
doc_ref.docStatus = "invalid"
417+
418+
event = create_test_api_gateway_event(
419+
headers=create_headers(),
420+
body=doc_ref.model_dump_json(exclude_none=True),
421+
)
422+
423+
result = handler(event, create_mock_context())
424+
body = result.pop("body")
425+
426+
assert result == {
427+
"statusCode": "400",
428+
"headers": default_response_headers(),
429+
"isBase64Encoded": False,
430+
}
431+
432+
parsed_body = json.loads(body)
433+
assert parsed_body == {
434+
"resourceType": "OperationOutcome",
435+
"issue": [
436+
{
437+
"severity": "error",
438+
"code": "invalid",
439+
"details": {
440+
"coding": [
441+
{
442+
"code": "MESSAGE_NOT_WELL_FORMED",
443+
"display": "Message not well formed",
444+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
445+
}
446+
],
447+
},
448+
"diagnostics": "Request body could not be parsed (docStatus: Input should be 'entered-in-error', 'amended', 'preliminary' or 'final')",
449+
"expression": ["docStatus"],
450+
},
451+
],
452+
}
453+
454+
414455
def test_create_document_reference_invalid_custodian_id():
415456
doc_ref = load_document_reference("Y05868-736253002-Valid")
416457

api/producer/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ components:
13511351
description: The status of this document reference.
13521352
docStatus:
13531353
type: string
1354-
pattern: "[^\\s]+(\\s[^\\s]+)*"
1354+
enum: ["entered-in-error", "amended", "preliminary", "final"]
13551355
description: The status of the underlying document.
13561356
type:
13571357
$ref: "#/components/schemas/CodeableConcept"

api/producer/upsertDocumentReference/tests/test_upsert_document_reference.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,47 @@ def test_upsert_document_reference_with_no_practiceSetting():
455455
}
456456

457457

458+
def test_upsert_document_reference_with_invalid_docStatus():
459+
doc_ref = load_document_reference("Y05868-736253002-Valid")
460+
doc_ref.docStatus = "invalid"
461+
462+
event = create_test_api_gateway_event(
463+
headers=create_headers(),
464+
body=doc_ref.model_dump_json(exclude_none=True),
465+
)
466+
467+
result = handler(event, create_mock_context())
468+
body = result.pop("body")
469+
470+
assert result == {
471+
"statusCode": "400",
472+
"headers": default_response_headers(),
473+
"isBase64Encoded": False,
474+
}
475+
476+
parsed_body = json.loads(body)
477+
assert parsed_body == {
478+
"resourceType": "OperationOutcome",
479+
"issue": [
480+
{
481+
"severity": "error",
482+
"code": "invalid",
483+
"details": {
484+
"coding": [
485+
{
486+
"code": "MESSAGE_NOT_WELL_FORMED",
487+
"display": "Message not well formed",
488+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
489+
}
490+
],
491+
},
492+
"diagnostics": "Request body could not be parsed (docStatus: Input should be 'entered-in-error', 'amended', 'preliminary' or 'final')",
493+
"expression": ["docStatus"],
494+
},
495+
],
496+
}
497+
498+
458499
def test_upsert_document_reference_invalid_producer_id():
459500
doc_ref = load_document_reference("Y05868-736253002-Valid")
460501
doc_ref.id = "X26-99999-99999-999999"

layer/nrlf/consumer/fhir/r4/model.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: swagger.yaml
3-
# timestamp: 2024-12-12T13:19:56+00:00
3+
# timestamp: 2024-12-13T11:19:30+00:00
44

55
from __future__ import annotations
66

@@ -669,11 +669,8 @@ class DocumentReference(BaseModel):
669669
),
670670
]
671671
docStatus: Annotated[
672-
Optional[str],
673-
Field(
674-
description="The status of the underlying document.",
675-
pattern="[^\\s]+(\\s[^\\s]+)*",
676-
),
672+
Optional[Literal["entered-in-error", "amended", "preliminary", "final"]],
673+
Field(description="The status of the underlying document."),
677674
] = None
678675
type: Annotated[
679676
Optional[CodeableConcept],

0 commit comments

Comments
 (0)