[HOTE-1138] feat: simplify results lambda#404
Conversation
Signed-off-by: lewisbirks <lewis.birks1@nhs.net>
Signed-off-by: lewisbirks <lewis.birks1@nhs.net>
…r status handling
- Import extraction functions from validation-service instead of duplicating - Type buildTaskFromObservation() return as FHIRTask - Type sendResult() parameter as FHIRTask and remove error handling (let caller handle it)
There was a problem hiding this comment.
Pull request overview
This PR refactors order-result-lambda so that, after request validation and DB/idempotency checks, the validated FHIR Observation is handed off to a downstream “result processor” Lambda (removing HIV-specific processing from this lambda to support other test types later).
Changes:
- Add a lambda-invocation client (
AWSLambdaClient) and aResultProcessingHandoffServiceto invoke the downstream processor lambda. - Update
order-result-lambdato delegate validated results to the handoff service and adjust unit tests accordingly. - Update local Terraform to grant invoke permissions and pass the processor function name via environment variable.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| local-environment/infra/main.tf | Adds an IAM inline policy for lambda invoke and updates env vars for order_result_lambda |
| lambdas/src/order-result-lambda/result-processing-service.ts | New service that invokes the processor lambda with the validated observation |
| lambdas/src/order-result-lambda/result-processing-service.test.ts | Unit tests for the new handoff service |
| lambdas/src/order-result-lambda/models.ts | Adds a handoff message type and updates Observation schema constraints |
| lambdas/src/order-result-lambda/init.ts | Wires in AWSLambdaClient + ResultProcessingHandoffService and reads RESULT_PROCESSING_FUNCTION_NAME |
| lambdas/src/order-result-lambda/init.test.ts | Extends init tests to cover the new dependency/env var |
| lambdas/src/order-result-lambda/index.ts | Delegates validated observations to resultProcessingService and adds middy wrapper export pattern |
| lambdas/src/order-result-lambda/index.test.ts | Updates handler tests to assert delegation to the new service |
| lambdas/src/order-result-lambda/cors-configuration.ts | Adds lambda-specific CORS options composition |
| lambdas/src/lib/lambda/lambda-client.ts | New reusable AWS Lambda invoke client wrapper |
| lambdas/src/lib/lambda/lambda-client.test.ts | Unit tests for the new lambda client wrapper |
0144d58 to
2fd31c4
Compare
There was a problem hiding this comment.
Pull request overview
Refactors order-result-lambda to validate incoming FHIR Observations and hand off downstream test-specific processing to a separate “result processor” Lambda, introducing a shared Lambda invocation client to support this new flow.
Changes:
- Added
ResultProcessingHandoffServiceinorder-result-lambdaand wired it viainit.tsusing a newRESULT_PROCESSING_FUNCTION_NAMEenv var. - Introduced a shared
AWSLambdaClient(src/lib/lambda/lambda-client.ts) for synchronous Lambda-to-Lambda invocation and response parsing. - Updated local Terraform to grant invoke permissions and set the result-processing function name for the local environment.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| local-environment/infra/main.tf | Adds IAM policy for Lambda invocation and updates env vars for order_result_lambda. |
| lambdas/src/order-result-lambda/result-processing-service.ts | New service to invoke the downstream result processor Lambda. |
| lambdas/src/order-result-lambda/result-processing-service.test.ts | Unit tests for the new result processing handoff service. |
| lambdas/src/order-result-lambda/models.ts | Adds handoff message model and adjusts Observation schema. |
| lambdas/src/order-result-lambda/init.ts | Wires Lambda client + handoff service and reads new env var. |
| lambdas/src/order-result-lambda/init.test.ts | Updates init wiring tests for new dependencies/env var. |
| lambdas/src/order-result-lambda/index.ts | Replaces in-lambda HIV processing with delegation + adds Middy wrapper. |
| lambdas/src/order-result-lambda/index.test.ts | Updates handler tests to validate delegation to the processing service. |
| lambdas/src/order-result-lambda/cors-configuration.ts | Adds CORS options module for the lambda. |
| lambdas/src/lib/lambda/lambda-client.ts | New shared AWS Lambda invoke client wrapper with payload decoding/validation. |
| lambdas/src/lib/lambda/lambda-client.test.ts | Unit tests for the new Lambda client wrapper. |
| lambdas/package.json | Adds @aws-sdk/client-lambda dependency. |
| lambdas/package-lock.json | Locks the new dependency tree for @aws-sdk/client-lambda. |
Files not reviewed (1)
- lambdas/package-lock.json: Language not supported
2fd31c4 to
5684f46
Compare
5684f46 to
f4afc08
Compare
f4afc08 to
6b2434f
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors order-result-lambda to stop performing HIV-specific result processing and instead hand off validated FHIR Observations to a downstream “result processor” Lambda, supporting a more extensible multi-test flow.
Changes:
- Added a Lambda invocation client (
AWSLambdaClient) and aResultProcessingHandoffServiceto invoke the downstream processor function. - Updated
order-result-lambdahandler to delegate validated results to the processor lambda and adjusted unit tests accordingly. - Updated local Terraform to allow Lambda→Lambda invocation and configured the processor function name via env var.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| local-environment/infra/main.tf | Adds IAM policy for InvokeFunction and sets processor function name env var for order-result in local infra. |
| lambdas/src/order-result-lambda/result-processing-service.ts | New service to hand off validated observations to the processor Lambda. |
| lambdas/src/order-result-lambda/result-processing-service.test.ts | Unit tests for the new handoff service behavior. |
| lambdas/src/order-result-lambda/models.ts | Adds a handoff message shape and formatting/quoting normalization. |
| lambdas/src/order-result-lambda/init.ts | Wires AWSLambdaClient + ResultProcessingHandoffService into the lambda environment. |
| lambdas/src/order-result-lambda/init.test.ts | Updates init tests for new dependencies + mandatory env var. |
| lambdas/src/order-result-lambda/index.ts | Switches to lambdaHandler + middy wrapper; delegates processing to downstream lambda; retains notification dispatch logic. |
| lambdas/src/order-result-lambda/index.test.ts | Updates handler unit tests to mock the new processing service and new error path. |
| lambdas/src/order-result-lambda/cors-configuration.ts | Adds per-lambda CORS options merged from shared defaults. |
| lambdas/src/lib/lambda/lambda-client.ts | New AWS SDK v3 Lambda invoke wrapper that decodes and validates proxy-style responses. |
| lambdas/src/lib/lambda/lambda-client.test.ts | Unit tests for AWSLambdaClient success and error cases. |
| lambdas/package.json | Adds @aws-sdk/client-lambda dependency. |
| lambdas/package-lock.json | Locks transitive deps for @aws-sdk/client-lambda. |
Files not reviewed (1)
- lambdas/package-lock.json: Language not supported
6b2434f to
cadb769
Compare
e225ef1 to
c1f5108
Compare
…te-1209/test-processed-status # Conflicts: # lambdas/src/lib/utils/validation-result.ts # lambdas/src/lib/validation/index.ts # lambdas/src/order-result-lambda/validation-service.ts # lambdas/src/order-result-lambda/validation.ts # lambdas/src/order-status-lambda/index.test.ts # lambdas/src/order-status-lambda/types.ts # lambdas/src/order-status-lambda/utils.ts
…te-1138/simplify-results-lambda # Conflicts: # lambdas/pnpm-lock.yaml # lambdas/src/order-result-lambda/index.ts # local-environment/infra/main.tf
…hub.com/NHSDigital/hometest-service into feature/hote-1209/test-processed-status
…ote-1138/simplify-results-lambda # Conflicts: # lambdas/src/order-result-lambda/services/validation-service.ts
# Conflicts: # lambdas/src/order-result-lambda/services/validation-service.ts
|



Description
HOTE-1138
Remove HIV processing logic from order-result lambda as this is now being done by processor lambda being implemented in HOTE-1099.
Context
We are aiming to detangle HIV logic from order-results lambda to enable support for other types of testing in the future. The new flow is that Order-results lambda receives and validates -> processor lambda carrys out bussiness logic/checks specific to different types of tests -> 3rd lambda HOTE-1100 posts result to database.
Type of changes
Checklist
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.