fix: field order, minor fixes -

patient - update customer, releated fields
patient appointment - send message
This commit is contained in:
anoop 2020-04-27 19:36:49 +05:30
parent c02eceb989
commit e30cc83591
12 changed files with 168 additions and 111 deletions

View File

@ -87,8 +87,8 @@ frappe.ui.form.on('Clinical Procedure', {
['<a class="bold" href="#Form/Stock Entry/'+ r.message + '">' + r.message + '</a>']),
indicator: 'green'
});
frm.reload_doc();
}
frm.reload_doc();
}
});
}
@ -156,11 +156,13 @@ frappe.ui.form.on('Clinical Procedure', {
age = __('{0} as on {1}', [age, data.message.age_as_on]);
}
}
frm.set_value('patient_name', data.message.patient_name);
frm.set_value('patient_age', age);
frm.set_value('patient_sex', data.message.sex);
}
});
} else {
frm.set_value('patient_name', '');
frm.set_value('patient_age', '');
frm.set_value('patient_sex', '');
}
@ -179,6 +181,7 @@ frappe.ui.form.on('Clinical Procedure', {
'patient':data.message.patient,
'procedure_template': data.message.procedure_template,
'medical_department': data.message.department,
'practitioner': data.message.practitioner,
'start_date': data.message.appointment_date,
'start_time': data.message.appointment_time,
'notes': data.message.notes,
@ -188,8 +191,7 @@ frappe.ui.form.on('Clinical Procedure', {
frm.set_value(values);
}
});
}
else{
} else {
let values = {
'patient': '',
'patient_name': '',
@ -252,9 +254,11 @@ frappe.ui.form.on('Clinical Procedure', {
name: frm.doc.practitioner
},
callback: function (data) {
frappe.model.set_value(frm.doctype,frm.docname, 'medical_department',data.message.department);
frappe.model.set_value(frm.doctype,frm.docname, 'practitioner_name', data.message.practitioner_name);
}
});
} else {
frappe.model.set_value(frm.doctype,frm.docname, 'practitioner_name', '');
}
},
@ -302,14 +306,6 @@ frappe.ui.form.on('Clinical Procedure', {
});
cur_frm.set_query('procedure_template', function(doc) {
return {
filters: {
'medical_department': doc.medical_department
}
};
});
frappe.ui.form.on('Clinical Procedure Item', {
qty: function(frm, cdt, cdn) {
let d = locals[cdt][cdn];

View File

@ -9,27 +9,29 @@
"field_order": [
"naming_series",
"appointment",
"column_break_30",
"procedure_template",
"column_break_30",
"company",
"invoiced",
"section_break_6",
"patient",
"patient_name",
"patient_sex",
"patient_age",
"medical_department",
"practitioner",
"practitioner_name",
"inpatient_record",
"notes",
"column_break_7",
"status",
"practitioner",
"practitioner_name",
"medical_department",
"service_unit",
"warehouse",
"start_date",
"start_time",
"sample",
"invoiced",
"notes",
"consumables_section",
"consume_stock",
"warehouse",
"items",
"section_break_24",
"invoice_separately_as_consumables",
@ -38,8 +40,6 @@
"column_break_27",
"consumption_details",
"sb_refs",
"inpatient_record",
"company",
"column_break_34",
"prescription",
"amended_from"
@ -64,10 +64,10 @@
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Appointment",
"options": "Patient Appointment"
"options": "Patient Appointment",
"set_only_once": 1
},
{
"fetch_from": "inpatient_record.patient",
"fieldname": "patient",
"fieldtype": "Link",
"in_standard_filter": 1,
@ -217,6 +217,7 @@
"read_only": 1
},
{
"depends_on": "eval:!doc.__islocal",
"fieldname": "status",
"fieldtype": "Select",
"in_list_view": 1,
@ -235,6 +236,8 @@
"read_only": 1
},
{
"collapsible": 1,
"collapsible_depends_on": "consume_stock",
"fieldname": "consumables_section",
"fieldtype": "Section Break",
"label": "Consumables"
@ -261,14 +264,12 @@
"fieldtype": "Section Break"
},
{
"fetch_from": "patient.patient_name",
"fieldname": "patient_name",
"fieldtype": "Data",
"label": "Patient Name",
"read_only": 1
},
{
"fetch_from": "practitioner.practitioner_name",
"fieldname": "practitioner_name",
"fieldtype": "Data",
"in_list_view": 1,
@ -282,7 +283,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2020-04-03 23:06:04.009856",
"modified": "2020-04-24 22:53:13.156901",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Clinical Procedure",
@ -298,6 +299,21 @@
"report": 1,
"role": "Nursing User",
"share": 1,
"submit": 1,
"write": 1
},
{
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Physician",
"share": 1,
"submit": 1,
"write": 1
}
],

View File

@ -137,13 +137,13 @@ var get_lab_test_prescribed = function(frm){
});
}
else{
frappe.msgprint(__("Please select a Patient to get Lab Orders"));
frappe.msgprint(__("Please select a Patient to get Lab Tests"));
}
};
var show_lab_tests = function(frm, result){
var d = new frappe.ui.Dialog({
title: __("Lab Test Prescriptions"),
title: __("Lab Tests"),
fields: [
{
fieldtype: "HTML", fieldname: "lab_test"
@ -161,7 +161,7 @@ var show_lab_tests = function(frm, result){
<div class="col-xs-1">\
<a data-name="%(name)s" data-lab-test="%(lab_test)s"\
data-encounter="%(encounter)s" data-practitioner="%(practitioner)s"\
data-invoiced="%(invoiced)s" href="#"><button class="btn btn-default btn-xs">Get Lab Test\
data-invoiced="%(invoiced)s" href="#"><button class="btn btn-default btn-xs">Get Lab Tests\
</button></a></div></div>', {name:y[0], lab_test: y[1], encounter:y[2], invoiced:y[3], practitioner:y[4], date:y[5]})).appendTo(html_field);
row.find("a").click(function() {
frm.doc.template = $(this).attr("data-lab-test");
@ -181,7 +181,7 @@ var show_lab_tests = function(frm, result){
});
});
if(!result.length){
var msg = "No Lab Orders found for patient <b>" + frm.doc.patient_name + "</b>";
var msg = __("No Lab Tests found for the Patient {0}", [frm.doc.patient_name.bold()]);
html_field.empty();
$(repl('<div class="col-xs-12" style="padding-top:0px;" >%(msg)s</div>', {msg: msg})).appendTo(html_field);
}

View File

@ -69,7 +69,7 @@ def create_multiple(doctype, docname):
lab_test_created = create_lab_test_from_encounter(docname)
if lab_test_created:
frappe.msgprint(_("Lab Test(s) " + lab_test_created + " created."))
frappe.msgprint(_("Lab Test(s) {0} created".format(lab_test_created)))
else:
frappe.msgprint(_("No Lab Tests created"))
@ -111,7 +111,7 @@ def create_lab_test_from_invoice(invoice_name):
if lab_test_created != 1:
template = get_lab_test_template(item.item_code)
if template:
lab_test = create_lab_test_doc(True, invoice.ref_practitioner, patient, template, company, invoice.company)
lab_test = create_lab_test_doc(True, invoice.ref_practitioner, patient, template, invoice.company)
if item.reference_dt == "Lab Prescription":
lab_test.prescription = item.reference_dn
lab_test.save(ignore_permissions = True)

View File

@ -10,6 +10,8 @@ frappe.ui.form.on('Patient', {
]
};
});
frm.set_query('customer_group', {'is_group': 0});
frm.set_query('default_price_list', { 'selling': 1});
if (frappe.defaults.get_default('patient_name_by') != 'Naming Series') {
frm.toggle_display('naming_series', false);

View File

@ -72,6 +72,7 @@
{
"fieldname": "inpatient_status",
"fieldtype": "Select",
"in_preview": 1,
"label": "Inpatient Status",
"options": "\nAdmission Scheduled\nAdmitted\nDischarge Scheduled",
"read_only": 1
@ -106,6 +107,7 @@
{
"fieldname": "sex",
"fieldtype": "Link",
"in_preview": 1,
"label": "Gender",
"options": "Gender",
"reqd": 1
@ -114,6 +116,7 @@
"bold": 1,
"fieldname": "blood_group",
"fieldtype": "Select",
"in_preview": 1,
"label": "Blood Group",
"options": "\nA Positive\nA Negative\nAB Positive\nAB Negative\nB Positive\nB Negative\nO Positive\nO Negative"
},
@ -121,6 +124,7 @@
"bold": 1,
"fieldname": "dob",
"fieldtype": "Date",
"in_preview": 1,
"label": "Date of birth"
},
{
@ -147,6 +151,7 @@
"fieldname": "image",
"fieldtype": "Attach Image",
"hidden": 1,
"in_preview": 1,
"label": "Image",
"no_copy": 1,
"print_hide": 1,
@ -161,9 +166,9 @@
"fieldname": "customer",
"fieldtype": "Link",
"ignore_user_permissions": 1,
"in_preview": 1,
"label": "Customer",
"options": "Customer"
"options": "Customer",
"set_only_once": 1
},
{
"fieldname": "report_preference",
@ -390,7 +395,7 @@
"image_field": "image",
"links": [],
"max_attachments": 50,
"modified": "2020-04-11 14:53:48.767245",
"modified": "2020-04-25 17:24:32.146415",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient",

View File

@ -10,6 +10,7 @@ from frappe.utils import cint, cstr, getdate
import dateutil
from frappe.model.naming import set_name_by_naming_series
from frappe.utils.nestedset import get_root_of
from erpnext import get_default_currency
from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account, send_registration_sms
class Patient(Document):
@ -17,6 +18,9 @@ class Patient(Document):
self.set_full_name()
self.add_as_website_user()
def before_insert(self):
self.set_missing_customer_details()
def after_insert(self):
self.add_as_website_user()
self.reload()
@ -28,12 +32,44 @@ class Patient(Document):
send_registration_sms(self)
self.reload() # self.notify_update()
def on_update(self):
if self.customer:
customer = frappe.get_doc('Customer', self.customer)
if self.customer_group:
customer.customer_group = self.customer_group
if self.territory:
customer.territory = self.territory
customer.default_price_list = self.default_price_list
customer.default_currency = self.default_currency
customer.language = self.language
customer.save(ignore_permissions=True)
else:
if frappe.db.get_single_value('Healthcare Settings', 'link_customer_to_patient'):
create_customer(self)
def set_full_name(self):
if self.last_name:
self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name]))
else:
self.patient_name = self.first_name
def set_missing_customer_details(self):
if not self.customer_group:
self.customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group') or get_root_of('Customer Group')
if not self.territory:
self.territory = frappe.db.get_single_value('Selling Settings', 'territory') or get_root_of('Territory')
if not self.default_price_list:
self.default_price_list = frappe.db.get_single_value('Selling Settings', 'selling_price_list')
if not self.customer_group or not self.territory or not self.default_price_list:
frappe.msgprint(_('Please set defaults for Customer Group, Territory and Selling Price List in Selling Settings'), alert=True)
if not self.default_currency:
self.default_currency = get_default_currency()
if not self.language:
self.language = frappe.db.get_single_value('System Settings', 'language')
def add_as_website_user(self):
if self.email:
if not frappe.db.exists ('User', self.email):
@ -87,21 +123,14 @@ class Patient(Document):
return {'invoice': sales_invoice.name}
def create_customer(doc):
customer_group = doc.customer_group or frappe.db.get_single_value('Selling Settings', 'customer_group')
territory = doc.territory or frappe.db.get_single_value('Selling Settings', 'territory')
if not (customer_group and territory):
customer_group = get_root_of('Customer Group')
territory = get_root_of('Territory')
frappe.msgprint(_('Please set default customer group and territory in Selling Settings'), alert=True)
customer = frappe.get_doc({
'doctype': 'Customer',
'customer_name': doc.patient_name,
'customer_group': customer_group,
'territory' : territory,
'customer_group': doc.customer_group or frappe.db.get_single_value('Selling Settings', 'customer_group'),
'territory' : doc.territory or frappe.db.get_single_value('Selling Settings', 'territory'),
'customer_type': 'Individual',
'default_currency': doc.default_currency,
'default_price_ist': doc.default_price_list,
'default_price_list': doc.default_price_list,
'language': doc.language
}).insert(ignore_permissions=True, ignore_mandatory=True)

View File

@ -127,6 +127,11 @@ frappe.ui.form.on('Patient Appointment', {
patient: function(frm) {
if (frm.doc.patient) {
frm.trigger('toggle_payment_fields');
} else {
frm.set_value('patient_name', '');
frm.set_value('patient_sex', '');
frm.set_value('patient_age', '');
frm.set_value('inpatient_record', '');
}
},

View File

@ -10,33 +10,30 @@
"engine": "InnoDB",
"field_order": [
"naming_series",
"status",
"patient",
"patient_name",
"patient_sex",
"patient_age",
"column_break_1",
"inpatient_record",
"column_break_1",
"company",
"service_unit",
"status",
"section_break_11",
"get_procedure_from_encounter",
"column_break_13",
"procedure_template",
"get_procedure_from_encounter",
"procedure_prescription",
"therapy_type",
"get_prescribed_therapies",
"therapy_plan",
"service_unit",
"section_break_12",
"practitioner",
"department",
"section_break_12",
"appointment_type",
"duration",
"column_break_17",
"appointment_date",
"appointment_time",
"appointment_datetime",
"duration",
"section_break_16",
"mode_of_payment",
"billing_item",
@ -45,9 +42,10 @@
"invoiced",
"ref_sales_invoice",
"section_break_3",
"notes",
"referring_practitioner",
"reminded"
"reminded",
"column_break_36",
"notes"
],
"fields": [
{
@ -59,7 +57,6 @@
"read_only": 1
},
{
"fetch_from": "inpatient_record.patient",
"fieldname": "patient",
"fieldtype": "Link",
"ignore_user_permissions": 1,
@ -83,7 +80,8 @@
"fieldname": "duration",
"fieldtype": "Int",
"in_filter": 1,
"label": "Duration (In Minutes)"
"label": "Duration (In Minutes)",
"set_only_once": 1
},
{
"fieldname": "column_break_1",
@ -102,6 +100,7 @@
"search_index": 1
},
{
"depends_on": "eval:doc.patient;",
"fieldname": "procedure_template",
"fieldtype": "Link",
"label": "Clinical Procedure Template",
@ -133,7 +132,8 @@
},
{
"fieldname": "section_break_12",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Appointment Details"
},
{
"fieldname": "practitioner",
@ -179,11 +179,13 @@
"fieldtype": "Time",
"in_list_view": 1,
"label": "Time",
"read_only": 1
"read_only": 1,
"reqd": 1
},
{
"fieldname": "section_break_16",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Payments"
},
{
"fetch_from": "patient.patient_name",
@ -212,6 +214,7 @@
{
"fieldname": "appointment_datetime",
"fieldtype": "Datetime",
"hidden": 1,
"label": "Appointment Datetime",
"print_hide": 1,
"read_only": 1,
@ -243,9 +246,12 @@
{
"fieldname": "company",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Company",
"no_copy": 1,
"options": "Company"
"options": "Company",
"reqd": 1,
"set_only_once": 1
},
{
"collapsible": 1,
@ -311,24 +317,20 @@
"options": "HLC-APP-.YYYY.-",
"set_only_once": 1
},
{
"fieldname": "section_break_11",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_13",
"fieldtype": "Column Break"
},
{
"fieldname": "billing_item",
"fieldtype": "Link",
"label": "Billing Item",
"options": "Item",
"read_only": 1
},
{
"fieldname": "column_break_36",
"fieldtype": "Column Break"
}
],
"links": [],
"modified": "2020-04-23 11:16:34.981240",
"modified": "2020-04-25 17:23:49.841975",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient Appointment",

View File

@ -369,17 +369,19 @@ def send_appointment_reminder():
frappe.db.set_value('Patient Appointment', doc.name, 'reminded', 1)
def send_message(doc, message):
patient = frappe.get_doc('Patient', doc.patient)
if patient.mobile:
patient_mobile = frappe.db.get_value("Patient", doc.patient, "mobile")
if patient_mobile:
context = {'doc': doc, 'alert': doc, 'comments': None}
if doc.get('_comments'):
context['comments'] = json.loads(doc.get('_comments'))
# jinja to string convertion happens here
message = frappe.render_template(message, context)
number = [patient.mobile]
number = [patient_mobile]
try:
send_sms(number, message)
except Exception as e:
frappe.msgprint(_("SMS not sent, please check SMS Settings"), alert=True)
@frappe.whitelist()
def get_events(start, end, filters=None):

View File

@ -25,7 +25,7 @@ frappe.ui.form.on('Patient Encounter', {
refresh_field('lab_test_prescription');
if (!frm.doc.__islocal) {
if (frm.doc.docstatus == 1) {
if (frm.doc.inpatient_status == 'Admission Scheduled' || frm.doc.inpatient_status == 'Admitted') {
frm.add_custom_button(__('Schedule Discharge'), function() {
schedule_discharge(frm);
@ -35,6 +35,7 @@ frappe.ui.form.on('Patient Encounter', {
schedule_inpatient(frm);
});
}
}
frm.add_custom_button(__('Patient History'), function() {
if (frm.doc.patient) {
@ -101,6 +102,11 @@ frappe.ui.form.on('Patient Encounter', {
frm.events.set_patient_info(frm);
},
practitioner: function(frm) {
if(!frm.doc.practitioner) {
frm.set_value('practitioner_name', '');
}
},
set_appointment_fields: function(frm) {
if (frm.doc.appointment) {
frappe.call({
@ -118,6 +124,7 @@ frappe.ui.form.on('Patient Encounter', {
'company': data.message.company
};
frm.set_value(values);
frm.set_df_property('patient', 'read_only', 1);
}
});
}
@ -134,6 +141,7 @@ frappe.ui.form.on('Patient Encounter', {
'inpatient_status': ''
};
frm.set_value(values);
frm.set_df_property('patient', 'read_only', 0);
}
},
@ -149,15 +157,20 @@ frappe.ui.form.on('Patient Encounter', {
if (data.message.dob) {
age = calculate_age(data.message.dob);
}
frappe.model.set_value(frm.doctype, frm.docname, 'patient_mame', data.message.patient_mame);
frappe.model.set_value(frm.doctype, frm.docname, 'patient_age', age);
frappe.model.set_value(frm.doctype, frm.docname, 'patient_sex', data.message.sex);
if (data.message.inpatient_record) {
frappe.model.set_value(frm.doctype, frm.docname, 'inpatient_record', data.message.inpatient_record);
frappe.model.set_value(frm.doctype, frm.docname, 'inpatient_status', data.message.inpatient_status);
} else {
frappe.model.set_value(frm.doctype, frm.docname, 'inpatient_record', '');
frappe.model.set_value(frm.doctype, frm.docname, 'inpatient_status', '');
}
}
});
} else {
frappe.model.set_value(frm.doctype, frm.docname, 'patient_mame', '');
frappe.model.set_value(frm.doctype, frm.docname, 'patient_sex', '');
frappe.model.set_value(frm.doctype, frm.docname, 'patient_age', '');
frappe.model.set_value(frm.doctype, frm.docname, 'inpatient_record', '');

View File

@ -17,17 +17,16 @@
"patient_name",
"patient_sex",
"patient_age",
"inpatient_record",
"inpatient_status",
"column_break_6",
"company",
"encounter_date",
"encounter_time",
"practitioner",
"practitioner_name",
"medical_department",
"encounter_date",
"encounter_time",
"invoiced",
"section_break_1",
"inpatient_record",
"column_break_17",
"inpatient_status",
"sb_symptoms",
"symptoms",
"symptoms_in_print",
@ -48,7 +47,6 @@
"section_break_33",
"encounter_comment",
"sb_refs",
"company",
"amended_from"
],
"fields": [
@ -59,12 +57,6 @@
"options": "Inpatient Record",
"read_only": 1
},
{
"collapsible": 1,
"fieldname": "section_break_1",
"fieldtype": "Section Break",
"label": "Inpatient Details"
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
@ -79,10 +71,10 @@
"ignore_user_permissions": 1,
"label": "Appointment",
"options": "Patient Appointment",
"search_index": 1
"search_index": 1,
"set_only_once": 1
},
{
"fetch_from": "inpatient_record.patient",
"fieldname": "patient",
"fieldtype": "Link",
"ignore_user_permissions": 1,
@ -93,7 +85,6 @@
"search_index": 1
},
{
"fetch_from": "patient.patient_name",
"fieldname": "patient_name",
"fieldtype": "Data",
"label": "Patient Name",
@ -206,29 +197,29 @@
{
"fieldname": "codification_table",
"fieldtype": "Table",
"label": "Medical Coding",
"label": "Medical Codes",
"options": "Codification Table"
},
{
"fieldname": "sb_drug_prescription",
"fieldtype": "Section Break",
"label": "Medication"
"label": "Medications"
},
{
"fieldname": "drug_prescription",
"fieldtype": "Table",
"label": "Drug Prescription",
"label": "Items",
"options": "Drug Prescription"
},
{
"fieldname": "sb_test_prescription",
"fieldtype": "Section Break",
"label": "Investigation"
"label": "Investigations"
},
{
"fieldname": "lab_test_prescription",
"fieldtype": "Table",
"label": "Lab Prescription",
"label": "Lab Tests",
"options": "Lab Prescription"
},
{
@ -239,7 +230,7 @@
{
"fieldname": "procedure_prescription",
"fieldtype": "Table",
"label": "Procedure Prescription",
"label": "Clinical Procedures",
"no_copy": 1,
"options": "Procedure Prescription"
},
@ -309,10 +300,6 @@
"label": "Inpatient Status",
"read_only": 1
},
{
"fieldname": "column_break_17",
"fieldtype": "Column Break"
},
{
"fieldname": "sb_refs",
"fieldtype": "Section Break"
@ -328,7 +315,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2020-04-23 23:06:16.348846",
"modified": "2020-04-27 18:59:25.713887",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient Encounter",