Skip to content

add patient filter to token#3573

Open
Jacobjeevan wants to merge 1 commit intoohcnetwork:developfrom
Jacobjeevan:token-patient-filter
Open

add patient filter to token#3573
Jacobjeevan wants to merge 1 commit intoohcnetwork:developfrom
Jacobjeevan:token-patient-filter

Conversation

@Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Mar 13, 2026

Proposed Changes

  • add patient filter to token viewset

Merge Checklist

  • 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

  • New Features
    • Added patient identifier filtering capability to token scheduling operations, enabling more granular filtering of scheduling tokens by patient.

@Jacobjeevan Jacobjeevan requested a review from a team as a code owner March 13, 2026 09:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

A single filter field patient_filter was added to the TokenFilters class, configured to filter on the patient__external_id field using a UUIDFilter. No logic changes or behavioral modifications were introduced.

Changes

Cohort / File(s) Summary
Token Filter Enhancement
care/emr/api/viewsets/scheduling/token.py
Added patient_filter field to TokenFilters class, backed by UUIDFilter on patient__external_id.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the 'Associated Issue' section and lacks detail about the problem being solved. While it includes the merge checklist, it doesn't meet the template requirements. Add the 'Associated Issue' section linking to the relevant issue and explaining how this change solves it. Provide more context about why this filter is needed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a patient filter to the token viewset filter class.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link
Contributor

@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 the current code and only fix it if needed.

Inline comments:
In `@care/emr/api/viewsets/scheduling/token.py`:
- Line 37: Add unit tests covering the new patient_filter =
UUIDFilter(field_name="patient__external_id") on the Token viewset: write three
concise tests for the Token list endpoint (or TokenViewSet) that assert (1) a
token is returned when filtering by a valid patient's external_id, (2) no tokens
are returned when the external_id does not match any patient, and (3) the API
returns a 400/validation error (or behaves as your filter layer does) when given
an invalid UUID string; create test fixtures for a patient with external_id and
associated tokens, call the viewset list route with query param
patient=<external_id> and assert responses accordingly, and include these tests
in the repo test suite so the new patient_filter is covered.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 865bbed2-8fba-4e01-8dc3-db6fdab4bb15

📥 Commits

Reviewing files that changed from the base of the PR and between 3557a8f and bb7faad.

📒 Files selected for processing (1)
  • care/emr/api/viewsets/scheduling/token.py

sub_queue_is_null = NullFilter(field_name="sub_queue")
date = DateFilter(field_name="queue__date") # For dependent filtering only
patient_name = CharFilter(field_name="patient__name", lookup_expr="icontains")
patient_filter = UUIDFilter(field_name="patient__external_id")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add coverage for the new patient filter before merge.

Line 37 introduces a new list-filter surface, so it really should ship with tests (valid patient external_id match, non-match, and invalid UUID input). The implementation itself is clean, but leaving it untested is an easy way to regress quietly later.

Based on learnings: Token booking flows assume a patient is always associated, and external_id-path filtering is a supported pattern in this codebase.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@care/emr/api/viewsets/scheduling/token.py` at line 37, Add unit tests
covering the new patient_filter = UUIDFilter(field_name="patient__external_id")
on the Token viewset: write three concise tests for the Token list endpoint (or
TokenViewSet) that assert (1) a token is returned when filtering by a valid
patient's external_id, (2) no tokens are returned when the external_id does not
match any patient, and (3) the API returns a 400/validation error (or behaves as
your filter layer does) when given an invalid UUID string; create test fixtures
for a patient with external_id and associated tokens, call the viewset list
route with query param patient=<external_id> and assert responses accordingly,
and include these tests in the repo test suite so the new patient_filter is
covered.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.06%. Comparing base (3557a8f) to head (bb7faad).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3573      +/-   ##
===========================================
+ Coverage    77.05%   77.06%   +0.01%     
===========================================
  Files          474      474              
  Lines        22271    22272       +1     
  Branches      2325     2325              
===========================================
+ Hits         17161    17164       +3     
+ Misses        4553     4552       -1     
+ Partials       557      556       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant