Skip to content

feat: redesign medication search results with semantic badges and safety-aware actions#477

Merged
BigSimmo merged 9 commits into
mainfrom
claude/wonderful-fermat-f00d79
Jul 11, 2026
Merged

feat: redesign medication search results with semantic badges and safety-aware actions#477
BigSimmo merged 9 commits into
mainfrom
claude/wonderful-fermat-f00d79

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

  • Redesign the medication prescribing search results onto the canonical semantic badge system: contraindication/monitoring content in the "Prescribing action" column now carries a source-derived actionTone (danger/warning/neutral) rendered as a quiet Ban/TriangleAlert icon with a screen-reader prefix, per the badge governance guide (red stays reserved for true contraindications).
  • Surface per-row identity badges (S8 lock, PBS streamlined, Authority required, TGA, Reviewed) through the existing ClinicalBadge/medicationIdentityBadges vocabulary; the match-quality badge renders only when it differentiates rows (kills the N× "Exact clinical fit" repetition).
  • Filter chips (Best / Indication / Safety / Monitor) gain icons and live counts; Safety/Monitor now also match on actionTone (the old regex missed "Contraindicated…" text entirely — the Safety chip showed 0 while every row displayed a contraindication).
  • Add empty states: zero-result filter → inset panel with a "Show all N matches" reset; no matches at all → guidance panel. The desktop table no longer renders an empty shell.
  • Polish: micro-caps tinted table header, query-token <mark> highlight in medication names, hover chevron affordance (motion-safe), stronger top-match accent bar, tabular numerals on doses.
  • Data quality: new firstClinicalSentence helper stops action/dose text truncating at abbreviations ("Any hepatic impairment (e" → "Any hepatic impairment (e.g. cirrhosis)") or decimals.
  • New unit coverage for actionTone derivation and sentence truncation (tests/medications.test.ts).

Note: this branch also carries a pre-existing commit from another session (docs: align readiness runtime version); its content has since landed on main independently, so the net PR diff is exactly the four files above.

Verification

  • npm run verify:pr-local equivalent run as individual gates post-merge: format:check, lint, typecheck, test (full vitest), plus verify:cheap earlier in the session — all green. Under heavy machine load some unrelated RAG tests (e.g. rag-cache-invalidation) flake on the 15s default timeout; they pass with --testTimeout=60000 and are untouched by this diff.

  • npm run verify:ui when UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changed — Chromium suite green post-merge (also 124/124 pre-merge). Manual Playwright QA: desktop/mobile × light/dark, filter counts, empty states, hover states.

  • npm run verify:release before release or handoff confidence claims — not run (not a release).

  • npm run eval:retrieval:quality — not run: no retrieval, ranking, selection, chunking, or scoring behavior changed (rankMedicationRecords untouched; the new filters are client-side display predicates on already-ranked results).

  • npm run eval:rag -- --limit 15 + npm run eval:quality -- --rag-only — not run: answer generation, synthesis prompt, and post-processing unchanged.

  • npm run check:production-readiness — not run: no clinical workflow/privacy/env/Supabase/governance/deployment behavior change (display-layer only).

  • npm run check:deployment-readiness — not run: no deployment behavior change.

Clinical Governance Preflight

Completed because the change touches clinical output presentation (medication search results display).

  • Source-backed claims still require linked source verification before clinical use (rows still link to the full prescribing reference; no new claim generation)
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy) — no env/config change
  • Service-role keys and private document access remain server-only — no API/auth change beyond an additive optional response field
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative — contraindication content becomes more visually conservative (danger icon), tones derive from data source fields, not heuristics
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed — presentation-only change following the established badge governance guide (docs/clinical-badge-system-guide.md); no new decision logic

Notes

  • API contract change is additive-only: MedicationSearchResult.actionTone plus threading the existing per-slug governance map through the catalog hook type.
  • Existing ui-smoke hooks preserved: medication-result-{slug}-desktop/-phone testids, desktop row stays an <a href="/medications/{slug}">, mobile action text stays in a <p>.

🤖 Generated with Claude Code

BigSimmo and others added 6 commits July 10, 2026 21:54
…ety-aware actions

- Derive actionTone (danger/warning/neutral) from the source field that
  supplies the prescribing action; render Ban/TriangleAlert icons with
  sr-only prefixes so contraindications carry visual + a11y weight
