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

Add search functionality to DeviceViewSet with registered_name and user_friendly_name filters #2877

Merged
merged 5 commits into from
Mar 1, 2025

Conversation

Rishith25
Copy link
Contributor

@Rishith25 Rishith25 commented Feb 27, 2025

Proposed Changes

Associated Issue

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 device search functionality now allows you to filter devices by both registered and user-friendly names.

@Rishith25 Rishith25 requested a review from a team as a code owner February 27, 2025 16:36
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

📝 Walkthrough

Walkthrough

The changes update the device API by modifying the DeviceViewSet class. The filter_backends attribute has been changed from a list containing only the Django filter backend to a tuple that also includes the search filter. Additionally, a new attribute search_fields has been added, allowing searches on the registered_name and user_friendly_name fields. These modifications enable enhanced query filtering for devices. How novel!

Changes

File Changes Summary
care/.../api/viewsets/device.py Modified filter_backends from [filters.DjangoFilterBackend] to (filters.DjangoFilterBackend, drf_filters.SearchFilter). Added search_fields with ["registered_name", "user_friendly_name"].

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DeviceViewSet
    participant DjangoFilterBackend
    participant SearchFilter

    Client->>DeviceViewSet: GET /devices?search=<query>
    DeviceViewSet->>DjangoFilterBackend: Apply standard filters
    DeviceViewSet->>SearchFilter: Apply search filter on specified fields
    DeviceViewSet-->>Client: Return filtered device list
Loading

Possibly related PRs

Suggested reviewers

  • vigneshhari

Poem

In code’s quiet art, a search begins,
Filtering through names where the query spins.
With Django and search in clever embrace,
Our devices now find their rightful place.
A tweak so neat, it earns a knowing grin!

(Keep up the work, even if it was inevitable.)


📜 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 d2a31a3 and 2081809.

📒 Files selected for processing (1)
  • care/emr/api/viewsets/device.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • care/emr/api/viewsets/device.py

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/device.py (1)

60-61: Search functionality looks good, but be aware of potential redundancy.

The implementation of search functionality is correct and aligns with DRF best practices. However, I noticed there's now some redundancy between the new search field for "registered_name" and the existing filter for the same field in DeviceFilters class (line 51). This means users can filter by registered_name using either the filter parameter or the search parameter.

While this redundancy isn't necessarily a problem, it might be worth adding a code comment explaining why both are available, to prevent someone from removing one of them in the future thinking it's unnecessary duplication.

    filter_backends = (filters.DjangoFilterBackend, drf_filters.SearchFilter)
-   search_fields = ["registered_name", "user_friendly_name"]
+   # Note: registered_name is available both as a filter and search field for different query use cases
+   search_fields = ["registered_name", "user_friendly_name"]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d654e9 and 3397572.

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

6-6: New import added correctly, but consider consolidating imports.

The new import for DRF filters is correctly added, but you might want to consider consolidating your filter imports for slightly better code organization. Not a big deal though, I suppose.

@Rishith25
Copy link
Contributor Author

@rithviknishad @vigneshhari Can you please review this PR let me know if any changes are required

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.32%. Comparing base (3d654e9) to head (41cb1c0).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2877   +/-   ##
========================================
  Coverage    56.32%   56.32%           
========================================
  Files          226      226           
  Lines        10948    10950    +2     
  Branches      1112     1112           
========================================
+ Hits          6166     6168    +2     
  Misses        4765     4765           
  Partials        17       17           

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

@DraKen0009
Copy link
Contributor

LGTM. Note that registered_name and user_friendly_name both will be searched together when using ?search param from frontend.

@Rishith25
Copy link
Contributor Author

LGTM. Note that registered_name and user_friendly_name both will be searched together when using ?search param from frontend.

Yeah implemented same in the frontend

@ohcnetwork ohcnetwork deleted a comment from DraKen0009 Mar 1, 2025
@vigneshhari vigneshhari merged commit 7c6f624 into ohcnetwork:develop Mar 1, 2025
1 check 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 searching user_friendly_name for Device
4 participants