fix: tests

This commit is contained in:
Rucha Mahabal 2020-03-23 10:40:39 +05:30
parent 0eeaad8ce7
commit 4f9a1471e4
8 changed files with 65 additions and 64 deletions

View File

@ -11,21 +11,32 @@ from frappe.utils import nowdate, add_days, getdate
test_dependencies = ["Company"] test_dependencies = ["Company"]
class TestFeeValidity(unittest.TestCase): class TestFeeValidity(unittest.TestCase):
def test_fee_validity(self): def setUp(self):
frappe.db.sql("""delete from `tabPatient Appointment`""") frappe.db.sql("""delete from `tabPatient Appointment`""")
frappe.db.sql("""delete from `tabFee Validity`""") frappe.db.sql("""delete from `tabFee Validity`""")
def test_fee_validity(self):
patient = get_random("Patient") patient = get_random("Patient")
practitioner = get_random("Healthcare Practitioner") practitioner = get_random("Healthcare Practitioner")
department = get_random("Medical Department") medical_department = get_random("Medical Department")
item = create_healthcare_service_items()
healthcare_settings = frappe.get_single("Healthcare Settings")
healthcare_settings.enable_free_follow_ups = 1
healthcare_settings.max_visits = 2
healthcare_settings.valid_days = 7
healthcare_settings.automate_appointment_invoicing = 1
healthcare_settings.op_consulting_charge_item = item
healthcare_settings.save(ignore_permissions=True)
if not patient: if not patient:
patient = frappe.new_doc("Patient") patient = frappe.new_doc("Patient")
patient.patient_name = "_Test Patient" patient.first_name = "_Test Patient"
patient.sex = "Male" patient.sex = "Male"
patient.save(ignore_permissions=True) patient.save(ignore_permissions=True)
patient = patient.name patient = patient.name
if not department: if not medical_department:
medical_department = frappe.new_doc("Medical Department") medical_department = frappe.new_doc("Medical Department")
medical_department.department = "_Test Medical Department" medical_department.department = "_Test Medical Department"
medical_department.save(ignore_permissions=True) medical_department.save(ignore_permissions=True)
@ -34,71 +45,53 @@ class TestFeeValidity(unittest.TestCase):
if not practitioner: if not practitioner:
practitioner = frappe.new_doc("Healthcare Practitioner") practitioner = frappe.new_doc("Healthcare Practitioner")
practitioner.first_name = "_Test Healthcare Practitioner" practitioner.first_name = "_Test Healthcare Practitioner"
practitioner.gender = 'Female'
practitioner.department = department practitioner.department = department
practitioner.op_consulting_charge = 500
practitioner.save(ignore_permissions=True) practitioner.save(ignore_permissions=True)
practitioner = practitioner.name practitioner = practitioner.name
# appointment should not be invoiced as it is within fee validity
appointment = create_appointment(patient, practitioner, nowdate())
frappe.db.set_value("Healthcare Settings", None, "max_visits", 2)
frappe.db.set_value("Healthcare Settings", None, "valid_days", 7)
appointment = create_appointment(patient, practitioner, nowdate(), department)
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, 0)
invoice_appointment(appointment) # 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), department)
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
self.assertTrue(invoiced)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), department)
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, 0)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), department) # appointment should be invoiced as it is within fee validity but the max_visits are exceeded
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), invoice=1)
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)
def create_appointment(patient, practitioner, appointment_date, department): # appointment should be invoiced as it is not within fee validity and the max_visits are exceeded
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), invoice=1)
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
self.assertEqual(invoiced, 1)
def create_appointment(patient, practitioner, appointment_date, invoice=0):
appointment = frappe.new_doc("Patient Appointment") appointment = frappe.new_doc("Patient Appointment")
appointment.patient = patient appointment.patient = patient
appointment.practitioner = practitioner appointment.practitioner = practitioner
appointment.department = department appointment.department = "_Test Medical Department"
appointment.appointment_date = appointment_date appointment.appointment_date = appointment_date
appointment.company = "_Test Company" appointment.company = "_Test Company"
appointment.duration = 15 appointment.duration = 15
if invoice:
appointment.mode_of_payment = "Cash"
appointment.paid_amount = 500
appointment.save(ignore_permissions=True) appointment.save(ignore_permissions=True)
return appointment return appointment
def invoice_appointment(appointment_doc): def create_healthcare_service_items():
if not appointment_doc.name: if frappe.db.exists("Item", "HLC-SI-001"):
return False return "HLC-SI-001"
sales_invoice = frappe.new_doc("Sales Invoice") item = frappe.new_doc("Item")
sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") item.item_code = "HLC-SI-001"
sales_invoice.due_date = getdate() item.item_name = "Consulting Charges"
sales_invoice.is_pos = 0 item.item_group = "Services"
sales_invoice.company = appointment_doc.company item.is_stock_item = 0
sales_invoice.debit_to = "_Test Receivable - _TC" item.save()
return item.name
create_invoice_items(appointment_doc, sales_invoice)
sales_invoice.save(ignore_permissions=True)
sales_invoice.submit()
def create_invoice_items(appointment, invoice):
item_line = invoice.append("items")
item_line.item_name = "Consulting Charges"
item_line.description = "Consulting Charges: " + appointment.practitioner
item_line.uom = "Nos"
item_line.conversion_factor = 1
item_line.income_account = "_Test Account Cost for Goods Sold - _TC"
item_line.cost_center = "_Test Cost Center - _TC"
item_line.rate = 250
item_line.amount = 250
item_line.qty = 1
item_line.reference_dt = "Patient Appointment"
item_line.reference_dn = appointment.name
return invoice

