Skip to content

fix: support Diagnostic Report creation for manual Observation Service Requests#1010

Open
md-umair-21 wants to merge 3 commits into
earthians:developfrom
md-umair-21:manual-service-request
Open

fix: support Diagnostic Report creation for manual Observation Service Requests#1010
md-umair-21 wants to merge 3 commits into
earthians:developfrom
md-umair-21:manual-service-request

Conversation

@md-umair-21

Copy link
Copy Markdown
Contributor

This fixes a mismatch between two observation flows:
- Patient Encounter -> Service Request -> Observation -> Diagnostic Report
- Manual Service Request -> Invoice -> Observation

Previously, encounter-created service requests generated diagnostic reports correctly, but manually created observation service requests did not. In the manual flow, Create Observation could create the observation, but the diagnostic report was not created.

The root cause was that the observation/report flow assumed every observation service request came from a Patient Encounter and depended on source_doc and order_group. That works for encounter-generated requests, but manual service requests often do not have those fields populated.

This fix adds a fallback reference for manual service requests:
- if source_doc and order_group exist, existing behavior is preserved
- otherwise, the system uses the Service Request itself as the diagnostic reference

Changes included:
1)service_request.py
added get_service_request_reference()
updated observation, sample collection, and diagnostic report creation to use the resolved reference

2)observation.py
added support for diagnostic reports linked directly to Service Request

3)test_service_request.py
added a regression test for the manual flow

Result (After fix):
- encounter-based behavior stays unchanged
- manual observation service requests now generate and resolve diagnostic reports correctly

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Walkthrough

The PR centralizes Service Request reference resolution with get_service_request_reference(), uses its (ref_doctype, ref_docname) when creating Observations, Sample Collections, and Diagnostic Reports, updates Diagnostic Report lookup to use those reference fields, adds a Service Request branch to get_observation_details to query top-level observations by service_request, and adds a test that creates a Service Request, runs make_observation, and asserts a Diagnostic Report and observation count are correct.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for Diagnostic Report creation in manual Observation Service Requests, which is the primary objective addressed across all modified files.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, the fix approach, and listing the specific changes made across service_request.py, observation.py, and test_service_request.py 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
healthcare/healthcare/doctype/service_request/service_request.py (1)

287-290: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Component observations still use encounter-only references.

Line 287 and Line 288 still hardcode "Patient Encounter" + order_group. In manual Service Request flow, this can detach child observations from the Service Request diagnostic reference, so downstream diagnostic report status resolution can miss updates.

Suggested fix
 		if len(non_sample_reqd_component_obs) > 0:
 			for comp in non_sample_reqd_component_obs:
 				add_observation(
 					patient=service_request.patient,
 					template=comp,
-					doc="Patient Encounter",
-					docname=service_request.order_group,
+					doc=ref_doctype,
+					docname=ref_docname,
 					parent=observation.name,
+					service_request=service_request.name,
 				)
🤖 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/doctype/service_request/service_request.py` around
lines 287 - 290, The code currently hardcodes doc="Patient Encounter" and
docname=service_request.order_group when creating component observations, which
breaks links in manual Service Request flows; change the observation parent
reference to use the Service Request itself by setting doc to the Service
Request doctype and docname to the service_request identifier (e.g., use
doc=service_request.doctype or literal "Service Request" and
docname=service_request.name) instead of service_request.order_group so that
observation links (see variables observation and service_request.order_group)
attach to the Service Request and not the encounter.
🤖 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.

Outside diff comments:
In `@healthcare/healthcare/doctype/service_request/service_request.py`:
- Around line 287-290: The code currently hardcodes doc="Patient Encounter" and
docname=service_request.order_group when creating component observations, which
breaks links in manual Service Request flows; change the observation parent
reference to use the Service Request itself by setting doc to the Service
Request doctype and docname to the service_request identifier (e.g., use
doc=service_request.doctype or literal "Service Request" and
docname=service_request.name) instead of service_request.order_group so that
observation links (see variables observation and service_request.order_group)
attach to the Service Request and not the encounter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1e46c775-cf48-4930-a7cd-c8909c15826a

📥 Commits

Reviewing files that changed from the base of the PR and between a032347 and 1291264.

📒 Files selected for processing (3)
  • healthcare/healthcare/doctype/observation/observation.py
  • healthcare/healthcare/doctype/service_request/service_request.py
  • healthcare/healthcare/doctype/service_request/test_service_request.py

@Sajinsr Sajinsr force-pushed the manual-service-request branch from 69add93 to cda1cbc Compare June 4, 2026 16:02

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
healthcare/healthcare/doctype/service_request/service_request.py (1)

284-290: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Child observations use hardcoded reference instead of helper-derived values.

This add_observation call hardcodes doc="Patient Encounter" and uses service_request.order_group directly. For manual service requests where order_group is empty, child observations will have incorrect/empty reference fields. The helper-derived ref_doctype and ref_docname (computed at line 239) should be used here for consistency with the parent observation created at lines 403-404.

Proposed fix
 		if len(non_sample_reqd_component_obs) > 0:
 			for comp in non_sample_reqd_component_obs:
 				add_observation(
 					patient=service_request.patient,
 					template=comp,
-					doc="Patient Encounter",
-					docname=service_request.order_group,
+					doc=ref_doctype,
+					docname=ref_docname,
 					parent=observation.name,
 				)
🤖 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/doctype/service_request/service_request.py` around
lines 284 - 290, The call to add_observation is using a hardcoded doc="Patient
Encounter" and service_request.order_group for docname which breaks child
observation references for manual requests; change that add_observation
invocation to pass the helper-derived ref_doctype and ref_docname (the variables
computed earlier as ref_doctype and ref_docname) instead of the hardcoded values
so child observations use the same reference as the parent observation created
later (see add_observation and the parent observation creation).
🤖 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.

Outside diff comments:
In `@healthcare/healthcare/doctype/service_request/service_request.py`:
- Around line 284-290: The call to add_observation is using a hardcoded
doc="Patient Encounter" and service_request.order_group for docname which breaks
child observation references for manual requests; change that add_observation
invocation to pass the helper-derived ref_doctype and ref_docname (the variables
computed earlier as ref_doctype and ref_docname) instead of the hardcoded values
so child observations use the same reference as the parent observation created
later (see add_observation and the parent observation creation).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 53c21331-e3bf-42be-b7ac-339d2a6d0d17

📥 Commits

Reviewing files that changed from the base of the PR and between d610768 and cda1cbc.

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

@md-umair-21

md-umair-21 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@Sajinsr Could you please provide update on this PR. Please let me know if any further changes needs to be made.

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