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 abatement and chronic_condition to conditions #2771

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

sainak
Copy link
Member

@sainak sainak commented Jan 22, 2025

Proposed Changes

  • Add abatement and chronic_condition to conditions

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

    • Added support for tracking condition abatement details
    • Introduced new category for chronic conditions
  • Bug Fixes

    • Corrected category naming from "encounter-diagnosis" to "encounter_diagnosis"
  • Refactor

    • Enhanced data model to include more comprehensive condition information

@sainak sainak requested a review from a team as a code owner January 22, 2025 12:39
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

📝 Walkthrough

Walkthrough

This pull request introduces an abatement field to the Condition model, enhancing the data representation for medical conditions. The changes span across migration, model, and specification files, adding a JSONField to store abatement details. The migration also includes a function to update the category field from "encounter-diagnosis" to "encounter_diagnosis" and introduces a new category for chronic conditions.

Changes

File Change Summary
care/emr/migrations/0010_condition_abatement.py Added migration to introduce abatement JSONField and category update functions
care/emr/models/condition.py Added abatement JSONField with default empty dictionary
care/emr/resources/condition/spec.py - Added ConditionAbatementSpec class
- Updated CategoryChoices enum
- Added abatement attribute to ConditionSpec, ConditionSpecRead, and ConditionSpecUpdate

Sequence Diagram

sequenceDiagram
    participant Model as Condition Model
    participant Migration as Database Migration
    participant Spec as Condition Specification

    Migration->>Model: Add abatement JSONField
    Migration->>Model: Update category field
    Spec->>Model: Define abatement specification
    Model-->>Spec: Validate abatement details
Loading

Possibly related PRs

Suggested reviewers

  • vigneshhari

Poem

🩺 Conditions evolve, data takes flight
Abatement whispers, medical insight
From dashes to underscores, categories align
A JSONField blooms, where details intertwine
Code grows wiser, with each gentle stride 🌱

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@vigneshhari vigneshhari merged commit 2f59824 into develop Jan 22, 2025
5 of 6 checks passed
@vigneshhari vigneshhari deleted the sainak/update-condition-categories branch January 22, 2025 12:41
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 (4)
care/emr/migrations/0010_condition_abatement.py (2)

6-12: Consider adding a batch size for large datasets.

The category update looks fine, but for larger datasets, you might want to consider using .iterator() and processing in batches. Not that I'm suggesting you have performance issues, but it's always good to plan ahead.

 def fix_encounter_diagnosis_category_case(apps, schema_editor):
     Condition = apps.get_model("emr", "Condition")
-    Condition.objects.filter(category="encounter-diagnosis").update(category="encounter_diagnosis")
+    batch_size = 1000
+    queryset = Condition.objects.filter(category="encounter-diagnosis")
+    for batch in queryset.iterator(chunk_size=batch_size):
+        batch.category = "encounter_diagnosis"
+        batch.save()

17-29: Maintain consistent quote style.

I noticed you're using single quotes. The static analysis tool suggests using double quotes to maintain consistency. Not a big deal, but consistency is nice.

     dependencies = [
-        ('emr', '0009_medicationrequest_authored_on'),
+        ("emr", "0009_medicationrequest_authored_on"),
     ]

     operations = [
         migrations.AddField(
-            model_name='condition',
-            name='abatement',
+            model_name="condition",
+            name="abatement",
             field=models.JSONField(default=dict),
         ),
🧰 Tools
🪛 Ruff (0.8.2)

17-17: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


17-17: 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)

care/emr/resources/condition/spec.py (2)

53-58: Consider adding field validation for age and datetime.

The ConditionAbatementSpec looks good, following the same pattern as ConditionOnSetSpec. However, you might want to add some validation to ensure abatement_age is non-negative and abatement_datetime is not in the future. Just a thought.

from pydantic import validator
from datetime import datetime

class ConditionAbatementSpec(EMRResource):
    # ... existing fields ...

    @validator("abatement_age")
    def validate_age(cls, v):
        if v is not None and v < 0:
            raise ValueError("Age cannot be negative")
        return v

    @validator("abatement_datetime")
    def validate_datetime(cls, v):
        if v is not None and v > datetime.now():
            raise ValueError("Abatement datetime cannot be in the future")
        return v

73-73: Ensure consistent default value usage across specs.

I notice you're using {} in some places and dict in others for the abatement default. While both work, it might be better to stick to one style:

# ConditionSpec
abatement: ConditionAbatementSpec = {}  # Line 73

# ConditionSpecRead
abatement: ConditionAbatementSpec = dict  # Line 114

# ConditionSpecUpdate
abatement: ConditionAbatementSpec = {}  # Line 136

Also applies to: 114-114, 136-136

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba647ba and b04d8a2.

📒 Files selected for processing (3)
  • care/emr/migrations/0010_condition_abatement.py (1 hunks)
  • care/emr/models/condition.py (1 hunks)
  • care/emr/resources/condition/spec.py (5 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
care/emr/migrations/0010_condition_abatement.py

17-17: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


17-17: 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)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / test
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
care/emr/models/condition.py (1)

16-16: Consider documenting the abatement field's purpose and structure.

I see we're adding another JSONField with default=dict. While I'm sure you know what you're doing, it might be helpful for others (and your future self) to document the expected structure and purpose of this field. Also, remember that using default=dict can lead to shared state issues if not handled properly.

Let's check if there are any other JSONFields with similar patterns in the codebase:

✅ Verification successful

The abatement field follows established codebase patterns.

Looking at the extensive use of JSONField(default=dict) across the codebase, particularly in medical record models, this implementation is perfectly consistent with the project's conventions. The field name is actually quite self-documenting for those familiar with medical records, though I suppose a little documentation never hurt anyone... if you're into that sort of thing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for JSONField usage patterns
rg "JSONField\(default=dict" -A 2 -B 2

Length of output: 51389

care/emr/resources/condition/spec.py (1)

36-37: Verify the impact of category enum changes.

The addition of chronic_condition and modification of encounter_diagnosis might affect existing code. I assume you've thoroughly tested this, but it wouldn't hurt to verify.

✅ Verification successful

Everything seems perfectly fine with the category changes

The changes are properly handled through migration file 0010_condition_abatement.py. The chronic_condition is a new addition that doesn't affect existing code, and the encounter_diagnosis format change is managed through proper data migration. I suppose we can all rest easy now.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of the modified category values
echo "Searching for old category value usage..."
rg "encounter-diagnosis" --type py

echo "Searching for chronic_condition references..."
rg "chronic_condition" --type py

Length of output: 638

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.74%. Comparing base (ba647ba) to head (b04d8a2).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2771      +/-   ##
===========================================
+ Coverage    64.72%   64.74%   +0.02%     
===========================================
  Files          252      252              
  Lines        12733    12743      +10     
  Branches      1119     1119              
===========================================
+ Hits          8241     8251      +10     
  Misses        4384     4384              
  Partials       108      108              

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

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