Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
3f6f092
NRL-1176 Fix warnings in integration tests due to pointer already del…
axelkrastek1-nhs Nov 12, 2024
e716136
NRL-853 WIP cloud backup setup
katebobyn-nhs Nov 15, 2024
732c833
[NRL-853] Fix perms errors with AWSCC resources for backup restore te…
mattdean3-nhs Nov 18, 2024
b00d598
[NRL-853] Move notification email config out of lambda-error module a…
mattdean3-nhs Nov 18, 2024
b465e2b
NRL-853 combine dynamodb and s3 policies, protect access to report bu…
katebobyn-nhs Nov 18, 2024
87b7316
NRL-853 add backup tag to pointer table
katebobyn-nhs Nov 18, 2024
e18d117
NRL-853 disallow http requests in s3 buckets
katebobyn-nhs Nov 18, 2024
2c6ef7e
NRL-519 add practice setting codes from nrl2.8 to FHIR resources
katebobyn-nhs Nov 18, 2024
a4a9fd8
[NRL-853] Move backup infrastructure TF state into S3 and add README.…
mattdean3-nhs Nov 19, 2024
d6376e7
NRL-1075 split category by list for multi category search
eesa456 Nov 22, 2024
22e931b
NRL-1075 less duplication
eesa456 Nov 22, 2024
1ebf07b
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Nov 22, 2024
bd0ce6b
NRL-853 fix tags for table and buckets
katebobyn-nhs Nov 22, 2024
ef6a542
NRL-853 fix tags to match policy
katebobyn-nhs Nov 22, 2024
dd52446
NRL-1075 add tests
eesa456 Nov 22, 2024
1d715a2
NRL-853 split back into different plans for s3 and ddb
katebobyn-nhs Nov 22, 2024
179eeb9
NRL-853 split back into different plans for s3 and ddb
katebobyn-nhs Nov 22, 2024
cd14fd7
Merge branch 'develop' into feature/kabo5-NRL-853-cloud-backup-red-line
katebobyn-nhs Nov 22, 2024
29e4dae
NRL-1075 fix test
eesa456 Nov 22, 2024
31501c8
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Nov 22, 2024
aae1596
[NRL-1192] Add LICENSE file with MIT license
mattdean3-nhs Nov 25, 2024
8de586c
NRL-519 add practice setting validator
katebobyn-nhs Nov 26, 2024
ad5110e
Merge branch 'develop' into feature/kabo5-NRL519-validate-practice-se…
katebobyn-nhs Nov 26, 2024
1d0756d
Merge pull request #749 from NHSDigital/feature/made14-NRL-1192-add-l…
mattdean3-nhs Nov 26, 2024
eea1b39
Merge branch 'develop' into feature/eema1-NRL-1075-multiCategorySearch
mattdean3-nhs Nov 27, 2024
aed5ca6
NRL-519 add unit tests
katebobyn-nhs Nov 29, 2024
94f08db
SPII-000 add context to smoke test setup
eesa456 Nov 29, 2024
7ec8278
NRL-1213 add smoke tests to pr deploy workflow
eesa456 Nov 29, 2024
70dbd40
Merge pull request #748 from NHSDigital/feature/eema1-NRL-1075-multiC…
eesa456 Nov 29, 2024
23095a9
NRL-000 add mising type display
eesa456 Nov 29, 2024
7882742
Merge branch 'develop' into feature/eema1-fix-smoke-tests
eesa456 Nov 29, 2024
08520f2
NRL-1213 make smoke test public
eesa456 Nov 29, 2024
1da2c66
NRL-000 Merge branch 'feature/eema1-fix-smoke-tests' of github.com:NH…
eesa456 Nov 29, 2024
0f71411
NRL-000 use pr env for smoke tests - internal
eesa456 Nov 29, 2024
1f3e502
NRL-000 stay on mgmt acct for smoke tests
eesa456 Nov 29, 2024
13a863e
NRL-000 run smoke tests after perf tests
eesa456 Nov 29, 2024
515c7e7
NRL-1213 move smoke tests up and change call
eesa456 Nov 29, 2024
dd1e91d
NRL-000 trying something
eesa456 Nov 30, 2024
2eea40c
NRL-853 use different tags for S3 an dynamodb resources
katebobyn-nhs Dec 1, 2024
cb8d949
NRL-000 setup python env
eesa456 Dec 2, 2024
db37396
NRL-1213 comment out smoke test
eesa456 Dec 2, 2024
3ba98a4
Merge branch 'feature/kabo5-NRL-853-cloud-backup-red-line' of https:/…
katebobyn-nhs Dec 2, 2024
d15fcae
[NRL-000] Fix up smoke tests to use TF to get domain
mattdean3-nhs Dec 2, 2024
61fad34
[NRL-853] Added backup destination vault arn as secret. Moved backup …
mattdean3-nhs Dec 2, 2024
8ab94e2
Merge pull request #754 from NHSDigital/feature/eema1-fix-smoke-tests
mattdean3-nhs Dec 2, 2024
64cf5f4
NRL-518 Validate display as per the definition
axelkrastek1-nhs Nov 27, 2024
dcde0a9
NRL-518 Fix pydantic error reporting
axelkrastek1-nhs Dec 2, 2024
a50f1a5
NRL-518 Update models with mandatory fields
axelkrastek1-nhs Dec 2, 2024
d29aa5f
NRL-518 Add step for upserts, refactor create and upsert into one method
axelkrastek1-nhs Dec 2, 2024
d58fdca
NRL-518 Add default format to default test document reference
axelkrastek1-nhs Dec 3, 2024
548435b
NRL-518 Fix parameter should not be fix to content
axelkrastek1-nhs Dec 3, 2024
84a5f10
NRL-518 Add method to change default parameters for an update
axelkrastek1-nhs Dec 3, 2024
d3f26c6
NRL-518 Add validator method for content and add tests
axelkrastek1-nhs Dec 3, 2024
02a9a7e
NRL-518 Fix default contentType
axelkrastek1-nhs Dec 3, 2024
de90659
NRL-518 Fix integration tests expected without format
axelkrastek1-nhs Dec 3, 2024
48ace9e
NRL-518 Add ContentStability value set
axelkrastek1-nhs Dec 3, 2024
7a6e430
NRL-518 Fix smoke tests missing format
axelkrastek1-nhs Dec 3, 2024
3c6c1b8
NRL-518 Fix unused parameter
axelkrastek1-nhs Dec 3, 2024
4820d08
NRL-518 Fix content_type for smoke test
axelkrastek1-nhs Dec 3, 2024
32e1363
NRL-518 Fix format for smoke tests
axelkrastek1-nhs Dec 3, 2024
7b7f2bd
NRL-518 Add documentation for content validation
axelkrastek1-nhs Dec 4, 2024
6b8e9e6
NRL-518 Add NRLFormatCode valueset
axelkrastek1-nhs Dec 4, 2024
202b4f7
NRL-518 Update postman link in documentation
axelkrastek1-nhs Dec 4, 2024
9f44e02
NRL-519 include practice setting in integration tests
katebobyn-nhs Dec 4, 2024
ef96623
NRL-519 include practice setting in integration tests
katebobyn-nhs Dec 4, 2024
dbde35d
NRL-519 include practice setting in integration tests
katebobyn-nhs Dec 4, 2024
4b3ab85
NRL-519 include practice setting in integration tests
katebobyn-nhs Dec 4, 2024
04b2c9d
NRL-519 include practice setting in integration tests
katebobyn-nhs Dec 4, 2024
97be487
NRL-1137 implement daily builds workflow
eesa456 Dec 5, 2024
4d1220a
NRL-477 validate docStatus
eesa456 Dec 5, 2024
da4802c
NRL-502 validate format code for attachment types
eesa456 Dec 5, 2024
772a93b
NRL-502 add integration test
eesa456 Dec 5, 2024
a8c0352
NRL-502 add format to setup
eesa456 Dec 5, 2024
37aed66
NRL-502 fix tests
eesa456 Dec 5, 2024
31d2dc9
NRL-502 fix new tests
eesa456 Dec 5, 2024
2aef83d
NRL-519 add create failure scenarios for invalid practice settings
katebobyn-nhs Dec 5, 2024
39645c0
Merge branch 'develop' into feature/kabo5-NRL519-validate-practice-se…
katebobyn-nhs Dec 5, 2024
4f64694
NRL-519 update smoketest to use a valid practiceSetting
katebobyn-nhs Dec 5, 2024
8e4aa3e
NRL-519 fix confounding issue in create integration test
katebobyn-nhs Dec 5, 2024
c52fc09
NRL-519 fix formatting error
katebobyn-nhs Dec 5, 2024
5a46d45
NRL-518 Remove tests no longer valid due to upstream pydantic validation
axelkrastek1-nhs Dec 5, 2024
b9f7d40
NRL-519 implement sonarcloud suggestions
katebobyn-nhs Dec 5, 2024
bfc1850
NRL-519 implement sonarcloud suggestions
katebobyn-nhs Dec 5, 2024
e6d10c6
NRL-518 Simplify test, fix lint warnings
axelkrastek1-nhs Dec 5, 2024
1d58d65
NRL-518 Revert contentType regex to simple version
axelkrastek1-nhs Dec 5, 2024
90822a6
NRL-518 Fix lint issue
axelkrastek1-nhs Dec 5, 2024
07fd1e3
NRL-518 Remove checks, pydantic validates that, add invalid contentTy…
axelkrastek1-nhs Dec 5, 2024
3d8f0bd
NRL-518 Improve pydantic diagnostic message
axelkrastek1-nhs Dec 5, 2024
75534a3
NRL-518 ContentStability validation mostly on pydantic
axelkrastek1-nhs Dec 6, 2024
3452fa3
NRL-518 Better naming for scenario
axelkrastek1-nhs Dec 6, 2024
9bc5d31
NRL-518 Better format for single value enum in swagger
axelkrastek1-nhs Dec 6, 2024
52f1d24
NRL-518 Pydantic will ensure extension is always there
axelkrastek1-nhs Dec 6, 2024
f8663e7
NRL-518 Pydantic format validation, fix casing format display
axelkrastek1-nhs Dec 6, 2024
5098eca
NRL-518 Fix integration tests
axelkrastek1-nhs Dec 6, 2024
aca3ca4
NRL-518 Add value set for pydantic diagnostic messages
axelkrastek1-nhs Dec 6, 2024
7886799
NRL-518 Fix smoke tests
axelkrastek1-nhs Dec 6, 2024
3137b90
NRL-518 Fix linting issue
axelkrastek1-nhs Dec 6, 2024
ed9fd52
Merge pull request #750 from NHSDigital/feature/kabo5-NRL519-validate…
eesa456 Dec 9, 2024
8c5a628
Merge pull request #743 from NHSDigital/feature/kabo5-NRL-853-cloud-b…
eesa456 Dec 9, 2024
58a7408
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Dec 11, 2024
5260be2
NRL-1202 validate type not just system
eesa456 Dec 11, 2024
b67cb13
NRL-1202 fix int tests
eesa456 Dec 11, 2024
e664a3f
Revert "NRL-1202 fix int tests"
eesa456 Dec 11, 2024
c113df8
NRL-518 Add validation for format code display mismatch
axelkrastek1-nhs Dec 11, 2024
e505b70
NRL-518 Add feature tests for format code display mismatch
axelkrastek1-nhs Dec 11, 2024
c62a993
[NRL-853] Fixup S3 bucket tag values
mattdean3-nhs Dec 11, 2024
eed5022
Merge pull request #768 from NHSDigital/feature/made14-NRL-853-fixup-…
mattdean3-nhs Dec 11, 2024
cef4616
NRL-477 update model and error messages
eesa456 Dec 11, 2024
85efa9e
NRL-518 Better model inheritance
axelkrastek1-nhs Dec 11, 2024
22523d9
NRL-518 Update narrative
axelkrastek1-nhs Dec 11, 2024
3595c4f
Merge branch 'develop' into feature/eema1-NRL-1202-permsNotCheckedFor…
eesa456 Dec 11, 2024
cb1375b
Merge pull request #766 from NHSDigital/feature/eema1-NRL-1202-permsN…
eesa456 Dec 11, 2024
d48ab5a
NRL-518 Move content fhir url strings to constants
axelkrastek1-nhs Dec 12, 2024
64e6312
NRL-518 Remove extension from CodeableConcept
axelkrastek1-nhs Dec 12, 2024
a95f144
[NRL-1228] Fix advance care plan naming. Add report script to find in…
mattdean3-nhs Dec 12, 2024
b1cba0a
Merge branch 'develop' into feature/axkr1-NRL-518-validate-context
axelkrastek1-nhs Dec 12, 2024
309c88a
Merge pull request #770 from NHSDigital/bugfix/made14-NRL-1228-advanc…
katebobyn-nhs Dec 12, 2024
c6546b2
Merge branch 'develop' into feature/axkr1-NRL-518-validate-context
eesa456 Dec 13, 2024
d946923
NRL-1076 add integration and unit tests for identifier accession numb…
eesa456 Dec 13, 2024
4abb3e3
NRL-1076 fix tests
eesa456 Dec 13, 2024
8b398a7
NRL-518 add import for smoke tests
eesa456 Dec 13, 2024
e203cc1
[NRL-1228] Fixup sonar cloud warnings
mattdean3-nhs Dec 13, 2024
1754771
NRL-1202 standardise message
eesa456 Dec 13, 2024
26407d4
Merge pull request #772 from NHSDigital/bugfix/made14-NRL-1228-advanc…
mattdean3-nhs Dec 13, 2024
e58aee9
Merge branch 'develop' into feature/axkr1-NRL-518-validate-context
axelkrastek1-nhs Dec 13, 2024
123f837
NRL-1202 fix int tests
eesa456 Dec 13, 2024
889a2a4
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Dec 13, 2024
8215abe
Merge pull request #760 from NHSDigital/feature/axkr1-NRL-518-validat…
eesa456 Dec 13, 2024
99cb5b0
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Dec 13, 2024
9408c91
NRL-477 fix tests
eesa456 Dec 13, 2024
9c16a6c
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Dec 13, 2024
e0aaa15
NRL-477 fix int tests
eesa456 Dec 13, 2024
99d43c1
NRL-477 fix int tests
eesa456 Dec 13, 2024
0db9d07
Merge pull request #762 from NHSDigital/feature/eema1-NRL-477-validat…
eesa456 Dec 13, 2024
19ad615
Merge branch 'develop' of github.com:NHSDigital/NRLF into feature/eem…
eesa456 Dec 13, 2024
32d461f
Merge pull request #771 from NHSDigital/feature/eema1-NRL-1076-Identi…
eesa456 Dec 13, 2024
218d3d5
Merge branch 'develop' into feature/axkr1-NRL-1176-fix-feature-test-e…
katebobyn-nhs Dec 13, 2024
fa1baef
Merge pull request #732 from NHSDigital/feature/axkr1-NRL-1176-fix-fe…
axelkrastek1-nhs Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build NRL Project on Environment
run-name: Build NRL Project on ${{ inputs.environment || 'dev' }}
permissions:
id-token: write
contents: read
actions: write

