Patient Appointment form doesn't fetch Practitioner data

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

Did you set practitioner schedules?

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

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

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

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,

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!

Thanks @akurungadam,

I’ll raise an issue with details.

Kind regards

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: Patient Appointment form doesn’t fetch Practitioner data · Issue #44 · frappe/health · GitHub

1 Like

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.

Hi @Muzzy,

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

Cheers

Hi @roquegv @Muzzy

Any update for this? is it merged? I checked healthcare_practitioner.py … but seems like the code has been changed since. I am still having the same error. can you help me? really appreciate it… Thank you

.

Practitioner link is filtered by Department. Also, please ensure that the Practitioner is “Active”.

hi @akurungadam

Really thank you for the reply. I have assigned the department and all practitioners are in active mode. but still its the same way… (tested in official 14 day trial version, V11 and V12… seems like its showing the same in all installs)

I just raised an issue in github. Healthcare Practitioner list doesn't fetch in any form · Issue #74 · frappe/health · GitHub

1 Like

you just hide a 198th line in hooks.py.

Then it will work fine

Thanks worked for me

Hi everyone please I have the same problem but on the user interface when he wants to make an appointment.

In the desk I don’t have this problem

Capture%20d%E2%80%99%C3%A9cran%20de%202021-10-26%2009-55-37

I have several practitioners registered and activated

Thanks.

On Web Form I guess you should enable Allow Read On All Link Options for the link field.

But then, booking appointment from via the portal is not currently supported, you’ll need to do necessary customizations to get the availability slots for the practitioner.

1 Like

thank you very much my problem is solved. :pray: