Skip to content

[HOTE-1138] feat: simplify results lambda#404

Open
TSeelig wants to merge 8 commits intofeature/hote-1209/test-processed-statusfrom
feature/hote-1138/simplify-results-lambda
Open

[HOTE-1138] feat: simplify results lambda#404
TSeelig wants to merge 8 commits intofeature/hote-1209/test-processed-statusfrom
feature/hote-1138/simplify-results-lambda

Conversation

@TSeelig
Copy link
Copy Markdown
Contributor

@TSeelig TSeelig commented Apr 23, 2026

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

  • 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.

Copilot AI review requested due to automatic review settings April 23, 2026 13:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 a ResultProcessingHandoffService to invoke the downstream processor lambda.
  • Update order-result-lambda to 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

Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.test.ts Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread lambdas/src/order-result-lambda/models.ts
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Copilot AI review requested due to automatic review settings April 23, 2026 14:14
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 0144d58 to 2fd31c4 Compare April 23, 2026 14:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ResultProcessingHandoffService in order-result-lambda and wired it via init.ts using a new RESULT_PROCESSING_FUNCTION_NAME env 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

Comment thread lambdas/src/order-result-lambda/models.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread local-environment/infra/main.tf Outdated
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 2fd31c4 to 5684f46 Compare April 23, 2026 14:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

Lambdas Coverage Report

Lines Statements Branches Functions
Coverage: 98%
98.14% (2217/2259) 91.71% (609/664) 96.59% (369/382)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

UI Coverage Report

Lines Statements Branches Functions
Coverage: 96%
96.32% (5927/6153) 88.4% (724/819) 88.44% (222/251)

Copilot AI review requested due to automatic review settings April 23, 2026 15:08
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 5684f46 to f4afc08 Compare April 23, 2026 15:08
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from f4afc08 to 6b2434f Compare April 23, 2026 15:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 a ResultProcessingHandoffService to invoke the downstream processor function.
  • Updated order-result-lambda handler 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

Comment thread local-environment/infra/main.tf Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 6b2434f to cadb769 Compare April 23, 2026 15:23
Copilot AI review requested due to automatic review settings April 23, 2026 15:25
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from cadb769 to 7ac209b Compare April 23, 2026 15:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors order-result-lambda to validate incoming FHIR Observations and then hand off the validated payload to a dedicated “result processor” Lambda (supporting the new multi-lambda results flow described in HOTE-1138/HOTE-1099).

Changes:

  • Added a ResultProcessingHandoffService and wiring in order-result-lambda to invoke a downstream Lambda after validation.
  • Introduced a shared AWSLambdaClient wrapper (AWS SDK v3) for Lambda-to-Lambda invocation, with unit tests.
  • Updated local Terraform to grant invoke permissions and pass the downstream 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 lambda:InvokeFunction and injects RESULT_PROCESSING_FUNCTION_NAME into order_result_lambda (currently broken due to missing/incorrect module references and missing env vars).
