fix: resolve remaining roster, teaching, clinical-math, form-print, diff-integrity, and doc governance issues

Merged
BI
1mo ago
+1704-267

User description

Summary

Resolves the remaining actionable non-RAG, non-migration open issues (#NHR0MM, #WFYDV6, #08216B, #3ZHFH9, #WMGPSG, #1WAA0Z, and #100 Phase 0(a)), and queues issues:done inbox records for #CFHRJY and #3B4S3Z:

  • Roster, Teaching & WA Public Holidays (#NHR0MM):
    • src/components/roster/roster-week-strip.tsx: Deduplicates shift kinds and words per day and renders a secondary +N indicator when distinct shift kinds share a day, while keeping duplicate shifts of the same kind as a single badge.
    • src/components/teaching/teaching-view-model.ts: Restores the Perth calendar-day guard (perthDateKey(s.startsAt) >= todayKey) for allDay: true scheduled sessions in nextSession.
    • src/lib/on-call/wa-public-holidays.ts, src/lib/roster/team/fairness.ts, src/lib/roster/team/calendar-model.ts, src/components/roster/team/calendar/week-board.tsx, src/components/roster/team/roster-today-team.tsx: Exports isWaPublicHolidayDate(dateKey) and routes fairness and team calendar holiday checks through it so post-2028 and historical WA public holidays resolve via waPublicHolidaysByRule(year).
  • WA MHA Form Print & Clinical Math Calculators (#WFYDV6 & #08216B):
    • src/components/forms/wa-mha-form-print.tsx: Replaces Form 6B prior-consent wording with statutory post-order "Report to the Chief Psychiatrist (Form 6B attachment)" wording matching src/lib/form-register.ts, and replaces WA Department of Health branding with an explicit "Non-Statutory Study Layout — Mental Health Act 2014 (WA)" header and warning banner.
    • src/lib/calculators/clinical-math/renal.ts, lithium.ts, types.ts: Adds Devine Ideal Body Weight (IBW) and Adjusted Body Weight (ABW) guidance to calculateCockcroftGault, aligns the >= 1.2 mmol/L toxic lithium boundary across evaluateLithiumLevel and calculateProportionalLithiumDose, clarifies haemodialysis clinical thresholds at >= 2.0 mmol/L, and updates proportional lithium dose rounding to 125 mg Australian scored-tablet increments.
  • Answer Stream Danger-Suppression & Diff-Integrity Guard (#100 & #3ZHFH9):
    • tests/answer-stream-preview-order.test.ts: Adds offline route-level POST(/api/answer/stream) tests verifying zero evidence_preview units are emitted over SSE when sources or answer-level relevance have danger-level governance status (all_sources_danger, answer_level_danger, contract_rejected).
    • scripts/check-diff-integrity.mjs & tests/diff-integrity.test.ts: Extends test-case and assertion counting to Python test files (def test_* and @pytest.mark.parametrize), weights inline test.each/it.each/test.for array literals by element count, and detects mass-skipping (.skip/.fixme) reductions in active test coverage.
  • Documentation, Skills & Encoding Governance (#WMGPSG & #1WAA0Z):
    • Losslessly repairs all double-encoded UTF-8 mojibake across docs/privacy-impact-assessment.md and docs/openai-cross-border-basis.md, documents ragRanking and canary-pair safeguards in .agents/skills/rag/SKILL.md and .agents/skills/reindex/SKILL.md, and documents the deliberate !min-h-[48px] SSO button floor in docs/redesign/07-token-adoption-audit.md.

Risk and rollout

  • Tier: Tier 2 (Clinical-adjacent calculators, non-statutory form study sheet, UI components, and verification scripts; zero RAG retrieval/ranking or database migration changes).
  • Rollback plan: Pure code, test, and documentation changes; revert commit dd68df5ce6 cleanly with zero database or storage state side effects.

Clinical Governance Preflight

  • Source verification & statutory alignment: WaMhaFormPrintSheet now matches src/lib/form-register.ts on Form 6B statutory post-order report wording and carries an explicit Non-Statutory Study Layout header and warning banner; clinical-math calculators align with Australian Therapeutic Guidelines (Devine IBW/ABW Cockcroft-Gault guidance, >= 1.2 mmol/L lithium toxicity threshold, clarified >= 2.0 mmol/L severe toxicity vs haemodialysis criteria, and 125 mg half-tablet increments).
  • Patient-data handling & service-role confinement: Zero changes to patient-data storage, authentication, or service-role boundaries.

Verification

  • npm run typecheck — passed (0 errors)
  • npm run lint — passed (0 errors, 0 warnings)
  • npm run docs:maintain — passed (organisation: exit 0, CLINICAL_HAZARD_CONTROLS_PASS, retired-rules: pass, instruction-budget: pass)
  • node scripts/check-ledger-write-discipline.mjs — passed (fa526775c6ca..HEAD)
  • node scripts/check-diff-integrity.mjs --self-test & node scripts/check-diff-integrity.mjs — passed (27/27 self-tests, 98 -> 122 test cases)
  • npx vitest run tests/roster-teaching-holiday-fixes.dom.test.tsx tests/wa-mha-form-print.dom.test.tsx tests/clinical-math-calculators.test.ts tests/clinical-math-bounds.test.ts tests/answer-stream-preview-order.test.ts tests/diff-integrity.test.ts tests/doc-governance-encoding-and-skills.test.ts — passed (192 tests)
  • UI verification not run: covered locally by focused JSDOM suites (roster-teaching-holiday-fixes.dom.test.tsx, wa-mha-form-print.dom.test.tsx) and on GitHub Actions by Production UI.

Summary by cubic

Closes seven open non-RAG, non-migration issues across roster/teaching displays, clinical-math calculators, form printing, diff-integrity verification, and documentation governance, and records issues:done inbox entries for #CFHRJY and #3B4S3Z. RosterWeekStrip deduplicates shift kinds per day and shows a +N badge when distinct kinds share a day; nextSession keeps today's and future all-day teaching in Perth dates while dropping past all-day sessions; and WA public holiday checks route through isWaPublicHolidayDate so pre-2026 dates use published WA dates (including the Sunday 2025-01-26 correction) and post-2028 dates resolve by statutory rule. Rollback is a clean revert with no database or storage side effects.

Form print and clinical calculators

  • Form 6B attachment wording now matches form-register.ts statutory post-order reporting; department branding replaced with a Non-Statutory Study Layout header and warning; chiefPsychiatristConsent deprecated for chiefPsychiatristReportSubmitted.
  • Cockcroft-Gault accepts optional height and applies Devine IBW/ABW effective CrCl only for overweight patients, warning when height is omitted; lithium toxicity boundary aligned at >= 2.0 mmol/L with severe-toxicity guidance tied to EXTRIP extracorporeal criteria; proportional lithium doses round to 125 mg increments and rounded doses are validated so toxic results are rejected.

Verification and documentation

  • Answer-stream tests confirm zero evidence_preview units are emitted over SSE when sources or answers carry danger-level governance status.
  • check-diff-integrity.mjs counts Python test cases, weights inline test.each/it.each/test.for arrays by element, counts skipped suite descendants, and fails on mass-skipping reductions in active coverage.
  • Fixed double-encoded UTF-8 mojibake in the two PIA docs; documented the ragRanking/canary-pair and SSO button floor safeguards in skills and audit docs.

CodeAnt-AI Description

Correct roster and teaching dates, refine clinical guidance, and clarify WA form prints

What Changed

  • Roster weeks distinguish different shift types on the same day without duplicating badges. WA holidays are recognized in roster calendars and fairness counts, including dates after 2028.
  • The next-session view includes all-day sessions scheduled for today in Perth and excludes past all-day sessions.
  • Renal clearance guidance can account for height and adjusted body weight. Lithium levels at 1.2 mmol/L are treated as toxic; severe toxicity guidance no longer implies automatic dialysis at 2.0 mmol/L, and suggested doses round to practical tablet increments.
  • WA Form 6A/6B print layouts are clearly marked as non-statutory study materials and direct clinicians to official forms. Form 6B now describes the Chief Psychiatrist attachment as a post-order report, not prior consent.

Impact

✅ Correct holiday counts for future rosters
✅ All-day sessions appear on the correct Perth date
✅ Clearer lithium toxicity and dose guidance
✅ Clearer warnings on WA form printouts

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • New Features

    • Roster week views now indicate when a day includes multiple distinct shift types.
    • Upcoming teaching sessions now include all-day sessions scheduled for today or later.
    • Clinical calculators now provide weight-based guidance for Cockcroft–Gault estimates and configurable lithium dose rounding.
  • Bug Fixes

    • Corrected WA public-holiday recognition across historical and future dates.
    • Updated lithium toxicity thresholds and guidance, including safer handling of high levels.
    • WA mental health print forms now clarify that they are non-statutory study aids and update Form 6B notification wording.