Skip to content

fix: separate diagnostic reports by observation category#1002

Open
md-umair-21 wants to merge 3 commits into
earthians:developfrom
md-umair-21:diag-rep
Open

fix: separate diagnostic reports by observation category#1002
md-umair-21 wants to merge 3 commits into
earthians:developfrom
md-umair-21:diag-rep

Conversation

@md-umair-21

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d1b581c3-d73b-418a-8b9c-fd74c9ed443f

📥 Commits

Reviewing files that changed from the base of the PR and between 404de4c and 4599168.

📒 Files selected for processing (4)
  • healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.json
  • healthcare/healthcare/doctype/observation/observation.py
  • healthcare/healthcare/doctype/service_request/service_request.py
  • healthcare/healthcare/utils.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.json
  • healthcare/healthcare/utils.py
  • healthcare/healthcare/doctype/observation/observation.py

Walkthrough

This 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)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely summarizes the main change: separating diagnostic reports by observation category to prevent collapsing different categories into one report.
Description check ✅ Passed The description is well-related to the changeset, providing clear context about the problem being solved and detailing the specific changes made across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Apply formatter output to unblock CI.

The pipeline reports ruff-format modified 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

📥 Commits

Reviewing files that changed from the base of the PR and between f0080ec and 79913a2.

📒 Files selected for processing (4)
  • healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.json
  • healthcare/healthcare/doctype/observation/observation.py
  • healthcare/healthcare/doctype/service_request/service_request.py
  • healthcare/healthcare/utils.py

Comment thread healthcare/healthcare/utils.py Outdated
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.

1 participant