Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed patient filter in consent viewset #2942

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

khavinshankar
Copy link
Member

@khavinshankar khavinshankar commented Mar 20, 2025

Proposed Changes

  • Currently consents are not filtered by patients; added patient filter to the queryset in the 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

    • Enhanced data retrieval to return only consent records relevant to the specified patient.
  • Tests

    • Added a test to validate that only the appropriate consent records are returned for the authenticated patient.

@khavinshankar khavinshankar requested a review from a team as a code owner March 20, 2025 12:03
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

The changes update the ConsentViewSet by modifying its get_queryset method to filter consent records based on a patient's external ID provided in the keyword arguments. Additionally, a new test method named test_list_consent_are_filtered_by_patients has been added to verify that only the consent records for the authenticated patient are returned when making a GET request. The filtering logic and test ensure the endpoint behaves as intended when handling patient-specific queries. How novel!

Changes

File(s) Change Summary
care/emr/api/.../consent.py Updated get_queryset in ConsentViewSet to filter records by matching the patient's external_id from the provided kwargs, while retaining the existing logic.
care/emr/tests/.../test_consent_api.py Added test method test_list_consent_are_filtered_by_patients to confirm that the GET endpoint returns only the consent records for the authenticated patient.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant V as ConsentViewSet
    participant DB as Database

    U->>V: GET /consents?patient_external_id=xyz
    V->>DB: Filter query on consents (by patient_external_id)
    DB-->>V: Return matching consent records
    V-->>U: 200 OK with filtered consent data
Loading

Suggested reviewers

  • sainak
  • vigneshhari

Poem

In our code a new filter now stands,
Sorting out consents with meticulous hands.
A test to confirm what should be aligned,
Even if it seems obvious, precision is defined.
Cheers to clarity in logic, however belated it might be!

🚀🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b9e804 and 9146d25.

📒 Files selected for processing (1)
  • care/emr/tests/test_consent_api.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test / Test
🔇 Additional comments (1)
care/emr/tests/test_consent_api.py (1)

78-106: Good addition to verify patient filtering - though the method name could use a small grammatical tweak.

The test effectively verifies that consents are properly filtered by patient, creating scenarios with multiple patients and checking that only the appropriate consents are returned. This aligns nicely with the PR objective of fixing patient filtering in the consent viewset.

Minor detail, but the method name test_list_consent_are_filtered_by_patients has a slight grammatical inconsistency. Consider either test_list_consents_are_filtered_by_patients (plural) or test_list_consent_is_filtered_by_patients (singular) for perfect grammar.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (2)
care/emr/tests/test_consent_api.py (2)

78-102: Test case properly validates the filtering functionality

The test case creates an appropriate scenario with multiple patients and consents, then verifies that only the consent belonging to the authenticated patient is returned. This confirms the patient filtering in the viewset is working correctly.

However, there's a minor formatting issue flagged by the linter:

 encounter_self = self.create_encounter(
-            patient=self.patient, facility=self.facility, organization=self.organization
+            patient=self.patient,
+            facility=self.facility,
+            organization=self.organization,
         )
🧰 Tools
🪛 GitHub Actions: Lint Code Base

[error] 87-89: ruff-format failed. 1 file reformatted. Please review the changes made by the hook.


100-101: Clear assertion message would be helpful

The assertion is correct, but adding a descriptive message would make failures easier to debug.

-self.assertEqual(len(consents), 1)
-self.assertEqual(consents[0]["external_id"], consent_self.external_id)
+self.assertEqual(len(consents), 1, "Only one consent should be returned")
+self.assertEqual(consents[0]["external_id"], consent_self.external_id, "The returned consent should belong to the authenticated patient")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7c10c and c9c374f.

📒 Files selected for processing (2)
  • care/emr/api/viewsets/consent.py (1 hunks)
  • care/emr/tests/test_consent_api.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lint Code Base
care/emr/tests/test_consent_api.py

[error] 87-89: ruff-format failed. 1 file reformatted. Please review the changes made by the hook.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test / Test
🔇 Additional comments (1)
care/emr/api/viewsets/consent.py (1)

32-39: Good addition of patient filtering

The added filter ensures consents are properly filtered by patient's external_id, which aligns with the PR objectives. This improvement enhances data isolation between patients and fixes the issue mentioned in the PR description.

I would suggest adding a comment explaining the purpose of this filter since it's a security-related change, but I suppose the code is clear enough... maybe.

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.33%. Comparing base (9d7c10c) to head (9146d25).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2942   +/-   ##
========================================
  Coverage    52.33%   52.33%           
========================================
  Files          239      239           
  Lines        10710    10710           
  Branches      1177     1177           
========================================
  Hits          5605     5605           
  Misses        5088     5088           
  Partials        17       17           

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

@vigneshhari vigneshhari merged commit e68ce1c into develop Mar 20, 2025
8 checks passed
@vigneshhari vigneshhari deleted the khavinshankar/fix/fix-consent-patient-filter branch March 20, 2025 12:47
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