8000 fix for entered in error choices by praffq · Pull Request #3061 · ohcnetwork/care · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix for entered in error choices #3061

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

praffq
Copy link
Contributor
@praffq praffq commented Jun 3, 2025

Proposed Changes

  • added validation to specs and removed delete endpoints from viewsets

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

    • Added validation to prevent updates to records (such as conditions, consents, devices, encounters, medication requests, medication statements, allergy intolerances, and bookings) that are marked as "entered in error".
  • Refactor

    • Modularized and streamlined several EMR viewsets for improved maintainability. No visible changes to user-facing features or workflows.
  • Bug Fixes

    • Ensured that updates to EMR resources consistently enforce new validation rules for error states.
  • Tests

    • Updated test cases to reflect new validation rules and removed tests related to deleting certain records.

@praffq praffq requested a review from a team as a code owner June 3, 2025 14:56
Copy link
Contributor
coderabbitai bot commented Jun 3, 2025
📝 Walkthrough

Walkthrough

This change refactors EMR viewset classes to use explicit mixins instead of a monolithic base class and adds model-level validators across multiple resource specs to prevent updates to records with a status of entered_in_error. Delete functionality and related tests are removed for affected resources.

Changes

Files/Paths Change Summary
care/emr/api/viewsets/condition.py, consent.py, device.py, medication_administration.py, medication_request.py, medication_statement.py Refactored viewset inheritance from EMRModelViewSet to explicit mixins and base class; removed device delete methods.
care/emr/resources/allergy_intolerance/spec.py, condition/spec.py, consent/spec.py, device/spec.py, encounter/spec.py, medication/administration/spec.py, medication/request/spec.py, medication/statement/spec.py, scheduling/slot/spec.py Added model-level validators to prevent updates if status is entered_in_error.
care/emr/tests/test_allergy_intolerance_api.py, test_consent_api.py, test_device_api.py, test_diagnosis_api.py, test_symptom_api.py Updated tests to set explicit statuses; removed all delete-related test cases for affected resources.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_ViewSet
    participant ModelValidator

    Client->>API_ViewSet: PATCH/PUT (update resource)
    API_ViewSet->>ModelValidator: validate_status/validate_verification_status
    ModelValidator-->>API_ViewSet: Raise error if status == "entered_in_error"
    API_ViewSet-->>Client: Return error if update not allowed
    API_ViewSet-->>Client: Proceed with update if allowed
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent updates to any resource with entered_in_error status (#112)
Remove delete endpoints and related logic for resources where entered_in_error is used (#112)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Refactoring all viewset inheritance to explicit mixins (multiple files) While not strictly required by #112, this structural change is a general refactor, not out-of-scope as it supports finer-grained control for the new validators.
Removal of device-specific delete logic (care/emr/api/viewsets/device.py) Aligned with issue #112's requirement to remove delete endpoints, so not out-of-scope.
Removal of delete-related tests (multiple test files) Matches the objective to disallow deletion, so not out-of-scope.

Possibly related PRs

Suggested labels

waiting-for-review

Suggested reviewers

  • vigneshhari

Poem

In the land of EMR, where bugs once did dwell,
Now "entered_in_error" is a fortress, a shell.
No edits may enter, no deletes sneak by—
Mixins march in, as monoliths wave goodbye.
The tests all agree, as the status stands tall,
Uneditable errors—no updates at all!
🏰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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
codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 43.15789% with 54 lines in your changes missing coverage. Please review.

Project coverage is 51.17%. Comparing base (c076917) to head (bd9f1c8).

Files with missing lines Patch % Lines
care/emr/resources/allergy_intolerance/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/condition/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/consent/spec.py 33.33% 6 Missing ⚠️
care/emr/resources/device/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/encounter/spec.py 40.00% 6 Missing ⚠️
...re/emr/resources/medication/administration/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/medication/request/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/medication/statement/spec.py 40.00% 6 Missing ⚠️
care/emr/resources/scheduling/slot/spec.py 40.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3061      +/-   ##
===========================================
- Coverage    51.28%   51.17%   -0.11%     
===========================================
  Files          251      251              
  Lines        11371    11444      +73     
  Branches      1280     1288       +8     
===========================================
+ Hits          5832     5857      +25     
- Misses        5518     5566      +48     
  Partials        21       21              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 (8)
care/emr/resources/medication/administration/spec.py (1)

161-176: Validation logic is sound and consistent.

The validate_status method correctly implements the business rule to prevent updates on records marked as "entered_in_error". The logic matches the pattern used across other resource specs, which is... reassuring, I suppose.

Consider adding a docstring to document the validation rule:

 @model_validator(mode="after")
 def validate_status(self, info: ValidationInfo):
+    """Prevent updates to medication administration records with 'entered_in_error' status."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 162-162: Missing function or method docstring

(C0116)

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

98-111: Validator implementation follows the established pattern correctly.

The validation logic appropriately prevents updates to consent records with "entered_in_error" status. The implementation is consistent with similar validators across the codebase.

Adding a docstring would improve code documentation:

 @model_validator(mode="after")
 def validate_status(self, info: ValidationInfo):
+    """Prevent updates to consent records with 'entered_in_error' status."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 99-99: Missing function or method docstring

(C0116)

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

93-105: Validation implementation is consistent and correct.

The validate_status method properly prevents updates to encounter records with "entered_in_error" status. The use of StatusChoices.entered_in_error.value correctly references the imported enum.

Consider adding a docstring for better documentation:

 @model_validator(mode="after")
 def validate_status(self, info: ValidationInfo):
+    """Prevent updates to encounter records with 'entered_in_error' status."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 94-94: Missing function or method docstring

(C0116)

care/emr/resources/scheduling/slot/spec.py (1)

75-87: Add docstring for better code documentation.

The validation logic correctly prevents updates to bookings with "entered_in_error" status, which aligns with the PR objectives. However, the method would benefit from a docstring explaining its purpose and behavior.

 @model_validator(mode="after")
 def validate_status(self, info: ValidationInfo):
+    """Prevent updates to bookings that are marked as entered in error."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 76-76: Missing function or method docstring

(C0116)

care/emr/resources/medication/statement/spec.py (1)

59-71: Validation logic is solid, but please add documentation.

The implementation correctly prevents updates to medication statements marked as "entered_in_error" and follows the same pattern as other resource specs in this PR. The error message is appropriately descriptive, though a docstring would improve maintainability.

 @model_validator(mode="after")
 def validate_verification_status(self, info: ValidationInfo):
+    """Prevent updates to medication statements with entered_in_error status."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 60-60: Missing function or method docstring

(C0116)

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

80-98: Validation implementation is correct and appropriately adapted.

The validator correctly prevents updates to allergy intolerance records with "entered_in_error" verification status. The method name and error message are appropriately specific to the verification_status field, which is a nice touch compared to the generic status checks in other files. Just missing a docstring for completeness.

 @model_validator(mode="after")
 def validate_verification_status(self, info: ValidationInfo):
+    """Prevent updates to allergy intolerance records with entered_in_error verification status."""
     context = info.context or {}
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 81-81: Missing function or method docstring

(C0116)

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

150-167: Validation logic is correct and follows established pattern.

The implementation properly prevents updates to conditions with "entered_in_error" verification status and maintains consistency with the allergy intolerance validation approach. The error message accurately reflects the field being validated. As with the other files, a docstring would improve documentation.

 @model_validator(mode="after")
 def validate_verification_status(self, info: ValidationInfo):
+    """Prevent updates to conditions with entered_in_error verification status."""
     context = info.context or {}

Consider abstracting the validation pattern.

While the validation logic is correctly implemented across all files, there's notable code duplication. Since this pattern appears in multiple resource specs, consider creating a base validation mixin or utility function to reduce duplication and improve maintainability.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 151-151: Missing function or method docstring

(C0116)

care/emr/api/viewsets/device.py (1)

54-61: Excellent architectural improvement with explicit mixin composition.

This refactoring makes the viewset's capabilities crystal clear and provides better modularity than the previous monolithic inheritance. The removal of delete functionality aligns perfectly with the PR's goal of restricting operations on "entered_in_error" records.

One tiny suggestion though - perhaps consider adding a class docstring to document the viewset's purpose and capabilities?

 class DeviceViewSet(
     EMRCreateMixin,
     EMRRetrieveMixin,
     EMRUpdateMixin,
     EMRListMixin,
     EMRBaseViewSet,
     EMRUpsertMixin,
 ):
+    """
+    ViewSet for managing medical devices within facilities.
+    
+    Provides CRUD operations and device association management with
+    encounters, locations, and organizations.
+    """
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 54-54: Missing class docstring

(C0115)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c076917 and bd9f1c8.

📒 Files selected for processing (20)
  • care/emr/api/viewsets/condition.py (3 hunks)
  • care/emr/api/viewsets/consent.py (2 hunks)
  • care/emr/api/viewsets/device.py (2 hunks)
  • care/emr/api/viewsets/medication_administration.py (2 hunks)
  • care/emr/api/viewsets/medication_request.py (2 hunks)
  • care/emr/api/viewsets/medication_statement.py (2 hunks)
  • care/emr/resources/allergy_intolerance/spec.py (2 hunks)
  • care/emr/resources/condition/spec.py (2 hunks)
  • care/emr/resources/consent/spec.py (2 hunks)
  • care/emr/resources/device/spec.py (2 hunks)
  • care/emr/resources/encounter/spec.py (2 hunks)
  • care/emr/resources/medication/administration/spec.py (2 hunks)
  • care/emr/resources/medication/request/spec.py (2 hunks)
  • care/emr/resources/medication/statement/spec.py (2 hunks)
  • care/emr/resources/scheduling/slot/spec.py (2 hunks)
  • care/emr/tests/test_allergy_intolerance_api.py (7 hunks)
  • care/emr/tests/test_consent_api.py (2 hunks)
  • care/emr/tests/test_device_api.py (2 hunks)
  • care/emr/tests/test_diagnosis_api.py (5 hunks)
  • care/emr/tests/test_symptom_api.py (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
care/em 8000 r/resources/allergy_intolerance/spec.py (1)
Learnt from: DraKen0009
PR: ohcnetwork/care#2931
File: care/emr/migrations/0023_allergyintolerance_allergy_intolerance_type.py:16-16
Timestamp: 2025-03-19T14:53:14.299Z
Learning: For the AllergyIntolerance model, field validations are handled by Pydantic specs (AllergyIntoleranceWriteSpec) using enum types rather than in the Django model definition. The field `allergy_intolerance_type` is validated through the AllergyIntoleranceTypeOptions enum which contains "allergy" and "intolerance" options.
🧬 Code Graph Analysis (18)
care/emr/tests/test_diagnosis_api.py (1)
care/emr/resources/condition/spec.py (1)
  • VerificationStatusChoices (29-35)
care/emr/resources/device/spec.py (4)
care/emr/resources/consent/spec.py (1)
  • validate_status (99-111)
care/emr/resources/encounter/spec.py (1)
  • validate_status (94-105)
care/emr/resources/medication/administration/spec.py (1)
  • validate_status (162-176)
care/emr/resources/scheduling/slot/spec.py (1)
  • validate_status (76-87)
care/emr/resources/consent/spec.py (4)
care/emr/resources/encounter/spec.py (1)
  • validate_status (94-105)
care/emr/resources/medication/administration/spec.py (1)
  • validate_status (162-176)
care/emr/resources/device/spec.py (1)
  • validate_status (71-81)
care/emr/resources/scheduling/slot/spec.py (1)
  • validate_status (76-87)
care/emr/tests/test_consent_api.py (1)
care/emr/resources/consent/spec.py (1)
  • ConsentStatusChoices (22-27)
care/emr/resources/encounter/spec.py (5)
care/emr/resources/consent/spec.py (1)
  • validate_status (99-111)
care/emr/resources/medication/administration/spec.py (1)
  • validate_status (162-176)
care/emr/resources/device/spec.py (1)
  • validate_status (71-81)
care/emr/resources/scheduling/slot/spec.py (1)
  • validate_status (76-87)
care/emr/resources/encounter/constants.py (1)
  • StatusChoices (4-13)
care/emr/resources/medication/statement/spec.py (3)
care/emr/resources/allergy_intolerance/spec.py (1)
  • validate_verification_status (81-98)
care/emr/resources/condition/spec.py (1)
  • validate_verification_status (151-167)
care/emr/resources/medication/request/spec.py (1)
  • validate_verification_status (200-211)
care/emr/resources/scheduling/slot/spec.py (4)
care/emr/resources/consent/spec.py (1)
  • validate_status (99-111)
care/emr/resources/encounter/spec.py (1)
  • validate_status (94-105)
care/emr/resources/medication/administration/spec.py (1)
  • validate_status (162-176)
care/emr/resources/device/spec.py (1)
  • validate_status (71-81)
care/emr/tests/test_symptom_api.py (1)
care/emr/resources/allergy_intolerance/spec.py (1)
  • VerificationStatusChoices (22-27)
care/emr/resources/medication/administration/spec.py (4)
care/emr/resources/consent/spec.py (1)
  • validate_status (99-111)
care/emr/resources/encounter/spec.py (1)
  • validate_status (94-105)
care/emr/resources/device/spec.py (1)
  • validate_status (71-81)
care/emr/resources/scheduling/slot/spec.py (1)
  • validate_status (76-87)
care/emr/tests/test_allergy_intolerance_api.py (1)
care/emr/resources/allergy_intolerance/spec.py (1)
  • VerificationStatusChoices (22-27)
care/emr/tests/test_device_api.py (1)
care/emr/resources/device/spec.py (1)
  • DeviceStatusChoices (16-19)
care/emr/resources/allergy_intolerance/spec.py (4)
care/emr/resources/condition/spec.py (2)
  • validate_verification_status (151-167)
  • VerificationStatusChoices (29-35)
care/emr/resources/medication/request/spec.py (1)
  • validate_verification_status (200-211)
care/emr/resources/medication/statement/spec.py (1)
  • validate_verification_status (60-71)
care/emr/resources/base.py (1)
  • is_update (41-42)
care/emr/resources/condition/spec.py (1)
care/emr/resources/allergy_intolerance/spec.py (2)
  • validate_verification_status (81-98)
  • VerificationStatusChoices (22-27)
care/emr/api/viewsets/medication_statement.py (2)
care/emr/api/viewsets/base.py (7)
  • EMRBaseViewSet (229-271)
  • EMRCreateMixin (70-108)
  • EMRListMixin (111-124)
  • EMRQuestionnaireResponseMixin (274-275)
  • EMRRetrieveMixin (63-67)
  • EMRUpdateMixin (127-179)
  • EMRUpsertMixin (201-226)
care/emr/api/viewsets/encounter_authz_base.py (1)
  • EncounterBasedAuthorizationBase (8-44)
care/emr/api/viewsets/medication_request.py (2)
care/emr/api/viewsets/base.py (7)
  • EMRBaseViewSet (229-271)
  • EMRCreateMixin (70-108)
  • EMRListMixin (111-124)
  • EMRQuestionnaireResponseMixin (274-275)
  • EMRRetrieveMixin (63-67)
  • EMRUpdateMixin (127-179)
  • EMRUpsertMixin (201-226)
care/emr/api/viewsets/encounter_authz_base.py (1)
  • EncounterBasedAuthorizationBase (8-44)
care/emr/api/viewsets/device.py (1)
care/emr/api/viewsets/base.py (6)
  • EMRUpsertMixin (201-226)
  • EMRCreateMixin (70-108)
  • EMRRetrieveMixin (63-67)
  • EMRUpdateMixin (127-179)
  • EMRListMixin (111-124)
  • EMRBaseViewSet (229-271)
care/emr/resources/medication/request/spec.py (3)
care/emr/resources/allergy_intolerance/spec.py (1)
  • validate_verification_status (81-98)
care/emr/resources/condition/spec.py (1)
  • validate_verification_status (151-167)
care/emr/resources/medication/statement/spec.py (1)
  • validate_verification_status (60-71)
care/emr/api/viewsets/condition.py (1)
care/emr/api/viewsets/base.py (7)
  • EMRBaseViewSet (229-271)
  • EMRCreateMixin (70-108)
  • EMRListMixin (111-124)
  • EMRQuestionnaireResponseMixin (274-275)
  • EMRRetrieveMixin (63-67)
  • EMRUpdateMixin (127-179)
  • EMRUpsertMixin (201-226)
🪛 Pylint (3.3.7)
care/emr/resources/device/spec.py

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 71-71: Missing function or method docstring

(C0116)

care/emr/resources/consent/spec.py

[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 99-99: Missing function or method docstring

(C0116)

care/emr/resources/encounter/spec.py

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 94-94: Missing function or method docstring

(C0116)

care/emr/resources/medication/statement/spec.py

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 60-60: Missing function or method docstring

(C0116)

care/emr/resources/scheduling/slot/spec.py

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 76-76: Missing function or method docstring

(C0116)

care/emr/api/viewsets/consent.py

[error] 7-14: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/resources/medication/administration/spec.py

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 162-162: Missing function or method docstring

(C0116)

care/emr/tests/test_device_api.py

[convention] 177-177: Missing function or method docstring

(C0116)

care/emr/resources/allergy_intolerance/spec.py

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 81-81: Missing function or method docstring

(C0116)

care/emr/api/viewsets/medication_administration.py

[error] 4-12: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/resources/condition/spec.py

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 151-151: Missing function or method docstring

(C0116)

care/emr/api/viewsets/medication_statement.py

[error] 4-12: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/api/viewsets/medication_request.py

[error] 6-14: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/api/viewsets/device.py

[convention] 54-54: Missing class docstring

(C0115)

care/emr/resources/medication/request/spec.py

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)


[convention] 200-200: Missing function or method docstring

(C0116)

care/emr/api/viewsets/condition.py

[error] 7-15: Unable to import 'care.emr.api.viewsets.base'

(E0401)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test / Test
🔇 Additional comments (36)
care/emr/tests/test_diagnosis_api.py (5)

504-508: LGTM! Explicit status setting improves test reliability.

The explicit verification_status=VerificationStatusChoices.provisional.value ensures the test consistently creates diagnoses that can be updated, preventing any potential flakiness from random status selection.


536-540: Consistent with other update tests.

Good pattern consistency with the previous test method.


569-573: Maintaining the established pattern.

Follows the same explicit status setting approach.


602-606: Well, at least you're being consistent.

Same explicit status setting pattern continues across all update tests.


633-637: Final test method follows suit.

Completes the consistent pattern of explicit status setting for update scenarios.

care/emr/tests/test_consent_api.py (2)

223-225: Explicit status setting for update test consistency.

Setting status=ConsentStatusChoices.active.value ensures the consent can be updated in the test, aligning with the new validation rules that prevent updates to "entered_in_error" records.


237-239: Consistent pattern maintained.

Follows the same explicit status approach as the previous test method.

care/emr/tests/test_device_api.py (3)

171-171: Explicit device status for update test.

Setting status=DeviceStatusChoices.active.value ensures the device can be updated, preventing test failures due to the new validation rules.


178-178: Maintaining consistency across update tests.

Same explicit status approach as the previous test.


187-189: Complete parameter specification for care plan test.

Includes both care_type and explicit status setting for comprehensive test setup.

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

4-5: Required imports for validation functionality.

The model_validator and ValidationInfo imports are necessary for the new status validation logic.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)


70-82: Solid validation logic to enforce business rules.

The validate_status method correctly prevents updates to devices with "entered_in_error" status. The implementation:

  • Properly checks for update context
  • Validates the existing model object's status
  • Raises an appropriate error message
  • Follows the established pattern from other resource specs

This enforces the core business rule mentioned in the PR objectives.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 71-71: Missing function or method docstring

(C0116)

care/emr/resources/medication/administration/spec.py (1)

4-5: Import additions look correct.

The added imports for model_validator and ValidationInfo are necessary for the new validation functionality and follow the established import patterns in the codebase.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)

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

6-6: Import addition is appropriate.

The ValidationInfo import is correctly placed and necessary for the new validator functionality.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)

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

5-6: Import changes are correct and necessary.

The additions to the pydantic imports and the new ValidationInfo import are properly placed and required for the validation functionality.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)

care/emr/tests/test_allergy_intolerance_api.py (1)

544-546: Test data updates are necessary and well-implemented.

The explicit setting of verification_status=VerificationStatusChoices.confirmed.value in update test methods ensures compatibility with the new validation rules that prevent updates to "entered_in_error" records. I suppose it's fortunate that someone thought to update the tests accordingly.

Also applies to: 578-580, 612-614, 645-647, 678-680, 717-717, 763-763

care/emr/resources/scheduling/slot/spec.py (1)

4-5: LGTM! Imports added correctly for the new validation logic.

The addition of model_validator and ValidationInfo imports is necessary for the new status validation functionality.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)

care/emr/resources/medication/statement/spec.py (1)

4-5: LGTM! Imports properly added for validation functionality.

The pydantic imports are correctly added to support the new model-level validation.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)

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

4-5: LGTM! Required imports added for validation enhancement.

The pydantic imports are properly included to support the new verification status validation.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'pydantic'

(E0401)


[error] 5-5: Unable to import 'pydantic_core.core_schema'

(E0401)

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

5-6: LGTM! Imports added correctly for validation functionality.

The necessary pydantic imports are properly included for the new model validation.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)

care/emr/resources/medication/request/spec.py (2)

5-6: LGTM: Clean import additions for validation functionality.

The imports align perfectly with the validation pattern used throughout the codebase.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 5-5: Unable to import 'pydantic'

(E0401)


[error] 6-6: Unable to import 'pydantic_core.core_schema'

(E0401)


199-211: Solid validation implementation following established patterns.

The validate_verification_status method correctly prevents updates to medication requests marked as "entered_in_error", which is exactly what this PR aims to achieve. The implementation is consistent with similar validators in other resource specs.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 200-200: Missing function or method docstring

(C0116)

care/emr/tests/test_symptom_api.py (5)

506-510: Excellent foresight in test data preparation.

Setting verification_status=VerificationStatusChoices.confirmed.value ensures this test won't inadvertently trip over the new validation rules that prevent updates to "entered_in_error" records. Nicely done.


538-542: Consistent test data management.

Same smart approach here - explicitly setting the verification status to a safe value for update operations.


571-575: Maintaining test reliability with proper status setup.

Good practice to explicitly set verification status even in permission-denied scenarios to ensure consistent test behavior.


604-608: Thorough consistency in test data preparation.

Appreciate the attention to detail in setting verification status across all update test scenarios.


635-639: Complete coverage of test scenario adjustments.

Even for closed encounter tests, the verification status is properly set. This demonstrates a comprehensive understanding of the validation changes.

care/emr/api/viewsets/consent.py (2)

7-14: Clean modularization of viewset functionality.

The explicit mixin imports provide much clearer visibility into what capabilities this viewset actually uses, rather than inheriting everything from a monolithic base class.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 7-14: Unable to import 'care.emr.api.viewsets.base'

(E0401)


28-37: Well-structured inheritance hierarchy.

The explicit mixin composition gives you precise control over the viewset's capabilities. The addition of EMRUpsertMixin is particularly nice for bulk operations.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 28-28: Missing class docstring

(C0115)

care/emr/api/viewsets/device.py (1)

18-18: Helpful addition of upsert capability.

Adding EMRUpsertMixin provides convenient bulk create/update functionality to the device viewset.

care/emr/api/viewsets/medication_request.py (1)

6-14: Nicely modularized viewset inheritance

The refactoring to use explicit mixins instead of the monolithic EMRModelViewSet makes the capabilities much clearer. I notice the delete functionality is conspicuously absent, which I'm sure aligns perfectly with the PR objectives.

Also applies to: 46-53

🧰 Tools
🪛 Pylint (3.3.7)

[error] 6-14: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/api/viewsets/medication_statement.py (1)

4-12: Consistent refactoring pattern maintained

Good to see the same explicit mixin approach here. The inheritance order remains consistent with other viewsets in the PR.

Also applies to: 34-41

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-12: Unable to import 'care.emr.api.viewsets.base'

(E0401)

care/emr/api/viewsets/condition.py (2)

7-15: Both viewsets updated uniformly

The refactoring has been applied consistently to both SymptomViewSet and DiagnosisViewSet. The placement of ValidateEncounterMixin at the beginning of the inheritance chain is appropriate for ensuring validation occurs early in the method resolution order.

Also applies to: 71-76, 120-125

🧰 Tools
🪛 Pylint (3.3.7)

[error] 7-15: Unable to import 'care.emr.api.viewsets.base'

(E0401)


71-125:

✅ Verification successful

Verify integration with entered_in_error validators

While the viewset refactoring looks solid, just want to make sure the model-level validators mentioned in the PR objectives are properly integrated with these viewsets through the pydantic specs.

Run the following script to verify the validators are in place:


🏁 Script executed:

#!/bin/bash
# Description: Check for entered_in_error validators in the condition spec files

# Search for validation methods in condition spec
ast-grep --pattern 'def validate_verification_status($_) {
  $$$
}'

# Also check for any references to entered_in_error
rg -A 5 "entered_in_error" care/emr/resources/condition/

Length of output: 957


Sure, let’s peek into the spec to confirm the validator is wired up as expected.


🏁 Script executed:

#!/bin/bash
# Show any Pydantic validator on verification_status
rg -C5 '@validator\("verification_status"\)' care/emr/resources/condition/spec.py

# Show context around entered_in_error checks
rg -C5 'entered_in_error' care/emr/resources/condition/spec.py

Length of output: 808


entered_in_error validation already enforced in ConditionSpec

I’ve confirmed in care/emr/resources/condition/spec.py that the update logic checks for
verification_status == VerificationStatusChoices.entered_in_error.value
and raises a ValueError if so. Since your viewsets use ConditionUpdateSpec, this guard will run on all updates. No further integration work needed here.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 95-95: Missing function or method docstring

(C0116)


[convention] 99-99: Missing function or method docstring

(C0116)


[convention] 116-116: Missing class docstring

(C0115)

care/emr/api/viewsets/medication_administration.py (2)

4-12: LGTM! Explicit mixins improve code clarity.

The refactoring from a monolithic base class to explicit mixins is a solid architectural improvement. It makes the viewset's capabilities much more transparent, though I suppose someone could argue that having everything spelled out like this is a bit... verbose compared to the previous approach.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-12: Unable to import 'care.emr.api.viewsets.base'

(E0401)


35-44:

✅ Verification successful

Verify the mixin order for proper method resolution.

The explicit mixin inheritance looks good and follows composition over inheritance principles. However, please ensure that the order of mixins is correct for Django's method resolution order, particularly with EncounterBasedAuthorizationBase first and EMRBaseViewSet toward the end.


🏁 Script executed:

#!/bin/bash
# Description: Verify that other viewsets in the EMR module follow the same mixin pattern
# Expected: Similar refactoring patterns across related viewsets

echo "Checking for similar refactoring patterns in related EMR viewsets..."
rg -A 10 "class.*ViewSet" care/emr/api/viewsets/ | grep -E "(EMRCreateMixin|EMRUpdateMixin|EMRBaseViewSet)" -A 5 -B 5

Length of output: 17323


Mixin order is consistent across EMR viewsets

I verified that MedicationAdministrationViewSet follows the same mixin sequence as other encounter-based viewsets (e.g. medication_statement.py, medication_request.py):
EncounterBasedAuthorizationBase → EMRQuestionnaireResponseMixin → EMRCreateMixin → EMRRetrieveMixin → EMRUpdateMixin → EMRListMixin → EMRBaseViewSet → EMRUpsertMixin

No adjustments required.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 35-35: Missing class docstring

(C0115)


[refactor] 35-35: Too few public methods (1/2)

(R0903)

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.

Any resource with an entered_in_error state, should remain uneditable
1 participant
0