feat: Add ordered-by practitioner fields to Therapy Plan and populate them from Patient Encounter - #975
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdded practitioner fields to the Therapy Plan DocType and updated Patient Encounter creation logic to populate them. The Therapy Plan JSON now includes a 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
healthcare/healthcare/doctype/patient_encounter/patient_encounter.py (1)
417-418: Settingpractitioner_nameis redundant —fetch_fromwill populate it on save.The new
practitioner_namefield intherapy_plan.jsondeclares"fetch_from": "practitioner.practitioner_name", so Frappe auto-populates it from the Healthcare Practitioner record on save. Copying it from the encounter here is unnecessary and could even diverge from the source of truth if the practitioner's name has been updated since the encounter was created. Consider only settingpractitionerand letting the fetch_from handle the name.♻️ Proposed simplification
doc.practitioner = encounter.practitioner - doc.practitioner_name = encounter.practitioner_name🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@healthcare/healthcare/doctype/patient_encounter/patient_encounter.py` around lines 417 - 418, Remove the redundant manual assignment of practitioner_name on the Therapy Plan document: keep setting doc.practitioner = encounter.practitioner but delete the doc.practitioner_name = encounter.practitioner_name line so the field configured with "fetch_from": "practitioner.practitioner_name" in therapy_plan.json can auto-populate the name on save; update any related comments to reflect that practitioner_name is derived via fetch_from.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@healthcare/healthcare/doctype/therapy_plan/therapy_plan.json`:
- Around line 158-168: The tests fail because the Therapy Plan field
"practitioner" is now required; update the test helper function
create_therapy_plan() to populate the practitioner (and practitioner_name)
fields when constructing the Therapy Plan so .save() passes validation;
specifically modify create_therapy_plan() used by test_status() and
test_therapy_plan_from_template() to set practitioner to an existing Healthcare
Practitioner (or create a test practitioner fixture) and set practitioner_name
accordingly; also ensure any other test helpers creating Therapy Plan instances
follow the same change to avoid save-time validation errors.
---
Nitpick comments:
In `@healthcare/healthcare/doctype/patient_encounter/patient_encounter.py`:
- Around line 417-418: Remove the redundant manual assignment of
practitioner_name on the Therapy Plan document: keep setting doc.practitioner =
encounter.practitioner but delete the doc.practitioner_name =
encounter.practitioner_name line so the field configured with "fetch_from":
"practitioner.practitioner_name" in therapy_plan.json can auto-populate the name
on save; update any related comments to reflect that practitioner_name is
derived via fetch_from.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6749aa18-4801-421e-a930-838bb4b191e5
📒 Files selected for processing (2)
healthcare/healthcare/doctype/patient_encounter/patient_encounter.pyhealthcare/healthcare/doctype/therapy_plan/therapy_plan.json
This PR adds ordering practitioner details to Therapy Plan and ensures they are populated when a Therapy Plan is created from a Patient Encounter.
Changes:-
Added two new fields to Therapy Plan:
1)Ordered By Practitioner (practitioner)
2)Ordered By Practitioner Name (practitioner_name)
Updated create_therapy_plan in patient_encounter.py (line 409)
Populated the above fields as :
doc.practitioner = encounter.practitioner
doc.practitioner_name = encounter.practitioner_name
Also updated test_therapy_plan.py to populate practitioner fields in test plan.
Why:-
Therapy Plans should capture who ordered the plan for better traceability and consistency with other healthcare documents.
Without this change, the newly added Therapy Plan fields remained empty when the plan was created from a Patient Encounter.
Impact:-
New Therapy Plans created from Patient Encounters will automatically store the ordering practitioner and practitioner name.
Existing Therapy Plans are not affected.
Closes Issue #587
no-docs