composer packages update (#6006)
[openemr.git] / controllers / C_PatientFinder.class.php
blob492e67488c787a89e757b6a13e945dbd0d6a6f90
1 <?php
3 class C_PatientFinder extends Controller
5 var $template_mod;
7 function __construct($template_mod = "general")
9 parent::__construct();
10 $this->template_mod = $template_mod;
11 $this->assign("FORM_ACTION", $GLOBALS['webroot'] . "/controller.php?" . attr($_SERVER['QUERY_STRING']));
12 ///////////////////////////////////
13 //// What should this be?????
14 //////////////////////////////////
15 $this->assign("CURRENT_ACTION", $GLOBALS['webroot'] . "/controller.php?" . "practice_settings&patient_finder&");
16 /////////////////////////////////
17 $this->assign("STYLE", $GLOBALS['style']);
20 function default_action($form_id = '', $form_name = '', $pid = '')
22 return $this->find_action($form_id, $form_name, $pid);
25 /**
26 * Function that will display a patient finder widget, allowing
27 * the user to input search parameters to find a patient id.
29 function find_action($form_id, $form_name, $pid = null)
31 $isPid = false;
33 $this->assign('form_id', $form_id);
34 $this->assign('form_name', $form_name);
35 if (!empty($pid)) {
36 $isPid = true;
39 $this->assign('hidden_ispid', $isPid);
41 return $this->fetch($GLOBALS['template_dir'] . "patient_finder/" . $this->template_mod . "_find.html");
44 /**
45 * Function that will take a search string, parse it out and return all patients from the db matching.
46 * @param string $search_string - String from html form giving us our search parameters
48 function find_action_process()
51 if ($_POST['process'] != "true") {
52 return;
55 $isPub = false;
56 $search_string = $_POST['searchstring'];
57 if (!empty($_POST['pid'])) {
58 $isPub = !$_POST['pid'];
61 //get the db connection and pass it to the helper functions
62 $sql = "SELECT CONCAT(lname, ' ', fname, ' ', mname) as name, DOB, pubpid, pid FROM patient_data";
63 //parse search_string to determine what type of search we have
64 $pos = strpos($search_string, ',');
66 // get result set into array and pass to array
67 $result_array = array();
69 if ($pos === false) {
70 //no comma just last name
71 $result_array = $this->search_by_lName($sql, $search_string);
72 } elseif ($pos === 0) {
73 //first name only
74 $result_array = $this->search_by_fName($sql, $search_string);
75 } else {
76 //last and first at least
77 $result_array = $this->search_by_FullName($sql, $search_string);
80 $this->assign('search_string', $search_string);
81 $this->assign('result_set', $result_array);
82 $this->assign('ispub', $isPub);
83 // we're done
84 $_POST['process'] = "";
87 /**
88 * Function that returns an array containing the
89 * Results of a LastName search
90 * @-param string $sql base sql query
91 * @-param string $search_string parsed for last name
93 function search_by_lName($sql, $search_string)
95 $lName = add_escape_custom($search_string);
96 $sql .= " WHERE lname LIKE '$lName%' ORDER BY lname, fname";
97 $results = sqlStatement($sql);
99 $result_array = [];
100 while ($result = sqlFetchArray($results)) {
101 $result_array[] = $result;
104 return $result_array;
108 * Function that returns an array containing the
109 * Results of a FirstName search
110 * @param string $sql base sql query
111 * @param string $search_string parsed for first name
113 function search_by_fName($sql, $search_string)
115 $name_array = explode(",", $search_string);
116 $fName = add_escape_custom(trim($name_array[1]));
117 $sql .= " WHERE fname LIKE '$fName%' ORDER BY lname, fname";
118 $results = sqlStatement($sql);
120 $result_array = [];
121 while ($result = sqlFetchArray($results)) {
122 $result_array[] = $result;
125 return $result_array;
129 * Function that returns an array containing the
130 * Results of a Full Name search
131 * @param string $sql base sql query
132 * @param string $search_string parsed for first, last and middle name
134 function search_by_FullName($sql, $search_string)
136 $name_array = explode(",", $search_string);
137 $lName = add_escape_custom($name_array[0]);
138 $fName = add_escape_custom(trim($name_array[1]));
139 $sql .= " WHERE fname LIKE '%$fName%' AND lname LIKE '$lName%' ORDER BY lname, fname";
140 $results = sqlStatement($sql);
142 $result_array = [];
143 while ($result = sqlFetchArray($results)) {
144 $result_array[] = $result;
147 return $result_array;