fix: support Diagnostic Report creation for manual Observation Service Requests#1010
fix: support Diagnostic Report creation for manual Observation Service Requests#1010md-umair-21 wants to merge 3 commits into
Conversation
WalkthroughThe 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)
✏️ 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.
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 winComponent 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
📒 Files selected for processing (3)
healthcare/healthcare/doctype/observation/observation.pyhealthcare/healthcare/doctype/service_request/service_request.pyhealthcare/healthcare/doctype/service_request/test_service_request.py
…ndatory Company field in observation
69add93 to
cda1cbc
Compare
There was a problem hiding this comment.
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 winChild observations use hardcoded reference instead of helper-derived values.
This
add_observationcall hardcodesdoc="Patient Encounter"and usesservice_request.order_groupdirectly. For manual service requests whereorder_groupis empty, child observations will have incorrect/empty reference fields. The helper-derivedref_doctypeandref_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
📒 Files selected for processing (3)
healthcare/healthcare/doctype/observation/observation.pyhealthcare/healthcare/doctype/service_request/service_request.pyhealthcare/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
|
@Sajinsr Could you please provide update on this PR. Please let me know if any further changes needs to be made. |
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