feat: Allow selecting admission service unit in Patient Appointment for inpatients
This commit is contained in:
parent
ea19434af4
commit
20e5315480
@ -655,6 +655,34 @@ def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters):
|
||||
return frappe.db.sql(query, filters)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_healthcare_service_units(doctype, txt, searchfield, start, page_len, filters):
|
||||
query = """
|
||||
select name
|
||||
from `tabHealthcare Service Unit`
|
||||
where
|
||||
is_group = 0
|
||||
and company = {company}
|
||||
and name like {txt}""".format(
|
||||
company = frappe.db.escape(filters.get('company')), txt = frappe.db.escape('%{0}%'.format(txt)))
|
||||
|
||||
if filters and filters.get('inpatient_record'):
|
||||
from erpnext.healthcare.doctype.inpatient_medication_entry.inpatient_medication_entry import get_current_healthcare_service_unit
|
||||
service_unit = get_current_healthcare_service_unit(filters.get('inpatient_record'))
|
||||
|
||||
# if the patient is admitted, then appointments should be allowed against the admission service unit,
|
||||
# inspite of it being an Inpatient Occupancy service unit
|
||||
if service_unit:
|
||||
query += " and (allow_appointments = 1 or name = {service_unit})".format(service_unit = frappe.db.escape(service_unit))
|
||||
else:
|
||||
query += " and allow_appointments = 1"
|
||||
else:
|
||||
query += " and allow_appointments = 1"
|
||||
|
||||
return frappe.db.sql(query, filters)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_tax_template(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
@ -264,7 +264,7 @@ def get_filters(entry):
|
||||
|
||||
def get_current_healthcare_service_unit(inpatient_record):
|
||||
ip_record = frappe.get_doc('Inpatient Record', inpatient_record)
|
||||
if ip_record.inpatient_occupancies:
|
||||
if ip_record.status in ['Admitted', 'Discharge Scheduled'] and ip_record.inpatient_occupancies:
|
||||
return ip_record.inpatient_occupancies[-1].service_unit
|
||||
return
|
||||
|
||||
|
@ -31,14 +31,14 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('service_unit', function(){
|
||||
frm.set_query('service_unit', function() {
|
||||
return {
|
||||
query: 'erpnext.controllers.queries.get_healthcare_service_units',
|
||||
filters: {
|
||||
'is_group': false,
|
||||
'allow_appointments': true,
|
||||
'company': frm.doc.company
|
||||
company: frm.doc.company,
|
||||
inpatient_record: frm.doc.inpatient_record
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query('therapy_plan', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user