refactor: Healthcare Settings

This commit is contained in:
Rucha Mahabal 2020-01-28 18:06:23 +05:30
parent 7fda3a12cc
commit c7417c08ed
8 changed files with 136 additions and 126 deletions

View File

@ -8,7 +8,7 @@
"field_order": [
"sb_op_settings",
"patient_master_name",
"manage_customer",
"link_customer_to_patient",
"default_medical_code_standard",
"column_break_9",
"collect_registration_fee",
@ -21,9 +21,19 @@
"op_consulting_charge_item",
"column_break_13",
"clinical_procedure_consumable_item",
"sb_in_ac",
"income_account",
"receivable_account",
"sb_lab_settings",
"create_lab_test_on_si_submit",
"create_sample_collection_for_lab_test",
"column_break_34",
"employee_name_and_designation_in_print",
"lab_test_approval_required",
"custom_signature_in_print",
"out_patient_sms_alerts",
"reg_sms",
"reg_msg",
"reg_sms",
"app_con",
"app_con_msg",
"no_con",
@ -31,17 +41,6 @@
"app_rem",
"app_rem_msg",
"rem_before",
"sb_in_ac",
"income_account",
"sb_r_ac",
"receivable_account",
"sb_lab_settings",
"create_test_on_si_submit",
"require_sample_collection",
"require_test_result_approval",
"column_break_34",
"employee_name_and_designation_in_print",
"custom_signature_in_print",
"laboratory_sms_alerts",
"sms_printed",
"column_break_28",
@ -59,13 +58,6 @@
"label": "Patient Name By",
"options": "Patient Name\nNaming Series"
},
{
"default": "1",
"description": "If checked, a customer will be created, mapped to Patient.\nPatient Invoices will be created against this Customer. You can also select existing Customer while creating Patient.",
"fieldname": "manage_customer",
"fieldtype": "Check",
"label": "Manage Customer"
},
{
"fieldname": "default_medical_code_standard",
"fieldtype": "Link",
@ -98,20 +90,23 @@
"label": "Invoice Appointments Automatically"
},
{
"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",
"fieldname": "valid_days",
"fieldtype": "Int",
"label": "Valid number of days"
},
{
"collapsible": 1,
"description": "You can configure default Items for billing consultation charges, procedure consumption items and inpatient visits",
"fieldname": "healthcare_service_items",
"fieldtype": "Section Break",
"label": "Healthcare Service Items"
"label": "Default Healthcare Service Items"
},
{
"fieldname": "inpatient_visit_charge_item",
@ -203,25 +198,19 @@
},
{
"collapsible": 1,
"description": "Default income accounts to be used if not set in Healthcare Practitioner to book Appointment charges.",
"fieldname": "sb_in_ac",
"fieldtype": "Section Break",
"label": "Income Account"
"label": "Default Accounts"
},
{
"description": "Default income accounts to be used if not set in Healthcare Practitioner to book Appointment charges.",
"fieldname": "income_account",
"fieldtype": "Table",
"label": "Income Account",
"options": "Party Account"
},
{
"collapsible": 1,
"description": "Default receivable accounts to be used if not set in Patient to book Appointment charges.",
"fieldname": "sb_r_ac",
"fieldtype": "Section Break",
"label": "Receivable Account"
},
{
"description": "Default receivable accounts to be used to book Appointment charges.",
"fieldname": "receivable_account",
"fieldtype": "Table",
"label": "Receivable Account",
@ -233,31 +222,13 @@
"fieldtype": "Section Break",
"label": "Laboratory Settings"
},
{
"default": "0",
"fieldname": "create_test_on_si_submit",
"fieldtype": "Check",
"label": "Create Lab Test(s) on Sales Invoice Submit"
},
{
"default": "0",
"description": "Create documents for sample collection",
"fieldname": "require_sample_collection",
"fieldtype": "Check",
"label": "Manage Sample Collection"
},
{
"default": "0",
"fieldname": "require_test_result_approval",
"fieldtype": "Check",
"label": "Require Lab Test Approval"
},
{
"fieldname": "column_break_34",
"fieldtype": "Column Break"
},
{
"default": "1",
"description": "Check this if you want the Name and Designation of the Employee associated with the User who submits the document to be printed in the Lab Test Report.",
"fieldname": "employee_name_and_designation_in_print",
"fieldtype": "Check",
"label": "Employee name and designation in print"
@ -279,7 +250,7 @@
"fieldname": "sms_printed",
"fieldtype": "Small Text",
"ignore_xss_filter": 1,
"label": "Result Printed"
"label": "Result Printed Message"
},
{
"fieldname": "column_break_28",
@ -290,12 +261,40 @@
"fieldname": "sms_emailed",
"fieldtype": "Small Text",
"ignore_xss_filter": 1,
"label": "Result Emailed"
"label": "Result Emailed Message"
},
{
"default": "0",
"description": "Checking this will restrict printing and emailing of Lab Test documents unless they have the status as Approved.",
"fieldname": "lab_test_approval_required",
"fieldtype": "Check",
"label": "Do not print or email Lab Tests without Approval"
},
{
"default": "1",
"description": "If checked, a customer will be created, mapped to Patient.\nPatient Invoices will be created against this Customer. You can also select existing Customer while creating Patient.",
"fieldname": "link_customer_to_patient",
"fieldtype": "Check",
"label": "Link Customer to Patient"
},
{
"default": "0",
"description": "Checking this will create Lab Test(s) specified in the Sales Invoice on submission.",
"fieldname": "create_lab_test_on_si_submit",
"fieldtype": "Check",
"label": "Create Lab Test(s) on Sales Invoice Submission"
},
{
"default": "0",
"description": "Checking this will create a Sample Collection document every time you create a Lab Test",
"fieldname": "create_sample_collection_for_lab_test",
"fieldtype": "Check",
"label": "Create Sample Collection document for Lab Test"
}
],
"issingle": 1,
"links": [],
"modified": "2020-01-23 13:31:43.699711",
"modified": "2020-01-28 18:04:48.671093",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Settings",

