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

Remove Summarization Tasks and Related Code #2653

Merged
merged 8 commits into from
Dec 20, 2024

Conversation

areebahmeddd
Copy link
Contributor

@areebahmeddd areebahmeddd commented Dec 15, 2024

Proposed Changes

  • Removed periodic summarization tasks from tasks/__init__.py.
  • Removed all summarization task definitions from tasks/summarisation.py.
  • Removed summarization task settings from config/settings/base.py.
  • Removed mentions of summarization tasks from documentation.
  • Removed summarization task serializers from api/serializers/summary.py.
  • Removed summarization task viewsets from api/viewsets/summary.py.
  • Removed summarization task API routes from config/api_router.py.

Associated Issue

  • Closes Remove summarization tasks and apis #2651. The proposed changes remove all summarization tasks, their definitions, related API endpoints, serializers, views, models, settings, and mentions in the documentation as requested in the issue.

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • Bug Fixes

    • Removed several classes and methods related to facility and district data summarization.
    • Eliminated periodic task registrations for summarization tasks.
  • Documentation

    • Updated documentation to reflect the removal of environment variable configurations related to summarization tasks.
  • Chores

    • Streamlined codebase by removing unused serializers, viewsets, and Celery tasks.
    • Removed obsolete models and their associated logic from the application.

@areebahmeddd areebahmeddd requested a review from a team as a code owner December 15, 2024 17:20
Copy link

coderabbitai bot commented Dec 15, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request systematically removes summarization-related components across multiple files in the Django project. This comprehensive cleanup eliminates Celery tasks, API endpoints, serializers, viewsets, configuration settings, and documentation references for various summary-related functionalities including triage, tests, facility capacity, patient, and district patient summaries. The changes suggest a deliberate streamlining of the project's summarization infrastructure, perhaps to make room for something more... efficient?

Changes

File Change Summary
care/facility/api/serializers/summary.py Deleted FacilitySummarySerializer and DistrictSummarySerializer
care/facility/api/viewsets/summary.py Removed multiple summary viewsets: FacilityCapacitySummaryViewSet, TriageSummaryViewSet, TestsSummaryViewSet, PatientSummaryViewSet, DistrictPatientSummaryViewSet
care/facility/tasks/__init__.py Removed periodic task registrations for summarization tasks
care/facility/tasks/summarisation.py Deleted entire file with Celery tasks for summarization
config/api_router.py Removed route registrations for summary-related viewsets
config/settings/base.py Deleted environment variables for summarization tasks
docs/django-configuration/configuration.rst Removed documentation for summarization task environment variables

Assessment against linked issues

