Internal error, no drug ID specified! After upgrade to 7.0.3

  • Your Version: OpenEMR 7.0.3
  • Your Environment: Windows 10, XAMPP (Apache 2.4.58, PHP 8.2.12, MariaDB/MySQL version if known)
  • The Problem: “Internal error, no drug ID specified!” message after upgrading from a 7.0.1
  • How to Reproduce: Open patient chart X, click Prescriptions, click Add, search for drug Y, click Save…
  • What You’ve Checked: OpenEMR Audit Log (shows successful DB operations), the Apache error log (showed some crashes earlier), and the PHP error log (C:\xampp\php\logs\php_error_log).
  • Log Findings: The PHP error log shows frequent OpenEMR CSRF token authentication error messages and an unrelated ERROR: Not all selected assets were included..., but no PHP Warning or PHP Fatal error corresponding to the “no drug ID specified” message itself.

Okay how I fixed it is I used Gemini Advanced 2.5. Basically, I found this file: \xampp\htdocs\openemr\templates\prescription*general_edit.html.twig*

and I changed this:

{% for key,drug in DRUG_ARRAY_VALUES %}
<option value=“drug” … >{{ DRUG_ARRAY_OUTPUT[key]|text }}
{% endfor %}

to this:

function selchoose(sel, value) {
// === ADD THIS CHECK BELOW ===
if (!sel || typeof sel.options === ‘undefined’) {
console.error(“selchoose function called with invalid dropdown element:”, sel);
return; // Exit the function
}
// === END OF ADDED CHECK ===
var o = sel.options;
// … rest of function
}

and this:

function dispense() {
var f = document.forms[0];
var selected_drug_id = “0”;
var inHouseDropdown = f.drug_id;

if (inHouseDropdown && inHouseDropdown.selectedIndex > 0) {
// Attempt to get value, warn if it’s the placeholder “drug”
if (inHouseDropdown.value && inHouseDropdown.value !== “drug”) {
selected_drug_id = inHouseDropdown.value;
} else {
console.warn(“Selected inventory item value is ‘drug’. Attempting fix might fail. PHP template fix needed for value attribute.”);
// If value=“drug”, the simple JS fix might not get the real ID.
// A more complex JS fix would involve using selectedIndex to look up the ID
// from the drugopts array IF the ID was included there by PHP. It doesn’t look like it is.
}
}

if (selected_drug_id === “0”) {
alert(“Please select a specific drug from the ‘in-house’ inventory list before dispensing.”);
return;
}

// Note the change here to use selected_drug_id
dlgopen(‘interface/drugs/dispense_drug.php’ +
‘?drug_id=’ + encodeURIComponent(selected_drug_id) + // ← USE THE JS VARIABLE
‘&prescription=’ + encodeURIComponent(f.id.value) +
‘&quantity=’ + encodeURIComponent(f.disp_quantity.value) +
‘&fee=’ + encodeURIComponent(f.disp_fee.value),
‘_blank’, 400, 200);
}

and this:

{{ DRUG_ARRAY_OUTPUT[key]|text }}

To this:

{{ DRUG_ARRAY_OUTPUT[key]|text }}

It said:

Just keep in mind:

  1. Manual Patch: You’ve successfully patched the bug in your specific installation of OpenEMR 7.0.3.
  2. Future Upgrades: When you eventually upgrade OpenEMR to a newer version (e.g., 7.0.4 or later), the official upgrade process will likely overwrite the general_edit.html.twig file, and your manual changes will be lost. Hopefully, the official version you upgrade to will already include a fix for this bug, but it’s something to be aware of.
  3. Community: Since you found and fixed a definite bug, you might consider checking the OpenEMR GitHub Issues one last time for reports related to the prescription edit drug_id or the value="drug" issue in that template. If there’s an existing issue, you could add a comment confirming the fix worked for you. If not, reporting it could help the developers incorporate an official fix in future releases.

Hope this helps someone.