refactor: Patient master
This commit is contained in:
parent
a4202d1660
commit
be29a24de5
@ -7,7 +7,7 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"sb_op_settings",
|
"sb_op_settings",
|
||||||
"patient_master_name",
|
"patient_name_by",
|
||||||
"link_customer_to_patient",
|
"link_customer_to_patient",
|
||||||
"default_medical_code_standard",
|
"default_medical_code_standard",
|
||||||
"column_break_9",
|
"column_break_9",
|
||||||
@ -52,12 +52,6 @@
|
|||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Out Patient Settings"
|
"label": "Out Patient Settings"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "patient_master_name",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"label": "Patient Name By",
|
|
||||||
"options": "Patient Name\nNaming Series"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "default_medical_code_standard",
|
"fieldname": "default_medical_code_standard",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
@ -291,11 +285,17 @@
|
|||||||
"fieldname": "create_sample_collection_for_lab_test",
|
"fieldname": "create_sample_collection_for_lab_test",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Create Sample Collection document for Lab Test"
|
"label": "Create Sample Collection document for Lab Test"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "patient_name_by",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Patient Name By",
|
||||||
|
"options": "Patient Name\nNaming Series"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-01-29 10:49:00.758580",
|
"modified": "2020-01-29 14:31:56.983534",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Healthcare Settings",
|
"name": "Healthcare Settings",
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import json
|
|||||||
|
|
||||||
class HealthcareSettings(Document):
|
class HealthcareSettings(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_master_name',
|
for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_name_by',
|
||||||
'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']:
|
'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']:
|
||||||
frappe.db.set_default(key, self.get(key, ""))
|
frappe.db.set_default(key, self.get(key, ""))
|
||||||
|
|
||||||
@ -46,12 +46,12 @@ def get_sms_text(doc):
|
|||||||
return sms_text
|
return sms_text
|
||||||
|
|
||||||
def send_registration_sms(doc):
|
def send_registration_sms(doc):
|
||||||
if frappe.db.get_value('Healthcare Settings', None, 'reg_sms'):
|
if frappe.db.get_single_value('Healthcare Settings', 'reg_sms'):
|
||||||
if doc.mobile:
|
if doc.mobile:
|
||||||
context = {'doc': doc, 'alert': doc, 'comments': None}
|
context = {'doc': doc, 'alert': doc, 'comments': None}
|
||||||
if doc.get('_comments'):
|
if doc.get('_comments'):
|
||||||
context['comments'] = json.loads(doc.get('_comments'))
|
context['comments'] = json.loads(doc.get('_comments'))
|
||||||
messages = frappe.db.get_value('Healthcare Settings', None, 'reg_msg')
|
messages = frappe.db.get_single_value('Healthcare Settings', 'reg_msg')
|
||||||
messages = frappe.render_template(messages, context)
|
messages = frappe.render_template(messages, context)
|
||||||
number = [doc.mobile]
|
number = [doc.mobile]
|
||||||
send_sms(number,messages)
|
send_sms(number,messages)
|
||||||
|
|||||||
@ -3,128 +3,77 @@
|
|||||||
|
|
||||||
frappe.ui.form.on('Patient', {
|
frappe.ui.form.on('Patient', {
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
frm.set_query("patient", "patient_relation", function () {
|
frm.set_query('patient', 'patient_relation', function () {
|
||||||
return {
|
return {
|
||||||
filters: [
|
filters: [
|
||||||
["Patient", "name", "!=", frm.doc.name]
|
['Patient', 'name', '!=', frm.doc.name]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
if (frappe.defaults.get_default("patient_master_name") != "Naming Series") {
|
|
||||||
frm.toggle_display("naming_series", false);
|
if (frappe.defaults.get_default('patient_name_by') != 'Naming Series') {
|
||||||
|
frm.toggle_display('naming_series', false);
|
||||||
} else {
|
} else {
|
||||||
erpnext.toggle_naming_series();
|
erpnext.toggle_naming_series();
|
||||||
}
|
}
|
||||||
if (frappe.defaults.get_default("collect_registration_fee") && frm.doc.status == 'Disabled') {
|
|
||||||
|
if (frappe.defaults.get_default('collect_registration_fee') && frm.doc.status == 'Disabled') {
|
||||||
frm.add_custom_button(__('Invoice Patient Registration'), function () {
|
frm.add_custom_button(__('Invoice Patient Registration'), function () {
|
||||||
btn_invoice_registration(frm);
|
invoice_registration(frm);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (frm.doc.patient_name && frappe.user.has_role("Physician")) {
|
|
||||||
frm.add_custom_button(__('Patient History'), function () {
|
if (frm.doc.patient_name && frappe.user.has_role('Physician')) {
|
||||||
frappe.route_options = { "patient": frm.doc.name };
|
frm.add_custom_button(__('Patient History'), function() {
|
||||||
frappe.set_route("patient_history");
|
frappe.route_options = {'patient': frm.doc.name};
|
||||||
},"View");
|
frappe.set_route('patient_history');
|
||||||
|
},'View');
|
||||||
}
|
}
|
||||||
if (!frm.doc.__islocal && (frappe.user.has_role("Nursing User") || frappe.user.has_role("Physician"))) {
|
|
||||||
|
if (!frm.doc.__islocal && (frappe.user.has_role('Nursing User') || frappe.user.has_role('Physician'))) {
|
||||||
frm.add_custom_button(__('Vital Signs'), function () {
|
frm.add_custom_button(__('Vital Signs'), function () {
|
||||||
btn_create_vital_signs(frm);
|
create_vital_signs(frm);
|
||||||
}, "Create");
|
}, 'Create');
|
||||||
frm.add_custom_button(__('Medical Record'), function () {
|
frm.add_custom_button(__('Medical Record'), function () {
|
||||||
create_medical_record(frm);
|
create_medical_record(frm);
|
||||||
}, "Create");
|
}, 'Create');
|
||||||
frm.add_custom_button(__('Patient Encounter'), function () {
|
frm.add_custom_button(__('Patient Encounter'), function () {
|
||||||
btn_create_encounter(frm);
|
create_encounter(frm);
|
||||||
}, "Create");
|
}, 'Create');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onload: function (frm) {
|
onload: function (frm) {
|
||||||
if(!frm.doc.dob){
|
if(!frm.doc.dob){
|
||||||
$(frm.fields_dict['age_html'].wrapper).html("");
|
$(frm.fields_dict['age_html'].wrapper).html('');
|
||||||
}
|
}
|
||||||
if(frm.doc.dob){
|
if(frm.doc.dob){
|
||||||
$(frm.fields_dict['age_html'].wrapper).html("AGE : " + get_age(frm.doc.dob));
|
$(frm.fields_dict['age_html'].wrapper).html('AGE : ' + get_age(frm.doc.dob));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frappe.ui.form.on("Patient", "dob", function(frm) {
|
frappe.ui.form.on('Patient', 'dob', function(frm) {
|
||||||
if(frm.doc.dob) {
|
if (frm.doc.dob) {
|
||||||
var today = new Date();
|
let today = new Date();
|
||||||
var birthDate = new Date(frm.doc.dob);
|
let birthDate = new Date(frm.doc.dob);
|
||||||
if(today < birthDate){
|
if (today < birthDate){
|
||||||
frappe.msgprint(__("Please select a valid Date"));
|
frappe.msgprint(__('Please select a valid Date'));
|
||||||
frappe.model.set_value(frm.doctype,frm.docname, "dob", "");
|
frappe.model.set_value(frm.doctype,frm.docname, 'dob', '');
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
var age_str = get_age(frm.doc.dob);
|
let age_str = get_age(frm.doc.dob);
|
||||||
$(frm.fields_dict['age_html'].wrapper).html("AGE : " + age_str);
|
$(frm.fields_dict['age_html'].wrapper).html('AGE : ' + age_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$(frm.fields_dict['age_html'].wrapper).html("");
|
$(frm.fields_dict['age_html'].wrapper).html('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var create_medical_record = function (frm) {
|
|
||||||
frappe.route_options = {
|
|
||||||
"patient": frm.doc.name,
|
|
||||||
"status": "Open",
|
|
||||||
"reference_doctype": "Patient Medical Record",
|
|
||||||
"reference_owner": frm.doc.owner
|
|
||||||
};
|
|
||||||
frappe.new_doc("Patient Medical Record");
|
|
||||||
};
|
|
||||||
|
|
||||||
var get_age = function (birth) {
|
|
||||||
var ageMS = Date.parse(Date()) - Date.parse(birth);
|
|
||||||
var age = new Date();
|
|
||||||
age.setTime(ageMS);
|
|
||||||
var years = age.getFullYear() - 1970;
|
|
||||||
return years + " Year(s) " + age.getMonth() + " Month(s) " + age.getDate() + " Day(s)";
|
|
||||||
};
|
|
||||||
|
|
||||||
var btn_create_vital_signs = function (frm) {
|
|
||||||
if (!frm.doc.name) {
|
|
||||||
frappe.throw(__("Please save the patient first"));
|
|
||||||
}
|
|
||||||
frappe.route_options = {
|
|
||||||
"patient": frm.doc.name,
|
|
||||||
};
|
|
||||||
frappe.new_doc("Vital Signs");
|
|
||||||
};
|
|
||||||
|
|
||||||
var btn_create_encounter = function (frm) {
|
|
||||||
if (!frm.doc.name) {
|
|
||||||
frappe.throw(__("Please save the patient first"));
|
|
||||||
}
|
|
||||||
frappe.route_options = {
|
|
||||||
"patient": frm.doc.name,
|
|
||||||
};
|
|
||||||
frappe.new_doc("Patient Encounter");
|
|
||||||
};
|
|
||||||
|
|
||||||
var btn_invoice_registration = function (frm) {
|
|
||||||
frappe.call({
|
|
||||||
doc: frm.doc,
|
|
||||||
method: "invoice_patient_registration",
|
|
||||||
callback: function(data){
|
|
||||||
if(!data.exc){
|
|
||||||
if(data.message.invoice){
|
|
||||||
/* frappe.show_alert(__('Sales Invoice {0} created',
|
|
||||||
['<a href="#Form/Sales Invoice/'+data.message.invoice+'">' + data.message.invoice+ '</a>'])); */
|
|
||||||
frappe.set_route("Form", "Sales Invoice", data.message.invoice);
|
|
||||||
}
|
|
||||||
cur_frm.reload_doc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
frappe.ui.form.on('Patient Relation', {
|
frappe.ui.form.on('Patient Relation', {
|
||||||
patient_relation_add: function(frm){
|
patient_relation_add: function(frm){
|
||||||
frm.fields_dict['patient_relation'].grid.get_field('patient').get_query = function(doc){
|
frm.fields_dict['patient_relation'].grid.get_field('patient').get_query = function(doc){
|
||||||
var patient_list = [];
|
let patient_list = [];
|
||||||
if(!doc.__islocal) patient_list.push(doc.name);
|
if(!doc.__islocal) patient_list.push(doc.name);
|
||||||
$.each(doc.patient_relation, function(idx, val){
|
$.each(doc.patient_relation, function(idx, val){
|
||||||
if (val.patient) patient_list.push(val.patient);
|
if (val.patient) patient_list.push(val.patient);
|
||||||
@ -133,3 +82,56 @@ frappe.ui.form.on('Patient Relation', {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let create_medical_record = function (frm) {
|
||||||
|
frappe.route_options = {
|
||||||
|
'patient': frm.doc.name,
|
||||||
|
'status': 'Open',
|
||||||
|
'reference_doctype': 'Patient Medical Record',
|
||||||
|
'reference_owner': frm.doc.owner
|
||||||
|
};
|
||||||
|
frappe.new_doc('Patient Medical Record');
|
||||||
|
};
|
||||||
|
|
||||||
|
let get_age = function (birth) {
|
||||||
|
let ageMS = Date.parse(Date()) - Date.parse(birth);
|
||||||
|
let age = new Date();
|
||||||
|
age.setTime(ageMS);
|
||||||
|
let years = age.getFullYear() - 1970;
|
||||||
|
return years + ' Year(s) ' + age.getMonth() + ' Month(s) ' + age.getDate() + ' Day(s)';
|
||||||
|
};
|
||||||
|
|
||||||
|
let create_vital_signs = function (frm) {
|
||||||
|
if (!frm.doc.name) {
|
||||||
|
frappe.throw(__('Please save the patient first'));
|
||||||
|
}
|
||||||
|
frappe.route_options = {
|
||||||
|
'patient': frm.doc.name,
|
||||||
|
};
|
||||||
|
frappe.new_doc('Vital Signs');
|
||||||
|
};
|
||||||
|
|
||||||
|
let create_encounter = function (frm) {
|
||||||
|
if (!frm.doc.name) {
|
||||||
|
frappe.throw(__('Please save the patient first'));
|
||||||
|
}
|
||||||
|
frappe.route_options = {
|
||||||
|
'patient': frm.doc.name,
|
||||||
|
};
|
||||||
|
frappe.new_doc('Patient Encounter');
|
||||||
|
};
|
||||||
|
|
||||||
|
let invoice_registration = function (frm) {
|
||||||
|
frappe.call({
|
||||||
|
doc: frm.doc,
|
||||||
|
method: 'invoice_patient_registration',
|
||||||
|
callback: function(data) {
|
||||||
|
if (!data.exc) {
|
||||||
|
if (data.message.invoice) {
|
||||||
|
frappe.set_route('Form', 'Sales Invoice', data.message.invoice);
|
||||||
|
}
|
||||||
|
cur_frm.reload_doc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@ -12,9 +12,10 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"basic_info",
|
"basic_info",
|
||||||
"inpatient_status",
|
|
||||||
"inpatient_record",
|
|
||||||
"naming_series",
|
"naming_series",
|
||||||
|
"first_name",
|
||||||
|
"middle_name",
|
||||||
|
"last_name",
|
||||||
"patient_name",
|
"patient_name",
|
||||||
"sex",
|
"sex",
|
||||||
"blood_group",
|
"blood_group",
|
||||||
@ -23,11 +24,17 @@
|
|||||||
"image",
|
"image",
|
||||||
"column_break_14",
|
"column_break_14",
|
||||||
"status",
|
"status",
|
||||||
|
"inpatient_status",
|
||||||
|
"inpatient_record",
|
||||||
"customer",
|
"customer",
|
||||||
"report_preference",
|
|
||||||
"mobile",
|
"mobile",
|
||||||
"email",
|
"email",
|
||||||
"phone",
|
"phone",
|
||||||
|
"report_preference",
|
||||||
|
"personal_and_social_history",
|
||||||
|
"occupation",
|
||||||
|
"column_break_25",
|
||||||
|
"marital_status",
|
||||||
"sb_relation",
|
"sb_relation",
|
||||||
"patient_relation",
|
"patient_relation",
|
||||||
"allergy_medical_and_surgical_history",
|
"allergy_medical_and_surgical_history",
|
||||||
@ -36,10 +43,6 @@
|
|||||||
"column_break_20",
|
"column_break_20",
|
||||||
"medical_history",
|
"medical_history",
|
||||||
"surgical_history",
|
"surgical_history",
|
||||||
"personal_and_social_history",
|
|
||||||
"occupation",
|
|
||||||
"column_break_25",
|
|
||||||
"marital_status",
|
|
||||||
"risk_factors",
|
"risk_factors",
|
||||||
"tobacco_past_use",
|
"tobacco_past_use",
|
||||||
"tobacco_current_use",
|
"tobacco_current_use",
|
||||||
@ -87,12 +90,11 @@
|
|||||||
"bold": 1,
|
"bold": 1,
|
||||||
"fieldname": "patient_name",
|
"fieldname": "patient_name",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_filter": 1,
|
"in_global_search": 1,
|
||||||
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Full Name",
|
"label": "Full Name",
|
||||||
"no_copy": 1,
|
"read_only": 1,
|
||||||
"oldfieldtype": "Data",
|
|
||||||
"reqd": 1,
|
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -149,6 +151,7 @@
|
|||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"description": "If \"Link Customer to Patient\" is checked in Healthcare Settings and an existing Customer is not selected then, a Customer will be created for this Patient for recording transactions in Accounts module.",
|
||||||
"fieldname": "customer",
|
"fieldname": "customer",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"ignore_user_permissions": 1,
|
"ignore_user_permissions": 1,
|
||||||
@ -263,27 +266,31 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "tobacco_past_use",
|
"fieldname": "tobacco_past_use",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Select",
|
||||||
"ignore_xss_filter": 1,
|
"ignore_xss_filter": 1,
|
||||||
"label": "Tobacco Past Use"
|
"label": "Tobacco Consumption (Past)",
|
||||||
|
"options": "\nYes\nNo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "tobacco_current_use",
|
"fieldname": "tobacco_current_use",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Select",
|
||||||
"ignore_xss_filter": 1,
|
"ignore_xss_filter": 1,
|
||||||
"label": "Tobacco Current Use"
|
"label": "Tobacco Consumption (Present)",
|
||||||
|
"options": "\nYes\nNo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "alcohol_past_use",
|
"fieldname": "alcohol_past_use",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Select",
|
||||||
"ignore_xss_filter": 1,
|
"ignore_xss_filter": 1,
|
||||||
"label": "Alcohol Past Use"
|
"label": "Alcohol Consumption (Past)",
|
||||||
|
"options": "\nYes\nNo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "alcohol_current_use",
|
"fieldname": "alcohol_current_use",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Select",
|
||||||
"ignore_user_permissions": 1,
|
"ignore_user_permissions": 1,
|
||||||
"label": "Alcohol Current Use"
|
"label": "Alcohol Consumption (Present)",
|
||||||
|
"options": "\nYes\nNo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_32",
|
"fieldname": "column_break_32",
|
||||||
@ -331,13 +338,31 @@
|
|||||||
"label": "Default Currency",
|
"label": "Default Currency",
|
||||||
"options": "Currency",
|
"options": "Currency",
|
||||||
"print_hide": 1
|
"print_hide": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "last_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Last Name",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "first_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "First Name",
|
||||||
|
"oldfieldtype": "Data",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "middle_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Middle Name (optional)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-user",
|
"icon": "fa fa-user",
|
||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"links": [],
|
"links": [],
|
||||||
"max_attachments": 50,
|
"max_attachments": 50,
|
||||||
"modified": "2020-01-29 11:22:40.698125",
|
"modified": "2020-01-29 13:56:10.174897",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Patient",
|
"name": "Patient",
|
||||||
|
|||||||
@ -9,43 +9,49 @@ from frappe.model.document import Document
|
|||||||
from frappe.utils import cint, cstr, getdate, flt
|
from frappe.utils import cint, cstr, getdate, flt
|
||||||
import dateutil
|
import dateutil
|
||||||
from frappe.model.naming import set_name_by_naming_series
|
from frappe.model.naming import set_name_by_naming_series
|
||||||
from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account,get_income_account,send_registration_sms
|
from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account, send_registration_sms
|
||||||
|
|
||||||
class Patient(Document):
|
class Patient(Document):
|
||||||
|
def validate(self):
|
||||||
|
self.set_full_name()
|
||||||
|
self.add_as_website_user()
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if(frappe.db.get_value("Healthcare Settings", None, "link_customer_to_patient") == '1' and not self.customer):
|
if frappe.db.get_value('Healthcare Settings', None, 'link_customer_to_patient') and not self.customer:
|
||||||
create_customer(self)
|
create_customer(self)
|
||||||
if frappe.db.get_single_value('Healthcare Settings', 'collect_registration_fee'):
|
if frappe.db.get_single_value('Healthcare Settings', 'collect_registration_fee'):
|
||||||
frappe.db.set_value('Patient', self.name, 'status', 'Disabled')
|
frappe.db.set_value('Patient', self.name, 'status', 'Disabled')
|
||||||
else:
|
else:
|
||||||
send_registration_sms(self)
|
send_registration_sms(self)
|
||||||
|
self.add_as_website_user()
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
def on_update(self):
|
def set_full_name(self):
|
||||||
self.add_as_website_user()
|
self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name]))
|
||||||
|
|
||||||
def add_as_website_user(self):
|
def add_as_website_user(self):
|
||||||
if(self.email):
|
if self.email:
|
||||||
if not frappe.db.exists ("User", self.email):
|
if not frappe.db.exists ('User', self.email):
|
||||||
user = frappe.get_doc({
|
user = frappe.get_doc({
|
||||||
"doctype": "User",
|
'doctype': 'User',
|
||||||
"first_name": self.patient_name,
|
'first_name': self.first_name,
|
||||||
"email": self.email,
|
'last_name': self.last_name,
|
||||||
"user_type": "Website User"
|
'email': self.email,
|
||||||
|
'user_type': 'Website User'
|
||||||
})
|
})
|
||||||
user.flags.ignore_permissions = True
|
user.flags.ignore_permissions = True
|
||||||
user.add_roles("Patient")
|
user.add_roles('Patient')
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
patient_master_name = frappe.defaults.get_global_default('patient_master_name')
|
patient_name_by = frappe.db.get_single_value('Healthcare Settings', 'patient_name_by')
|
||||||
if patient_master_name == 'Patient Name':
|
if patient_name_by == 'Patient Name':
|
||||||
self.name = self.get_patient_name()
|
self.name = self.get_patient_name()
|
||||||
else:
|
else:
|
||||||
set_name_by_naming_series(self)
|
set_name_by_naming_series(self)
|
||||||
|
|
||||||
def get_patient_name(self):
|
def get_patient_name(self):
|
||||||
name = self.patient_name
|
name = self.patient_name
|
||||||
if frappe.db.get_value("Patient", name):
|
if frappe.db.get_value('Patient', name):
|
||||||
count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) AS UNSIGNED)), 0) from tabPatient
|
count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) AS UNSIGNED)), 0) from tabPatient
|
||||||
where name like %s""", "%{0} - %".format(name), as_list=1)[0][0]
|
where name like %s""", "%{0} - %".format(name), as_list=1)[0][0]
|
||||||
count = cint(count) + 1
|
count = cint(count) + 1
|
||||||
@ -54,56 +60,59 @@ class Patient(Document):
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
def get_age(self):
|
def get_age(self):
|
||||||
age_str = ""
|
age_str = ''
|
||||||
if self.dob:
|
if self.dob:
|
||||||
born = getdate(self.dob)
|
dob = getdate(self.dob)
|
||||||
age = dateutil.relativedelta.relativedelta(getdate(), born)
|
age = dateutil.relativedelta.relativedelta(getdate(), dob)
|
||||||
age_str = str(age.years) + " year(s) " + str(age.months) + " month(s) " + str(age.days) + " day(s)"
|
age_str = str(age.years) + ' year(s) ' + str(age.months) + ' month(s) ' + str(age.days) + ' day(s)'
|
||||||
return age_str
|
return age_str
|
||||||
|
|
||||||
def invoice_patient_registration(self):
|
def invoice_patient_registration(self):
|
||||||
frappe.db.set_value("Patient", self.name, "status", "Active")
|
if frappe.db.get_single_value('Healthcare Settings', 'registration_fee'):
|
||||||
send_registration_sms(self)
|
|
||||||
if(flt(frappe.get_value("Healthcare Settings", None, "registration_fee"))>0):
|
|
||||||
company = frappe.defaults.get_user_default('company')
|
company = frappe.defaults.get_user_default('company')
|
||||||
if not company:
|
if not company:
|
||||||
company = frappe.db.get_value("Global Defaults", None, "default_company")
|
company = frappe.db.get_single_value('Global Defaults', 'default_company')
|
||||||
|
|
||||||
sales_invoice = make_invoice(self.name, company)
|
sales_invoice = make_invoice(self.name, company)
|
||||||
sales_invoice.save(ignore_permissions=True)
|
sales_invoice.save(ignore_permissions=True)
|
||||||
|
frappe.db.set_value('Patient', self.name, 'status', 'Active')
|
||||||
|
send_registration_sms(self)
|
||||||
|
|
||||||
return {'invoice': sales_invoice.name}
|
return {'invoice': sales_invoice.name}
|
||||||
|
|
||||||
def create_customer(doc):
|
def create_customer(doc):
|
||||||
customer_group = frappe.get_value("Selling Settings", None, "customer_group")
|
customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group')
|
||||||
territory = frappe.get_value("Selling Settings", None, "territory")
|
territory = frappe.db.get_single_value('Selling Settings', 'territory')
|
||||||
if not (customer_group and territory):
|
if not (customer_group and territory):
|
||||||
customer_group = "Commercial"
|
customer_group = 'All Customer Groups'
|
||||||
territory = "Rest Of The World"
|
territory = 'All Territories'
|
||||||
frappe.msgprint(_("Please set default customer group and territory in Selling Settings"), alert=True)
|
frappe.msgprint(_('Please set default customer group and territory in Selling Settings'), alert=True)
|
||||||
customer = frappe.get_doc({"doctype": "Customer",
|
customer = frappe.get_doc({
|
||||||
"customer_name": doc.patient_name,
|
'doctype': 'Customer',
|
||||||
"customer_group": customer_group,
|
'customer_name': doc.patient_name,
|
||||||
"territory" : territory,
|
'customer_group': customer_group,
|
||||||
"customer_type": "Individual"
|
'territory' : territory,
|
||||||
|
'customer_type': 'Individual'
|
||||||
}).insert(ignore_permissions=True)
|
}).insert(ignore_permissions=True)
|
||||||
frappe.db.set_value("Patient", doc.name, "customer", customer.name)
|
frappe.db.set_value('Patient', doc.name, 'customer', customer.name)
|
||||||
frappe.msgprint(_("Customer {0} is created.").format(customer.name), alert=True)
|
frappe.msgprint(_('Customer {0} is created.').format(customer.name), alert=True)
|
||||||
|
|
||||||
def make_invoice(patient, company):
|
def make_invoice(patient, company):
|
||||||
sales_invoice = frappe.new_doc("Sales Invoice")
|
sales_invoice = frappe.new_doc('Sales Invoice')
|
||||||
sales_invoice.customer = frappe.get_value("Patient", patient, "customer")
|
sales_invoice.customer = frappe.get_value('Patient', patient, 'customer')
|
||||||
sales_invoice.due_date = getdate()
|
sales_invoice.due_date = getdate()
|
||||||
sales_invoice.company = company
|
sales_invoice.company = company
|
||||||
sales_invoice.is_pos = '0'
|
sales_invoice.is_pos = 0
|
||||||
sales_invoice.debit_to = get_receivable_account(company)
|
sales_invoice.debit_to = get_receivable_account(company)
|
||||||
|
|
||||||
item_line = sales_invoice.append("items")
|
item_line = sales_invoice.append('items')
|
||||||
item_line.item_name = "Registeration Fee"
|
item_line.item_name = 'Registeration Fee'
|
||||||
item_line.description = "Registeration Fee"
|
item_line.description = 'Registeration Fee'
|
||||||
item_line.qty = 1
|
item_line.qty = 1
|
||||||
item_line.uom = "Nos"
|
item_line.uom = 'Nos'
|
||||||
item_line.conversion_factor = 1
|
item_line.conversion_factor = 1
|
||||||
item_line.income_account = get_income_account(None, company)
|
item_line.income_account = get_income_account(None, company)
|
||||||
item_line.rate = frappe.get_value("Healthcare Settings", None, "registration_fee")
|
item_line.rate = frappe.db.get_single_value('Healthcare Settings', 'registration_fee')
|
||||||
item_line.amount = item_line.rate
|
item_line.amount = item_line.rate
|
||||||
sales_invoice.set_missing_values()
|
sales_invoice.set_missing_values()
|
||||||
return sales_invoice
|
return sales_invoice
|
||||||
@ -112,7 +121,7 @@ def make_invoice(patient, company):
|
|||||||
def get_patient_detail(patient):
|
def get_patient_detail(patient):
|
||||||
patient_dict = frappe.db.sql("""select * from tabPatient where name=%s""", (patient), as_dict=1)
|
patient_dict = frappe.db.sql("""select * from tabPatient where name=%s""", (patient), as_dict=1)
|
||||||
if not patient_dict:
|
if not patient_dict:
|
||||||
frappe.throw(_("Patient not found"))
|
frappe.throw(_('Patient not found'))
|
||||||
vital_sign = frappe.db.sql("""select * from `tabVital Signs` where patient=%s
|
vital_sign = frappe.db.sql("""select * from `tabVital Signs` where patient=%s
|
||||||
order by signs_date desc limit 1""", (patient), as_dict=1)
|
order by signs_date desc limit 1""", (patient), as_dict=1)
|
||||||
|
|
||||||
|
|||||||
@ -1,134 +1,52 @@
|
|||||||
{
|
{
|
||||||
|
"actions": [],
|
||||||
"allow_copy": 1,
|
"allow_copy": 1,
|
||||||
"allow_guest_to_view": 0,
|
|
||||||
"allow_import": 0,
|
|
||||||
"allow_rename": 0,
|
|
||||||
"beta": 1,
|
"beta": 1,
|
||||||
"creation": "2017-04-26 15:40:11.561855",
|
"creation": "2017-04-26 15:40:11.561855",
|
||||||
"custom": 0,
|
|
||||||
"docstatus": 0,
|
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"document_type": "",
|
|
||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"patient",
|
||||||
|
"relation",
|
||||||
|
"description"
|
||||||
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "relation",
|
"fieldname": "relation",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Relation",
|
"label": "Relation",
|
||||||
"length": 0,
|
"options": "\nFather\nMother\nSpouse\nSiblings\nFamily\nOther",
|
||||||
"no_copy": 0,
|
"search_index": 1
|
||||||
"options": "\nFather\nMother\nSpouse\nSiblings\nFamily",
|
|
||||||
"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": 1,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "patient",
|
"fieldname": "patient",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 1,
|
"ignore_user_permissions": 1,
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Patient",
|
"label": "Patient",
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"options": "Patient",
|
"options": "Patient",
|
||||||
"permlevel": 0,
|
"reqd": 1
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 1,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Small Text",
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 1,
|
"ignore_xss_filter": 1,
|
||||||
"in_filter": 0,
|
"label": "Description"
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Description",
|
|
||||||
"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,
|
|
||||||
"unique": 0
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"has_web_view": 0,
|
|
||||||
"hide_heading": 0,
|
|
||||||
"hide_toolbar": 0,
|
|
||||||
"idx": 0,
|
|
||||||
"image_view": 0,
|
|
||||||
"in_create": 0,
|
|
||||||
"is_submittable": 0,
|
|
||||||
"issingle": 0,
|
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"max_attachments": 0,
|
"links": [],
|
||||||
"modified": "2017-10-04 16:12:45.485333",
|
"modified": "2020-01-29 12:45:40.081899",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Patient Relation",
|
"name": "Patient Relation",
|
||||||
"name_case": "",
|
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"read_only": 0,
|
|
||||||
"read_only_onload": 0,
|
|
||||||
"restrict_to_domain": "Healthcare",
|
"restrict_to_domain": "Healthcare",
|
||||||
"show_name_in_global_search": 0,
|
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"track_changes": 1,
|
"track_changes": 1
|
||||||
"track_seen": 0
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user