View File

@ -11,69 +11,80 @@ import json
class HealthcareSettings(Document):
def validate(self):
for key in ["collect_registration_fee","manage_customer","patient_master_name",
"require_test_result_approval","require_sample_collection", "default_medical_code_standard"]:
for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_master_name',
'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']:
frappe.db.set_default(key, self.get(key, ""))
if(self.collect_registration_fee):
if self.collect_registration_fee:
if self.registration_fee <= 0:
frappe.throw(_("Registration fee can not be Zero"))
frappe.throw(_('Registration Fee cannot be negative or zero'))
if self.inpatient_visit_charge_item:
validate_service_item(self.inpatient_visit_charge_item, "Configure a service Item for Inpatient Visit Charge Item")
validate_service_item(self.inpatient_visit_charge_item)
if self.op_consulting_charge_item:
validate_service_item(self.op_consulting_charge_item, "Configure a service Item for Out Patient Consulting Charge Item")
validate_service_item(self.op_consulting_charge_item)
if self.clinical_procedure_consumable_item:
validate_service_item(self.clinical_procedure_consumable_item, "Configure a service Item for Clinical Procedure Consumable Item")
validate_service_item(self.clinical_procedure_consumable_item)
def validate_service_item(item):
if frappe.db.get_value('Item', item, 'is_stock_item'):
frappe.throw(_('Configure a service Item for {0}').format(item))
@frappe.whitelist()
def get_sms_text(doc):
sms_text = {}
doc = frappe.get_doc("Lab Test",doc)
#doc = json.loads(doc)
context = {"doc": doc, "alert": doc, "comments": None}
emailed = frappe.db.get_value("Healthcare Settings", None, "sms_emailed")
doc = frappe.get_doc('Lab Test', doc)
context = {'doc': doc, 'alert': doc, 'comments': None}
emailed = frappe.db.get_value('Healthcare Settings', None, 'sms_emailed')
sms_text['emailed'] = frappe.render_template(emailed, context)
printed = frappe.db.get_value("Healthcare Settings", None, "sms_printed")
printed = frappe.db.get_value('Healthcare Settings', None, 'sms_printed')
sms_text['printed'] = frappe.render_template(printed, context)
return sms_text
def send_registration_sms(doc):
if (frappe.db.get_value("Healthcare Settings", None, "reg_sms")=='1'):
if frappe.db.get_value('Healthcare Settings', None, 'reg_sms'):
if doc.mobile:
context = {"doc": doc, "alert": doc, "comments": None}
if doc.get("_comments"):
context["comments"] = json.loads(doc.get("_comments"))
messages = frappe.db.get_value("Healthcare Settings", None, "reg_msg")
context = {'doc': doc, 'alert': doc, 'comments': None}
if doc.get('_comments'):
context['comments'] = json.loads(doc.get('_comments'))
messages = frappe.db.get_value('Healthcare Settings', None, 'reg_msg')
messages = frappe.render_template(messages, context)
number = [doc.mobile]
send_sms(number,messages)
else:
frappe.msgprint(doc.name + " Has no mobile number to send registration SMS", alert=True)
frappe.msgprint(doc.name + ' has no mobile number to send registration SMS', alert=True)
def get_receivable_account(company):
receivable_account = get_account(None, "receivable_account", "Healthcare Settings", company)
receivable_account = get_account(None, 'receivable_account', 'Healthcare Settings', company)
if receivable_account:
return receivable_account
return frappe.get_cached_value('Company', company, "default_receivable_account")
return frappe.get_cached_value('Company', company, 'default_receivable_account')
def get_income_account(practitioner, company):
if(practitioner):
income_account = get_account("Healthcare Practitioner", None, practitioner, company)
# check income account in Healthcare Practitioner
if practitioner:
income_account = get_account('Healthcare Practitioner', None, practitioner, company)
if income_account:
return income_account
income_account = get_account(None, "income_account", "Healthcare Settings", company)
# else check income account in Healthcare Settings
income_account = get_account(None, 'income_account', 'Healthcare Settings', company)
if income_account:
return income_account
return frappe.get_cached_value('Company', company, "default_income_account")
# else return default income account of company
return frappe.get_cached_value('Company', company, 'default_income_account')
def get_account(parent_type, parent_field, parent, company):
if(parent_type):
return frappe.db.get_value("Party Account",
{"parenttype": parent_type, "parent": parent, "company": company}, "account")
if(parent_field):
return frappe.db.get_value("Party Account",
{"parentfield": parent_field, "parent": parent, "company": company}, "account")
if parent_type:
return frappe.db.get_value('Party Account',
{'parenttype': parent_type, 'parent': parent, 'company': company}, 'account')
def validate_service_item(item, msg):
if frappe.db.get_value("Item", item, "is_stock_item") == 1:
frappe.throw(_(msg))
if parent_field:
return frappe.db.get_value('Party Account',
{'parentfield': parent_field, 'parent': parent, 'company': company}, 'account')

