Skip to content

Commit

Permalink
fix(Service Request): fetch therapy type no of sessions and status up…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
Sajinsr committed Jan 1, 2025
1 parent d89d198 commit 848be83
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from healthcare.healthcare.doctype.healthcare_settings.healthcare_settings import get_account
from healthcare.healthcare.doctype.lab_test.lab_test import create_sample_doc
from healthcare.healthcare.doctype.nursing_task.nursing_task import NursingTask
from healthcare.healthcare.doctype.service_request.service_request import (
update_service_request_status,
)
from healthcare.healthcare.utils import validate_nursing_tasks


Expand Down Expand Up @@ -56,11 +53,6 @@ def on_cancel(self):
frappe.db.set_value("Service Request", self.service_request, "status", "active-Request Status")

def after_insert(self):
if self.service_request:
update_service_request_status(
self.service_request, self.doctype, self.name, "completed-Request Status"
)

if self.appointment:
frappe.db.set_value("Patient Appointment", self.appointment, "status", "Closed")

Expand All @@ -75,6 +67,10 @@ def after_insert(self):

def on_submit(self):
self.create_nursing_tasks(post_event=False)
if self.service_request:
frappe.db.set_value(
"Service Request", self.service_request, "status", "completed-Request Status"
)

def create_nursing_tasks(self, post_event=True):
if post_event:
Expand Down
4 changes: 0 additions & 4 deletions healthcare/healthcare/doctype/lab_test/lab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from frappe.utils import get_link_to_form, getdate, now_datetime

from healthcare.healthcare.doctype.nursing_task.nursing_task import NursingTask
from healthcare.healthcare.doctype.service_request.service_request import (
update_service_request_status,
)


class LabTest(Document):
Expand Down Expand Up @@ -47,7 +44,6 @@ def on_update(self):

def after_insert(self):
if self.service_request:
update_service_request_status(self.service_request, self.doctype, self.name)
billing_status = frappe.db.get_value("Service Request", self.service_request, "billing_status")
if billing_status == "Invoiced":
self.db_set("invoiced", True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def make_medication_request(self):
drug.medication_request = order.name

def get_order_details(self, template_doc, line_item, medication_request=False):
qty = 1
if line_item.get("doctype") == "Drug Prescription":
qty = line_item.get_quantity()
elif line_item.get("doctype") == "Therapy Plan Detail":
qty = line_item.get("no_of_sessions")
order = frappe.get_doc(
{
"doctype": "Medication Request" if medication_request else "Service Request",
Expand All @@ -239,7 +244,7 @@ def get_order_details(self, template_doc, line_item, medication_request=False):
"sequence": line_item.get("sequence"),
"intent": line_item.get("intent"),
"priority": line_item.get("priority"),
"quantity": line_item.get_quantity() if line_item.get("doctype") == "Drug Prescription" else 1,
"quantity": qty,
"dosage": line_item.get("dosage"),
"dosage_form": line_item.get("dosage_form"),
"period": line_item.get("period"),
Expand Down
37 changes: 26 additions & 11 deletions healthcare/healthcare/doctype/service_request/service_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,33 @@ frappe.ui.form.on('Service Request', {

} else if (frm.doc.template_dt === 'Therapy Type') {
frm.add_custom_button(__("Therapy Session"), function() {
frappe.db.get_value("Therapy Session", {"service_request": frm.doc.name, "docstatus":["!=", 2]}, "name")
.then(r => {
if (Object.keys(r.message).length == 0) {
frm.trigger('make_therapy_session');
frappe.db.get_list("Therapy Session", {
filters: {
"service_request": frm.doc.name,
"docstatus":["!=", 2],
"therapy_type": frm.doc.template_dn
},
fields: ["name"]
}).then(response => {
if (response.length == frm.doc.quantity) {
frappe.set_route("List", "Therapy Session", {
service_request: frm.doc.name,
});
} else {
if (r.message && r.message.name) {
frappe.set_route("Form", "Therapy Session", r.message.name);
frappe.show_alert({
message: __(`Therapy Session is already created`),
indicator: "info",
});
}
frappe.db.get_value("Therapy Session", {"service_request": frm.doc.name, "docstatus": 0}, "name")
.then(r => {
if (Object.keys(r.message).length == 0) {
frm.trigger('make_therapy_session');
} else {
if (r.message && r.message.name) {
frappe.set_route("Form", "Therapy Session", r.message.name);
frappe.show_alert({
message: __(`Therapy Session is already created`),
indicator: "info",
});
}
}
})
}
})
}, __('Create'));
Expand Down
27 changes: 17 additions & 10 deletions healthcare/healthcare/doctype/therapy_session/therapy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
get_receivable_account,
)
from healthcare.healthcare.doctype.nursing_task.nursing_task import NursingTask
from healthcare.healthcare.doctype.service_request.service_request import (
update_service_request_status,
)
from healthcare.healthcare.utils import validate_nursing_tasks


Expand All @@ -29,11 +26,6 @@ def validate(self):
self.set_total_counts()

def after_insert(self):
if self.service_request:
update_service_request_status(
self.service_request, self.doctype, self.name, "completed-Request Status"
)

self.create_nursing_tasks(post_event=False)

def on_update(self):
Expand Down Expand Up @@ -90,7 +82,12 @@ def on_submit(self):
self.update_sessions_count_in_therapy_plan()

if self.service_request:
frappe.db.set_value("Service Request", self.service_request, "status", "Completed")
status = "active-Request Status"
sessions_completed = self.check_sessions_completed()
if sessions_completed:
status = "completed-Request Status"

frappe.db.set_value("Service Request", self.service_request, "status", status)

def create_nursing_tasks(self, post_event=True):
template = frappe.db.get_value("Therapy Type", self.therapy_type, "nursing_checklist_template")
Expand Down Expand Up @@ -138,7 +135,7 @@ def before_insert(self):
if self.service_request:
therapy_session = frappe.db.exists(
"Therapy Session",
{"service_request": self.service_request, "docstatus": ["!=", 2]},
{"service_request": self.service_request, "docstatus": 0},
)
if therapy_session:
frappe.throw(
Expand All @@ -149,6 +146,16 @@ def before_insert(self):
title=_("Already Exist"),
)

def check_sessions_completed(self):
total_sessions_requested = frappe.db.get_value(
"Service Request", self.service_request, "quantity"
)
sessions = frappe.db.count(
"Therapy Session", filters={"docstatus": ["!=", 2], "service_request": self.service_request}
)

return True if total_sessions_requested == sessions else False


@frappe.whitelist()
def create_therapy_session(source_name, target_doc=None):
Expand Down

0 comments on commit 848be83

Please sign in to comment.