test: cover the discharge summary and the LLM provider dispatch - #672
Conversation
Two features had no tests at all. `GET /summary/<admission>` assembles the discharge summary screen. The integration tests cover the patient header and derived IMC, the recent out-of-range exams, the active allergies, the saved draft, and the annotation time windows that decide which clinical note feeds each summary topic — including the `clinicalSummary` composition, the de-duplication across notes and the `?mock=true` prompt preview. `llm_service.prompt` dispatches to the model named by the `summary-config` record. The unit tests mock the config lookup and the Bedrock client to cover the dispatch table, each provider's request body and region, the answer extraction (including the gpt-oss `<reasoning>` stripping), and the validation branches. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kmjcsax3vdE2YXXDKEBk96
There was a problem hiding this comment.
This PR adds comprehensive test coverage for two previously untested features: the discharge summary endpoint and the LLM provider dispatch logic. The integration tests thoroughly validate the annotation windowing logic, exam filtering, and authorization boundaries. The unit tests provide complete coverage of the provider dispatch table and response parsing. Both test suites follow best practices with proper mocking, synthetic data, and self-cleaning fixtures. All 33 new tests are well-structured and the PR achieves the stated coverage improvements (30% → 100% for summary_service and 24% → 100% for llm_service).
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
Two features had no tests at all. This adds one integration suite and one unit suite for them.
GET /summary/<admission_number>— discharge summary (integration)tests/integration/test_summary.py— 17 tests,services/summary_service.pygoes from 30% → 100%.The interesting logic is the annotation windowing: each summary topic reads its own time window relative to the first or the last clinical note of the admission (the admission reason covers the first four days, previous drugs only the first day, the discharge topics only the last day, and diagnosis/procedures/exams have no window at all). The fixture lays out four notes so every window has a note inside it and a note outside it, and the tests assert both sides.
Also covered: the patient header and the derived IMC (and the
Nonecase when weight/height are unknown), the exams filter (out-of-range and within the last 7 days), active-only allergies named by substance when the drug is catalogued, de-duplication across notes, theclinicalSummarycomposition from reason + procedures + summary, the saved draft, the?mock=trueprompt preview, an admission with no notes, and the 401/400 boundaries.llm_service.prompt— model provider dispatch (unit)tests/unit/test_llm_service.py— 16 tests,services/llm_service.pygoes from 24% → 100%.Both boundaries are mocked (the
summary-configlookup and the Bedrock client), so no database and no AWS access. Covers the dispatch table, each provider's request body, model id and region, the answer extraction for claude / gpt_oss / llama (including the<reasoning>stripping, single and repeated), and the guards: permission gating, empty messages, missing configuration, unknown provider, and the two configurable-but-unimplemented providers.Notes
ruff checkclean.services+repositorycoverage: 80% → 81%.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kmjcsax3vdE2YXXDKEBk96
Generated by Claude Code