Implemented Api Test cases for Encounter Viewset
Merge Checklist
- [x] Tests added/fixed
- [ ] Update docs in
/docs - [ ] Linting Complete
- [ ] Any other necessary step
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
- Tests
- Added comprehensive tests for the Encounter API, including filtering, permissions, CRUD operations, organization management, discharge summary generation, and care team management. These tests help ensure robust API behavior and proper permission enforcement.
📝 Walkthrough
Walkthrough
Adds a new comprehensive test module for Encounter APIs and updates a single exception message string in the Encounter viewset; tests cover filtering, CRUD, permissions, organization and care-team management, discharge-summary async flows, and appointment linkage.
Changes
| Cohort / File(s) | Summary |
|---|---|
Encounter API testscare/emr/tests/test_encounter_api.py |
New test suite introducing EncounterAPITests, EncounterOrganizationAPITests, and EncounterAppointmentAPITests. Covers list filters, CRUD, validations, permission checks, org add/remove and care-team rules, discharge-summary async behavior (with mocks), and appointment-linking scenarios. |
Minor viewset message changecare/emr/api/viewsets/encounter.py |
Minor text change in a raised PermissionDenied message: "User Cannot access patient" → "User cannot access patient". No logic changes. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor User
participant API as Encounter API
participant Auth as Permissions
participant Prog as Progress Tracker
participant Q as Task Queue
participant SVC as Discharge Service
User->>API: POST /encounters/{id}/discharge_summary
API->>Auth: Check permission
alt Authorized
API->>Prog: Check in-progress state
alt None in progress
API->>Q: Enqueue generate_discharge_summary(encounter_id)
Q-->>SVC: Invoke async task
SVC->>Prog: Update progress (queued→running→done)
API-->>User: 202 Accepted (tracking info)
else Already in progress
API-->>User: 409 Conflict
end
else Forbidden
API-->>User: 403 Forbidden
end
sequenceDiagram
autonumber
actor User
participant API as Encounter API
participant Auth as Permissions
participant Appt as Appointment Store
User->>API: POST /encounters (appointment_id=...)
API->>Auth: Validate create permissions
alt Authorized
API->>Appt: Check if appointment is unlinked
alt Unlinked
API-->>User: 201 Created (encounter linked)
else Linked elsewhere
API-->>User: 400/409 Error
end
else Forbidden
API-->>User: 403 Forbidden
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested reviewers
- praffq
- sainak
- vigneshhari
Poem
New tests arrive with promises bold,
They poke at edges, tidy and cold.
Async queues and orgs in line,
One sentence tweaked — oh, how fine.
Run them, please; don’t be too kind.
Pre-merge checks and finishing touches
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description Check | ⚠️ Warning | The PR description only contains the Merge Checklist and omits required template sections such as "Proposed Changes", "Associated Issue", and "Architecture changes", so it does not conform to the repository's description template and lacks essential context about what the tests cover. This omission makes it harder for reviewers to understand scope and rationale, and reviewer comments about failing tests are not documented in the PR description. | Please update the PR description to include a "Proposed Changes" section summarizing the added test classes and their intent, an "Associated Issue" section with a link or explicit "none", and an "Architecture changes" section or a note that none apply; also update the Merge Checklist to reflect lint/test status and add a short note about current failing tests and how you will address reviewer feedback (for example adding GET verification after POST/PUT as requested). After those additions the description will match the repository template and provide reviewers the context needed to proceed. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title Check | ✅ Passed | The PR title "Implemented Api Test cases for Encounter Viewset" concisely states the primary change—adding API tests for the Encounter viewset—and directly matches the changes in the diff. It is short, specific, and readable for a reviewer scanning history. Minor style nit: use "API" (all caps) and consider "ViewSet" for consistent casing. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
nandkishor/test/feat/encounter
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 @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:x: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 53.99%. Comparing base (97fa8a8) to head (2ef3d7a).
:warning: Report is 28 commits behind head on develop.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| care/emr/api/viewsets/encounter.py | 0.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #3071 +/- ##
========================================
Coverage 53.99% 53.99%
========================================
Files 416 416
Lines 18705 18705
Branches 2013 2013
========================================
Hits 10099 10099
Misses 8578 8578
Partials 28 28
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
for all tests for which include creating/updating using POST/PUT , once this request is success can you make a GET request to get the created/updated object and verify if it actually got created and updated
test cases failing , please check @nandkishorr
patient filter tests pending