Skip to content

Add patient-info medication considerations/alerts#620

Merged
BigSimmo merged 2 commits into
mainfrom
claude/medication-alerts-database-cb8o83
Jul 14, 2026
Merged

Add patient-info medication considerations/alerts#620
BigSimmo merged 2 commits into
mainfrom
claude/medication-alerts-database-cb8o83

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Brings the Medications app's "fill in a patient → see prescribing considerations" feature into the Database app, on both medication surfaces.

The catalogue snapshot (exported from the Medications app) already carries per-row patient-match metadata (factors, action, severity, structured match criteria, and source-backed note) on 754 rows across 321/328 records — previously only rendered as static badges. This PR adds the missing interactive layer:

  • Engine src/lib/medication-patient-alerts.ts (pure, framework-free): evaluates a PatientProfile against a medication's rows — age/egfr/crcl/scr/qtc/hepatic gates (OR across keys) plus pregnancy, breastfeeding, and allergy-class factors — returning tone-coded considerations with human-readable reasons, plus a safety-first unassessed list for contraindication gates the profile didn't supply (a blank field is never read as an all-clear). A match key is authoritative for the factors it covers, so a numeric gate and its factor never double-report.
  • Shared state patient-profile-storage.ts + patient-profile-context.tsx: a sessionStorage-backed external store (same pattern as use-theme/use-sidebar-collapsed), provider mounted in GlobalSearchShellClient so the profile carries between the prescribing search and detail pages. Anonymous physiology only — no PHI, cleared on tab close.
  • Shared form patient-profile-panel.tsx: age, renal function (eGFR/CrCl/serum creatinine + µmol/L↔mg/dL toggle), hepatic severity, QTc, pregnancy/breastfeeding, allergy classes — reusing existing fieldControl*/ToggleSwitch/badge primitives.
  • Detail page (medication-record-page.tsx): a "Considerations for this patient" block above the tabs — considerations via InlineNotice with factor + reason badges, an all-clear success state, and an empty-state prompt.
  • Prescribing search (medication-prescribing-workspace.tsx): a compact panel above the filter strip and a per-row "N alerts" badge tone-coded to the highest-severity consideration.

Verification

  • npm run lint — clean
  • npm run typecheck — clean for changed files (3 pre-existing errors in tests/ui-accessibility.spec.ts from a missing @axe-core/playwright dev dependency, unrelated to this change)
  • npm run test — 2045 passed / 3 skipped, including new tests/medication-patient-alerts.test.ts (19 tests: every match key + inclusive edges, mg/dL→µmol/L conversion, factor triggers, factor/match dedupe, partial/empty profiles + unassessed, severity sort, and a full-corpus smoke test)
  • brand:check / check:type-scale / check:icon-scale — pass
  • Browser verification (Chromium): panel renders on both surfaces; SCr 150 surfaces the renal contraindication; SCr + severe hepatic + pregnancy stacks to 4 considerations; Clear resets; profile carries across pages via sessionStorage
  • npm run verify:pr-local — not run (production build step) in this environment; equivalent sub-checks run individually above
  • npm run verify:ui — ran a targeted Chromium script instead of the full Playwright suite

No retrieval/ranking/selection/chunking/answer-generation changes, so the RAG/answer eval gates are not applicable.

Clinical Governance Preflight

This adds a patient-specific decision-support view over existing source-backed medication data (client-side only; no ingestion/answer/privacy/Supabase changes).

  • Source-backed claims still require linked source verification before clinical use — considerations render the source-backed note and a "Decision support, not medical advice" disclaimer
  • No patient-identifiable document workflow introduced or expanded — the profile is anonymous physiology only, session-scoped, cleared on tab close, with explicit "no PHI" copy
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy) — no Supabase/schema changes
  • Service-role keys and private document access remain server-only — unchanged
  • Demo/synthetic content remains clearly separated from real clinical sources — unchanged
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative — reuses existing data unchanged
  • Deployment classification/TGA SaMD impact — flagging for maintainer: this introduces a new patient-specific decision-support surface; a formal SaMD classification review was not performed in this PR

Notes

  • Reference reconciliation: adding BigSimmo/Medications was blocked by an approval this environment couldn't grant, so the engine was built to the shared exported data contract (authoritative, since Database's snapshot is the Medications export). Three heuristic thresholds — RENAL_IMPAIRMENT_EGFR = 60, QTC_PROLONGED_MS = 450, elderly ≥ 65 / paediatric < 18 — apply only to bare factors that carry no numeric match, and are named constants for one-edit tuning if the reference app uses different cut-offs.
  • Optional static-badge parity (extending patientBadges for egfr/crcl/qtc/hepatic) was intentionally left out to keep the diff additive.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Added an optional patient details panel for entering anonymous clinical information.
    • Added patient-specific medication considerations, alerts, severity badges, and unassessed contraindication prompts.
    • Patient details now appear in medication search results and record views.
    • Profile information persists for the current session and can be edited, cleared, and updated across views.
  • Tests

    • Added coverage for medication alert matching, severity ordering, profile handling, and unit conversions.

Surface per-patient prescribing considerations from the patient-match
metadata already carried on medication records (factors, action,
severity, structured match criteria, source-backed notes) in the
catalogue snapshot. Previously this data was only rendered as static
badges; there was no way to evaluate it against a specific patient.

- New pure engine (medication-patient-alerts.ts) evaluates a
  PatientProfile against a medication's rows: age/eGFR/CrCl/serum
  creatinine/QTc/hepatic gates plus pregnancy, breastfeeding, and
  allergy-class factors, with safety-first "unassessed" reporting for
  contraindication gates the profile did not supply.
- Shared, sessionStorage-backed profile (external-store pattern) via a
  provider mounted in GlobalSearchShellClient, so the profile carries
  between the prescribing search and medication detail pages. Anonymous
  physiology only; no PHI, cleared on tab close.
- Reusable PatientProfilePanel form (age, renal function with unit
  toggle, hepatic severity, QTc, pregnancy/breastfeeding, allergies)
  reusing existing field/toggle/badge primitives.
- Detail page renders tone-coded considerations via InlineNotice with
  factor + reason badges and an all-clear/empty state; prescribing
  result rows show a per-row alert badge.
- Unit tests cover every match key, unit conversion, factor triggers,
  factor/match dedupe, partial/empty profiles, sort order, and a
  full-corpus smoke test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bdb04f34-a455-45de-9fe0-e987b8de31d6

📥 Commits

Reviewing files that changed from the base of the PR and between 84cebf3 and c3b9523.

📒 Files selected for processing (9)
  • src/components/clinical-dashboard/global-search-shell.tsx
  • src/components/clinical-dashboard/medication-considerations.tsx
  • src/components/clinical-dashboard/medication-prescribing-workspace.tsx
  • src/components/clinical-dashboard/medication-record-page.tsx
  • src/components/clinical-dashboard/patient-profile-context.tsx
  • src/components/clinical-dashboard/patient-profile-panel.tsx
  • src/lib/medication-patient-alerts.ts
  • src/lib/patient-profile-storage.ts
  • tests/medication-patient-alerts.test.ts

📝 Walkthrough

Walkthrough

Adds session-scoped patient profiles, medication alert evaluation, editable profile UI, and patient-specific considerations across medication search and detail views, with dashboard provider wiring and evaluator tests.

Changes

Patient considerations

Layer / File(s) Summary
Medication alert evaluation
src/lib/medication-patient-alerts.ts
Evaluates medication patient metadata against profile fields, returning sorted considerations, tone counts, and unassessed contraindication gates.
Profile persistence and editing
src/lib/patient-profile-storage.ts, src/components/clinical-dashboard/patient-profile-context.tsx, src/components/clinical-dashboard/patient-profile-panel.tsx
Stores sanitized profiles in session storage, exposes context operations, and renders editable patient profile controls.
Dashboard alert presentation
src/components/clinical-dashboard/global-search-shell.tsx, src/components/clinical-dashboard/medication-*.tsx
Provides profile context to dashboard paths and displays profile panels, alert badges, and medication considerations in search and detail views.
Alert evaluation validation
tests/medication-patient-alerts.test.ts
Tests matching boundaries, factor triggers, incomplete profiles, ordering, real records, corpus evaluation, and tone mapping.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/medication-alerts-database-cb8o83

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 13, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe
@BigSimmo
BigSimmo marked this pull request as ready for review July 14, 2026 05:12
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@BigSimmo
BigSimmo merged commit d53e5cc into main Jul 14, 2026
16 checks passed
BigSimmo pushed a commit that referenced this pull request Jul 14, 2026
Record that the patient-info medication considerations feature (PR #620) is
a new patient-specific decision-support surface whose formal TGA SaMD
classification is an open decision for a human/regulatory reviewer. Captures
existing mitigations and open questions; asserts no classification.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe
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