Skip to content

[NDR-423] CORE DB to use ID, all endpoints ignore SNOMED code#1151

Open
jameslinnell wants to merge 19 commits intomainfrom
NDR-423
Open

[NDR-423] CORE DB to use ID, all endpoints ignore SNOMED code#1151
jameslinnell wants to merge 19 commits intomainfrom
NDR-423

Conversation

@jameslinnell
Copy link
Contributor

Overview

Jira ticket: NDR-423

Description

Changes CORE db calls to use the updated DB design. All FHIR endpoints now longer require snomed code as part of their request

Context

SNOMED is a redundant parameter, IDs were previously not FHIR compliant.

Checklist

Tasks for all changes:

  • 1. I have linked this PR to its Jira ticket.
  • 2. I have run git pre-commits.
  • 3. I have added and/or updated relevant tests.
  • 4. I have updated relevant documentation.
  • 5. I have considered the cross-team impact (and have PR approval from both Core & Demographics if necessary).
  • 6. I have successfully deployed this change to a sandbox and witnessed unit, e2e and smoke tests passing:

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Code security issues found

View full details here.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026


if not document_id or not snomed_code:
if not document_id:
logger.error("Missing document id or snomed code in request path parameters.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove reference to snomed code here

return SnomedCodes.LLOYD_GEORGE.value

if common_name not in MtlsCommonNames:
logger.error(f"mTLS common name {common_name} - is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really to do with this PR, more a note to what Fraser was saying about updating the ssm param - I would expect there to be a fhir lambda error if an mtls request is used, with an invalid common name, but it seemed like access and store were alerted to an error on their stuff, implying it went down the LG route?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's a ticket to look into Mtls errors


document = model_class.model_validate(response["Item"])
return document
if not return_deleted:
Copy link
Contributor

Choose a reason for hiding this comment

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

Might need a run through of this - would it be simpler to reverse this and if return_deleted exit earlier?

def get_item_agnostic(
self,
partion_key: dict,
partition_key: dict,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh surprised this wasn't causing issues before!

document_id: str,
table,
) -> DocumentReference | None:
documentreference = self.document_service.get_item(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be document_reference to keep with existing syntax patterns

object_parts = object_key.split("/")
document_key = object_parts[-1]
nhs_number = None
if len(object_parts) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not a shared service used by access & store too? Would they still need this as their ID's are made up of snomed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this in, now I'm removing it. It's not needed anymore.

if not documents:
logger.error(
f"Failed to process object key with ID: {document_key}",
f"No document with the following key found in {self.table_name} table: {document_key}",
Copy link
Contributor

Choose a reason for hiding this comment

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

What is document_key in this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

document reference ID

assert len(body["issue"]) > 0
issue = body["issue"][0]
assert issue["severity"] == "error"
# Commented this out for now as this will no longer retunr a 500 but now a 400
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a ticket for this to be fixed in? And should we remove the test or change it to assert a 400 for now, to keep the coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added 400 invalid tests, so this is covered. Yeah Matt added this test in his PR to fix 500 FHIR response. but now it doesn't return a 500. Could be worth talking it through

(f"{pdm_data_helper.snomed_code}+{str(uuid.uuid4())}", 400, "invalid"),
(f"{pdm_data_helper.snomed_code}&{str(uuid.uuid4())}", 400, "invalid"),
(f"{pdm_data_helper.snomed_code}{str(uuid.uuid4())}", 400, "invalid"),
(f"{str(uuid.uuid4())}~{pdm_data_helper.snomed_code}", 400, "invalid"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add empty string here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah can see this is on line 113 - can it be combined into this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH, that test works in a different way. It's easier to leave as separate tests.

_assert_operation_outcome(body=body, code="MISSING_VALUE")


def test_no_snomed_or_document_id_in_path_param_id():
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this one redundant now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, there is a still a function to look for path params. IT's not used but may be used in the future. I think as it doesn''t affect the current code it can be left in

"pdm_record",
)

def retrieve_document_reference(self, record):
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know if I'm missing something here but don't we need these? We reference data_helper.retrieve_document_reference a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are no longer required to be different compared to the same methods on the base class so, we don't need them on the pdm_helper class anymore.

mock_document_service.handle_get_document_reference_request.assert_not_called()


def test_lambda_handler_id_malformed(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this one not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because
MOCK_INVALID_EVENT_ID_MALFORMED["pathParameters"]["id"] = f"~{TEST_UUID}"

This is now a valid ID. the function that gets the ID will split by ~ and take the last item.

Invalid IDs would be non-uuids and a test for that has been added by

def test_get_id_from_path_parameters_raises_error(path_parameter):

patched_service.document_service.get_item.return_value = None

with pytest.raises(GetFhirDocumentReferenceException) as exc_info:
with pytest.raises(GetFhirDocumentReferenceException) as excinfo:
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't exc_info the standard everywhere else?

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