Skip to content

[HOTE-1211] feat: Refactor DB clients to use latest_order_status view#414

Open
cptiv2020 wants to merge 2 commits intomainfrom
feature/hote-1211/refactoring-db-queries
Open

[HOTE-1211] feat: Refactor DB clients to use latest_order_status view#414
cptiv2020 wants to merge 2 commits intomainfrom
feature/hote-1211/refactoring-db-queries

Conversation

@cptiv2020
Copy link
Copy Markdown
Contributor

Description

https://nhsd-jira.digital.nhs.uk/browse/HOTE-1211

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.

Copilot AI review requested due to automatic review settings April 27, 2026 11:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

Lambdas Coverage Report

Lines Statements Branches Functions
Coverage: 97%
97.99% (2052/2094) 91.46% (579/633) 96.37% (346/359)

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 Lambda DB access to use the existing latest_order_status Postgres view instead of repeating “latest status” subqueries/lateral joins, simplifying queries while preserving behavior.

Changes:

  • Update TestResultDbClient.getResult to filter by latest_order_status rather than an inline “latest COMPLETE” subquery.
  • Update OrderService and OrderDbClient queries to join latest_order_status for the current order status.
  • Update Jest unit tests to match the revised SQL and minor formatting changes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lambdas/src/lib/db/test-result-db-client.ts Uses latest_order_status to require the order be COMPLETE before returning the latest result.
lambdas/src/lib/db/test-result-db-client.test.ts Updates expected SQL and call shapes for the refactored query.
lambdas/src/lib/db/order-db.ts Replaces lateral “latest status” lookup and dedupe check with latest_order_status.
lambdas/src/lib/db/order-db.test.ts Updates expected SQL for the latest_order_status join and NOT EXISTS clause.
lambdas/src/lib/db/order-db-client.ts Joins latest_order_status to return the latest status without ORDER BY/LIMIT on order_status.
lambdas/src/lib/db/order-db-client.test.ts Updates expected SQL to match the new latest_order_status-based query.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

UI Coverage Report

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

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

2 participants