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

Filter by name and status in valueset #2867

Merged

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 24, 2025

Proposed Changes

  • Filter by name and status in valueset to make it consistent with frontend

Associated Issue

Architecture changes

  • Remove this section if not used

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
    • Introduced enhanced filtering options for refined data queries based on name and status criteria.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 24, 2025 18:32
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

This pull request enhances the filtering capabilities of the ValueSetViewSet by introducing a new ValueSetFilter class. This class includes two filters: one for name using a case-insensitive containment lookup and another for status using an exact match lookup. The ValueSetViewSet is updated to use this new filter class and the DjangoFilterBackend, allowing for more precise query operations. How innovative!

Changes

File Change Summary
care/emr/api/viewsets/valueset.py Added ValueSetFilter with filters for name (icontains) and status (iexact). Updated ValueSetViewSet to set filterset_class and filter_backends.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant V as ValueSetViewSet
    participant D as DjangoFilterBackend
    participant F as ValueSetFilter

    C->>V: Request with filter parameters
    V->>D: Pass request for filtering
    D->>F: Apply filters (name, status)
    F-->>D: Return filtered query set
    D-->>V: Provide filtered data
    V-->>C: Return response
Loading

Possibly related PRs

Suggested reviewers

  • vigneshhari

Poem

In lines of code, a filter's born anew,
Refining queries with a subtle cue.
The viewset now listens with deliberate grace,
While parameters race in a measured pace.
Cheers to changes—finally, some order in this space!

(A tiny nod to our ever-evolving code base...)

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 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 7f4c369 and aa16b94.

📒 Files selected for processing (1)
  • care/emr/api/viewsets/valueset.py (2 hunks)
🔇 Additional comments (3)
care/emr/api/viewsets/valueset.py (3)

1-2: Appropriate import additions for filtering functionality.

The necessary imports have been correctly added to support the filtering features, which seems like something that probably should have been there from the beginning.


21-24: Good implementation of filter class with appropriate lookup expressions.

The ValueSetFilter class properly extends filters.FilterSet and defines two filter fields with suitable lookup expressions:

  • name using case-insensitive containment search
  • status using case-insensitive exact match

This implementation aligns with the PR objective to implement filtering by name and status.


30-31:

❓ Verification inconclusive

Verify if other filter backends should be preserved.

The implementation correctly configures the viewset to use the filter class, but it's replacing any existing filter backends with just DjangoFilterBackend. If there were other backends like SearchFilter or OrderingFilter that should be preserved, you might want to include them as well.


🏁 Script executed:

#!/bin/bash
# Check if this viewset previously had other filter_backends that should be preserved
git show HEAD~1:care/emr/api/viewsets/valueset.py | grep -A 3 "filter_backends"

Length of output: 116


Action: Verify Preservation of Additional Filter Backends

The current implementation in care/emr/api/viewsets/valueset.py only includes DjangoFilterBackend. However, it's unclear whether previous configuration included additional backends (such as SearchFilter or OrderingFilter). The initial verification script using HEAD~1 failed due to an invalid revision reference—so we couldn't confirm if any other backends were in use before.

Please verify manually by checking the commit history for this file. For example, you might run:

#!/bin/bash
# Get the previous commit that affected the file and inspect filter_backends
commit=$(git log -n 2 --pretty=format:"%H" -- care/emr/api/viewsets/valueset.py | tail -n 1)
if [ -z "$commit" ]; then
  echo "No previous commit found for this file."
else
  git show ${commit}:care/emr/api/viewsets/valueset.py | grep -A 3 "filter_backends"
fi

Double-check if there were other filter backends that need to be preserved. If any are identified, consider including them alongside DjangoFilterBackend.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 (1)
care/emr/api/viewsets/valueset.py (1)

20-22:

❓ Verification inconclusive

I couldn't help but notice the inconsistent naming.

The class is named ValuesetFilter while the model is ValueSet. I'm sure it was just an oversight, but consistency in naming would be lovely.

-class ValuesetFilter(filters.FilterSet):
+class ValueSetFilter(filters.FilterSet):

Also, let's verify that the status filter values are properly documented and validated.


🏁 Script executed:

#!/bin/bash
# Search for status field definition in the model and any related documentation
rg -l 'status.*=.*' care/emr/models/valueset.py

Length of output: 77


Fix naming inconsistency and verify status field validation

  • The filter class is named ValuesetFilter, but the model is defined as ValueSet. For consistency, please rename the filter class to ValueSetFilter:
    -class ValuesetFilter(filters.FilterSet):
    +class ValueSetFilter(filters.FilterSet):
  • Although the search confirms that the model file (care/emr/models/valueset.py) contains a definition for the status field, please double-check that the allowed values for status are well documented and properly validated (e.g., using a choices attribute or explicit validators).

