fix: filter Therapy Types and Therapy Plan in Patient Appointment
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
index 2d6b645..79e1775 100644
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
@@ -22,6 +22,7 @@
filters: {'status': 'Active'}
};
});
+
frm.set_query('practitioner', function() {
return {
filters: {
@@ -29,6 +30,7 @@
}
};
});
+
frm.set_query('service_unit', function(){
return {
filters: {
@@ -39,6 +41,16 @@
};
});
+ frm.set_query('therapy_plan', function() {
+ return {
+ filters: {
+ 'patient': frm.doc.patient
+ }
+ };
+ });
+
+ frm.trigger('set_therapy_type_filter');
+
if (frm.is_new()) {
frm.page.set_primary_action(__('Check Availability'), function() {
if (!frm.doc.patient) {
@@ -136,6 +148,24 @@
}
},
+ therapy_plan: function(frm) {
+ frm.trigger('set_therapy_type_filter');
+ },
+
+ set_therapy_type_filter: function(frm) {
+ if (frm.doc.therapy_plan) {
+ frm.call('get_therapy_types').then(r => {
+ frm.set_query('therapy_type', function() {
+ return {
+ filters: {
+ 'name': ['in', r.message]
+ }
+ };
+ });
+ });
+ }
+ },
+
therapy_type: function(frm) {
if (frm.doc.therapy_type) {
frappe.db.get_value('Therapy Type', frm.doc.therapy_type, 'default_duration', (r) => {
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
index e685b20..dc820cb 100755
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
@@ -91,6 +91,17 @@
if fee_validity:
frappe.msgprint(_('{0} has fee validity till {1}').format(self.patient, fee_validity.valid_till))
+ def get_therapy_types(self):
+ if not self.therapy_plan:
+ return
+
+ therapy_types = []
+ doc = frappe.get_doc('Therapy Plan', self.therapy_plan)
+ for entry in doc.therapy_plan_details:
+ therapy_types.append(entry.therapy_type)
+
+ return therapy_types
+
@frappe.whitelist()
def check_payment_fields_reqd(patient):
@@ -145,7 +156,7 @@
sales_invoice.flags.ignore_mandatory = True
sales_invoice.save(ignore_permissions=True)
sales_invoice.submit()
- frappe.msgprint(_('Sales Invoice {0} created'.format(sales_invoice.name)), alert=True)
+ frappe.msgprint(_('Sales Invoice {0} created').format(sales_invoice.name), alert=True)
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'invoiced', 1)
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'ref_sales_invoice', sales_invoice.name)