Skip to content

[CDAPI-72]: implemented pdm client#99

Open
MohammadPatelNHS wants to merge 1 commit intofeature/CDAPI-113from
feature/CDAPI-72
Open

[CDAPI-72]: implemented pdm client#99
MohammadPatelNHS wants to merge 1 commit intofeature/CDAPI-113from
feature/CDAPI-72

Conversation

@MohammadPatelNHS
Copy link
Copy Markdown
Contributor

@MohammadPatelNHS MohammadPatelNHS commented Apr 13, 2026

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request.

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-72 branch 3 times, most recently from fbcdca3 to 923a897 Compare April 14, 2026 15:20
Copy link
Copy Markdown
Collaborator

@nhsd-jack-wainwright nhsd-jack-wainwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor questions/suggestions

Comment thread mocks/src/pdm_mock/handler.py Outdated
_create_operation_outcome(400, "Missing X-Request-ID header", "required")
)
if not check_valid_uuid4(x_request_id):
_logger.error("Invalid X-Request-ID header.")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor but might be worth including the provided x_request_id here just to aid debugging?

def set_correlation_id(value: CorrelationID) -> None:
"""Set the correlation ID for the current request context."""
_correlation_id.set(value)
_correlation_id.set({"full_id": value["full_id"], "short_id": value["short_id"]})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a new CorrelationID instance here or could we just set the _correlation_id value to what's supplied?

def reset_correlation_id() -> None:
"""Reset the correlation ID to the default empty string."""
_correlation_id.set("")
print("resetting", _correlation_id.get())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this print required? If so I think this should be included via a logger.

correlation_id = _get_correlation_id()
if correlation_id:
return correlation_id["short_id"]
else:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I think an exception should be thrown here rather than defaulting to an empty string.

Comment thread pathology-api/src/pathology_api/test_handler.py
Comment on lines +13 to +19
os.environ["CLIENT_TIMEOUT"] = "3s"
os.environ["APIM_TOKEN_URL"] = "apim_url" # noqa S105 - dummy value
os.environ["APIM_PRIVATE_KEY_NAME"] = "apim_private_key_name"
os.environ["APIM_API_KEY_NAME"] = "apim_api_key_name"
os.environ["APIM_TOKEN_EXPIRY_THRESHOLD"] = "1s" # noqa S105 - dummy value
os.environ["APIM_KEY_ID"] = "apim_key"
os.environ["PDM_BUNDLE_URL"] = "pdm_bundle_url"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you're mocking the apim_authenticator in this file I don't think these environment variables are required? Instead calls to pathology_api.environment.values can be patched to return the required values in the tests themselves.

context: LambdaContext,
) -> None:
# First request sets a correlation ID
uuid_mock.return_value = "test_uuid"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth setting a separate return value here in between the first and second handler calls to verify that a new correlation ID is generated per handler call?

Copy link
Copy Markdown
Collaborator

@nhsd-jack-wainwright nhsd-jack-wainwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just a couple additional suggestions.

Comment thread pathology-api/lambda_handler.py Outdated

@_exception_handler(ValueError)
def handle_value_error(exception: ValueError) -> Response[str]:
if "Missing required header: nhsd-correlation-id" in str(exception):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than requiring this if statement based on exception message here. Maybe before throwing the ValueError when no correlation ID is provided we could set a correlation ID?

response_meta = response_bundle.meta
assert response_meta.last_updated is not None
assert response_meta.version_id is None
assert response_meta.version_id == "1"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding an assertion around the eTag header returned here also?

@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-72 branch 2 times, most recently from 40465e6 to 04519be Compare April 17, 2026 10:12
@MohammadPatelNHS MohammadPatelNHS marked this pull request as ready for review April 17, 2026 10:37
@MohammadPatelNHS MohammadPatelNHS requested review from a team as code owners April 17, 2026 10:37
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Deployment Complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants