frappe.provide("frappe.patient_history"); frappe.pages['patient_history'].on_page_load = function(wrapper) { var me = this; var page = frappe.ui.make_app_page({ parent: wrapper, title: 'Patient History', single_column: true }); frappe.breadcrumbs.add("Healthcare"); let pid = ''; page.main.html(frappe.render_template("patient_history", {})); var patient = frappe.ui.form.make_control({ parent: page.main.find(".patient"), df: { fieldtype: "Link", options: "Patient", fieldname: "patient", change: function(){ if(pid != patient.get_value() && patient.get_value()){ me.start = 0; me.page.main.find(".patient_documents_list").html(""); get_documents(patient.get_value(), me); show_patient_info(patient.get_value(), me); show_patient_vital_charts(patient.get_value(), me, "bp", "mmHg", "Blood Pressure"); } pid = patient.get_value(); } }, only_input: true, }); patient.refresh(); if (frappe.route_options){ patient.set_value(frappe.route_options.patient); } this.page.main.on("click", ".btn-show-chart", function() { var btn_show_id = $(this).attr("data-show-chart-id"), pts = $(this).attr("data-pts"); var title = $(this).attr("data-title"); show_patient_vital_charts(patient.get_value(), me, btn_show_id, pts, title); }); this.page.main.on("click", ".btn-more", function() { var doctype = $(this).attr("data-doctype"), docname = $(this).attr("data-docname"); if(me.page.main.find("."+docname).parent().find('.document-html').attr('data-fetched') == "1"){ me.page.main.find("."+docname).hide(); me.page.main.find("."+docname).parent().find('.document-html').show(); }else{ if(doctype && docname){ let exclude = ["patient", "patient_name", 'patient_sex', "encounter_date"]; frappe.call({ method: "erpnext.healthcare.utils.render_doc_as_html", args:{ doctype: doctype, docname: docname, exclude_fields: exclude }, callback: function(r) { if (r.message){ me.page.main.find("."+docname).hide(); me.page.main.find("."+docname).parent().find('.document-html').html(r.message.html+"\
"); me.page.main.find("."+docname).parent().find('.document-html').show(); me.page.main.find("."+docname).parent().find('.document-html').attr('data-fetched', "1"); } }, freeze: true }); } } }); this.page.main.on("click", ".btn-less", function() { var docname = $(this).attr("data-docname"); me.page.main.find("."+docname).parent().find('.document-id').show(); me.page.main.find("."+docname).parent().find('.document-html').hide(); }); me.start = 0; me.page.main.on("click", ".btn-get-records", function(){ get_documents(patient.get_value(), me); }); }; var get_documents = function(patient, me){ frappe.call({ "method": "erpnext.healthcare.page.patient_history.patient_history.get_feed", args: { name: patient, start: me.start, page_length: 20 }, callback: function (r) { var data = r.message; if(data.length){ add_to_records(me, data); }else{ me.page.main.find(".patient_documents_list").append("


No more records..

"); me.page.main.find(".btn-get-records").hide(); } } }); }; var add_to_records = function(me, data){ var details = ""; me.page.main.find(".patient_documents_list").append(details); me.start += data.length; if(data.length===20){ me.page.main.find(".btn-get-records").show(); }else{ me.page.main.find(".btn-get-records").hide(); me.page.main.find(".patient_documents_list").append("


No more records..

"); } }; var add_date_separator = function(data) { var date = frappe.datetime.str_to_obj(data.creation); var diff = frappe.datetime.get_day_diff(frappe.datetime.get_today(), frappe.datetime.obj_to_str(date)); if(diff < 1) { var pdate = 'Today'; } else if(diff < 2) { pdate = 'Yesterday'; } else { pdate = frappe.datetime.global_date_format(date); } data.date_sep = pdate; return data; }; var show_patient_info = function(patient, me){ frappe.call({ "method": "erpnext.healthcare.doctype.patient.patient.get_patient_detail", args: { patient: patient }, callback: function (r) { var data = r.message; var details = ""; if(data.image){ details += "
"; } details += "" + data.patient_name +"
" + data.sex; if(data.email) details += "
" + data.email; if(data.mobile) details += "
" + data.mobile; if(data.occupation) details += "

Occupation : " + data.occupation; if(data.blood_group) details += "
Blood group : " + data.blood_group; if(data.allergies) details += "

Allergies : "+ data.allergies.replace("\n", "
"); if(data.medication) details += "
Medication : "+ data.medication.replace("\n", "
"); if(data.alcohol_current_use) details += "

Alcohol use : "+ data.alcohol_current_use; if(data.alcohol_past_use) details += "
Alcohol past use : "+ data.alcohol_past_use; if(data.tobacco_current_use) details += "
Tobacco use : "+ data.tobacco_current_use; if(data.tobacco_past_use) details += "
Tobacco past use : "+ data.tobacco_past_use; if(data.medical_history) details += "

Medical history : "+ data.medical_history.replace("\n", "
"); if(data.surgical_history) details += "
Surgical history : "+ data.surgical_history.replace("\n", "
"); if(data.surrounding_factors) details += "

Occupational hazards : "+ data.surrounding_factors.replace("\n", "
"); if(data.other_risk_factors) details += "
Other risk factors : " + data.other_risk_factors.replace("\n", "
"); if(data.patient_details) details += "

More info : " + data.patient_details.replace("\n", "
"); if(details){ details = "
" + details + "
"; } me.page.main.find(".patient_details").html(details); } }); }; var show_patient_vital_charts = function(patient, me, btn_show_id, pts, title) { frappe.call({ method: "erpnext.healthcare.utils.get_patient_vitals", args:{ patient: patient }, callback: function(r) { if (r.message){ var show_chart_btns_html = "
Blood Pressure\ Respiratory/Pulse Rate\ Temperature\ BMI
"; me.page.main.find(".show_chart_btns").html(show_chart_btns_html); var data = r.message; let labels = [], datasets = []; let bp_systolic = [], bp_diastolic = [], temperature = []; let pulse = [], respiratory_rate = [], bmi = [], height = [], weight = []; for(var i=0; i (d + '').toUpperCase(), formatTooltipY: d => d + ' ' + pts, } }); }else{ me.page.main.find(".patient_vital_charts").html(""); me.page.main.find(".show_chart_btns").html(""); } } }); };