- Surface per-row identity badges (S8, PBS, TGA, Reviewed) through the
  existing ClinicalBadge/medicationIdentityBadges system
- Show the match-quality badge only when it differentiates rows
- Add icons + live counts to the Best/Indication/Safety/Monitor chips;
  Safety/Monitor now also match on actionTone (regex missed
  "Contraindicated..." text)
- Add empty states for zero-result filters (with reset) and no-match
  searches; gate the desktop table on non-empty results
- Highlight the query token in medication names; micro-caps table
  header; hover chevron affordance; tabular numerals on doses
- Add firstClinicalSentence so action/dose text no longer truncates at
  abbreviations like "e.g." or decimals

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@supabase

supabase Bot commented Jul 11, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 11, 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41254f9d-d0a1-4db7-aa4f-e49a99dd88a6

📥 Commits

Reviewing files that changed from the base of the PR and between cb52836 and d6284c7.

📒 Files selected for processing (2)
  • src/components/clinical-dashboard/medication-prescribing-workspace.tsx
  • tests/medications.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/medications.test.ts
  • src/components/clinical-dashboard/medication-prescribing-workspace.tsx

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Enhanced medication search with richer clinical badges, filter icons, per-filter result counts, and improved query highlighting.
    • Added safety-aware prescribing tone indicators (“danger”, “warning”, “neutral”) and action-tone driven guidance rendering.
    • Improved results presentation across desktop/mobile, including richer empty states and “show all matches” when other filters have results.
    • Improved dose and guidance sentence extraction for more accurate display.
  • Tests

    • Expanded coverage for action-tone derivation and sentence truncation behavior, including edge-case guidance text.

Walkthrough

Medication search results now derive structured action tones and clinical sentence text, use governance metadata for badges, expose filter counts, and render richer desktop/mobile result states with highlighting and contextual empty states.

Changes

Medication search and prescribing workspace

Layer / File(s) Summary
Medication action metadata
src/lib/medications.ts, tests/medications.test.ts
Medication guidance now produces concise action text with danger, warning, or neutral tones; sentence extraction handles abbreviations and decimals, with expanded test coverage.
Result preparation and filtering
src/components/clinical-dashboard/medication-prescribing-workspace.tsx, src/components/clinical-dashboard/use-medication-catalog.ts
Search result types incorporate action tones and governance data, while filtering, counts, badge derivation, and tone-aware helpers are updated.
Desktop and mobile result rendering
src/components/clinical-dashboard/medication-prescribing-workspace.tsx
Results render highlighted names, tone icons, clinical badges, contextual empty states, links, and updated mobile badge layouts.

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

Sequence Diagram(s)

sequenceDiagram
  participant MedicationCatalogResponse
  participant MedicationResults
  participant FilterStrip
  participant ClinicalBadge
  MedicationCatalogResponse->>MedicationResults: provide medication results and governance metadata
  MedicationResults->>FilterStrip: provide filtered rows and per-filter counts
  FilterStrip->>MedicationResults: select active filter
  MedicationResults->>ClinicalBadge: render identity and match badge data
