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 patient ordering by category #1235

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

Ashesh3
Copy link
Member

@Ashesh3 Ashesh3 commented Mar 30, 2023

Required for: coronasafe/care_fe#5197

This PR adds a new filter backend, PatientCustomOrderingFilter, to allow custom ordering of the Patient queryset based on the category_severity field. This field is annotated using a Case statement that maps each category value to its corresponding severity order. The filter backend accepts a new query parameter ordering to specify the ordering direction, which can be either ascending or descending.

This change also imports the Case and When classes from django.db.models to be used in the PatientCustomOrderingFilter`
implementation.

Overall, this PR enhances the functionality of the PatientViewSet by providing a new custom ordering option based on the severity of the patient's category.

@coronasafe/code-reviewers

@Ashesh3 Ashesh3 requested a review from a team as a code owner March 30, 2023 13:29
@sonarcloud
Copy link

sonarcloud bot commented Mar 30, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.1% 0.1% Duplication

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 45.45% and project coverage change: -0.02 ⚠️

Comparison is base (5b13720) 56.22% compared to head (7fc67a1) 56.20%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1235      +/-   ##
==========================================
- Coverage   56.22%   56.20%   -0.02%     
==========================================
  Files         193      193              
  Lines        9491     9502      +11     
  Branches     1600     1604       +4     
==========================================
+ Hits         5336     5341       +5     
- Misses       4100     4106       +6     
  Partials       55       55              
Impacted Files Coverage Δ
care/facility/api/viewsets/patient.py 45.56% <45.45%> (-0.01%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@siddnikh
Copy link
Contributor

siddnikh commented Apr 1, 2023

LGTM

@nihal467 nihal467 added the P2 label Apr 3, 2023
Copy link
Member

@vigneshhari vigneshhari left a comment

Choose a reason for hiding this comment

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

If this is a requirement then i would recommend creating a migration and moving the values into something that is queryable. Do create an issue for that and track separately.

default=(len(category_ordering) + 1),
output_field=models.IntegerField(),
)
).order_by(ordering)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you be ordering based on the new annotated field?

Copy link
Member Author

@Ashesh3 Ashesh3 Apr 6, 2023

Choose a reason for hiding this comment

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

@vigneshhari That is being already done, the annotated field is category_severity and here (.order_by(ordering)) ordering can be either category_severity or -category_severity.

@Ashesh3
Copy link
Member Author

Ashesh3 commented Apr 6, 2023

If this is a requirement then i would recommend creating a migration and moving the values into something that is queryable. Do create an issue for that and track separately.

For the separate issue, you mean a migration to move the values to numeric? So that we can return the category sorted in any order without needing a custom filter_backend? In that case I'd imagine the numeric value to be lowest [0] (Comfort) to highest [n] (Critical).

@gigincg gigincg merged commit 3e7f57b into coronasafe:master Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants