fix(healthcare): Made payment fields mandatory for new appointments (#26608)
* fix(healthcare): Made payment fields mandatory for new appointments * fix: sider issues * fix: Fix failing test * fix: Patient appointment invoicing Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com> Co-authored-by: Syed Mujeer Hashmi <mujeerhashmi@4csolutions.in>
This commit is contained in:
parent
b7ef4ce7a2
commit
a65498dc61
@ -29,10 +29,10 @@ class TestFeeValidity(unittest.TestCase):
|
|||||||
healthcare_settings.save(ignore_permissions=True)
|
healthcare_settings.save(ignore_permissions=True)
|
||||||
patient, medical_department, practitioner = create_healthcare_docs()
|
patient, medical_department, practitioner = create_healthcare_docs()
|
||||||
|
|
||||||
# appointment should not be invoiced. Check Fee Validity created for new patient
|
# For first appointment, invoice is generated
|
||||||
appointment = create_appointment(patient, practitioner, nowdate())
|
appointment = create_appointment(patient, practitioner, nowdate())
|
||||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||||
self.assertEqual(invoiced, 0)
|
self.assertEqual(invoiced, 1)
|
||||||
|
|
||||||
# appointment should not be invoiced as it is within fee validity
|
# appointment should not be invoiced as it is within fee validity
|
||||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4))
|
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4))
|
||||||
|
@ -241,6 +241,13 @@ frappe.ui.form.on('Patient Appointment', {
|
|||||||
frm.toggle_reqd('mode_of_payment', 0);
|
frm.toggle_reqd('mode_of_payment', 0);
|
||||||
frm.toggle_reqd('paid_amount', 0);
|
frm.toggle_reqd('paid_amount', 0);
|
||||||
frm.toggle_reqd('billing_item', 0);
|
frm.toggle_reqd('billing_item', 0);
|
||||||
|
} else if (data.message) {
|
||||||
|
frm.toggle_display('mode_of_payment', 1);
|
||||||
|
frm.toggle_display('paid_amount', 1);
|
||||||
|
frm.toggle_display('billing_item', 1);
|
||||||
|
frm.toggle_reqd('mode_of_payment', 1);
|
||||||
|
frm.toggle_reqd('paid_amount', 1);
|
||||||
|
frm.toggle_reqd('billing_item', 1);
|
||||||
} else {
|
} else {
|
||||||
// if automated appointment invoicing is disabled, hide fields
|
// if automated appointment invoicing is disabled, hide fields
|
||||||
frm.toggle_display('mode_of_payment', data.message ? 1 : 0);
|
frm.toggle_display('mode_of_payment', data.message ? 1 : 0);
|
||||||
|
@ -134,6 +134,7 @@
|
|||||||
"set_only_once": 1
|
"set_only_once": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "eval:doc.practitioner;",
|
||||||
"fieldname": "section_break_12",
|
"fieldname": "section_break_12",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Appointment Details"
|
"label": "Appointment Details"
|
||||||
@ -349,7 +350,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-02-08 13:13:15.116833",
|
"modified": "2021-06-16 00:40:26.841794",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Patient Appointment",
|
"name": "Patient Appointment",
|
||||||
@ -400,4 +401,4 @@
|
|||||||
"title_field": "title",
|
"title_field": "title",
|
||||||
"track_changes": 1,
|
"track_changes": 1,
|
||||||
"track_seen": 1
|
"track_seen": 1
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,6 @@ def check_payment_fields_reqd(patient):
|
|||||||
fee_validity = frappe.db.exists('Fee Validity', {'patient': patient, 'status': 'Pending'})
|
fee_validity = frappe.db.exists('Fee Validity', {'patient': patient, 'status': 'Pending'})
|
||||||
if fee_validity:
|
if fee_validity:
|
||||||
return {'fee_validity': fee_validity}
|
return {'fee_validity': fee_validity}
|
||||||
if check_is_new_patient(patient):
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -151,8 +149,6 @@ def invoice_appointment(appointment_doc):
|
|||||||
elif not fee_validity:
|
elif not fee_validity:
|
||||||
if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
|
if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
|
||||||
return
|
return
|
||||||
if check_is_new_patient(appointment_doc.patient, appointment_doc.name):
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
fee_validity = None
|
fee_validity = None
|
||||||
|
|
||||||
@ -196,9 +192,7 @@ def check_is_new_patient(patient, name=None):
|
|||||||
filters['name'] = ('!=', name)
|
filters['name'] = ('!=', name)
|
||||||
|
|
||||||
has_previous_appointment = frappe.db.exists('Patient Appointment', filters)
|
has_previous_appointment = frappe.db.exists('Patient Appointment', filters)
|
||||||
if has_previous_appointment:
|
return not has_previous_appointment
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_appointment_item(appointment_doc, item):
|
def get_appointment_item(appointment_doc, item):
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import unittest
|
import unittest
|
||||||
import frappe
|
import frappe
|
||||||
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import update_status, make_encounter
|
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import update_status, make_encounter, check_payment_fields_reqd, check_is_new_patient
|
||||||
from frappe.utils import nowdate, add_days, now_datetime
|
from frappe.utils import nowdate, add_days, now_datetime
|
||||||
from frappe.utils.make_random import get_random
|
from frappe.utils.make_random import get_random
|
||||||
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
|
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
|
||||||
|
|
||||||
|
|
||||||
class TestPatientAppointment(unittest.TestCase):
|
class TestPatientAppointment(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.db.sql("""delete from `tabPatient Appointment`""")
|
frappe.db.sql("""delete from `tabPatient Appointment`""")
|
||||||
@ -176,6 +177,28 @@ class TestPatientAppointment(unittest.TestCase):
|
|||||||
mark_invoiced_inpatient_occupancy(ip_record1)
|
mark_invoiced_inpatient_occupancy(ip_record1)
|
||||||
discharge_patient(ip_record1)
|
discharge_patient(ip_record1)
|
||||||
|
|
||||||
|
def test_payment_should_be_mandatory_for_new_patient_appointment(self):
|
||||||
|
frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 1)
|
||||||
|
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
|
||||||
|
frappe.db.set_value('Healthcare Settings', None, 'max_visits', 3)
|
||||||
|
frappe.db.set_value('Healthcare Settings', None, 'valid_days', 30)
|
||||||
|
|
||||||
|
patient = create_patient()
|
||||||
|
assert check_is_new_patient(patient)
|
||||||
|
payment_required = check_payment_fields_reqd(patient)
|
||||||
|
assert payment_required is True
|
||||||
|
|
||||||
|
def test_sales_invoice_should_be_generated_for_new_patient_appointment(self):
|
||||||
|
patient, medical_department, practitioner = create_healthcare_docs()
|
||||||
|
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
|
||||||
|
invoice_count = frappe.db.count('Sales Invoice')
|
||||||
|
|
||||||
|
assert check_is_new_patient(patient)
|
||||||
|
create_appointment(patient, practitioner, nowdate())
|
||||||
|
new_invoice_count = frappe.db.count('Sales Invoice')
|
||||||
|
|
||||||
|
assert new_invoice_count == invoice_count + 1
|
||||||
|
|
||||||
|
|
||||||
def create_healthcare_docs():
|
def create_healthcare_docs():
|
||||||
patient = create_patient()
|
patient = create_patient()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user