fix: separate diagnostic reports by observation category#1002
fix: separate diagnostic reports by observation category#1002md-umair-21 wants to merge 3 commits into
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 (4)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThis PR adds an observation_category Select field to the Diagnostic Report doctype and propagates it through code paths that create or query diagnostic reports: observation retrieval now fetches and uses observation_category in Observation queries, service_request.make_observation and insert_diagnostic_report accept and set observation_category, and the sample-collection utilities group observations by observation_category when creating diagnostic reports. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
healthcare/healthcare/utils.py (1)
1594-1607:⚠️ Potential issue | 🟠 Major | ⚡ Quick winApply formatter output to unblock CI.
The pipeline reports
ruff-formatmodified this file (around this region). Please run and commit formatting so lint checks pass.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@healthcare/healthcare/utils.py` around lines 1594 - 1607, The file fails ruff-format linting around the block using insert_diagnostic_report and insert_observation_and_sample_collection; run the project's formatter (ruff/ruff-format) on healthcare/healthcare/utils.py, fix formatting issues (ensure correct indentation and spacing around the if diag_report_required / else block and the subsequent if not meta.has_field("patient") check that references sample_collection), then stage and commit the formatted file so CI passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@healthcare/healthcare/utils.py`:
- Around line 1582-1599: Collect all observation categories (including
uncategorized) across the loop instead of relying on the last observation value
and create a Diagnostic Report for each category; specifically, in the grouped
branch where you already build observation_categories from
obs.get("observation_category"), include a representation for uncategorized
observations (e.g., None or a sentinel string) when
obs.get("observation_category") is falsy, and iterate over
observation_categories calling insert_diagnostic_report(doc, patient,
sample_collection.name, observation_category) for each entry. Apply the same
collection-and-iterate pattern to the non-grouped path (the code that currently
uses the last loop value at lines ~1610-1612) so it also builds an
observation_categories set and emits a report per category (including
uncategorized). Ensure you still respect diag_report_required and only call
insert_diagnostic_report when that flag is set.
---
Outside diff comments:
In `@healthcare/healthcare/utils.py`:
- Around line 1594-1607: The file fails ruff-format linting around the block
using insert_diagnostic_report and insert_observation_and_sample_collection; run
the project's formatter (ruff/ruff-format) on healthcare/healthcare/utils.py,
fix formatting issues (ensure correct indentation and spacing around the if
diag_report_required / else block and the subsequent if not
meta.has_field("patient") check that references sample_collection), then stage
and commit the formatted file so CI passes.
🪄 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: 41cd1292-2288-4822-8d7f-f52bd8df656c
📒 Files selected for processing (4)
healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.jsonhealthcare/healthcare/doctype/observation/observation.pyhealthcare/healthcare/doctype/service_request/service_request.pyhealthcare/healthcare/utils.py
This change makes Diagnostic Report unique per ref_doctype + docname + observation_category instead of effectively per reference document only. It prevents different categories for the same invoice or encounter from collapsing into one report.
It also updates report lookup and rendering so each report only tracks and prints observations from its own category.
Changes:-
1.Added the new observation_category field (hidden) on Diagnostic Report so the category can be stored and used in lookups.
2.Included observation_category when loading observation template data, changed Diagnostic Report existence checks to include category, and created reports per category in the invoice-driven flow.
3.Updated encounter/service-request report creation to pass the template’s observation_category and to check for an existing report using the category-aware key.
4.Filtered get_observation_details by the report’s observation_category, and changed Diagnostic Report lookup during observation status updates to include the observation’s category.