Overall, the changes look good aside from these two points—just a small refinement to keep things consistent and ensure data validation remains robust.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10fa74c and 6f0249c.

📒 Files selected for processing (1)
  • care/emr/api/viewsets/valueset.py (2 hunks)
🔇 Additional comments (2)
care/emr/api/viewsets/valueset.py (2)

5-6: LGTM! Nice and tidy imports.

The new imports are properly organized with other framework imports. I suppose we can all appreciate when someone takes the time to keep things orderly.


27-28:

❓ Verification inconclusive

The filtering setup looks good, but...

The implementation is correct, though I'm sure we'd all feel more confident with some test coverage for these new filters. You know, just to make absolutely certain everything works as intended.

Let's check if there are any test files that could use some filter-related test cases:


🏁 Script executed:

#!/bin/bash
# Search for existing test files related to ValueSet
fd -g "*test*valueset*.py" -g "*test*value_set*.py"

Length of output: 160


Filtering setup is solid, but test coverage appears to be missing

The filtering implementation in care/emr/api/viewsets/valueset.py (lines 27-28) correctly utilizes ValuesetFilter and DjangoFilterBackend, aligning with the PR’s objectives. However, our initial attempt to locate test files related to these filters didn’t produce any results—likely due to the search command’s syntax issues.

Could you please verify whether there are existing tests for these changes or consider adding some to ensure the filters behave as expected? For a more reliable file search, you might try running these corrected commands:

#!/bin/bash
# Search for test files related to ValueSet using separate glob patterns
fd --glob '*test*valueset*.py'
fd --glob '*test*value_set*.py'

Thanks for addressing this—ensuring proper test coverage will strengthen our confidence in the new functionality.

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 (1)
care/emr/api/viewsets/valueset.py (1)

20-22: Filter implementation looks correct, but could use some documentation.

The ValueSetFilter class is implemented correctly with appropriate filter fields and lookup expressions. However, it wouldn't hurt to add a docstring explaining the purpose of these filters, since not everyone has the luxury of understanding your code at first glance.

class ValueSetFilter(filters.FilterSet):
+    """
+    Filter for ValueSet objects.
+    - name: Filters by case-insensitive partial name match
+    - status: Filters by exact status match
+    """
    name = filters.CharFilter(field_name="name", lookup_expr="icontains")
    status = filters.CharFilter(field_name="status", lookup_expr="iexact")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f0249c and 7f4c369.

📒 Files selected for processing (1)
  • care/emr/api/viewsets/valueset.py (2 hunks)
🔇 Additional comments (3)
care/emr/api/viewsets/valueset.py (3)

5-6: Good job adding the necessary imports.

The new imports for Django filters are correctly added and properly organized with the rest of the imports. It's nice to see someone following import conventions... for once.


27-28: ViewSet configuration looks good.

The filter configuration is properly set up in the ViewSet. I suppose we can all agree this is the minimal amount of code required to make it work.


20-28:

❓ Verification inconclusive

Consider adding tests for the filtering functionality.

While the implementation looks correct, it would be nice if there were tests to verify that the filters actually work as expected. The PR checklist does mention adding tests, so I assume you're planning to add them... eventually.


🏁 Script executed:

#!/bin/bash
# Check if tests exist for ValueSetViewSet filtering

echo "Searching for test files related to ValueSet..."
fd -t f "test.*valueset.*" --exec grep -l "filter" {} \;

echo "Checking if PR includes test file changes..."
git diff --name-only origin/main..HEAD | grep -E "test.*\.py$"

Length of output: 526


Tests Needed for ValueSet Filtering Functionality

It appears that no tests were found verifying the filtering behavior in ValueSetViewSet (lines 20–28 in care/emr/api/viewsets/valueset.py). Please add tests to confirm that the name (using "icontains") and status (using "iexact") filters work as expected. Given the ambiguous git diff output, kindly double-check your test suite to ensure nothing was overlooked.

@rithviknishad
Copy link
Member

lint checks failing @AdityaJ2305

make sure you've installed pre-commit btw;

pre-commit install

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.31%. Comparing base (4a16a09) to head (aa16b94).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2867      +/-   ##
===========================================
+ Coverage    56.28%   56.31%   +0.02%     
===========================================
  Files          226      226              
  Lines        10939    10946       +7     
  Branches      1112     1112              
===========================================
+ Hits          6157     6164       +7     
  Misses        4765     4765              
  Partials        17       17              

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

@AdityaJ2305
Copy link
Contributor Author

AdityaJ2305 commented Feb 26, 2025

@rithviknishad @vigneshhari done

@vigneshhari vigneshhari merged commit 3d654e9 into ohcnetwork:develop Feb 27, 2025
5 checks passed
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.

Add Support for filter by name and status in valueset
3 participants