rajeeb
October 18, 2019, 7:10am
1
I’ve created a Page doctype and attached htmls page, css and all inside healthcare module. Now it is working fine.
Now i need to bring the patient field into this html page
When i select the patient, rest information should popup in respective html fields
i need an advice on this. Can anyone help me on this ??
Any kind of help much appreciated.
sanjay
October 18, 2019, 7:18am
2
call below function from page constructor:
make_control(){
const me = this;
me.page.add_field({
fieldtype: 'Link',
label: __('Patient'),
fieldname: 'patient',
options: "Patient",
reqd: 1,
onchange: function() {
// functionality
}
})
}
rajeeb
October 18, 2019, 8:39am
3
sanjay:
make_control(){ const me = this; me.page.add_field({ fieldtype: ‘Link’, label: __(‘Patient’), fieldname: ‘patient’, options: “Patient”, reqd: 1, onchange: function() { // functionality } }) }
Thanks for reply. As i am new to the code structure and framework of frappe, can you please explain little bit more ?
Should i add this code in custom_page.js file ?? if it so i tried but no luck…
sanjay
October 18, 2019, 9:36am
4
Please share your code of custom_page.js.
rajeeb
October 18, 2019, 9:48am
5
@sanjay
frappe.pages['custom-page'].on_page_load = function(wrapper) {
var page = frappe.ui.make_app_page({
parent: wrapper,
title: 'Custom Page',
single_column: true
});
$(frappe.render_template("custompage", page)).prependTo(page.main);
}
sanjay
October 18, 2019, 10:04am
6
sanjay:
me.page.add_field({ fieldtype: ‘Link’, label: __(‘Patient’), fieldname: ‘patient’, options: “Patient”, reqd: 1, onchange: function() { // functionality } })
Refer : erpnext/healthcare/page/patient_history.js
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+"\
<div align='center'><a class='btn octicon octicon-chevron-up btn-default btn-xs\
btn-less' data-doctype='"+doctype+"' data-docname='"+docname+"'></a></div>");
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);
});
};
4 Likes
rajeeb
October 18, 2019, 10:42am
7
@sanjay finally i got it. Thanks for guiding me to the correct route