Skip to content

Conversation

@nhsd-david-wass
Copy link
Contributor

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 am familiar with the contributing guidelines
  • 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

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.

@nhsd-david-wass nhsd-david-wass requested review from a team as code owners November 27, 2025 11:01
@nhsd-david-wass nhsd-david-wass force-pushed the feature/CCM-12952-Publish-MI-Events branch 7 times, most recently from 6f221b9 to c9b1df0 Compare December 4, 2025 11:07
@nhsd-david-wass nhsd-david-wass force-pushed the feature/CCM-12952-Publish-MI-Events branch from 6d0cb00 to 15c58d6 Compare December 4, 2025 13:58
@nhsd-david-wass nhsd-david-wass force-pushed the feature/CCM-12952-Publish-MI-Events branch 2 times, most recently from 9fcbc8e to 598d07a Compare December 17, 2025 08:13
@stevebux
Copy link
Contributor

I seem to remember you mentioning moving both the existing letter transformer and your new MI transformer into a transformers directory under lambdas. Did you decide not to do that in the end?

stevebux
stevebux previously approved these changes Dec 17, 2025

function extractMIData(record: DynamoDBRecord): MI {
const newImage = record.dynamodb?.NewImage!;
return MISchema.parse(unmarshall(newImage as any));
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for doing an MISchema.parse here is as an extra validation check, so it's probably worth having a test case where it's not valid (see it("does not publish invalid letter data"... in letter=updates-transformer-tests.ts

}

function extractMIData(record: DynamoDBRecord): MI {
const newImage = record.dynamodb?.NewImage!;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect NewImage would be undefined if a record was deleted from the MI table, causing this code to blow up. But perhaps we don't anticipate that ever happening?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't support that operation - only POST for creation of new data
It's maybe worth adding an INSERT filter for the kinesis event with a log out for unexpected event types for a bit of defense?

);
});

it("does not publish invalid letter data", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it("does not publish invalid letter data", async () => {
it("does not publish invalid MI data", async () => {

@nhsd-david-wass nhsd-david-wass force-pushed the feature/CCM-12952-Publish-MI-Events branch 3 times, most recently from 9e44d73 to 52e64d9 Compare December 19, 2025 11:06
@nhsd-david-wass nhsd-david-wass force-pushed the feature/CCM-12952-Publish-MI-Events branch from 52e64d9 to cefd277 Compare December 19, 2025 13:05
Copy link
Contributor

@masl2 masl2 left a comment

Choose a reason for hiding this comment

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

Think we need a guard on the kinesis event type

Comment on lines +62 to +70
function generateInsertRecord(newMI: MI): DynamoDBRecord {
const newImage = Object.fromEntries(
Object.entries(newMI).map(([key, value]) => [key, toAttr(value)]),
);
return {
eventName: "INSERT",
dynamodb: { NewImage: newImage },
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking further we probably should verify the behaviour for MODIFY/DELETE events.
While the API doesn't generate them, if we have to do any form of data correction, we could produce errors.
Probably just needs to drop them with a log

Comment on lines +55 to +59
const cloudEvents: MISubmittedEvent[] = streamEvent.Records.map((record) =>
extractPayload(record, deps),
)
.map((element) => extractMIData(element))
.map((payload) => mapMIToCloudEvent(payload, deps));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this does need a guard so it only maps those INSERT events
While standard operation shouldn't produce anything else, a DR scenario or data fix might and the downstream code makes the assumption that it will receive INSERT data (if my read is correct?)

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.

4 participants