Procedure | configuration not working

oEmr 8.2.0

Hi all
I recently upgraded openEMR from 7.0.3(4) to 8.2.0 without difficulty
Now, however, the Procedures | configuration tool is misbehaving
I’m doing these steps:
– Add Top Level
– Procedure Tier: group, name: GI, description: blank, sequence: 0
I am shown a new row with name: | 3, code: grp, tier: 1
If I look at the procedure_type table, I see a new row with parent: 0, name: 3, procedure_code: grp, procedure_type: procedure, sequence: 0, activity: 1, procedure_type_name: blank
If I do the same steps in a 7.0.3(4) system, all works properly, both in the UI and in the row added to the table.
I get no errors in php_errors.log
All of the database upgrade steps seemed to succeed during the upgrade

Any ideas?
Thanks

  • Hank

I tried the same thing in the 8.2.0 demo system. It is broken there as well

Found the problem
Sometime between 7.0.3(4) and 8.2.0 a refactoring of code was done in interface\orders\types_edit.php.
The updated code fails to build a proper Insert statement for adding rows to procedure_type.
This happens at the start of the Body section of the file
The code defines $sets as a string, and $bindValues as an array containing values to be used to fill in the question marks in $sets. But the code fails to actually perform the substitution, before executing this sql statement: sqlInsert(“INSERT INTO procedure_type SET parent = ?, $sets”, $bindValues);

This is the current code in 8.0.2 that does not work, and below this is a reworking of the older 7.0.3(4) code that does work in 8.0.2

            $sets = "name = ?, lab_id = ?, procedure_code = ?, procedure_type = ?, " .
                "procedure_type_name = ?, body_site = ?, specimen = ?, route_admin = ?, " .
                "laterality = ?, description = ?, units = ?, `range` = ?, " .
                "standard_code = ?, related_code = ?, seq = ?";
            $bindValues = [
                types_invalue('form_name'),
                types_invalue('form_lab_id'),
                $p_procedure_code,
                types_invalue('form_procedure_type'),
                types_invalue('form_procedure_type_name'),
                types_invalue('form_body_site'),
                types_invalue('form_specimen'),
                types_invalue('form_route_admin'),
                types_invalue('form_laterality'),
                types_invalue('form_description'),
                types_invalue('form_units'),
                types_invalue('form_range'),
                types_invalue('form_standard_code'),
                isset($_POST['form_diagnosis_code']) ? types_invalue('form_diagnosis_code') : types_invalue('form_related_code'),
                types_invalue('form_seq'),
            ];

            if ($typeid) {
                $bindValues[] = $typeid;
                sqlStatement("UPDATE procedure_type SET $sets WHERE procedure_type_id = ?", $bindValues);
                // Get parent ID so we can refresh the tree view.
                $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
                    "procedure_type_id = ?", [$typeid]);
                $parent = $row['parent'];
            } else {
                $bindValues[] = $parent;
                $newid = sqlInsert("INSERT INTO procedure_type SET parent = ?, $sets", $bindValues);
                // $newid is not really used in this script
            }

Code that works (based on what is in 7.0.3(4))

            $sets =
                "name = " . types_invalue_old('form_name') . ", " .
                "lab_id = " . types_invalue_old('form_lab_id') . ", " .
                "procedure_code = '" . $p_procedure_code . "', " .
                "procedure_type = " . types_invalue_old('form_procedure_type') . ", " .
                "procedure_type_name = " . types_invalue_old('form_procedure_type_name') . ", " .
                "body_site = " . types_invalue_old('form_body_site') . ", " .
                "specimen = " . types_invalue_old('form_specimen') . ", " .
                "route_admin = " . types_invalue_old('form_route_admin') . ", " .
                "laterality = " . types_invalue_old('form_laterality') . ", " .
                "description = " . types_invalue_old('form_description') . ", " .
                "units = " . types_invalue_old('form_units') . ", " .
                "`range` = " . types_invalue_old('form_range') . ", " .
                "standard_code = " . types_invalue_old('form_standard_code') . ", " .
                "related_code = " . (isset($_POST['form_diagnosis_code']) ? types_invalue_old('form_diagnosis_code') : types_invalue_old('form_related_code')) . ", " .
                "seq = " . types_invalue_old('form_seq');

            if ($typeid) {
                sqlStatement("UPDATE procedure_type SET $sets WHERE procedure_type_id = '" . add_escape_custom($typeid) . "'");
                // Get parent ID so we can refresh the tree view.
                $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
                    "procedure_type_id = ?", [$typeid]);
                $parent = $row['parent'];
            } else {
                $newid = sqlInsert("INSERT INTO procedure_type SET parent = '" . add_escape_custom($parent) . "', $sets");
                // $newid is not really used in this script
            }

I created this to make the above work

function types_invalue_old($name)
{
    $fld = formData($name, "P", true);
    return "'$fld'";
}
1 Like

Actually, I have a much simpler solution

The 8.0.2 code did

$bindValues[] = $parent;
$newid = sqlInsert("INSERT INTO procedure_type SET parent = ?, $sets", $bindValues);

The

$bindValue[] = $parent;

syntax adds $parent to the end of the array
But the insert statement is expecting parent to be the first item in the array. That’s way the data in the added row is messed up.
Since the insert statement is specifying the field names, the fields can be in any order.
So changing it to

$newid = sqlInsert("INSERT INTO procedure_type SET $sets, parent = ?", $bindValues);

solves the problem