Extract pure ClinicalDashboard helpers into a tested module (+ SaMD note)#653
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe 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. ChangesClinical Dashboard helper extraction
SaMD classification documentation
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
ESLint install failed: one or more packages not found in the registry. Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
docs/samd-classification-medication-considerations.md (1)
48-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssign 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
📒 Files selected for processing (4)
docs/samd-classification-medication-considerations.mdsrc/components/ClinicalDashboard.tsxsrc/components/clinical-dashboard/clinical-dashboard-helpers.tstests/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
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-lineClinicalDashboard.tsxso the domain logic can be unit-tested directly:normalizedPollDelay,shorterPollDelay,hasActiveIndexingWork,setupNeedsSlowRecheck(+ the sharedsetupRecheckPollMsconstant)answerReferencesDocument,applyRenamedDocumentToAnswer,mergeDocumentRefreshcompactScopeFilters,hasNonProductionSupabaseApiKeyFallback,normalizeNavigationHash,isAbortError,answerTimedOutErrorClinicalDashboard.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— newclinical-dashboard-helpers.test.ts(12) passes; rest of the suite green (the only failures are pre-existing local env gaps:@testing-librarynot installed here / stale.nexttypes, both avoided by CI'snpm ci+ fresh build)npm run typecheck— clean for the changed filesnpm run lint— clean (--max-warnings 0)prettier --check— clean/, 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 aboveNo 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;
setupRecheckPollMsnow lives in the helpers module and is imported back intoClinicalDashboard.tsx. The branch was restarted from the latestmainafter PR #620 merged.🤖 Generated with Claude Code
https://claude.ai/code/session_01JBemWnYhqdGXBzwJUTQAqe
Generated by Claude Code
Summary by CodeRabbit
Documentation
Improvements
Tests