frappe.provide('frappe.patient_history'); frappe.pages['patient_history'].on_page_load = function(wrapper) { let me = this; let 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', {})); let patient = frappe.ui.form.make_control({ parent: page.main.find('.patient'), df: { fieldtype: 'Link', options: 'Patient', fieldname: 'patient', placeholder: __('Select Patient'), only_select: true, 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(); } }, }); patient.refresh(); if (frappe.route_options) { patient.set_value(frappe.route_options.patient); } this.page.main.on('click', '.btn-show-chart', function() { let btn_show_id = $(this).attr('data-show-chart-id'), pts = $(this).attr('data-pts'); let 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() { let 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 }, freeze: true, 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'); } } }); } } }); this.page.main.on('click', '.btn-less', function() { let 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); }); }; let 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) { let 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(); } } }); }; let add_to_records = function(me, data) { let 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..')}

`); } }; let add_date_separator = function(data) { let date = frappe.datetime.str_to_obj(data.creation); let pdate = ''; let diff = frappe.datetime.get_day_diff(frappe.datetime.get_today(), frappe.datetime.obj_to_str(date)); if (diff < 1) { pdate = __('Today'); } else if (diff < 2) { pdate = __('Yesterday'); } else { pdate = __('on ') + frappe.datetime.global_date_format(date); } data.date_sep = pdate; return data; }; let show_patient_info = function(patient, me) { frappe.call({ 'method': 'erpnext.healthcare.doctype.patient.patient.get_patient_detail', args: { patient: patient }, callback: function(r) { let data = r.message; let 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 += `

${__('Allerigies')} : ${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); } }); }; let 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) { let show_chart_btns_html = `
${__('Blood Pressure')} ${__('Respiratory/Pulse Rate')} ${__('Temperature')} ${__('BMI')}
`; me.page.main.find('.show_chart_btns').html(show_chart_btns_html); let data = r.message; let labels = [], datasets = []; let bp_systolic = [], bp_diastolic = [], temperature = []; let pulse = [], respiratory_rate = [], bmi = [], height = [], weight = []; for(let 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(''); } } }); };