Skip to content

feat(medical-case): full case detail endpoint#30

Merged
PreciousEzeigbo merged 5 commits into
devfrom
feature/full_case_detail_endpoint
May 16, 2026
Merged

feat(medical-case): full case detail endpoint#30
PreciousEzeigbo merged 5 commits into
devfrom
feature/full_case_detail_endpoint

Conversation

@Goldeno10
Copy link
Copy Markdown
Collaborator

@Goldeno10 Goldeno10 commented May 16, 2026

Description

  • Adds GET /api/v1/cases/{case_id}/full returning an aggregated full case detail payload (case metadata plus related domain objects exposed through existing services/schemas).
  • Introduces MedicalCaseDetailResponse (and supporting schema types) and get_case_full in the medical case service to assemble the response; interpretation is null when none exists.
  • Adds API tests for the full-detail endpoint and extends patient-oriented flow tests to cover the new behavior.
  • Adds docker-compose.yml with Postgres and Redis for local development, plus an optional Postgres init script under docker/postgres/init/.
  • Ignores local contributor notes new_changes_*.md in .gitignore and .dockerignore so 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?

  • Automated: uv run pytest (focused on tests/test_medical_case_full.py and tests/test_patient_medical_case_flow.py, plus full suite if CI runs everything).
  • Manual: docker compose up -d postgres redis, run migrations (uv run alembic upgrade head), start the app (uv run fastapi dev app/main.py), call GET /api/v1/cases/{id}/full as 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

full_Case_test_1 full_Case_test_1

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Summary by CodeRabbit

  • New Features

    • GET /cases/{id}/full returns a full case history: case details, lab results, optional AI interpretation (null when absent), and chat thread (oldest→newest). Supports authenticated users and guest sessions.
  • Tests

    • Added end-to-end tests covering nested payloads, null interpretation, guest access, authorization, 404 handling, and chronological chats; plus patient-facing history flow tests.
  • Chores

    • Updated ignore rules to exclude local changelog notes and Docker artifacts.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@Goldeno10 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 40 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2f868a0c-bc0f-4e9e-8e2b-74b49d58091a

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5d128 and 00b0927.

📒 Files selected for processing (1)
  • app/services/medical_case.py
📝 Walkthrough

Walkthrough

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

Changes

Medical Case Full Details Endpoint

Layer / File(s) Summary
Schema and Service Layer for Full Case Detail
app/schemas/medical_case.py, app/schemas/__init__.py, app/services/medical_case.py
MedicalCaseDetailResponse schema bundles case, lab results, optional interpretation, and chats. CaseFullDetail dataclass and get_case_full service function orchestrate loading from multiple repositories with ownership validation.
API Endpoint Integration
app/api/v1/endpoints/medical_case.py
New retrieve_full endpoint wires case, lab, interpretation, and chat repositories with dual user/guest context, calls get_case_full, and returns aggregated details as SuccessResponse[MedicalCaseDetailResponse].
Repository Count Methods
app/repositories/chat.py, app/repositories/lab_result.py
Adds count_by_case methods and imports func to enable COUNT aggregates used by the service.
Endpoint Authorization and Response Shape Tests
tests/test_medical_case_full.py
Tests authorization (owned access, 403 for wrong user, 200 for guest sessions), nested payload structure, null interpretation handling, 404 for unknown cases, and chat ordering by timestamp.
Patient-Facing Integration Tests
tests/test_patient_medical_case_flow.py
Tests patient workflows: creating case with pending lab, completing case with extraction and interpretation, listing cases, and verifying chat order matches dedicated chat endpoint.
Configuration and Maintenance
.dockerignore, .gitignore
Adds ignore rules for local changelog notes and Docker artifacts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • feat: Full case detail endpoint #7: Implements get_case_full, MedicalCaseDetailResponse, and the GET /cases/{id}/full endpoint with comprehensive test coverage, directly addressing the issue's requirements.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a new full case detail endpoint for medical cases. It is concise, specific, and directly related to the primary feature introduced in the changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/full_case_detail_endpoint

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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e251439 and 228bc3a.

📒 Files selected for processing (8)
  • .dockerignore
  • .gitignore
  • app/api/v1/endpoints/medical_case.py
  • app/schemas/__init__.py
  • app/schemas/medical_case.py
  • app/services/medical_case.py
  • tests/test_medical_case_full.py
  • tests/test_patient_medical_case_flow.py

Comment thread .gitignore Outdated
Comment thread app/services/medical_case.py Outdated
Use count_by_case so /full is not capped at arbitrary limits; drop redundant .env gitignore entries.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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

📥 Commits

Reviewing files that changed from the base of the PR and between 228bc3a and 5c5d128.

📒 Files selected for processing (4)
  • .gitignore
  • app/repositories/chat.py
  • app/repositories/lab_result.py
  • app/services/medical_case.py

Comment thread app/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.
@PreciousEzeigbo PreciousEzeigbo self-requested a review May 16, 2026 10:46
@PreciousEzeigbo PreciousEzeigbo merged commit b1514e0 into dev May 16, 2026
8 checks passed
@Lftobs Lftobs deleted the feature/full_case_detail_endpoint branch May 21, 2026 07:50
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.

2 participants