View File

@ -29,7 +29,7 @@ frappe.ui.form.on('Lab Test', {
get_lab_test_prescribed(frm);
});
}
if(frm.doc.docstatus==1 && frm.doc.status!='Approved' && frm.doc.status!='Rejected' && frappe.defaults.get_default("require_test_result_approval") && frappe.user.has_role("LabTest Approver")){
if(frm.doc.docstatus==1 && frm.doc.status!='Approved' && frm.doc.status!='Rejected' && frappe.defaults.get_default("lab_test_approval_required") && frappe.user.has_role("LabTest Approver")){
frm.add_custom_button(__('Approve'), function() {
status_update(1,frm);
});

View File

@ -224,7 +224,7 @@ def create_sample_doc(template, patient, invoice):
return sample_collection
def create_sample_collection(lab_test, template, patient, invoice):
if(frappe.db.get_value("Healthcare Settings", None, "require_sample_collection") == "1"):
if(frappe.db.get_value("Healthcare Settings", None, "create_sample_collection_for_lab_test") == "1"):
sample_collection = create_sample_doc(template, patient, invoice)
if(sample_collection):
lab_test.sample = sample_collection.name

View File

@ -13,7 +13,7 @@ from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import g
class Patient(Document):
def after_insert(self):
if(frappe.db.get_value("Healthcare Settings", None, "manage_customer") == '1' and not self.customer):
if(frappe.db.get_value("Healthcare Settings", None, "link_customer_to_patient") == '1' and not self.customer):
create_customer(self)
if(frappe.db.get_value("Healthcare Settings", None, "collect_registration_fee") == '1'):
frappe.db.set_value("Patient", self.name, "disabled", 1)

View File

@ -3,7 +3,7 @@
frappe.ui.form.on('Sample Collection', {
refresh: function(frm) {
if(frappe.defaults.get_default("require_sample_collection")){
if(frappe.defaults.get_default("create_sample_collection_for_lab_test")){
frm.add_custom_button(__("View Lab Tests"), function() {
frappe.route_options = {"sample": frm.doc.name};
frappe.set_route("List", "Lab Test");

File diff suppressed because one or more lines are too long

View File

@ -224,7 +224,7 @@ def manage_invoice_submit_cancel(doc, method):
if frappe.get_meta(item.reference_dt).has_field("invoiced"):
set_invoiced(item, method, doc.name)
if method=="on_submit" and frappe.db.get_value("Healthcare Settings", None, "create_test_on_si_submit") == '1':
if method=="on_submit" and frappe.db.get_value("Healthcare Settings", None, "create_lab_test_on_si_submit") == '1':
create_multiple("Sales Invoice", doc.name)
def set_invoiced(item, method, ref_invoice=None):