ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Patient Appointment form doesn't fetch Practitioner data

healthcare
erpnext-version-11

#1

Hello ERPNext Community,

I found a issue when creating a new Patient Appointment, in Healthcare module. Concretely, when I click the “Check Availability” button, a new dialog window opens. In this, I should select the “Medical Department”, “Healthcare Practitioner” and the “Date” of the appointment. Both “Medical Department” and “Healthcare Practitioner” are link fields. I have no problem with “Medical Department” and “Date”. However, when I what to select the Practitioner, the field doesn’t fetch the list of available Practitioners:

It should fetch the active Practitioners I’ve created:

I thought it could be because it seems to filter Practitioners based on Department. However, I removed the following piece of code (it appears two times) and nothing happened:

frm.set_query("practitioner", function() {
	return {
		filters: {
			'department': frm.doc.department
		}
	};
});

No errors in console (JS nor Python).

Testing Scenario:

  • ERPNext v11.1.4
  • Frappe v11.1.3

I only experience this issue in v11; also tried with v10 and works well.

What do you think could be the cause of this problem?

Regards


#2

Did you set practitioner schedules?


#3

Hello @Savad_Ibrahim, thanks for your answer.

Yes I did:

This schedule is Enabled and has valid time slots (monday to friday, from 8am to 8pm, 15min each). Looks like:

I didn’t have a “Service Unit” though, but I just created two and assigned to each Practitioner. But still the same result: nothing is fetched in Partitioner field. I tried with both root and child Service units.

Any clues?
Cheers


#4

Copying @akurungadam as he may be able to assist here.


#5

Practitioner link fields are filtered out based on the Medical Department. Please check if the there are any practitioners for the Department?


#6

Hello @akurungadam,

Yes, I double-checked that. All Practitioner have a Medical Department assigned. Furthermore, i just created a new Department and assigned to one Practitioner: nothing changes.

As I mentioned, there are two sections in the client code (erpnext/healthcare/doctype/patient_appointment/patient_appointment.js) which apply a filter over Practitioner by Department:

frm.set_query("practitioner", function() {
	return {
		filters: {
			'department': frm.doc.department
		}
	};
});

and:

d.fields_dict["department"].df.onchange = () => {
	d.set_values({
		'practitioner': ''
	});
	var department = d.get_value('department');
	if(department){
		d.fields_dict.practitioner.get_query = function() {
			return {
				filters: {
					"department": department
				}
			};
		};
	}
};

These seem to be fine. Nonetheless, I also tried to remove these pieces of code.

What else can I try? Maybe rewriting the fetch function? :thinking:

Cheers,


#7

I’m not quite sure, the two things I know of are the Department filters and the Active flag. It’s best you create an issue on GitHub with relevant details to reproduce this.

thanks!


#8

Thanks @akurungadam,

I’ll raise an issue with details.

Kind regards


#9

I finally solve the issue.

Long story short, the query in get_practitioner_list (erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.py) should be:

query = \
	"""select %s from `tabHealthcare Practitioner` where docstatus < 2 
	and (%s like %s or first_name like %s) and active = 1 
	%s 
	order by case when name like %s then 0 else 1 end, 
	case when first_name like %s then 0 else 1 end, 
	name, first_name limit %s, %s""" \
	% (
	', '.join(fields),
	frappe.db.escape(searchfield),
	"\'%%%s%%\'" % txt,
	"\'%%%s%%\'" % txt,
	match_conditions,
	"\'%%%s%%\'" % txt,
	"\'%%%s%%\'" % txt,
	start,
	page_len,
	)
result = frappe.db.sql(query)
return result

Explanation: the problem is with "%%%s%%" % frappe.db.escape(txt) which when the formatting is applied results in %'txt'% (where txt is the actual text in the input field) but it should be '%txt%' (that is the ' symbol enclosing the % pair, not the other way around).

Github issue: https://github.com/frappe/erpnext/issues/16638


#10

Hi, I think you should make a PR so the fix gets merged. Thank you for the explanation. Would help others fix it manually till its fixed on Git.


#11

Hi @Muzzy,

Yes, I was thinking the same thing. I’ll do it as soon as I can.

Cheers