View File

@ -61,8 +61,7 @@
{ {
"fieldname": "last_name", "fieldname": "last_name",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Last Name", "label": "Last Name"
"reqd": 1
}, },
{ {
"fieldname": "image", "fieldname": "image",
@ -278,7 +277,7 @@
], ],
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"modified": "2020-02-01 00:39:49.455988", "modified": "2020-03-20 15:13:13.382212",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Healthcare", "module": "Healthcare",
"name": "Healthcare Practitioner", "name": "Healthcare Practitioner",

View File

@ -44,7 +44,10 @@ class HealthcarePractitioner(Document):
frappe.permissions.add_user_permission('Healthcare Practitioner', self.name, self.user_id) frappe.permissions.add_user_permission('Healthcare Practitioner', self.name, self.user_id)
def set_full_name(self): def set_full_name(self):
if self.last_name:
self.practitioner_name = ' '.join(filter(None, [self.first_name, self.last_name])) self.practitioner_name = ' '.join(filter(None, [self.first_name, self.last_name]))
else:
self.practitioner_name = self.first_name
def validate_user_id(self): def validate_user_id(self):
if not frappe.db.exists('User', self.user_id): if not frappe.db.exists('User', self.user_id):

View File

@ -79,7 +79,7 @@ def get_patient():
patient = get_random("Patient") patient = get_random("Patient")
if not patient: if not patient:
patient = frappe.new_doc("Patient") patient = frappe.new_doc("Patient")
patient.patient_name = "Test Patient" patient.first_name = "_Test Patient"
patient.sex = "Male" patient.sex = "Male"
patient.save(ignore_permissions=True) patient.save(ignore_permissions=True)
return patient.name return patient.name

View File

@ -342,8 +342,7 @@
{ {
"fieldname": "last_name", "fieldname": "last_name",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Last Name", "label": "Last Name"
"reqd": 1
}, },
{ {
"fieldname": "first_name", "fieldname": "first_name",
@ -362,7 +361,7 @@
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"max_attachments": 50, "max_attachments": 50,
"modified": "2020-02-25 17:56:46.351080", "modified": "2020-03-20 14:59:53.945849",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Healthcare", "module": "Healthcare",
"name": "Patient", "name": "Patient",

View File

@ -27,7 +27,10 @@ class Patient(Document):
self.reload() self.reload()
def set_full_name(self): def set_full_name(self):
if self.last_name:
self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name])) self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name]))
else:
self.patient_name = self.first_name
def add_as_website_user(self): def add_as_website_user(self):
if self.email: if self.email:

View File

@ -23,9 +23,9 @@ class PatientAppointment(Document):
self.set_status() self.set_status()
def after_insert(self): def after_insert(self):
invoice_appointment(self)
self.update_prescription_details() self.update_prescription_details()
self.update_fee_validity() self.update_fee_validity()
invoice_appointment(self)
send_confirmation_msg(self) send_confirmation_msg(self)
def set_status(self): def set_status(self):
@ -105,6 +105,10 @@ def invoice_appointment(appointment_doc):
automate_invoicing = frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing') automate_invoicing = frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing')
appointment_invoiced = frappe.db.get_value('Patient Appointment', appointment_doc.name, 'invoiced') appointment_invoiced = frappe.db.get_value('Patient Appointment', appointment_doc.name, 'invoiced')
fee_validity = check_fee_validity(appointment_doc) fee_validity = check_fee_validity(appointment_doc)
if not fee_validity:
if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
return
if automate_invoicing and not appointment_invoiced and not fee_validity: if automate_invoicing and not appointment_invoiced and not fee_validity:
sales_invoice = frappe.new_doc('Sales Invoice') sales_invoice = frappe.new_doc('Sales Invoice')
sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer')

View File

@ -232,11 +232,11 @@ def get_service_item_and_practitioner_charge(doc):
def throw_config_service_item(is_inpatient): def throw_config_service_item(is_inpatient):
service_item_lable = 'Out Patient Consulting Charge Item' service_item_label = 'Out Patient Consulting Charge Item'
if is_inpatient: if is_inpatient:
service_item_lable = 'Inpatient Visit Charge Item' service_item_label = 'Inpatient Visit Charge Item'
msg = _(('Please Configure {0} in ').format(service_item_lable) \ msg = _(('Please Configure {0} in ').format(service_item_label) \
+ '''<b><a href='#Form/Healthcare Settings'>Healthcare Settings</a></b>''') + '''<b><a href='#Form/Healthcare Settings'>Healthcare Settings</a></b>''')
frappe.throw(msg, title=_('Missing Configuration')) frappe.throw(msg, title=_('Missing Configuration'))