From 997d94280d40b3ea16ccd205a0d2b6e408102918 Mon Sep 17 00:00:00 2001 From: Akash Date: Thu, 14 Dec 2023 14:21:43 +0530 Subject: [PATCH] fix: Sample Collection - move create observation function to long queue --- .../sample_collection/sample_collection.js | 10 ++++++++++ .../sample_collection/sample_collection.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/healthcare/healthcare/doctype/sample_collection/sample_collection.js b/healthcare/healthcare/doctype/sample_collection/sample_collection.js index 51117ba11d..ec5c9d99c9 100644 --- a/healthcare/healthcare/doctype/sample_collection/sample_collection.js +++ b/healthcare/healthcare/doctype/sample_collection/sample_collection.js @@ -2,11 +2,20 @@ // For license information, please see license.txt frappe.ui.form.on('Sample Collection', { + onload: function(frm) { + frappe.realtime.on("observation_creation_progress", (status) => { + if (status == "Completed") { + frm.reload_doc(); + frappe.dom.unfreeze(); + } + }) + }, refresh: function(frm) { frm.fields_dict.observation_sample_collection.grid.add_custom_button(__("Mark Collected"), () => { selected_child = frm.fields_dict.observation_sample_collection.grid.get_selected_children() if (selected_child.length > 0) { frappe.confirm(__("Are you sure you want to mark selected samples as Collected"), function () { + frappe.dom.freeze(__('Creating Observations! Please Wait...')); frappe.call({ "method": "healthcare.healthcare.doctype.sample_collection.sample_collection.create_observation", args: { @@ -224,6 +233,7 @@ frappe.ui.form.on("Observation Sample Collection", { let selected_row = d.fields_dict.items.grid.get_selected_children(); if (selected_row.length > 0) { frappe.confirm(__("Are you sure you want to mark selected samples as Collected"), function () { + frappe.dom.freeze(__('Creating Observations! Please Wait...')); frappe.call({ "method": "healthcare.healthcare.doctype.sample_collection.sample_collection.create_observation", args: { diff --git a/healthcare/healthcare/doctype/sample_collection/sample_collection.py b/healthcare/healthcare/doctype/sample_collection/sample_collection.py index e9539bd20e..c077757940 100644 --- a/healthcare/healthcare/doctype/sample_collection/sample_collection.py +++ b/healthcare/healthcare/doctype/sample_collection/sample_collection.py @@ -70,6 +70,18 @@ def validate(self): @frappe.whitelist() def create_observation(selected, sample_collection, component_observations=None, child_name=None): + frappe.enqueue( + "healthcare.healthcare.doctype.sample_collection.sample_collection.insert_observation", + selected=selected, + sample_collection=sample_collection, + component_observations=component_observations, + child_name=child_name, + queue="long", + timeout=3600, + ) + + +def insert_observation(selected, sample_collection, component_observations=None, child_name=None): sample_col_doc = frappe.db.get_value( "Sample Collection", sample_collection, @@ -177,6 +189,13 @@ def create_observation(selected, sample_collection, component_observations=None, frappe.db.set_value("Sample Collection", sample_collection, "status", set_status) + frappe.publish_realtime( + event="observation_creation_progress", + message="Completed", + doctype="Sample Collection", + docname=sample_collection, + ) + def create_specimen(patient, selected, component_observations): groups = {}