on:
schedule:
- cron: "0 1 * * *"
workflow_dispatch:
inputs:
environment:
type: environment
description: "The environment to deploy changes to"
default: "dev"
required: true

jobs:
build:
name: Build - develop
runs-on: [self-hosted, ci]

steps:
- name: Git clone - develop
uses: actions/checkout@v4
with:
ref: develop

- name: Setup asdf cache
uses: actions/cache@v4
with:
path: ~/.asdf
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
restore-keys: |
${{ runner.os }}-asdf-

- name: Install asdf
uses: asdf-vm/actions/install@v3.0.2
with:
asdf_branch: v0.13.1

- name: Install zip
run: sudo apt-get install zip

- name: Setup Python environment
run: |
poetry install --no-root
source $(poetry env info --path)/bin/activate

- name: Run Linting
run: make lint

- name: Run Unit Tests
run: make test

- name: Build Project
run: make build

- name: Configure Management Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-2
role-to-assume: ${{ secrets.MGMT_ROLE_ARN }}
role-session-name: github-actions-ci-${{ inputs.environment || 'dev' }}-${{ github.run_id }}

- name: Add S3 Permissions to Lambda
run: |
account=$(echo '${{ inputs.environment || 'dev' }}' | cut -d '-' -f1)
inactive_stack=$(poetry run python ./scripts/get_env_config.py inactive-stack ${{ inputs.environment || 'dev' }})
make get-s3-perms ENV=${account} TF_WORKSPACE_NAME=${inactive_stack}

- name: Save Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/*.zip
!dist/nrlf_permissions.zip

- name: Save NRLF Permissions cache
uses: actions/cache/save@v4
with:
key: ${{ github.run_id }}-nrlf-permissions
path: dist/nrlf_permissions.zip
47 changes: 47 additions & 0 deletions .github/workflows/pr-env-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,53 @@ jobs:
- name: Run Integration Tests
run: make test-features-integration TF_WORKSPACE_NAME=${{ needs.set-environment-id.outputs.environment_id }}

smoke-test:
name: Run Smoke Tests
needs: [set-environment-id, integration-test]
environment: pull-request
runs-on: [self-hosted, ci]
steps:
- name: Git Clone - ${{ github.event.pull_request.head.ref }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup asdf cache
uses: actions/cache@v4
with:
path: ~/.asdf
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
restore-keys: |
${{ runner.os }}-asdf-

- name: Install asdf and tools
uses: asdf-vm/actions/install@v3.0.2
with:
asdf_branch: v0.13.1

- name: Setup Python environment
run: |
poetry install --no-root
source $(poetry env info --path)/bin/activate

- name: Configure Management Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-2
role-to-assume: ${{ secrets.MGMT_ROLE_ARN }}
role-session-name: github-actions-ci-${{ needs.set-environment-id.outputs.environment_id }}

- name: Terraform Init
run: |
terraform -chdir=terraform/infrastructure init
terraform -chdir=terraform/infrastructure workspace new ${{ needs.set-environment-id.outputs.environment_id }} || \
terraform -chdir=terraform/infrastructure workspace select ${{ needs.set-environment-id.outputs.environment_id }}

- name: Smoke Test
run: |
make ENV=dev truststore-pull-client
make ENV=dev TF_WORKSPACE_NAME=${{ needs.set-environment-id.outputs.environment_id }} test-smoke-internal

performance-test:
name: Run Performance Tests
needs: [set-environment-id, integration-test]
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Crown Copyright

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from nrlf.core.logger import LogReference, logger
from nrlf.core.model import ConnectionMetadata, ConsumerRequestParams
from nrlf.core.response import Response, SpineErrorResponse
from nrlf.core.validators import validate_category, validate_type_system
from nrlf.core.validators import validate_category, validate_type


@request_handler(params=ConsumerRequestParams)
Expand Down Expand Up @@ -46,19 +46,19 @@ def handler(
base_url = f"https://{config.ENVIRONMENT}.api.service.nhs.uk/"
self_link = f"{base_url}record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|{params.nhs_number}"

# TODO - Add checks for the type code as well as system
if not validate_type_system(params.type, metadata.pointer_types):
if not validate_type(params.type, metadata.pointer_types):
logger.log(
LogReference.CONSEARCH002,
type=params.type,
pointer_types=metadata.pointer_types,
)
return SpineErrorResponse.INVALID_CODE_SYSTEM(
diagnostics="Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
diagnostics="Invalid query parameter (The provided type does not match the allowed types for this organisation)",
expression="type",
)

if not validate_category(params.category):
categories = params.category.root.split(",") if params.category else []
if not validate_category(categories):
logger.log(
LogReference.CONSEARCH002b,
category=params.category,
Expand Down Expand Up @@ -102,7 +102,7 @@ def handler(
nhs_number=params.nhs_number,
custodian=custodian_id,
pointer_types=pointer_types,
categories=[params.category.root] if params.category else [],
categories=categories,
):
try:
document_reference = DocumentReference.model_validate_json(result.document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
from moto import mock_aws

from api.consumer.searchDocumentReference.search_document_reference import handler
from nrlf.core.constants import (
CATEGORY_ATTRIBUTES,
TYPE_ATTRIBUTES,
Categories,
PointerTypes,
)
from nrlf.core.dynamodb.repository import DocumentPointer, DocumentPointerRepository
from nrlf.tests.data import load_document_reference
from nrlf.tests.dynamodb import mock_repository
Expand Down Expand Up @@ -53,6 +59,56 @@ def test_search_document_reference_happy_path(repository: DocumentPointerReposit
}


@mock_aws
@mock_repository
def test_search_document_reference_accession_number_in_pointer(
repository: DocumentPointerRepository,
):
doc_ref = load_document_reference("Y05868-736253002-Valid")
doc_ref.identifier = [
{"type": {"text": "Accession-Number"}, "value": "Y05868.123456789"}
]
doc_pointer = DocumentPointer.from_document_reference(doc_ref)
repository.create(doc_pointer)

event = create_test_api_gateway_event(
headers=create_headers(),
query_string_parameters={
"subject:identifier": "https://fhir.nhs.uk/Id/nhs-number|6700028191",
},
)

result = handler(event, create_mock_context())
body = result.pop("body")

assert result == {
"statusCode": "200",
"headers": default_response_headers(),
"isBase64Encoded": False,
}

parsed_body = json.loads(body)
assert parsed_body == {
"resourceType": "Bundle",
"type": "searchset",
"total": 1,
"link": [
{
"relation": "self",
"url": "https://pytest.api.service.nhs.uk/record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|6700028191",
}
],
"entry": [{"resource": doc_ref.model_dump(exclude_none=True)}],
}

created_doc_pointer = repository.get_by_id("Y05868-99999-99999-999999")

assert created_doc_pointer is not None
assert json.loads(created_doc_pointer.document)["identifier"] == [
{"type": {"text": "Accession-Number"}, "value": "Y05868.123456789"}
]


@mock_aws
@mock_repository
def test_search_document_reference_happy_path_with_custodian(
Expand Down Expand Up @@ -144,6 +200,19 @@ def test_search_document_reference_happy_path_with_category(
doc_pointer = DocumentPointer.from_document_reference(doc_ref)
repository.create(doc_pointer)

# Second pointer different category
doc_ref2 = load_document_reference("Y05868-736253002-Valid")
doc_ref2.id = "Y05868-736253002-Valid2"
doc_ref2.type.coding[0].code = PointerTypes.NEWS2_CHART.coding_value()
doc_ref2.type.coding[0].display = TYPE_ATTRIBUTES.get(
PointerTypes.NEWS2_CHART.value
).get("display")
doc_ref2.category[0].coding[0].code = Categories.OBSERVATIONS.coding_value()
doc_ref2.category[0].coding[0].display = CATEGORY_ATTRIBUTES.get(
Categories.OBSERVATIONS.value
).get("display")
repository.create(DocumentPointer.from_document_reference(doc_ref2))

event = create_test_api_gateway_event(
headers=create_headers(),
query_string_parameters={
Expand All @@ -160,7 +229,6 @@ def test_search_document_reference_happy_path_with_category(
"headers": default_response_headers(),
"isBase64Encoded": False,
}

parsed_body = json.loads(body)
assert parsed_body == {
"resourceType": "Bundle",
Expand All @@ -176,6 +244,63 @@ def test_search_document_reference_happy_path_with_category(
}


@mock_aws
@mock_repository
def test_search_document_reference_happy_path_with_multiple_categories(
repository: DocumentPointerRepository,
):
doc_ref = load_document_reference("Y05868-736253002-Valid")
doc_pointer = DocumentPointer.from_document_reference(doc_ref)
repository.create(doc_pointer)

# Second pointer different category
doc_ref2 = load_document_reference("Y05868-736253002-Valid")
doc_ref2.id = "Y05868-736253002-Valid2"
doc_ref2.type.coding[0].code = PointerTypes.NEWS2_CHART.coding_value()
doc_ref2.type.coding[0].display = TYPE_ATTRIBUTES.get(
PointerTypes.NEWS2_CHART.value
).get("display")
doc_ref2.category[0].coding[0].code = Categories.OBSERVATIONS.coding_value()
doc_ref2.category[0].coding[0].display = CATEGORY_ATTRIBUTES.get(
Categories.OBSERVATIONS.value
).get("display")
repository.create(DocumentPointer.from_document_reference(doc_ref2))

event = create_test_api_gateway_event(
headers=create_headers(),
query_string_parameters={
"subject:identifier": "https://fhir.nhs.uk/Id/nhs-number|6700028191",
"category": "http://snomed.info/sct|734163000,http://snomed.info/sct|1102421000000108",
},
)

result = handler(event, create_mock_context())
body = result.pop("body")

assert result == {
"statusCode": "200",
"headers": default_response_headers(),
"isBase64Encoded": False,
}

parsed_body = json.loads(body)
assert parsed_body == {
"resourceType": "Bundle",
"type": "searchset",
"link": [
{
"relation": "self",
"url": "https://pytest.api.service.nhs.uk/record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|6700028191&category=http://snomed.info/sct|734163000,http://snomed.info/sct|1102421000000108",
}
],
"total": 2,
"entry": [
{"resource": doc_ref2.model_dump(exclude_none=True)},
{"resource": doc_ref.model_dump(exclude_none=True)},
],
}


@mock_aws
@mock_repository
def test_search_document_reference_happy_path_with_nicip_type(
Expand Down Expand Up @@ -376,7 +501,7 @@ def test_search_document_reference_invalid_type(repository: DocumentPointerRepos
}
]
},
"diagnostics": "Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
"diagnostics": "Invalid query parameter (The provided type does not match the allowed types for this organisation)",
"expression": ["type"],
}
],
Expand Down
Loading
Loading