From a8dc97c94e01819e36f5d40130bd2752f4360376 Mon Sep 17 00:00:00 2001 From: eyalvo-matrix Date: Sun, 6 May 2018 12:57:48 +0300 Subject: [PATCH] Add new global to control the search exact/like int the Patient Finder (#1571) * Add new global to control the search exact/like int the Patient Finder * checkbox take1 * remove comma * remove new line * indentation * bug fixes * fix for persist user selection. * Remove Medx api and global. --- interface/main/finder/dynamic_finder.php | 314 +++++++++++++------------- interface/main/finder/dynamic_finder_ajax.php | 59 +++-- library/ajax/user_settings.php | 5 + 3 files changed, 205 insertions(+), 173 deletions(-) rewrite interface/main/finder/dynamic_finder.php (72%) diff --git a/interface/main/finder/dynamic_finder.php b/interface/main/finder/dynamic_finder.php dissimilarity index 72% index 579ed80ad..8773699a6 100644 --- a/interface/main/finder/dynamic_finder.php +++ b/interface/main/finder/dynamic_finder.php @@ -1,154 +1,160 @@ - -// Sponsored by David Eschelbacher, MD -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -require_once("../../globals.php"); - -$popup = empty($_REQUEST['popup']) ? 0 : 1; - -// Generate some code based on the list of columns. -// -$colcount = 0; -$header0 = ""; -$header = ""; -$coljson = ""; -$res = sqlStatement("SELECT option_id, title FROM list_options WHERE " . - "list_id = 'ptlistcols' AND activity = 1 ORDER BY seq, title"); -while ($row = sqlFetchArray($res)) { - $colname = $row['option_id']; - $title = xl_list_label($row['title']); - $header .= " "; - $header .= text($title); - $header .= "\n"; - $header0 .= " - - - - <?php echo xlt("Patient Finder"); ?> - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
...
- -
- - -
'> - -
- - - - + +// Sponsored by David Eschelbacher, MD +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +require_once("../../globals.php"); +require_once "$srcdir/user.inc"; + +$uspfx = 'patient_finder.'; //substr(__FILE__, strlen($webserver_root)) . '.'; +$patient_finder_exact_search = prevSetting($uspfx, 'patient_finder_exact_search', 'patient_finder_exact_search', ' '); + +$popup = empty($_REQUEST['popup']) ? 0 : 1; + +// Generate some code based on the list of columns. +// +$colcount = 0; +$header0 = ""; +$header = ""; +$coljson = ""; +$res = sqlStatement("SELECT option_id, title FROM list_options WHERE " . + "list_id = 'ptlistcols' AND activity = 1 ORDER BY seq, title"); +while ($row = sqlFetchArray($res)) { + $colname = $row['option_id']; + $title = xl_list_label($row['title']); + $header .= " "; + $header .= text($title); + $header .= "\n"; + $header0 .= " + + + + <?php echo xlt("Patient Finder"); ?> + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
...
+ +
+ + +
'> + +
+ + + diff --git a/interface/main/finder/dynamic_finder_ajax.php b/interface/main/finder/dynamic_finder_ajax.php index f0b63563a..f4d9a44ef 100644 --- a/interface/main/finder/dynamic_finder_ajax.php +++ b/interface/main/finder/dynamic_finder_ajax.php @@ -26,6 +26,9 @@ $limit = ''; if ($iDisplayStart >= 0 && $iDisplayLength >= 0) { $limit = "LIMIT " . escape_limit($iDisplayStart) . ", " . escape_limit($iDisplayLength); } +// Search parameter. -1 means . +// +$searchMethodInPatientList = isset($_GET['searchType' ]) && $_GET['searchType' ]==="true" ? true : false; // Column sorting parameters. // @@ -35,13 +38,13 @@ if (isset($_GET['iSortCol_0'])) { $iSortCol = intval($_GET["iSortCol_$i"]); if ($_GET["bSortable_$iSortCol"] == "true") { $sSortDir = escape_sort_order($_GET["sSortDir_$i"]); // ASC or DESC - // We are to sort on column # $iSortCol in direction $sSortDir. + // We are to sort on column # $iSortCol in direction $sSortDir. $orderby .= $orderby ? ', ' : 'ORDER BY '; - // + // if ($aColumns[$iSortCol] == 'name') { - $orderby .= "lname $sSortDir, fname $sSortDir, mname $sSortDir"; + $orderby .= "lname $sSortDir, fname $sSortDir, mname $sSortDir"; } else { - $orderby .= "`" . escape_sql_column_name($aColumns[$iSortCol], array('patient_data')) . "` $sSortDir"; + $orderby .= "`" . escape_sql_column_name($aColumns[$iSortCol], array('patient_data')) . "` $sSortDir"; } } } @@ -55,11 +58,20 @@ if (isset($_GET['sSearch']) && $_GET['sSearch'] !== "") { foreach ($aColumns as $colname) { $where .= $where ? "OR " : "WHERE ( "; if ($colname == 'name') { - $where .= - "lname LIKE '$sSearch%' OR " . - "fname LIKE '$sSearch%' OR " . - "mname LIKE '$sSearch%' "; - } else { + if (!$searchMethodInPatientList) { // exact search + $where .= + "lname LIKE '$sSearch' OR " . + "fname LIKE '$sSearch' OR " . + "mname LIKE '$sSearch' "; + } else { + $where .= // like search + "lname LIKE '$sSearch%' OR " . + "fname LIKE '$sSearch%' OR " . + "mname LIKE '$sSearch%' "; + } + } elseif (!$searchMethodInPatientList) { + $where .= "`" . escape_sql_column_name($colname, array('patient_data')) . "` LIKE '$sSearch' "; + } else { // exact search $where .= "`" . escape_sql_column_name($colname, array('patient_data')) . "` LIKE '$sSearch%' "; } } @@ -77,12 +89,21 @@ for ($i = 0; $i < count($aColumns); ++$i) { $where .= $where ? ' AND' : 'WHERE'; $sSearch = add_escape_custom($_GET["sSearch_$i"]); if ($colname == 'name') { - $where .= " ( " . - "lname LIKE '$sSearch%' OR " . - "fname LIKE '$sSearch%' OR " . - "mname LIKE '$sSearch%' )"; + if (!$searchMethodInPatientList) { // like search + $where .= " ( " . + "lname LIKE '$sSearch%' OR " . + "fname LIKE '$sSearch%' OR " . + "mname LIKE '$sSearch%' )"; + } else { // exact search + $where .= " ( " . + "lname LIKE '$sSearch' OR " . + "fname LIKE '$sSearch' OR " . + "mname LIKE '$sSearch' )"; + } + } elseif (!$searchMethodInPatientList) { + $where .= " `" . escape_sql_column_name($colname, array('patient_data')) . "` LIKE '$sSearch%'"; // like search } else { - $where .= " `" . escape_sql_column_name($colname, array('patient_data')) . "` LIKE '$sSearch%'"; + $where .= " `" . escape_sql_column_name($colname, array('patient_data')) . "` LIKE '$sSearch'"; // exact search } } } @@ -117,10 +138,10 @@ $iFilteredTotal = $row['count']; // Build the output data array. // $out = array( - "sEcho" => intval($_GET['sEcho']), - "iTotalRecords" => $iTotal, - "iTotalDisplayRecords" => $iFilteredTotal, - "aaData" => array() + "sEcho" => intval($_GET['sEcho']), + "iTotalRecords" => $iTotal, + "iTotalDisplayRecords" => $iFilteredTotal, + "aaData" => array() ); // save into variable data about fields of 'patient_data' from 'layout_options' @@ -134,7 +155,7 @@ while ($row = sqlFetchArray($res)) { $query = "SELECT $sellist FROM patient_data $where $orderby $limit"; $res = sqlStatement($query); while ($row = sqlFetchArray($res)) { - // Each will have an ID identifying the patient. + // Each will have an ID identifying the patient. $arow = array('DT_RowId' => 'pid_' . $row['pid']); foreach ($aColumns as $colname) { if ($colname == 'name') { diff --git a/library/ajax/user_settings.php b/library/ajax/user_settings.php index b948b1b37..2f690810c 100644 --- a/library/ajax/user_settings.php +++ b/library/ajax/user_settings.php @@ -27,3 +27,8 @@ if (( $_POST['mode'] == 1 || $_POST['mode'] == 0 ) && ( substr($_POST['target'], if ((isset($_POST['lab'])) && (isset($_POST['val']))) { setUserSetting($_POST['lab'], $_POST['val']); } + +// even more generic +if ((isset($_POST['target'])) && (isset($_POST['setting']))) { + setUserSetting($_POST['target'], $_POST['setting']); +} -- 2.11.4.GIT