How to bring patient field to html page created as a Page doctype?

I’ve created a Page doctype and attached htmls page, css and all inside healthcare module. Now it is working fine.

  1. Now i need to bring the patient field into this html page
  2. 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.

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
		}
	})
}

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…

Please share your code of custom_page.js.

@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);
    }

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);
	});
};
3 Likes

@sanjay finally i got it. Thanks for guiding me to the correct route