refactor(jubilee): enforce one-JSR-per-encounter in create_preauthorization_doc#1193
Merged
av-dev2 merged 1 commit intoAakvatech-Limited:nurse-ot-modulefrom Apr 28, 2026
Merged
Conversation
…zation_doc
Prevent duplicate Jubilee Service Request documents from being created
when a doctor clicks "Request Pre-Authorization" more than once for the
same Patient Encounter. Previously, each call unconditionally inserted a
new JSR; now the function checks for an existing one first.
create_preauthorization_doc() logic:
- Resolves benefit_name and benefit_balance upfront (before the existence
check) so the values are available regardless of which branch is taken
- Queries Jubilee Service Request filtered by patient_encounter to find
an existing document (latest by creation date), returning name + docstatus
- Three-branch execution:
1. Submitted JSR exists (docstatus == 1):
Return the stored preauth_status, submission_id, and preauth_description
immediately without re-calling the Jubilee API
2. Draft JSR exists (docstatus == 0):
Update benefit_code, benefit_name, benefit_balance on the existing draft
and call save(); the before_save hook (set_missing_values) re-populates
all encounter-derived fields with the latest encounter data before submit
3. No JSR found:
Create via frappe.new_doc(), set patient_encounter and benefit fields,
then call save() to trigger before_save population before submit
- Removed redundant jsr.reload() after submit; the before_submit hook already
writes preauth_status/submission_id/preauth_description onto self before
Frappe final document save, so the in-memory jsr object is already current
- Switched new-document path from frappe.get_doc + insert to
frappe.new_doc + attribute assignment + save for consistency with the
draft-reuse path and to ensure before_save fires in both cases
Not up to standards ⛔
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent duplicate Jubilee Service Request documents from being created when a doctor clicks "Request Pre-Authorization" more than once for the same Patient Encounter. Previously, each call unconditionally inserted a new JSR; now the function checks for an existing one first.
create_preauthorization_doc() logic: