BillingReport.php date range indexing error ...?

Hello All,

It seems that there is an “indexing” error in BillingReport.php lines 74, 77 and 80 …

class BillingReport
{
    public static function generateTheQueryPart()
    {
        if (isset($_REQUEST['final_this_page_criteria'])) {
            foreach ($_REQUEST['final_this_page_criteria'] as $criteria_key => $criteria_value) {
                ...
                } elseif (strpos($criteria_value, "form_encounter.date|between|") !== false) {
                    $elements = explode('|', $criteria_value);
[ line 74 ]         $query_part .= ' AND ' . "(form_encounter.date between '" . add_escape_custom($elements[1]) . "' and '" . add_escape_custom($elements[2]) . "')";
                ...
                }
            }
        }
    }

the problem is that when the criteria_value contains a “date range” as in the example below,

"form_encounter.date|between|2021-02-01 00:00:00|2021-02-21 23:59:59"

[ line 73 ]         $elements = explode('|', $criteria_value);

populates the “elements” array with 4 parts

$elements: array(4)
0: "form_encounter.date"
1: "between"
2: "2021-02-01 00:00:00"
3: "2021-02-21 23:59:59"

and line 74

$query_part .= ' AND ' . "(form_encounter.date between '"
                       . add_escape_custom($elements[1]) . "' and '"
                       . add_escape_custom($elements[2]) . "')";

creates the “query_part” below …

" AND (form_encounter.date between 'between' and '2021-02-01 00:00:00')"

It would seem that we should be using $elements[2] and $elements[3] rather than [1] and [2] …

I have made the above index change on lines 74, 77, and 80 of BillingReport.php and seem to have fixed a “broken” date range problem that has been plaguing our small practice’s OpenEMR installation ever since I upgraded to 6.0.0 from 5.0.0 a few weeks ago.

My attempt to upgrade was rife with problems as I simultaneously upgraded the server from Ubuntu 16.04 to 20.04. And I am new to PHP and web based applications as well, so maybe I am missing something fundamental ~ as I cannot understand how this apparent “indexing error” is not causing problems for ever other OpenEMR installation … ?

Please advise me as to another explanation for my “date range” billing manager problems.
See link below …

openemr-6-0-billing-manager-date-based-queries-not-working

Thank you,

Thomas E. Shepherd

thanks for the bug report @ThomasShepherd

it was fixed in master on the previously mentioned billing work in the other thread

1 Like

Thanks @stephenwaite! Yep, @ThomasShepherd this has been fixed in my re-write of the billing processor.