lambdas/src/order-result-lambda/index.ts Switches handler to Middy pattern and delegates validated results to resultProcessingService.
lambdas/src/order-result-lambda/init.ts Wires AWSLambdaClient + ResultProcessingHandoffService into the lambda environment.
lambdas/src/order-result-lambda/models.ts Formatting updates + adds ResultProcessingHandoffMessage type used for inter-lambda payloads.
lambdas/src/order-result-lambda/result-processing-service.ts New service that invokes the downstream processor Lambda with { headers, body } payload.
lambdas/src/order-result-lambda/cors-configuration.ts Adds lambda-specific CORS options built on shared defaults.
lambdas/src/order-result-lambda/*.test.ts Updates/introduces unit tests for the new handoff service, init wiring, and handler behavior.
lambdas/src/lib/lambda/lambda-client.ts New Lambda client wrapper around @aws-sdk/client-lambda with response decoding/validation.
lambdas/src/lib/lambda/lambda-client.test.ts Unit tests for the Lambda client wrapper.
lambdas/package.json Adds @aws-sdk/client-lambda dependency.
lambdas/package-lock.json Lockfile update for the new dependency and transitive packages.
Files not reviewed (1)
  • lambdas/package-lock.json: Language not supported

Comment thread local-environment/infra/main.tf
Comment thread local-environment/infra/main.tf Outdated
Comment thread lambdas/src/order-result-lambda/index.ts
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 7ac209b to 35159a0 Compare April 23, 2026 15:41
Copilot AI review requested due to automatic review settings April 23, 2026 15:46
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from 35159a0 to e225ef1 Compare April 23, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors order-result-lambda to stop performing HIV-specific result processing itself and instead hand off validated FHIR Observations to a downstream “result processor” Lambda, adding a small shared Lambda invocation client and wiring/config updates.

Changes:

  • Add ResultProcessingHandoffService and inject it via order-result-lambda/init.ts to invoke a downstream processor Lambda.
  • Refactor order-result-lambda/index.ts to delegate processing and adopt the repo’s lambdaHandler + Middy-wrapped handler structure.
  • Add local-environment Terraform wiring for invocation permissions and a new RESULT_PROCESSING_FUNCTION_NAME env var.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
local-environment/infra/main.tf Adds IAM policy + env var to allow order-result to invoke a processor lambda in local env
lambdas/src/order-result-lambda/result-processing-service.ts New service that invokes the downstream processor lambda
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 typed handoff message model and formatting cleanup
lambdas/src/order-result-lambda/init.ts Wires in AWSLambdaClient + ResultProcessingHandoffService via env var
lambdas/src/order-result-lambda/init.test.ts Extends init wiring tests to cover new dependencies/env var
lambdas/src/order-result-lambda/index.ts Delegates processing to the handoff service; wraps handler with Middy
lambdas/src/order-result-lambda/index.test.ts Updates handler tests to assert delegation to processing service
lambdas/src/order-result-lambda/cors-configuration.ts Adds local CORS options module for this lambda (matching other lambdas)
lambdas/src/lib/lambda/lambda-client.ts Introduces a shared AWS Lambda invoke client wrapper
lambdas/src/lib/lambda/lambda-client.test.ts Unit tests for the new invoke client wrapper
lambdas/package.json Adds @aws-sdk/client-lambda dependency
lambdas/package-lock.json Lockfile updates for the new dependency
Files not reviewed (1)
  • lambdas/package-lock.json: Language not supported

Comment thread local-environment/infra/main.tf Outdated
Comment thread local-environment/infra/main.tf Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
@TSeelig
Copy link
Copy Markdown
Contributor Author

TSeelig commented Apr 23, 2026

Playwright E2E tests currently failing due to undeclared terraform module:

│ 
│   on main.tf line 196, in resource "aws_iam_role_policy" "lambdas_invoke_result_processor":
│  196:         Resource = module.hiv_results_lambda.lambda_function_arn
│ 
│ No module call named "hiv_results_lambda" is declared in the root module.
╵
╷
│ Error: Reference to undeclared module
│ 
│   on main.tf line 425, in module "order_result_lambda":
│  425:     RESULT_PROCESSING_FUNCTION_NAME = module.hiv_results_lambda.function_name
│ 
│ No module call named "hiv_results_lambda" is declared in the root module.
╵
Error: Process completed with exit code 1.

This terraform module is for a lambda being implemented in #386

Comment thread lambdas/src/lib/lambda/lambda-client.ts Outdated
Comment thread lambdas/src/order-result-lambda/index.ts Outdated
@TSeelig TSeelig force-pushed the feature/hote-1138/simplify-results-lambda branch from e225ef1 to c1f5108 Compare April 27, 2026 13:34
…te-1138/simplify-results-lambda

# Conflicts:
#	lambdas/pnpm-lock.yaml
#	lambdas/src/order-result-lambda/index.ts
#	local-environment/infra/main.tf
Copilot AI review requested due to automatic review settings April 28, 2026 09:37
@cptiv2020 cptiv2020 changed the base branch from main to feature/hote-1099/hiv-result-processor April 28, 2026 09:38
@cptiv2020 cptiv2020 changed the base branch from feature/hote-1099/hiv-result-processor to feature/hote-1209/test-processed-status April 28, 2026 12:05
@sonarqubecloud
Copy link
Copy Markdown

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.

3 participants