Loading
🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (10 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: semantic badges and safety-aware medication search results.
Description check ✅ Passed The description follows the required template with Summary, Verification, Clinical Governance Preflight, and Notes sections filled in.
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.
Generated And Sensitive Files ✅ Passed Diff only touches TS/TSX source and tests; no secrets, .env files, caches, build outputs, or other sensitive artifacts were found.
Verification Claims ✅ Passed The PR note names exact checks (npm run verify:pr-local, npm run verify:ui, etc.) and gives explicit results or not-run reasons, so it complies.
Risky Git Or Deployment Actions ✅ Passed Changed files are UI/lib/test code only, and scans found no force-push/reset/clean/deploy instructions in the PR diff.
Supabase Project And Schema Safety ✅ Passed The PR only changes client-side medication UI/types/tests; no env, migration, RLS, or policy files were modified, and no Supabase project ref changes appear.
Runtime And Package Manager Integrity ✅ Passed Diff only touches UI/test files; package.json still pins npm@11.17.0 and Node 24.x with engine-strict=true, and package-lock.json is untouched.
Api Route Failure Handling ✅ Passed No API/server/RAG/provider code changed; the only fetch hook throws on non-OK responses and catches to surface an error state.
✨ 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/wonderful-fermat-f00d79
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/wonderful-fermat-f00d79

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 300701299f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/medications.ts

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

🧹 Nitpick comments (1)
src/components/clinical-dashboard/medication-prescribing-workspace.tsx (1)

63-66: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the shared MedicationActionTone/MedicationResultTone types instead of redeclaring them.

actionTone/tone are redefined here as inline literal unions that must exactly mirror MedicationActionTone/MedicationResultTone in src/lib/medications.ts. Since this file already imports from @/lib/medications (line 33), importing the two type aliases directly would remove the duplication and prevent drift if the tone set changes later (it's a brand-new type introduced in this very PR, so duplication risk is immediate).

♻️ Proposed fix
-import { medicationIdentityBadges, type MedicationRecord } from "`@/lib/medications`";
+import {
+  medicationIdentityBadges,
+  type MedicationActionTone,
+  type MedicationRecord,
+  type MedicationResultTone,
+} from "`@/lib/medications`";
   action: string;
-  actionTone: "danger" | "warning" | "neutral";
-  tone: "teal" | "blue" | "slate";
+  actionTone: MedicationActionTone;
+  tone: MedicationResultTone;
   href?: string;
🤖 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 `@src/components/clinical-dashboard/medication-prescribing-workspace.tsx`
around lines 63 - 66, Replace the inline literal unions for actionTone and tone
in the relevant props/type definition with the shared MedicationActionTone and
MedicationResultTone aliases from `@/lib/medications`, adding them to the existing
import and removing the duplicated declarations.
🤖 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.

Nitpick comments:
In `@src/components/clinical-dashboard/medication-prescribing-workspace.tsx`:
- Around line 63-66: Replace the inline literal unions for actionTone and tone
in the relevant props/type definition with the shared MedicationActionTone and
MedicationResultTone aliases from `@/lib/medications`, adding them to the existing
import and removing the duplicated declarations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0a8324e1-5e19-489c-a837-e1fc68cd9605

📥 Commits

Reviewing files that changed from the base of the PR and between a62c6b4 and 3007012.

📒 Files selected for processing (4)
  • src/components/clinical-dashboard/medication-prescribing-workspace.tsx
  • src/components/clinical-dashboard/use-medication-catalog.ts
  • src/lib/medications.ts
  • tests/medications.test.ts

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 11, 2026
Records whose avoid/contraindication field explicitly says NONE or 'no
absolute contraindication' (naloxone, acetylcysteine, nystatin, ...) no
longer render the Ban icon and 'Do not use' prefix: downgrade to warning
when the displayed sentence still carries a caution, else neutral.
Adds synthetic + naloxone snapshot coverage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07de31ee82

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/medications.ts
Avoid rows that are pure cautionary guidance (Pregnancy Category B2,
pharmacist review / dose reduction) now render the warning tone instead
of the Ban icon. Condition-list and setting-based hard stops (severe
respiratory depression; unmonitored environments) keep danger — the
downgrade is keyed to explicit caution phrasing with no hard-stop
keyword, so under-warning stays the avoided failure mode. Adds
synthetic coverage plus fexofenadine/loratadine snapshot regressions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@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: 1

🤖 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 `@tests/medications.test.ts`:
- Around line 195-200: Update the test using getMedicationRecord and
medicationActionDetail so each caution snapshot record explicitly asserts tone
is "warning" instead of merely asserting it is not "danger"; retain the existing
fexofenadine and loratadine coverage.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 53b69833-3693-4a87-bb69-757f317598e6

📥 Commits

Reviewing files that changed from the base of the PR and between 07de31e and cb52836.

📒 Files selected for processing (2)
  • src/lib/medications.ts
  • tests/medications.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/medications.ts

Comment thread tests/medications.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb528367db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/components/clinical-dashboard/medication-prescribing-workspace.tsx Outdated
…pshot assertions

Warning-toned avoid guidance (Pregnancy Category B2, pharmacist
review/dose reduction) now matches the Safety chip — any row rendering
a safety icon is reachable through it. Snapshot tests assert the exact
warning tone instead of merely not-danger.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant