Skip to content

Commit

Permalink
fix: Service Request - minor fixes,
Browse files Browse the repository at this point in the history
linters issue
  • Loading branch information
akashkrishna619 committed Oct 9, 2023
1 parent 85e0815 commit 39865d3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
40 changes: 22 additions & 18 deletions healthcare/healthcare/doctype/inpatient_record/inpatient_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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<br> {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<br> {0}")

frappe.throw(message, title=_("Incomplete Services"), is_minimizable=True, wide=True)
frappe.throw(message.format(", ".join(service_requests)))
2 changes: 1 addition & 1 deletion healthcare/healthcare/doctype/lab_test/lab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"inpatient_status",
"column_break_6",
"company",
"status",
"encounter_date",
"encounter_time",
"practitioner",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
11 changes: 10 additions & 1 deletion healthcare/healthcare/doctype/service_request/service_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions healthcare/healthcare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -569,7 +574,6 @@ def set_invoiced(item, method, ref_invoice=None):
}



def validate_invoiced_on_submit(item):
if (
item.reference_dt == "Clinical Procedure"
Expand Down

0 comments on commit 39865d3

Please sign in to comment.