Clinical: forecast double count, ended legal form wording, ED 24-hour boundary (D-145)

Merged
BI
1d ago
+284-50

Requested by Josh · project thread

The clinical part of the 11 November repository review. Josh approved it as D-145 item 1, which is recorded in the thread's normal PR, #1623. Josh signed it off on 11 November 2026 at 05:51 UTC ("I approve all of them to remove labels"), so the hold label is off; the sign-off is recorded under D-145 in #1623. Synthetic data only. No signed clinical value changes.

What changes

  1. Expected occupancy no longer counts one patient twice.
    • The bug: a patient who held a named bed (through a journey or a referral) and also had a booked planned admission to the same ward was counted twice. The ward's 24, 48 and 72 hour figures went up by 2 instead of 1.
    • The network forecast had the same double count for referral holds.
    • The fix: a new patientsHoldingANamedBed helper uses the same rule as numberedReservationBeds. It feeds plannedAdmissionsStillNeedingABed from expected-occupancy.ts, beds-forecast.ts and forecast/forecast-by-kind.ts, so all the forecast views agree.
    • The helper lives in capacity/planned-admissions-reducer.ts, which is already on the D-14 patient-link allowlist for the same yes/no id comparison. Its allowlist reason in tests/ward-patient-link-default-deny.test.ts now names this use. No new file joins the allowlist.
  2. An ended legal form no longer shows a live-looking expiry.
    • The Legal forms card and row now read "Form ended; expiry as typed was 15:42", or "Form ended" if no time was typed. The time stays exactly as typed (D-93).
  3. The ED screen flags a long wait at exactly 24 hours.
    • A shared isLongWait() now does the check on the ED screen and its timeline, matching Alerts, TV, the bed meeting and statistics ("24 h or more").

Phone size limits

RouteOld limitNew limitMeasured (CI, PR merged with main)
/ward-flow575.4575.7575.4
/ward-flow/referrals583.6583.9583.6
/ward-flow/ward/rph-adult-secure613.8614.1613.8
/ward-flow/capacity654.3654.7654.4
/ward-flow/ed535.4535.7535.4 (main alone 535.2)
  • All sizes are in KB, each raise under 1 KB. Reasons in docs/script-budget-history/2026-11-11-pr1621-held-clinical-review-fixes.md.

Checks (local, not hosted CI)

  • npx vitest run on 92 related test files: 742 passed; after the helper move, 20 related files (235 tests) including tests/ward-patient-link-default-deny.test.ts passed.
  • node --max-old-space-size=8192 node_modules/typescript/bin/tsc -p tsconfig.json --noEmit --incremental false: exit 0.
  • npx eslint on changed files: clean.
  • node docs/ward-flow/journey/verify.mjs --check, node scripts/doc-facts.mjs, node scripts/ward-flow/owner-rulings-index.mjs --check: passed after merging main 3aa63c3.
  • Not run locally: the full unit suite and the browser suite (left to CI).

🤖 Generated with Claude Code

https://claude.ai/code/session_01J352nkwW4xTv5Ftznofb8N