feat: Fee Validity status (Ongoing, Expired, Completed)
This commit is contained in:
parent
27512c86ae
commit
c4b2dceb01
@ -1,259 +1,120 @@
|
|||||||
{
|
{
|
||||||
|
"actions": [],
|
||||||
"allow_copy": 1,
|
"allow_copy": 1,
|
||||||
"allow_guest_to_view": 0,
|
|
||||||
"allow_import": 1,
|
"allow_import": 1,
|
||||||
"allow_rename": 0,
|
|
||||||
"beta": 1,
|
"beta": 1,
|
||||||
"creation": "2017-01-05 10:56:29.564806",
|
"creation": "2017-01-05 10:56:29.564806",
|
||||||
"custom": 0,
|
|
||||||
"docstatus": 0,
|
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"document_type": "Setup",
|
"document_type": "Setup",
|
||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"practitioner",
|
||||||
|
"patient",
|
||||||
|
"column_break_3",
|
||||||
|
"status",
|
||||||
|
"section_break_3",
|
||||||
|
"max_visits",
|
||||||
|
"visited",
|
||||||
|
"valid_till",
|
||||||
|
"column_break_6",
|
||||||
|
"ref_invoice",
|
||||||
|
"start_date"
|
||||||
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "practitioner",
|
"fieldname": "practitioner",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 0,
|
"in_list_view": 1,
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Healthcare Practitioner",
|
"label": "Healthcare Practitioner",
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"options": "Healthcare Practitioner",
|
"options": "Healthcare Practitioner",
|
||||||
"permlevel": 0,
|
"reqd": 1,
|
||||||
"precision": "",
|
"search_index": 1
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 1,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "patient",
|
"fieldname": "patient",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 0,
|
"in_list_view": 1,
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Patient",
|
"label": "Patient",
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"options": "Patient",
|
"options": "Patient",
|
||||||
"permlevel": 0,
|
"reqd": 1,
|
||||||
"precision": "",
|
"search_index": 1
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 1,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "max_visit",
|
|
||||||
"fieldtype": "Int",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Max number of visit",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "visited",
|
"fieldname": "visited",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"hidden": 0,
|
"label": "Visited yet"
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Visited yet",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "valid_till",
|
"fieldname": "valid_till",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"hidden": 0,
|
"label": "Valid till"
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Valid till",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "ref_invoice",
|
"fieldname": "ref_invoice",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 0,
|
"label": "Reference Invoice",
|
||||||
"ignore_user_permissions": 0,
|
"options": "Sales Invoice"
|
||||||
"ignore_xss_filter": 0,
|
},
|
||||||
"in_filter": 0,
|
{
|
||||||
"in_global_search": 0,
|
"fieldname": "section_break_3",
|
||||||
"in_list_view": 0,
|
"fieldtype": "Section Break",
|
||||||
"in_standard_filter": 0,
|
"label": "Validity"
|
||||||
"label": "Reference Inv",
|
},
|
||||||
"length": 0,
|
{
|
||||||
"no_copy": 0,
|
"fieldname": "column_break_6",
|
||||||
"options": "Sales Invoice",
|
"fieldtype": "Column Break"
|
||||||
"permlevel": 0,
|
},
|
||||||
"precision": "",
|
{
|
||||||
"print_hide": 0,
|
"fieldname": "max_visits",
|
||||||
"print_hide_if_no_value": 0,
|
"fieldtype": "Int",
|
||||||
"read_only": 0,
|
"label": "Max number of visit"
|
||||||
"remember_last_selected_value": 0,
|
},
|
||||||
"report_hide": 0,
|
{
|
||||||
"reqd": 0,
|
"fieldname": "column_break_3",
|
||||||
"search_index": 0,
|
"fieldtype": "Column Break"
|
||||||
"set_only_once": 0,
|
},
|
||||||
"translatable": 0,
|
{
|
||||||
"unique": 0
|
"fieldname": "status",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
|
"label": "Status",
|
||||||
|
"options": "Ongoing\nCompleted\nExpired",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "ref_invoice.posting_date",
|
||||||
|
"fieldname": "start_date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"label": "Start Date",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"has_web_view": 0,
|
"links": [],
|
||||||
"hide_heading": 0,
|
"modified": "2020-03-09 23:14:08.581821",
|
||||||
"hide_toolbar": 0,
|
|
||||||
"idx": 0,
|
|
||||||
"image_view": 0,
|
|
||||||
"in_create": 0,
|
|
||||||
"is_submittable": 0,
|
|
||||||
"issingle": 0,
|
|
||||||
"istable": 0,
|
|
||||||
"max_attachments": 0,
|
|
||||||
"modified": "2018-07-16 12:43:45.635230",
|
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Fee Validity",
|
"name": "Fee Validity",
|
||||||
"name_case": "",
|
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"delete": 1,
|
"delete": 1,
|
||||||
"email": 1,
|
"email": 1,
|
||||||
"export": 1,
|
"export": 1,
|
||||||
"if_owner": 0,
|
|
||||||
"import": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"print": 1,
|
"print": 1,
|
||||||
"read": 1,
|
"read": 1,
|
||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "Healthcare Administrator",
|
"role": "Healthcare Administrator",
|
||||||
"set_user_permissions": 0,
|
|
||||||
"share": 1,
|
"share": 1,
|
||||||
"submit": 0,
|
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"read_only": 0,
|
|
||||||
"read_only_onload": 0,
|
|
||||||
"restrict_to_domain": "Healthcare",
|
"restrict_to_domain": "Healthcare",
|
||||||
"search_fields": "practitioner, patient",
|
"search_fields": "practitioner, patient",
|
||||||
"show_name_in_global_search": 0,
|
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"title_field": "practitioner",
|
"title_field": "practitioner"
|
||||||
"track_changes": 0,
|
|
||||||
"track_seen": 0
|
|
||||||
}
|
}
|
@ -9,18 +9,31 @@ from frappe.utils import getdate
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class FeeValidity(Document):
|
class FeeValidity(Document):
|
||||||
pass
|
def validate(self):
|
||||||
|
self.update_status()
|
||||||
|
|
||||||
|
def update_status(self):
|
||||||
|
valid_till = getdate(self.valid_till)
|
||||||
|
today = getdate()
|
||||||
|
if self.visited >= self.max_visits:
|
||||||
|
self.status = 'Completed'
|
||||||
|
elif self.visited < self.max_visits:
|
||||||
|
if valid_till >= today:
|
||||||
|
self.status = 'Ongoing'
|
||||||
|
elif valid_till < today:
|
||||||
|
self.status = 'Expired'
|
||||||
|
|
||||||
|
|
||||||
def update_fee_validity(fee_validity, date, ref_invoice=None):
|
def update_fee_validity(fee_validity, date, ref_invoice=None):
|
||||||
max_visit = frappe.db.get_value("Healthcare Settings", None, "max_visit")
|
max_visits = frappe.db.get_single_value("Healthcare Settings", "max_visits")
|
||||||
valid_days = frappe.db.get_value("Healthcare Settings", None, "valid_days")
|
valid_days = frappe.db.get_single_value("Healthcare Settings", "valid_days")
|
||||||
if not valid_days:
|
if not valid_days:
|
||||||
valid_days = 1
|
valid_days = 1
|
||||||
if not max_visit:
|
if not max_visits:
|
||||||
max_visit = 1
|
max_visits = 1
|
||||||
date = getdate(date)
|
date = getdate(date)
|
||||||
valid_till = date + datetime.timedelta(days=int(valid_days))
|
valid_till = date + datetime.timedelta(days=int(valid_days))
|
||||||
fee_validity.max_visit = max_visit
|
fee_validity.max_visits = max_visits
|
||||||
fee_validity.visited = 1
|
fee_validity.visited = 1
|
||||||
fee_validity.valid_till = valid_till
|
fee_validity.valid_till = valid_till
|
||||||
fee_validity.ref_invoice = ref_invoice
|
fee_validity.ref_invoice = ref_invoice
|
||||||
@ -34,3 +47,9 @@ def create_fee_validity(practitioner, patient, date, ref_invoice=None):
|
|||||||
fee_validity.patient = patient
|
fee_validity.patient = patient
|
||||||
fee_validity = update_fee_validity(fee_validity, date, ref_invoice)
|
fee_validity = update_fee_validity(fee_validity, date, ref_invoice)
|
||||||
return fee_validity
|
return fee_validity
|
||||||
|
|
||||||
|
|
||||||
|
def update_validity_status():
|
||||||
|
docs = frappe.get_all('Fee Validity', filters={'status': ['not in', ['Completed', 'Expired']]})
|
||||||
|
for doc in docs:
|
||||||
|
frappe.get_doc("Task", doc.name).update_status()
|
||||||
|
10
erpnext/healthcare/doctype/fee_validity/fee_validity_list.js
Normal file
10
erpnext/healthcare/doctype/fee_validity/fee_validity_list.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
frappe.listview_settings['Fee Validity'] = {
|
||||||
|
get_indicator: function(doc) {
|
||||||
|
var colors = {
|
||||||
|
'Ongoing': 'orange',
|
||||||
|
'Completed': 'green',
|
||||||
|
'Expired': 'grey'
|
||||||
|
};
|
||||||
|
return [__(doc.status), colors[doc.status], 'status,=,' + doc.status];
|
||||||
|
}
|
||||||
|
};
|
@ -40,7 +40,7 @@ class TestFeeValidity(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
frappe.db.set_value("Healthcare Settings", None, "max_visit", 2)
|
frappe.db.set_value("Healthcare Settings", None, "max_visits", 2)
|
||||||
frappe.db.set_value("Healthcare Settings", None, "valid_days", 7)
|
frappe.db.set_value("Healthcare Settings", None, "valid_days", 7)
|
||||||
|
|
||||||
appointment = create_appointment(patient, practitioner, nowdate(), department)
|
appointment = create_appointment(patient, practitioner, nowdate(), department)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"collect_registration_fee",
|
"collect_registration_fee",
|
||||||
"registration_fee",
|
"registration_fee",
|
||||||
"automate_appointment_invoicing",
|
"automate_appointment_invoicing",
|
||||||
"max_visit",
|
"max_visits",
|
||||||
"valid_days",
|
"valid_days",
|
||||||
"healthcare_service_items",
|
"healthcare_service_items",
|
||||||
"inpatient_visit_charge_item",
|
"inpatient_visit_charge_item",
|
||||||
@ -77,12 +77,6 @@
|
|||||||
"mandatory_depends_on": "eval:doc.collect_registration_fee == 1",
|
"mandatory_depends_on": "eval:doc.collect_registration_fee == 1",
|
||||||
"options": "Currency"
|
"options": "Currency"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"description": "The number of free follow ups (Patient Encounters in valid days) allowed",
|
|
||||||
"fieldname": "max_visit",
|
|
||||||
"fieldtype": "Int",
|
|
||||||
"label": "Patient Encounters in valid days"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"description": "Time period (Valid number of days) for free consultations",
|
"description": "Time period (Valid number of days) for free consultations",
|
||||||
"fieldname": "valid_days",
|
"fieldname": "valid_days",
|
||||||
@ -291,11 +285,17 @@
|
|||||||
"fieldname": "remind_before",
|
"fieldname": "remind_before",
|
||||||
"fieldtype": "Time",
|
"fieldtype": "Time",
|
||||||
"label": "Remind Before"
|
"label": "Remind Before"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "The number of free follow ups (Patient Encounters in valid days) allowed",
|
||||||
|
"fieldname": "max_visits",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Number of Patient Encounters in valid days"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-02-24 10:51:23.015896",
|
"modified": "2020-03-09 17:43:23.251559",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Healthcare Settings",
|
"name": "Healthcare Settings",
|
||||||
|
@ -85,13 +85,13 @@ class PatientAppointment(Document):
|
|||||||
|
|
||||||
def check_fee_validity(self):
|
def check_fee_validity(self):
|
||||||
# Check fee validity exists
|
# Check fee validity exists
|
||||||
validity_exists = check_validity_exists(self.practitioner, self.patient)
|
validity = check_validity_exists(self.practitioner, self.patient)
|
||||||
if validity_exists:
|
if validity:
|
||||||
fee_validity = frappe.get_doc('Fee Validity', validity_exists.name)
|
fee_validity = frappe.get_doc('Fee Validity', validity)
|
||||||
|
|
||||||
# Check if the validity is valid
|
# Check if the validity is valid
|
||||||
appointment_date = getdate(self.appointment_date)
|
appointment_date = getdate(self.appointment_date)
|
||||||
if (fee_validity.valid_till >= appointment_date) and (fee_validity.visited < fee_validity.max_visit):
|
if (fee_validity.valid_till >= appointment_date) and (fee_validity.visited < fee_validity.max_visits):
|
||||||
visited = fee_validity.visited + 1
|
visited = fee_validity.visited + 1
|
||||||
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
||||||
if fee_validity.ref_invoice:
|
if fee_validity.ref_invoice:
|
||||||
@ -172,7 +172,7 @@ def cancel_appointment(appointment_id):
|
|||||||
|
|
||||||
def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoice):
|
def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoice):
|
||||||
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
||||||
max_visit = frappe.db.get_single_value('Healthcare Settings', 'max_visit')
|
max_visits = frappe.db.get_single_value('Healthcare Settings', 'max_visits')
|
||||||
valid_start_date = add_days(getdate(valid_end_date), -int(valid_days))
|
valid_start_date = add_days(getdate(valid_end_date), -int(valid_days))
|
||||||
|
|
||||||
# Appointments which have same fee validity range with the appointment
|
# Appointments which have same fee validity range with the appointment
|
||||||
@ -182,7 +182,7 @@ def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoic
|
|||||||
'appointment_date': ('<=', getdate(valid_end_date)),
|
'appointment_date': ('<=', getdate(valid_end_date)),
|
||||||
'appointment_date':('>=', getdate(valid_start_date)),
|
'appointment_date':('>=', getdate(valid_start_date)),
|
||||||
'practitioner': appointment.practitioner
|
'practitioner': appointment.practitioner
|
||||||
}, order_by='appointment_date desc', limit=int(max_visit))
|
}, order_by='appointment_date desc', limit=int(max_visits))
|
||||||
|
|
||||||
if appointments and len(appointments) > 0:
|
if appointments and len(appointments) > 0:
|
||||||
appointment_obj = appointments[len(appointments)-1]
|
appointment_obj = appointments[len(appointments)-1]
|
||||||
|
@ -45,7 +45,7 @@ def get_fee_validity(patient_appointments):
|
|||||||
fee_validity_details = []
|
fee_validity_details = []
|
||||||
items_to_invoice = []
|
items_to_invoice = []
|
||||||
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
||||||
max_visit = frappe.db.get_single_value('Healthcare Settings', 'max_visit')
|
max_visits = frappe.db.get_single_value('Healthcare Settings', 'max_visits')
|
||||||
for appointment in patient_appointments:
|
for appointment in patient_appointments:
|
||||||
if appointment.procedure_template:
|
if appointment.procedure_template:
|
||||||
if frappe.db.get_value('Clinical Procedure Template', appointment.procedure_template, 'is_billable'):
|
if frappe.db.get_value('Clinical Procedure Template', appointment.procedure_template, 'is_billable'):
|
||||||
@ -63,7 +63,7 @@ def get_fee_validity(patient_appointments):
|
|||||||
practitioner_exist_in_list = True
|
practitioner_exist_in_list = True
|
||||||
if validity['valid_till'] >= appointment.appointment_date:
|
if validity['valid_till'] >= appointment.appointment_date:
|
||||||
validity['visits'] = validity['visits'] + 1
|
validity['visits'] = validity['visits'] + 1
|
||||||
if int(max_visit) > validity['visits']:
|
if int(max_visits) > validity['visits']:
|
||||||
skip_invoice = True
|
skip_invoice = True
|
||||||
if not skip_invoice:
|
if not skip_invoice:
|
||||||
validity['visits'] = 1
|
validity['visits'] = 1
|
||||||
@ -72,9 +72,9 @@ def get_fee_validity(patient_appointments):
|
|||||||
if not practitioner_exist_in_list:
|
if not practitioner_exist_in_list:
|
||||||
valid_till = appointment.appointment_date + datetime.timedelta(days=int(valid_days))
|
valid_till = appointment.appointment_date + datetime.timedelta(days=int(valid_days))
|
||||||
visits = 0
|
visits = 0
|
||||||
validity_exist = check_validity_exists(appointment.practitioner, appointment.patient)
|
validity = check_validity_exists(appointment.practitioner, appointment.patient)
|
||||||
if validity_exist:
|
if validity:
|
||||||
fee_validity = frappe.get_doc('Fee Validity', validity_exist[0][0])
|
fee_validity = frappe.get_doc('Fee Validity', validity)
|
||||||
valid_till = fee_validity.valid_till
|
valid_till = fee_validity.valid_till
|
||||||
visits = fee_validity.visited
|
visits = fee_validity.visited
|
||||||
fee_validity_details.append({'practitioner': appointment.practitioner,
|
fee_validity_details.append({'practitioner': appointment.practitioner,
|
||||||
@ -348,19 +348,16 @@ def manage_prescriptions(invoiced, ref_dt, ref_dn, dt, created_check_field):
|
|||||||
|
|
||||||
|
|
||||||
def check_validity_exists(practitioner, patient):
|
def check_validity_exists(practitioner, patient):
|
||||||
return frappe.db.exists({
|
return frappe.db.get_value('Fee Validity', {'practitioner': practitioner, 'patient': patient}, 'name')
|
||||||
'doctype': 'Fee Validity',
|
|
||||||
'practitioner': practitioner,
|
|
||||||
'patient': patient})
|
|
||||||
|
|
||||||
|
|
||||||
def manage_fee_validity(appointment_name, method, ref_invoice=None):
|
def manage_fee_validity(appointment_name, method, ref_invoice=None):
|
||||||
appointment_doc = frappe.get_doc('Patient Appointment', appointment_name)
|
appointment_doc = frappe.get_doc('Patient Appointment', appointment_name)
|
||||||
validity_exists = check_validity_exists(appointment_doc.practitioner, appointment_doc.patient)
|
validity = check_validity_exists(appointment_doc.practitioner, appointment_doc.patient)
|
||||||
do_not_update = False
|
do_not_update = False
|
||||||
visited = 0
|
visited = 0
|
||||||
if validity_exist:
|
if validity:
|
||||||
fee_validity = frappe.get_doc('Fee Validity', validity_exists.name)
|
fee_validity = frappe.get_doc('Fee Validity', validity)
|
||||||
# Check if the validity is valid
|
# Check if the validity is valid
|
||||||
if fee_validity.valid_till >= appointment_doc.appointment_date:
|
if fee_validity.valid_till >= appointment_doc.appointment_date:
|
||||||
if method == 'on_cancel' and appointment_doc.status != 'Closed':
|
if method == 'on_cancel' and appointment_doc.status != 'Closed':
|
||||||
@ -370,7 +367,7 @@ def manage_fee_validity(appointment_name, method, ref_invoice=None):
|
|||||||
visited = 0
|
visited = 0
|
||||||
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
||||||
do_not_update = True
|
do_not_update = True
|
||||||
elif method == 'on_submit' and fee_validity.visited < fee_validity.max_visit:
|
elif method == 'on_submit' and fee_validity.visited < fee_validity.max_visits:
|
||||||
visited = fee_validity.visited + 1
|
visited = fee_validity.visited + 1
|
||||||
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
||||||
do_not_update = True
|
do_not_update = True
|
||||||
@ -383,12 +380,7 @@ def manage_fee_validity(appointment_name, method, ref_invoice=None):
|
|||||||
fee_validity = create_fee_validity(appointment_doc.practitioner, appointment_doc.patient, appointment_doc.appointment_date, ref_invoice)
|
fee_validity = create_fee_validity(appointment_doc.practitioner, appointment_doc.patient, appointment_doc.appointment_date, ref_invoice)
|
||||||
|
|
||||||
visited = fee_validity.visited
|
visited = fee_validity.visited
|
||||||
mark_appointments_as_invoiced(fee_validity, ref_invoice, method)
|
mark_appointments_as_invoiced(fee_validity, ref_invoice, method, appointment_doc)
|
||||||
|
|
||||||
if method == 'on_cancel':
|
|
||||||
invoiced = True
|
|
||||||
else:
|
|
||||||
invoiced = False
|
|
||||||
|
|
||||||
if method == 'on_cancel':
|
if method == 'on_cancel':
|
||||||
ref_invoice_in_fee_validity = frappe.db.get_value('Fee Validity', fee_validity.name, 'ref_invoice')
|
ref_invoice_in_fee_validity = frappe.db.get_value('Fee Validity', fee_validity.name, 'ref_invoice')
|
||||||
@ -396,7 +388,12 @@ def manage_fee_validity(appointment_name, method, ref_invoice=None):
|
|||||||
frappe.delete_doc('Fee Validity', fee_validity.name)
|
frappe.delete_doc('Fee Validity', fee_validity.name)
|
||||||
|
|
||||||
|
|
||||||
def mark_appointments_as_invoiced(fee_validity, ref_invoice, method):
|
def mark_appointments_as_invoiced(fee_validity, ref_invoice, method, appointment_doc):
|
||||||
|
if method == 'on_cancel':
|
||||||
|
invoiced = True
|
||||||
|
else:
|
||||||
|
invoiced = False
|
||||||
|
|
||||||
patient_appointments = appointments_valid_in_fee_validity(appointment_doc, invoiced)
|
patient_appointments = appointments_valid_in_fee_validity(appointment_doc, invoiced)
|
||||||
if patient_appointments and fee_validity:
|
if patient_appointments and fee_validity:
|
||||||
visit = visited
|
visit = visited
|
||||||
@ -409,7 +406,7 @@ def mark_appointments_as_invoiced(fee_validity, ref_invoice, method):
|
|||||||
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
||||||
frappe.db.set_value('Patient Appointment', appointment.name, 'invoiced', False)
|
frappe.db.set_value('Patient Appointment', appointment.name, 'invoiced', False)
|
||||||
manage_doc_for_appoitnment('Patient Encounter', appointment.name, False)
|
manage_doc_for_appoitnment('Patient Encounter', appointment.name, False)
|
||||||
elif method == 'on_submit' and int(fee_validity.max_visit) > visit:
|
elif method == 'on_submit' and int(fee_validity.max_visits) > visit:
|
||||||
if ref_invoice == fee_validity.ref_invoice:
|
if ref_invoice == fee_validity.ref_invoice:
|
||||||
visited += 1
|
visited += 1
|
||||||
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
frappe.db.set_value('Fee Validity', fee_validity.name, 'visited', visited)
|
||||||
@ -421,9 +418,9 @@ def mark_appointments_as_invoiced(fee_validity, ref_invoice, method):
|
|||||||
|
|
||||||
def appointments_valid_in_fee_validity(appointment, invoiced):
|
def appointments_valid_in_fee_validity(appointment, invoiced):
|
||||||
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
||||||
max_visit = frappe.db.get_single_value('Healthcare Settings', 'max_visit')
|
max_visits = frappe.db.get_single_value('Healthcare Settings', 'max_visits')
|
||||||
if int(max_visit) < 1:
|
if int(max_visits) < 1:
|
||||||
max_visit = 1
|
max_visits = 1
|
||||||
valid_days_date = add_days(getdate(appointment.appointment_date), int(valid_days))
|
valid_days_date = add_days(getdate(appointment.appointment_date), int(valid_days))
|
||||||
|
|
||||||
return frappe.get_list('Patient Appointment',{
|
return frappe.get_list('Patient Appointment',{
|
||||||
@ -432,12 +429,12 @@ def appointments_valid_in_fee_validity(appointment, invoiced):
|
|||||||
'appointment_date':('<=', valid_days_date),
|
'appointment_date':('<=', valid_days_date),
|
||||||
'appointment_date':('>=', getdate(appointment.appointment_date)),
|
'appointment_date':('>=', getdate(appointment.appointment_date)),
|
||||||
'practitioner': appointment.practitioner
|
'practitioner': appointment.practitioner
|
||||||
}, order_by='appointment_date', limit=int(max_visit)-1)
|
}, order_by='appointment_date', limit=int(max_visits)-1)
|
||||||
|
|
||||||
|
|
||||||
def manage_doc_for_appoitnment(dt_from_appointment, appointment, invoiced):
|
def manage_doc_for_appoitnment(dt_from_appointment, appointment, invoiced):
|
||||||
dn_from_appointment = frappe.db.exists(
|
dn_from_appointment = frappe.db.get_value(
|
||||||
doctype=dt_from_appointment,
|
dt_from_appointment,
|
||||||
filters={'appointment': appointment}
|
filters={'appointment': appointment}
|
||||||
)
|
)
|
||||||
if dn_from_appointment:
|
if dn_from_appointment:
|
||||||
|
@ -310,7 +310,8 @@ scheduler_events = {
|
|||||||
"erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts",
|
"erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts",
|
||||||
"erpnext.crm.doctype.email_campaign.email_campaign.set_email_campaign_status",
|
"erpnext.crm.doctype.email_campaign.email_campaign.set_email_campaign_status",
|
||||||
"erpnext.selling.doctype.quotation.quotation.set_expired_status",
|
"erpnext.selling.doctype.quotation.quotation.set_expired_status",
|
||||||
"erpnext.healthcare_healthcare.doctype.patient_appointment.patient_appointment.update_appointment_status"
|
"erpnext.healthcare.doctype.patient_appointment.patient_appointment.update_appointment_status",
|
||||||
|
"erpnext.healthcare.doctype.fee_validity.fee_validity.update_validity_status"
|
||||||
],
|
],
|
||||||
"daily_long": [
|
"daily_long": [
|
||||||
"erpnext.setup.doctype.email_digest.email_digest.send",
|
"erpnext.setup.doctype.email_digest.email_digest.send",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user