feat(medical-case): full case detail endpoint#30
Conversation
Expose full case payload via service + schemas and wire the new route.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds GET /cases/{case_id}/full to return an aggregated MedicalCaseDetailResponse (case, lab results, optional AI interpretation, chats). It introduces a service to assemble these pieces, repository count helpers, schema exports, endpoint wiring for auth/guest contexts, and comprehensive tests plus ignore-file updates. ChangesMedical Case Full Details Endpoint
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 @.gitignore:
- Around line 186-195: Redundant .env entries are listed even though `.env*`
already covers them; remove the specific `.env`, `.env.local`,
`.env.development.local`, `.env.test.local`, `.env.production.local`,
`.env.staging.local`, `.env.production`, `.env.staging`, `.env.development`, and
`.env.test` lines from .gitignore and keep the existing `.env*` pattern and any
explicit exceptions like `!.env.example`; if you need to preserve any specific
variants, add targeted negation rules (e.g., `!.env.example`) instead of
enumerating all variants.
In `@app/services/medical_case.py`:
- Around line 89-91: The current /full contract silently truncates related
records because lab_repo.list_by_case(..., limit=100) and
chat_repo.list_by_case(..., limit=500) hard‑cap results; update the logic so
/full truly returns complete histories by either (A) removing the fixed limits
and implementing a pagination loop that repeatedly calls
lab_repo.list_by_case(case_id, offset, limit) and
chat_repo.list_by_case(case_id, offset, limit) to aggregate all pages into
lab_results and chats, or (B) surface pagination explicitly by accepting
offset/limit params on the API and returning paging metadata with
interp_repo.get_latest_for_case still used for interpretation; reference
lab_results, chats, lab_repo.list_by_case, chat_repo.list_by_case, and
interp_repo.get_latest_for_case when making the change.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 14e95553-850f-41f6-a8bd-74e52ce4897c
📒 Files selected for processing (8)
.dockerignore.gitignoreapp/api/v1/endpoints/medical_case.pyapp/schemas/__init__.pyapp/schemas/medical_case.pyapp/services/medical_case.pytests/test_medical_case_full.pytests/test_patient_medical_case_flow.py
Use count_by_case so /full is not capped at arbitrary limits; drop redundant .env gitignore entries.
There was a problem hiding this comment.
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 `@app/services/medical_case.py`:
- Around line 84-88: The function currently calls get_case(...) with user: User
| None and guest_session_id: str | None and allows both to be None; add a guard
at the start of the function that enforces caller identity by raising an
appropriate exception (e.g., AuthenticationError or ValueError) if both user and
guest_session_id are None before calling get_case, referencing the parameters
user and guest_session_id and the call to get_case to locate where to add the
check; update any callers/tests as needed to provide identity or expect the new
error.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 1372dfe4-4109-4348-affa-a3c1518ebcd5
📒 Files selected for processing (4)
.gitignoreapp/repositories/chat.pyapp/repositories/lab_result.pyapp/services/medical_case.py
Add checks to ensure that either a user or a guest session ID is provided for accessing case details, raising ForbiddenError for invalid access attempts.
Description
GET /api/v1/cases/{case_id}/fullreturning an aggregated full case detail payload (case metadata plus related domain objects exposed through existing services/schemas).MedicalCaseDetailResponse(and supporting schema types) andget_case_fullin the medical case service to assemble the response; interpretation isnullwhen none exists.docker-compose.ymlwith Postgres and Redis for local development, plus an optional Postgres init script underdocker/postgres/init/.new_changes_*.mdin.gitignoreand.dockerignoreso they stay out of version control and Docker build contexts.Related Issue (Link to issue ticket)
Issue Link
Motivation and Context
Clients need a single request to load everything required for a case detail screen instead of chaining multiple endpoints. This reduces round-trip times and keeps assembly logic on the server. Local Compose makes it easier to run the API against real Postgres/Redis during development.
How Has This Been Tested?
uv run pytest(focused ontests/test_medical_case_full.pyandtests/test_patient_medical_case_flow.py, plus full suite if CI runs everything).docker compose up -d postgres redis, run migrations (uv run alembic upgrade head), start the app (uv run fastapi dev app/main.py), callGET /api/v1/cases/{id}/fullas an authenticated user who owns the case and verify shape/status codes (including cases with and without interpretation).Screenshots (if appropriate - Postman, etc):
Clinsights - Swagger UI_full_case_detail_test.pdf
Types of changes
Checklist:
Summary by CodeRabbit
New Features
Tests
Chores