Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions lambdas/enums/supported_document_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class SupportedDocumentTypes(StrEnum):
ARF = "ARF"
LG = SnomedCodes.LLOYD_GEORGE.value.code
EHR = SnomedCodes.EHR.value.code
EHR_ATTACHMENTS = SnomedCodes.EHR_ATTACHMENTS.value.code
Expand All @@ -33,7 +32,6 @@ def get_dynamodb_table_name(self) -> str:
"""

document_type_to_table_name = {
SupportedDocumentTypes.ARF: os.getenv("DOCUMENT_STORE_DYNAMODB_NAME"),
SupportedDocumentTypes.LG: os.getenv("LLOYD_GEORGE_DYNAMODB_NAME"),
SupportedDocumentTypes.EHR: os.getenv("LLOYD_GEORGE_DYNAMODB_NAME"),
SupportedDocumentTypes.EHR_ATTACHMENTS: os.getenv(
Expand All @@ -44,7 +42,6 @@ def get_dynamodb_table_name(self) -> str:

def get_s3_bucket_name(self) -> str:
lookup_dict = {
SupportedDocumentTypes.ARF: os.getenv("DOCUMENT_STORE_BUCKET_NAME"),
SupportedDocumentTypes.LG: os.getenv("LLOYD_GEORGE_BUCKET_NAME"),
SupportedDocumentTypes.EHR: os.getenv("LLOYD_GEORGE_BUCKET_NAME"),
SupportedDocumentTypes.EHR_ATTACHMENTS: os.getenv(
Expand Down
2 changes: 0 additions & 2 deletions lambdas/handlers/create_document_reference_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
"STAGING_STORE_BUCKET_NAME",
"DOCUMENT_STORE_BUCKET_NAME",
"PRESIGNED_ASSUME_ROLE",
]
)
Expand Down
2 changes: 0 additions & 2 deletions lambdas/handlers/data_collection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
names=[
"LLOYD_GEORGE_DYNAMODB_NAME",
"LLOYD_GEORGE_BUCKET_NAME",
"DOCUMENT_STORE_DYNAMODB_NAME",
"DOCUMENT_STORE_BUCKET_NAME",
"WORKSPACE",
"STATISTICS_TABLE",
]
Expand Down
1 change: 0 additions & 1 deletion lambdas/handlers/delete_document_reference_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
@validate_document_type
@ensure_environment_variables(
names=[
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
"UNSTITCHED_LLOYD_GEORGE_DYNAMODB_NAME",
]
Expand Down
1 change: 0 additions & 1 deletion lambdas/handlers/document_manifest_job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def get_manifest_job(event, context):
@set_request_context_for_logging
@ensure_environment_variables(
names=[
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
"ZIPPED_STORE_BUCKET_NAME",
"ZIPPED_STORE_DYNAMODB_NAME",
Expand Down
1 change: 0 additions & 1 deletion lambdas/handlers/document_status_check_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
]
)
Expand Down
2 changes: 0 additions & 2 deletions lambdas/handlers/update_document_reference_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
"STAGING_STORE_BUCKET_NAME",
"DOCUMENT_STORE_BUCKET_NAME",
"PRESIGNED_ASSUME_ROLE",
]
)
Expand Down
1 change: 0 additions & 1 deletion lambdas/handlers/update_upload_state_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
]
)
Expand Down
1 change: 0 additions & 1 deletion lambdas/handlers/virus_scan_result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
"DOCUMENT_STORE_DYNAMODB_NAME",
"LLOYD_GEORGE_DYNAMODB_NAME",
"STAGING_STORE_BUCKET_NAME",
"VIRUS_SCAN_STUB",
Expand Down
4 changes: 2 additions & 2 deletions lambdas/services/document_deletion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def handle_object_delete(self, deleted_reference: DocumentReference):
def get_documents_references_in_storage(
self,
nhs_number: str,
doc_type: Literal[SupportedDocumentTypes.ARF, SupportedDocumentTypes.LG],
doc_type: Literal[SupportedDocumentTypes.LG],
) -> list[DocumentReference]:
results = self.document_service.fetch_available_document_references_by_type(
nhs_number, doc_type, NotDeleted
Expand All @@ -102,7 +102,7 @@ def delete_documents_references_in_stitch_table(self, nhs_number: str):
def delete_specific_doc_type(
self,
nhs_number: str,
doc_type: Literal[SupportedDocumentTypes.ARF, SupportedDocumentTypes.LG],
doc_type: Literal[SupportedDocumentTypes.LG],
) -> list[DocumentReference]:
try:
results = self.get_documents_references_in_storage(nhs_number, doc_type)
Expand Down
2 changes: 1 addition & 1 deletion lambdas/services/pdf_stitching_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def process_message(self, stitching_message: PdfStitchingSqsMessage):
SupportedDocumentTypes.LG
if stitching_message.snomed_code_doc_type.code
== SnomedCodes.LLOYD_GEORGE.value.code
else SupportedDocumentTypes.ARF
else None
)

if doc_type != SupportedDocumentTypes.LG:
Expand Down
6 changes: 0 additions & 6 deletions lambdas/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
MOCK_CLOUDFRONT_URL = "test-cloudfront-url.com"
MOCKED_LG_BUCKET_ENV = "test"
MOCKED_LG_BUCKET_URL = f"{MOCKED_LG_BUCKET_ENV}-lloyd-test-test.com"
MOCK_ARF_TABLE_NAME_ENV_NAME = "DOCUMENT_STORE_DYNAMODB_NAME"
MOCK_ARF_BUCKET_ENV_NAME = "DOCUMENT_STORE_BUCKET_NAME"
MOCK_PDM_TABLE_NAME_ENV_NAME = "PDM_DYNAMODB_NAME"
MOCK_PDM_BUCKET_ENV_NAME = "PDM_BUCKET_NAME"

Expand Down Expand Up @@ -64,12 +62,10 @@
MOCK_STATISTICS_TABLE_NAME = "STATISTICS_TABLE"
MOCK_STATISTICAL_REPORTS_BUCKET_ENV_NAME = "STATISTICAL_REPORTS_BUCKET"

MOCK_ARF_TABLE_NAME = "test_arf_dynamoDB_table"
MOCK_PDM_TABLE_NAME = "test_pdm_dynamoDB_table"
MOCK_LG_TABLE_NAME = "test_lg_dynamoDB_table"
MOCK_UNSTITCHED_LG_TABLE_NAME = "test_unstitched_lg_table"
MOCK_BULK_REPORT_TABLE_NAME = "test_report_dynamoDB_table"
MOCK_ARF_BUCKET = "test_arf_s3_bucket"
MOCK_LG_BUCKET = "test_lg_s3_bucket"
MOCK_PDM_BUCKET = "test_pdm_s3_bucket"
MOCK_ZIP_OUTPUT_BUCKET = "test_s3_output_bucket"
Expand Down Expand Up @@ -146,8 +142,6 @@
@pytest.fixture
def set_env(monkeypatch):
monkeypatch.setenv("AWS_DEFAULT_REGION", REGION_NAME)
monkeypatch.setenv(MOCK_ARF_TABLE_NAME_ENV_NAME, MOCK_ARF_TABLE_NAME)
monkeypatch.setenv(MOCK_ARF_BUCKET_ENV_NAME, MOCK_ARF_BUCKET)
monkeypatch.setenv(MOCK_LG_TABLE_NAME_ENV_NAME, MOCK_LG_TABLE_NAME)
monkeypatch.setenv(MOCK_UNSTITCHED_LG_TABLE_ENV_NAME, MOCK_UNSTITCHED_LG_TABLE_NAME)
monkeypatch.setenv(MOCK_LG_BUCKET_ENV_NAME, MOCK_LG_BUCKET)
Expand Down
4 changes: 0 additions & 4 deletions lambdas/tests/unit/enums/test_supported_document_types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from enums.supported_document_types import SupportedDocumentTypes
from tests.unit.conftest import (
MOCK_ARF_BUCKET,
MOCK_ARF_TABLE_NAME,
MOCK_LG_BUCKET,
MOCK_LG_TABLE_NAME,
)
Expand All @@ -11,7 +9,6 @@
@pytest.mark.parametrize(
["doc_type", "expected"],
[
(SupportedDocumentTypes.ARF, MOCK_ARF_TABLE_NAME),
(SupportedDocumentTypes.LG, MOCK_LG_TABLE_NAME),
],
)
Expand All @@ -25,7 +22,6 @@ def test_get_dynamodb_table_name_return_table_name(set_env, doc_type, expected):
@pytest.mark.parametrize(
["doc_type", "expected"],
[
(SupportedDocumentTypes.ARF, MOCK_ARF_BUCKET),
(SupportedDocumentTypes.LG, MOCK_LG_BUCKET),
],
)
Expand Down
18 changes: 0 additions & 18 deletions lambdas/tests/unit/handlers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ def valid_id_post_event_with_auth_header():
return api_gateway_proxy_event


@pytest.fixture
def valid_id_and_both_doctype_event():
api_gateway_proxy_event = {
"httpMethod": "GET",
"queryStringParameters": {"patientId": "9000000009", "docType": "16521000000101,ARF"},
}
return api_gateway_proxy_event


@pytest.fixture
def valid_id_and_arf_doctype_event():
api_gateway_proxy_event = {
"httpMethod": "GET",
"queryStringParameters": {"patientId": "9000000009", "docType": "ARF"},
}
return api_gateway_proxy_event


@pytest.fixture
def valid_id_and_lg_doctype_event():
api_gateway_proxy_event = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from models.document_reference import CreateEventModel
from tests.unit.conftest import MOCK_STAGING_STORE_BUCKET, TEST_NHS_NUMBER, TEST_UUID
from tests.unit.helpers.data.create_document_reference import (
ARF_FILE_LIST,
ARF_MOCK_EVENT_BODY,
ARF_MOCK_RESPONSE,
LG_AND_ARF_MOCK_RESPONSE,
LG_MOCK_EVENT_BODY,
LG_MOCK_RESPONSE,
MOCK_EVENT_BODY,
Expand All @@ -24,12 +20,10 @@
from utils.lambda_exceptions import DocumentRefException, SearchPatientException
from utils.lambda_response import ApiGatewayResponse

TEST_DOCUMENT_LOCATION_ARF = f"s3://{MOCK_STAGING_STORE_BUCKET}/{TEST_UUID}"
TEST_DOCUMENT_LOCATION_LG = f"s3://{MOCK_STAGING_STORE_BUCKET}/{TEST_UUID}"

INVALID_NHS_NUMBER = "12345"

arf_environment_variables = ["STAGING_STORE_BUCKET_NAME"]
lg_environment_variables = ["LLOYD_GEORGE_BUCKET_NAME", "LLOYD_GEORGE_DYNAMODB_NAME"]


Expand All @@ -50,15 +44,6 @@ def both_type_event():
}


@pytest.fixture
def arf_type_event():
return {
"httpMethod": "POST",
"body": json.dumps(ARF_MOCK_EVENT_BODY),
"queryStringParameters": {"patientId": TEST_NHS_NUMBER},
}


@pytest.fixture
def lg_type_event():
return {
Expand All @@ -72,7 +57,7 @@ def lg_type_event():
def mock_process_event_body(mocker):
yield mocker.patch(
"handlers.create_document_reference_handler.process_event_body",
return_value=(TEST_NHS_NUMBER, ARF_FILE_LIST),
return_value=(TEST_NHS_NUMBER, PARSED_LG_FILE_LIST),
)


Expand All @@ -94,21 +79,6 @@ def mock_invalid_nhs_number_exception(mocker):
)


def test_create_document_reference_valid_both_lg_and_arf_type_returns_200(
set_env, both_type_event, context, mock_cdr_service, mock_upload_lambda_enabled
):
mock_cdr_service.create_document_reference_request.return_value = (
LG_AND_ARF_MOCK_RESPONSE
)
expected = ApiGatewayResponse(
200, json.dumps(LG_AND_ARF_MOCK_RESPONSE), "POST"
).create_api_gateway_response()

actual = lambda_handler(both_type_event, context)

assert actual == expected


def test_create_document_reference_valid_lg_type_returns_presigned_urls_and_200(
set_env, lg_type_event, context, mock_cdr_service, mock_upload_lambda_enabled
):
Expand Down Expand Up @@ -204,11 +174,11 @@ def test_cdr_request_when_lgr_is_in_process_of_uploading_returns_423(
mock_cdr_service.create_document_reference_request.assert_called_once()


@pytest.mark.parametrize("environment_variable", arf_environment_variables)
@pytest.mark.parametrize("environment_variable", ["STAGING_STORE_BUCKET_NAME"])
def test_lambda_handler_missing_environment_variables_type_staging_returns_500(
set_env,
monkeypatch,
arf_type_event,
lg_type_event,
environment_variable,
context,
):
Expand All @@ -224,7 +194,7 @@ def test_lambda_handler_missing_environment_variables_type_staging_returns_500(
json.dumps(expected_body),
"POST",
).create_api_gateway_response()
actual = lambda_handler(arf_type_event, context)
actual = lambda_handler(lg_type_event, context)
assert expected == actual


Expand Down Expand Up @@ -283,48 +253,6 @@ def test_process_event_body_with_lg_event(lg_type_event):
assert expected_doc_list == actual_doc_list


def test_lambda_handler_processing_event_details_raise_error(
mocker,
arf_type_event,
context,
set_env,
mock_process_event_body,
mock_upload_lambda_enabled,
):
mock_process_event_body.side_effect = DocumentRefException(400, MockError.Error)
expected = ApiGatewayResponse(
400,
json.dumps(MockError.Error.value),
"POST",
).create_api_gateway_response()
actual = lambda_handler(arf_type_event, context)
validated_event = CreateEventModel.model_validate(arf_type_event)
assert expected == actual
mock_process_event_body.assert_called_with(validated_event)


def test_lambda_handler_valid(
arf_type_event,
context,
set_env,
mock_process_event_body,
mock_upload_lambda_enabled,
mock_cdr_service,
):
mock_process_event_body.return_value = (TEST_NHS_NUMBER, ARF_FILE_LIST)
mock_cdr_service.create_document_reference_request.return_value = ARF_MOCK_RESPONSE

expected = ApiGatewayResponse(
200,
json.dumps(ARF_MOCK_RESPONSE),
"POST",
).create_api_gateway_response()
actual = lambda_handler(arf_type_event, context)
validated_event = CreateEventModel.model_validate(arf_type_event)
assert expected == actual
mock_process_event_body.assert_called_with(validated_event)


def test_no_event_processing_when_upload_lambda_flag_disabled(
set_env,
lg_type_event,
Expand Down
Loading
Loading