Help me with this - You do not have enough permissions to access this resource

You do not have enough permissions to access this resource. Please contact your manager to get access.
How can I solve this permission issue while I am using the Child(is grid) doctype.

Please mention where you get this error and what you are trying to do clearly

@gopikrishnan Thanks for your reply,

I intend to populate the Drug Prescription doctype (table) with the patientā€™s historical medication data from the Patient Encounter doctype. To achieve this, I will write a client script in the Patient Encounter doctype that automatically fills the past medication records when the custom ā€˜Fillā€™ button is clicked. However, when I attempt to click the ā€˜Fillā€™ button in the Patient Encounter doctype, I encounter an error message.

image

request.js:473 Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1718, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/client.py", line 50, in get_list
    check_parent_permission(parent, doctype)
  File "apps/frappe/frappe/model/db_query.py", line 1188, in check_parent_permission
    raise frappe.PermissionError
frappe.exceptions.PermissionError

Basically, permissions for a child DocType are inherited from its parent DocType. Therefore, you need to have permissions set for the parent DocType in order to access or modify data in the child DocType. Alternatively, if you want to bypass these permissions, you can create your own custom endpoint to fetch the data and return it. If you could provide your code or structure, it would help me assist you further

@gopikrishnan I have attached a script that fulfills the requirement to automatically populate the ā€˜previous medicationā€™ child table data into the ā€˜patient encounterā€™ parent doctype medication table when the ā€˜Fill Past Medicationā€™ button is clicked for a specific patient.

frappe.ui.form.on('Patient Encounter', {
    refresh: function(frm) {
        // Add a custom button called "Fill Past Medication"
        frm.add_custom_button('Fill Past Medication', function() {
            // Call the function to fill past medication
            fill_past_medication(frm);
        });
    }
});

function fill_past_medication(frm) {
    // Get the current patient ID
    const patient_id = frm.doc.patient;

    // Check if the patient ID is present
    if (!patient_id) {
        frappe.msgprint(__('Please select a patient first.'));
        return;
    }

    // Fetch the most recent Drug Prescription records for the patient
    frappe.call({
        method: 'frappe.client.get_list',
        args: {
            doctype: 'Drug Prescription',
            fields: ['drug_name', 'dosage', 'period', 'dosage_form', 'comment', 'intake_remarks', 'usage_interval', 'interval', 'interval_uom', 'medication', 'strength', 'strength_uom'],
            filters: {
                parent: patient_id,
                parenttype: 'Patient Encounter',
                parentfield: 'drug_prescription',
                name: ['!=', frm.doc.name] // Exclude the current encounter
            },
            order_by: 'creation desc',
            limit: 1 // Fetch the most recent Drug Prescription record
        },
        callback: function(response) {
            if (response.message && response.message.length > 0) {
                const last_drug_prescriptions = response.message;

                // Clear the existing Drug Prescription child table
                frm.clear_table('drug_prescription');

                // Fill the Drug Prescription child table with data from the most recent encounter
                last_drug_prescriptions.forEach(function(row) {
                    const new_row = frm.add_child('drug_prescription');
                    new_row.drug_name = row.drug_name;
                    new_row.dosage = row.dosage;
                    new_row.period = row.period;
                    new_row.dosage_form = row.dosage_form;
                    new_row.comment = row.comment;
                    new_row.intake_remarks = row.intake_remarks;
                    new_row.usage_interval = row.usage_interval;
                    new_row.interval = row.interval;
                    new_row.interval_uom = row.interval_uom;
                    new_row.medication = row.medication;
                    new_row.strength = row.strength;
                    new_row.strength_uom = row.strength_uom;
                });

                // Refresh the form to reflect the changes
                frm.refresh_field('drug_prescription');

                frappe.msgprint(__('Past medication data filled.'));
            } else {
                frappe.msgprint(__('No previous medication data found for this patient.'));
            }
        }
    });
}

After this, whenever I click the ā€˜Fillā€™ button in the Patient Encounter doctype, I receive an error message stating that I do not have sufficient permissions to access this resource. What can I do with this, pls help me with solving thisā€¦

If Drug Prescription is a child table, then it cannot be set directly in the frappe.client.get_list.

You will need to handle this scenario on the server side.

1 Like

@NCP

Thanks for your reply, Ok, But how can I handle this scenarion on the server-side. Can you pls guide me with this?.

Please check the documentation so check it and try it.