diff --git a/healthcare/healthcare/doctype/inpatient_record/inpatient_record.py b/healthcare/healthcare/doctype/inpatient_record/inpatient_record.py
index ace267530f..dd75e5e3e9 100644
--- a/healthcare/healthcare/doctype/inpatient_record/inpatient_record.py
+++ b/healthcare/healthcare/doctype/inpatient_record/inpatient_record.py
@@ -27,17 +27,23 @@ def after_insert(self):
{"inpatient_record": self.name, "inpatient_status": self.status},
)
- filters = {"order_group": self.admission_encounter, "docstatus":1}
+ filters = {"order_group": self.admission_encounter, "docstatus": 1}
medication_requests = frappe.get_all("Medication Request", filters, ["name"])
service_requests = frappe.get_all("Service Request", filters, ["name"])
for service_request in service_requests:
- frappe.db.set_value("Service Request", service_request.name,
- {"inpatient_record": self.name, "inpatient_status": self.status})
+ frappe.db.set_value(
+ "Service Request",
+ service_request.name,
+ {"inpatient_record": self.name, "inpatient_status": self.status},
+ )
for medication_request in medication_requests:
- frappe.db.set_value("Medication Request", medication_request.name,
- {"inpatient_record": self.name, "inpatient_status": self.status})
+ frappe.db.set_value(
+ "Medication Request",
+ medication_request.name,
+ {"inpatient_record": self.name, "inpatient_status": self.status},
+ )
if self.admission_nursing_checklist_template:
NursingTask.create_nursing_tasks_from_template(
@@ -301,10 +307,10 @@ def get_pending_doc(doc, doc_name_list, pending_invoices):
def get_unbilled_inpatient_docs(doc, inpatient_record):
filters = {
- "patient": inpatient_record.patient,
- "inpatient_record": inpatient_record.name,
- "docstatus": 1,
- }
+ "patient": inpatient_record.patient,
+ "inpatient_record": inpatient_record.name,
+ "docstatus": 1,
+ }
if doc in ["Service Request", "Medication Request"]:
filters.update(
{
@@ -423,16 +429,14 @@ def validate_incompleted_service_requests(inpatient_record):
"patient": inpatient_record.patient,
"inpatient_record": inpatient_record.name,
"docstatus": 1,
- "status": ["not in", ["Completed"]]
+ "status": ["not in", ["Completed"]],
}
- service_requests = frappe.db.get_list(
- "Service Request",
- filters=filters,
- pluck = "name"
- )
+ service_requests = frappe.db.get_list("Service Request", filters=filters, pluck="name")
if service_requests and len(service_requests) > 0:
- service_requests = [get_link_to_form("Service Request", service_request) for service_request in service_requests]
- message = _("There are Orders yet to be carried out
{0}".format(', '.join(map(str, service_requests))))
+ service_requests = [
+ get_link_to_form("Service Request", service_request) for service_request in service_requests
+ ]
+ message = _("There are Orders yet to be carried out
{0}")
- frappe.throw(message, title=_("Incomplete Services"), is_minimizable=True, wide=True)
+ frappe.throw(message.format(", ".join(service_requests)))
diff --git a/healthcare/healthcare/doctype/lab_test/lab_test.py b/healthcare/healthcare/doctype/lab_test/lab_test.py
index 6379d2cc66..ed0587b3cc 100644
--- a/healthcare/healthcare/doctype/lab_test/lab_test.py
+++ b/healthcare/healthcare/doctype/lab_test/lab_test.py
@@ -178,11 +178,11 @@ def create_lab_test_from_encounter(encounter):
template = get_lab_test_template(service_request_doc.template_dn)
if template:
lab_test = create_lab_test_doc(
- 1 if service_request_doc.billing_status == "Invoiced" else 0,
encounter.practitioner,
patient,
template,
encounter.company,
+ 1 if service_request_doc.billing_status == "Invoiced" else 0,
)
lab_test.service_request = service_request_doc.name
lab_test.save(ignore_permissions=True)
diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json
index 3fa8954a50..5ea2cd2bf3 100644
--- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json
+++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json
@@ -21,6 +21,7 @@
"inpatient_status",
"column_break_6",
"company",
+ "status",
"encounter_date",
"encounter_time",
"practitioner",
@@ -339,11 +340,18 @@
"fieldtype": "Data",
"label": "Google Meet Link",
"read_only": 1
+ },
+ {
+ "fieldname": "status",
+ "fieldtype": "Select",
+ "label": "Status",
+ "options": "\nOpen\nWaiting For Review\nCompleted\nCancelled",
+ "read_only": 1
}
],
"is_submittable": 1,
"links": [],
- "modified": "2023-01-14 19:09:28.299085",
+ "modified": "2023-09-13 03:25:39.573220",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient Encounter",
diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py
index ffcec598df..37f3eda921 100644
--- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py
+++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py
@@ -183,7 +183,7 @@ def get_order_details(self, template_doc, line_item, medication_request=False):
"patient": self.get("patient"),
"practitioner": self.practitioner,
"source_doc": "Patient Encounter",
- "order_group":self.name,
+ "order_group": self.name,
"sequence": line_item.get("sequence"),
"patient_care_type": template_doc.get("patient_care_type"),
"intent": line_item.get("intent"),
diff --git a/healthcare/healthcare/doctype/service_request/service_request.py b/healthcare/healthcare/doctype/service_request/service_request.py
index 92bedf4515..693ce463e5 100644
--- a/healthcare/healthcare/doctype/service_request/service_request.py
+++ b/healthcare/healthcare/doctype/service_request/service_request.py
@@ -59,15 +59,24 @@ def update_invoice_details(self, qty):
updates qty_invoiced and set billing status
"""
qty_invoiced = self.qty_invoiced + qty
-
+ invoiced = 0
if qty_invoiced == 0:
status = "Pending"
if qty_invoiced < self.quantity:
status = "Partly Invoiced"
else:
+ invoiced = 1
status = "Invoiced"
self.db_set({"qty_invoiced": qty_invoiced, "billing_status": status})
+ if self.template_dt == "Lab Test Template":
+ dt = "Lab Test"
+ elif self.template_dt == "Clinical Procedure Template":
+ dt = "Clinical Procedure"
+ elif self.template_dt == "Therapy Type":
+ dt = "Therapy Session"
+ dt_name = frappe.db.get_value(dt, {"service_request": self.name})
+ frappe.db.set_value(dt, dt_name, "invoiced", invoiced)
def update_service_request_status(service_request, service_dt, service_dn, status=None, qty=1):
diff --git a/healthcare/healthcare/utils.py b/healthcare/healthcare/utils.py
index ff88c0575e..1b0acdd3e0 100644
--- a/healthcare/healthcare/utils.py
+++ b/healthcare/healthcare/utils.py
@@ -333,7 +333,12 @@ def get_service_requests_to_invoice(patient, company):
service_requests = frappe.get_list(
"Service Request",
fields=["*"],
- filters={"patient": patient.name, "company": company, "invoiced": 0, "docstatus": 1},
+ filters={
+ "patient": patient.name,
+ "company": company,
+ "billing_status": ["!=", ["Invoiced"]],
+ "docstatus": 1,
+ },
)
for service_request in service_requests:
item, is_billable = frappe.get_cached_value(
@@ -569,7 +574,6 @@ def set_invoiced(item, method, ref_invoice=None):
}
-
def validate_invoiced_on_submit(item):
if (
item.reference_dt == "Clinical Procedure"