Skip to content

Extract pure ClinicalDashboard helpers into a tested module (+ SaMD note)#653

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

Extract pure ClinicalDashboard helpers into a tested module (+ SaMD note)#653
BigSimmo merged 3 commits into
mainfrom
claude/medication-alerts-database-cb8o83

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

A bounded, zero-behaviour-change slice of the front-end refactor (#51 — "centralise domain functions into reusable modules so they can be unit tested"), plus a governance tracking note.

  • src/components/clinical-dashboard/clinical-dashboard-helpers.ts (new): ~12 pure, module-scope helpers moved verbatim out of the 4.1k-line ClinicalDashboard.tsx so the domain logic can be unit-tested directly:
    • Polling: normalizedPollDelay, shorterPollDelay, hasActiveIndexingWork, setupNeedsSlowRecheck (+ the shared setupRecheckPollMs constant)
    • Document refresh: answerReferencesDocument, applyRenamedDocumentToAnswer, mergeDocumentRefresh
    • Misc pure: compactScopeFilters, hasNonProductionSupabaseApiKeyFallback, normalizeNavigationHash, isAbortError, answerTimedOutError
  • ClinicalDashboard.tsx: imports the helpers; deleted the moved definitions and now-orphaned imports. No other logic touched.
  • tests/clinical-dashboard-helpers.test.ts (new, 12 tests): poll-delay clamping/edge cases, indexing + slow-recheck detection, merge ordering with label/summary fallbacks, hash normalisation, abort detection, 408 timeout error, and answer document reference/rename.
  • docs/samd-classification-medication-considerations.md (new): tracks that the merged patient-considerations feature (PR Add patient-info medication considerations/alerts #620) is a new patient-specific decision-support surface whose formal TGA SaMD classification is an open decision for a human/regulatory reviewer. Asserts no classification.

Chosen as the one follow-up that's safely implementable and verifiable in this environment; #628 (needs live provider keys), #289/#229 (need source material + real clinical review — no fabricated statuses), and the Medications-repo reference reconciliation (repo-add blocked) are deferred with reasons.

Verification

  • npm run test — new clinical-dashboard-helpers.test.ts (12) passes; rest of the suite green (the only failures are pre-existing local env gaps: @testing-library not installed here / stale .next types, both avoided by CI's npm ci + fresh build)
  • npm run typecheck — clean for the changed files
  • npm run lint — clean (--max-warnings 0)
  • prettier --check — clean
  • Chromium smoke of /, the prescribing search, and /medications/acamprosate — rendered with no runtime/console errors (extraction preserved behaviour)
  • npm run verify:pr-local — not run (production build step) in this environment; equivalent sub-checks run individually above

No retrieval/ranking/answer-generation/ingestion/privacy/Supabase changes, so those eval/governance gates are not applicable.

Clinical Governance Preflight

Not applicable to the code change — it is a pure refactor (no ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output behaviour changes). The added doc is a governance tracking note only.

Notes

Behaviour-preserving move: all helpers were relocated verbatim; setupRecheckPollMs now lives in the helpers module and is imported back into ClinicalDashboard.tsx. The branch was restarted from the latest main after PR #620 merged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe


Generated by Claude Code

Summary by CodeRabbit

  • Documentation

    • Added a new “medication considerations” SaMD classification tracking page, including the current OPEN status, scope boundaries, safeguards/disclaimers, reviewer questions, and a documented next-step workflow.
  • Improvements

    • Enhanced Clinical Dashboard behavior around polling timing, indexing/setup status, navigation normalization, timed-out search errors, and maintaining consistent document citations (including renamed document titles).
  • Tests

    • Added Vitest coverage for the Clinical Dashboard helper behaviors (filters, polling selection/clamping, indexing/slow recheck logic, error handling, document refresh merging, and citation/reference handling).

claude added 2 commits July 14, 2026 10:01
Move ~12 pure, module-scope helpers out of the 4k-line ClinicalDashboard
component into src/components/clinical-dashboard/clinical-dashboard-helpers.ts
so the domain logic can be unit-tested directly (issue #51 — centralise
domain functions into reusable, tested modules). Verbatim moves, zero
behaviour change:

- Polling: normalizedPollDelay, shorterPollDelay, hasActiveIndexingWork,
  setupNeedsSlowRecheck (+ the shared setupRecheckPollMs constant)
- Document refresh: answerReferencesDocument, applyRenamedDocumentToAnswer,
  mergeDocumentRefresh
- Misc pure: compactScopeFilters, hasNonProductionSupabaseApiKeyFallback,
  normalizeNavigationHash, isAbortError, answerTimedOutError

ClinicalDashboard now imports them; orphaned imports removed. Adds
tests/clinical-dashboard-helpers.test.ts (12 tests) covering poll-delay
clamping, indexing/recheck detection, merge ordering + label/summary
fallbacks, hash normalisation, abort detection, and answer document
reference/rename.

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

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a747dd97-d771-45cb-931a-99b4c24334d8

📥 Commits

Reviewing files that changed from the base of the PR and between 0b3dd96 and b7f26c4.

📒 Files selected for processing (3)
  • docs/samd-classification-medication-considerations.md
  • src/components/clinical-dashboard/clinical-dashboard-helpers.ts
  • tests/clinical-dashboard-helpers.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • docs/samd-classification-medication-considerations.md
  • tests/clinical-dashboard-helpers.test.ts
  • src/components/clinical-dashboard/clinical-dashboard-helpers.ts

📝 Walkthrough

Walkthrough

The Clinical Dashboard’s reusable helper logic is moved into a dedicated module with focused tests. A new document records regulatory and classification questions for the medication considerations feature.

Changes

Clinical Dashboard helper extraction

Layer / File(s) Summary
Shared dashboard helper module
src/components/clinical-dashboard/clinical-dashboard-helpers.ts
Centralizes filtering, error handling, document reference updates, polling, indexing detection, setup checks, and document refresh merging.
Clinical Dashboard helper wiring
src/components/ClinicalDashboard.tsx
Imports the shared helpers and removes their duplicated local implementations and related unused imports.
Helper behavior validation
tests/clinical-dashboard-helpers.test.ts
Tests polling, indexing, setup checks, errors, filtering, document merging, and answer reference updates.

SaMD classification documentation

Layer / File(s) Summary
Medication considerations classification record
docs/samd-classification-medication-considerations.md
Records feature context, mitigations, data limitations, open classification questions, and the decision-recording workflow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the refactor and added governance note without being misleading.
Description check ✅ Passed The description follows the template with Summary, Verification, Clinical Governance Preflight, and Notes, and it covers the main changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 14, 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 ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 14, 2026 10:27
@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 enabled auto-merge (squash) July 14, 2026 10:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/samd-classification-medication-considerations.md (1)

48-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assign an owner and deadline for the open classification decision.

“Requires a human clinical + regulatory reviewer” is not an accountable assignment. Add an owner/team, target review date, and tracking or assessment reference so the OPEN status cannot persist indefinitely.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/samd-classification-medication-considerations.md` around lines 48 - 52,
Update the “Owner / next step” section to name an accountable owner or team,
specify a target review date, and include the relevant tracking ticket or
assessment reference. Preserve the requirement for human clinical and regulatory
review and the rule that the feature remains OPEN until the decision is
documented.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/clinical-dashboard/clinical-dashboard-helpers.ts`:
- Around line 73-109: Update answerReferencesDocument and
applyRenamedDocumentToAnswer in
src/components/clinical-dashboard/clinical-dashboard-helpers.ts to detect and
rename matching documents in quoteCards, smartPanel.bestSource, and
smartPanel.relatedDocuments. Add coverage in
tests/clinical-dashboard-helpers.test.ts for quoteCards and smartPanel-only
references, verifying their titles are updated.

In `@tests/clinical-dashboard-helpers.test.ts`:
- Around line 153-183: Add coverage in the existing “answerReferencesDocument /
applyRenamedDocumentToAnswer” suite for documents referenced only through
quoteCards and smartPanel.bestSource or smartPanel.relatedDocuments. Verify
answerReferencesDocument detects each reference, applyRenamedDocumentToAnswer
updates the matching titles in every supported location, and unrelated documents
preserve the original answer reference.

---

Nitpick comments:
In `@docs/samd-classification-medication-considerations.md`:
- Around line 48-52: Update the “Owner / next step” section to name an
accountable owner or team, specify a target review date, and include the
relevant tracking ticket or assessment reference. Preserve the requirement for
human clinical and regulatory review and the rule that the feature remains OPEN
until the decision is documented.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ee3fb1db-60ce-44e9-9097-861c5cab72b1

📥 Commits

Reviewing files that changed from the base of the PR and between 570e6ba and 0b3dd96.

📒 Files selected for processing (4)
  • docs/samd-classification-medication-considerations.md
  • src/components/ClinicalDashboard.tsx
  • src/components/clinical-dashboard/clinical-dashboard-helpers.ts
  • tests/clinical-dashboard-helpers.test.ts

Comment thread src/components/clinical-dashboard/clinical-dashboard-helpers.ts
Comment thread tests/clinical-dashboard-helpers.test.ts
answerReferencesDocument now checks every field applyRenamedDocumentToAnswer
rewrites — quoteCards and the nested smartPanel.bestSource /
smartPanel.relatedDocuments — so a document referenced only through those paths
is no longer guarded out and correctly picks up a rename (previously a
pre-existing latent mismatch carried over in the extraction). Adds tests for
quoteCards- and smartPanel-only detection + rename.

Also makes the SaMD tracking note's owner/next-step accountable: requires a
named owner, a target review-by date, and a tracking issue rather than an
open-ended "requires a reviewer".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe
@BigSimmo
BigSimmo merged commit 9f4dc13 into main Jul 14, 2026
16 checks passed
@BigSimmo
BigSimmo deleted the claude/medication-alerts-database-cb8o83 branch July 14, 2026 11:15
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