Objective Addressed Explanation
Remove task definitions [#2651]
Remove API endpoints [#2651]
Remove serializers and views [#2651]
Remove models Model removal not evident in this changeset. Curious, isn't it?
Remove settings and docs mentions [#2651]

Poem

Farewell, summaries of old,
Your data tales no longer told
Bits and bytes now set free
From tasks that used to be 🗑️
Simplicity reigns supreme!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


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. (Beta)
  • @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

@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

🧹 Nitpick comments (1)
care/facility/migrations/0468_alter_facilitypatientstatshistory_unique_together_and_more.py (1)

12-41: Consider migration irreversibility implications

Just a friendly reminder that this migration is effectively a point of no return - it completely removes several models and their data. While this aligns with our objectives, you might want to consider taking a backup... you know, just in case someone changes their mind later? 😉

🧰 Tools
🪛 Ruff (0.8.2)

14-14: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


18-18: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e5d914e and be297fc.

📒 Files selected for processing (16)
  • care/facility/api/serializers/patient.py (0 hunks)
  • care/facility/api/viewsets/facility.py (0 hunks)
  • care/facility/api/viewsets/patient.py (1 hunks)
  • care/facility/api/viewsets/summary.py (0 hunks)
  • care/facility/management/commands/summarize.py (0 hunks)
  • care/facility/migrations/0468_alter_facilitypatientstatshistory_unique_together_and_more.py (1 hunks)
  • care/facility/models/__init__.py (0 hunks)
  • care/facility/models/patient.py (0 hunks)
  • care/facility/models/summary.py (0 hunks)
  • care/facility/tasks/__init__.py (0 hunks)
  • care/facility/utils/summarization/district/patient_summary.py (0 hunks)
  • care/facility/utils/summarization/facility_capacity.py (0 hunks)
  • care/facility/utils/summarization/patient_summary.py (0 hunks)
  • care/facility/utils/summarization/tests_summary.py (0 hunks)
  • care/facility/utils/summarization/triage_summary.py (0 hunks)
  • config/api_router.py (0 hunks)
💤 Files with no reviewable changes (14)
  • care/facility/management/commands/summarize.py
  • care/facility/utils/summarization/triage_summary.py
  • care/facility/models/init.py
  • care/facility/utils/summarization/facility_capacity.py
  • care/facility/utils/summarization/patient_summary.py
  • care/facility/utils/summarization/tests_summary.py
  • care/facility/utils/summarization/district/patient_summary.py
  • care/facility/api/viewsets/summary.py
  • care/facility/api/serializers/patient.py
  • care/facility/tasks/init.py
  • care/facility/models/summary.py
  • config/api_router.py
  • care/facility/api/viewsets/facility.py
  • care/facility/models/patient.py
✅ Files skipped from review due to trivial changes (1)
  • care/facility/api/viewsets/patient.py
🧰 Additional context used
🪛 Ruff (0.8.2)
care/facility/migrations/0468_alter_facilitypatientstatshistory_unique_together_and_more.py

9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


14-14: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


18-18: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


30-30: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


33-33: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


36-36: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


39-39: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

🔇 Additional comments (3)
care/facility/migrations/0468_alter_facilitypatientstatshistory_unique_together_and_more.py (3)

13-16: LGTM: Constraint removal properly ordered

The unique constraint is correctly removed before touching the fields. Nice to see someone following proper migration hygiene!

🧰 Tools
🪛 Ruff (0.8.2)

14-14: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


1-10: Verify this is the latest migration in sequence

The migration setup looks correct, but let's make absolutely sure there aren't any newer migrations that might conflict with these changes... wouldn't want any surprises, would we? 😊

✅ Verification successful

Well, look who's the latest migration in town 🎯

I've thoroughly checked, and migration 0468 is indeed the latest in the sequence. No sneaky dependent migrations lurking around that could cause any... unfortunate surprises. How refreshingly orderly.

  • Latest migrations in sequence:
    • 0466_camera_presets.py
    • 0467_alter_hospitaldoctors_area.py
    • 0468_alter_facilitypatientstatshistory_unique_together_and_more.py (our current one)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any migrations that might depend on this one
fd --type f ".*\.py$" care/facility/migrations/ --exec grep -l "0468_alter_facilitypatientstatshistory"

Length of output: 103


Script:

#!/bin/bash
# Let's try a different approach to check for migrations after 0468
fd "^\d{4}.*\.py$" care/facility/migrations/ | sort -n | grep -A1 "0468_alter"

# Also check the content of __init__.py to see if there are any migration references
cat care/facility/migrations/__init__.py

# And let's see what other migrations exist in the directory
fd "^\d{4}.*\.py$" care/facility/migrations/ | sort -n | tail -n 5

Length of output: 605

🧰 Tools
🪛 Ruff (0.8.2)

9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


9-9: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


17-28: Consider data preservation needs

I notice we're removing some rather important-looking fields here. I trust you've already thought about whether any of this data needs to be preserved for historical or audit purposes? 🤔

🧰 Tools
🪛 Ruff (0.8.2)

18-18: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


19-19: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


22-22: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


23-23: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


26-26: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


27-27: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

Copy link

codecov bot commented Dec 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.48%. Comparing base (7d3d958) to head (20cd5cd).
Report is 9 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2653      +/-   ##
===========================================
+ Coverage    69.63%   70.48%   +0.85%     
===========================================
  Files          211      201      -10     
  Lines        11879    11439     -440     
  Branches      1202     1164      -38     
===========================================
- Hits          8272     8063     -209     
+ Misses        3240     3014     -226     
+ Partials       367      362       -5     

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

@areebahmeddd
Copy link
Contributor Author

areebahmeddd commented Dec 15, 2024

@sainak Seems like you've done the remaining changes? thanks haha :)
I did see several unused blocks of code, on searching those objects throughout codebase, i found several files were interlinked.

Decided best to ask in discussion after making pr

@sainak
Copy link
Member

sainak commented Dec 15, 2024

@sainak Seems like you've done the remaining changes? thanks haha :)

yeah, there was some other stuff that needed to be removed, and it was easier this was

@sainak
Copy link
Member

sainak commented Dec 15, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Dec 15, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

🔭 Outside diff range comments (1)
care/facility/api/viewsets/patient.py (1)

Line range hint 584-626: Enhance error handling in transfer method

The transfer method could benefit from:

  1. Using status codes from rest_framework.status instead of magic numbers
  2. Consolidating validation logic
  3. Adding transaction management
+from django.db import transaction
+from rest_framework import status

     @action(detail=True, methods=["POST"])
     def transfer(self, request, *args, **kwargs):
+        with transaction.atomic():
             patient = PatientRegistration.objects.get(external_id=kwargs["external_id"])
             facility = get_object_or_404(Facility, external_id=request.data["facility"])
 
+            validation_errors = []
             if patient.is_expired:
-                return Response(
-                    {
-                        "Patient": "Patient transfer cannot be completed because the patient is expired"
-                    },
-                    status=status.HTTP_406_NOT_ACCEPTABLE,
-                )
+                validation_errors.append("Patient is expired")
 
             if patient.is_active and facility == patient.facility:
-                return Response(
-                    {
-                        "Patient": "Patient transfer cannot be completed because the patient has an active consultation in the same facility"
-                    },
-                    status=status.HTTP_406_NOT_ACCEPTABLE,
-                )
+                validation_errors.append("Patient has an active consultation in the same facility")
 
             if patient.allow_transfer is False:
-                return Response(
-                    {
-                        "Patient": "Patient transfer cannot be completed because the source facility does not permit it"
-                    },
-                    status=status.HTTP_406_NOT_ACCEPTABLE,
-                )
+                validation_errors.append("Source facility does not permit transfer")
+
+            if validation_errors:
+                return Response(
+                    {"errors": validation_errors},
+                    status=status.HTTP_406_NOT_ACCEPTABLE,
+                )
🧹 Nitpick comments (3)
care/facility/api/viewsets/patient.py (3)

26-26: Consider grouping related imports together

The import of status seems a bit lonely there between serializers and mixins. Perhaps it would feel more at home grouped with other REST framework imports? Just saying...


Line range hint 316-349: Simplify the diagnoses filter implementation

The filter_by_diagnoses method could be more concise by extracting the verification status mapping to a class-level constant and using dict.get() for safer access.

class PatientFilterSet(filters.FilterSet):
+    VERIFICATION_STATUS_MAP = {
+        "diagnoses_unconfirmed": ConditionVerificationStatus.UNCONFIRMED,
+        "diagnoses_provisional": ConditionVerificationStatus.PROVISIONAL,
+        "diagnoses_differential": ConditionVerificationStatus.DIFFERENTIAL,
+        "diagnoses_confirmed": ConditionVerificationStatus.CONFIRMED,
+    }

     def filter_by_diagnoses(self, queryset, name, value):
         if not value:
             return queryset
         filter_q = Q(last_consultation__diagnoses__diagnosis_id__in=value.split(","))
         if name == "diagnoses":
             filter_q &= ~Q(
                 last_consultation__diagnoses__verification_status__in=INACTIVE_CONDITION_VERIFICATION_STATUSES
             )
         else:
-            verification_status = {
-                "diagnoses_unconfirmed": ConditionVerificationStatus.UNCONFIRMED,
-                "diagnoses_provisional": ConditionVerificationStatus.PROVISIONAL,
-                "diagnoses_differential": ConditionVerificationStatus.DIFFERENTIAL,
-                "diagnoses_confirmed": ConditionVerificationStatus.CONFIRMED,
-            }[name]
+            verification_status = self.VERIFICATION_STATUS_MAP.get(name)
+            if verification_status is None:
+                return queryset
             filter_q &= Q(
                 last_consultation__diagnoses__verification_status=verification_status
             )
         return queryset.filter(filter_q)

Line range hint 479-515: Add docstring to explain permission logic

The filter_queryset method contains complex permission logic that could use some explanation. It would be really nice if future developers understood why certain user types have specific access levels.

     def filter_queryset(self, queryset: QuerySet) -> QuerySet:
+        """
+        Filters queryset based on user permissions and CSV export requirements.
+        
+        Permission hierarchy:
+        - Superuser: Full access
+        - StateLabAdmin: Access to state facilities
+        - DistrictLabAdmin: Access to district facilities
+        - Other users: Access to allowed facilities, assigned patients
+        """
         if self.action == "list" and settings.CSV_REQUEST_PARAMETER in self.request.GET:
             for backend in (PatientDRYFilter, filters.DjangoFilterBackend):
                 queryset = backend().filter_queryset(self.request, queryset, self)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be297fc and 20cd5cd.

📒 Files selected for processing (1)
  • care/facility/api/viewsets/patient.py (1 hunks)
🔇 Additional comments (1)
care/facility/api/viewsets/patient.py (1)

Line range hint 479-515: Optimize database queries for better performance

The queryset could be optimized to reduce database load:

  1. Consider using prefetch_related for reverse relationships
  2. Cache frequently accessed querysets
  3. Use values() or values_list() for simple lookups

Let's verify the query performance:

@vigneshhari vigneshhari merged commit bae3201 into ohcnetwork:develop Dec 20, 2024
7 checks passed
@areebahmeddd areebahmeddd deleted the remove-summarization branch December 31, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Remove summarization tasks and apis
3 participants