minor documentation fix in docker dev env
[openemr.git] / controllers / C_PatientFinder.class.php
blobf18f77c32f57e05b6d97dcea95a2985c01558692
1 <?php
4 class C_PatientFinder extends Controller
7 var $template_mod;
8 var $_db;
10 function __construct($template_mod = "general")
12 parent::__construct();
13 $this->_db = $GLOBALS['adodb']['db'];
14 $this->template_mod = $template_mod;
15 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . attr($_SERVER['QUERY_STRING']));
16 ///////////////////////////////////
17 //// What should this be?????
18 //////////////////////////////////
19 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&patient_finder&");
20 /////////////////////////////////
21 $this->assign("STYLE", $GLOBALS['style']);
24 function default_action($form_id = '', $form_name = '', $pid = '')
26 return $this->find_action($form_id, $form_name, $pid);
29 /**
30 * Function that will display a patient finder widged, allowing
31 * the user to input search parameters to find a patient id.
33 function find_action($form_id, $form_name, $pid)
35 $isPid = false;
37 $this->assign('form_id', $form_id);
38 $this->assign('form_name', $form_name);
39 if (!empty($pid)) {
40 $isPid = true;
43 $this->assign('hidden_ispid', $isPid);
45 return $this->fetch($GLOBALS['template_dir'] . "patient_finder/" . $this->template_mod . "_find.html");
48 /**
49 * Function that will take a search string, parse it out and return all patients from the db matching.
50 * @param string $search_string - String from html form giving us our search parameters
52 function find_action_process()
55 if ($_POST['process'] != "true") {
56 return;
59 $isPub = false;
60 $search_string = $_POST['searchstring'];
61 if (!empty($_POST['pid'])) {
62 $isPub = !$_POST['pid'];
65 //get the db connection and pass it to the helper functions
66 $sql = "SELECT CONCAT(lname, ' ', fname, ' ', mname) as name, DOB, pubpid, pid FROM patient_data";
67 //parse search_string to determine what type of search we have
68 $pos = strpos($search_string, ',');
70 // get result set into array and pass to array
71 $result_array = array();
73 if ($pos === false) {
74 //no comma just last name
75 $result_array = $this->search_by_lName($sql, $search_string);
76 } else if ($pos === 0) {
77 //first name only
78 $result_array = $this->search_by_fName($sql, $search_string);
79 } else {
80 //last and first at least
81 $result_array = $this->search_by_FullName($sql, $search_string);
84 $this->assign('search_string', $search_string);
85 $this->assign('result_set', $result_array);
86 $this->assign('ispub', $isPub);
87 // we're done
88 $_POST['process'] = "";
91 /**
92 * Function that returns an array containing the
93 * Results of a LastName search
94 * @-param string $sql base sql query
95 * @-param string $search_string parsed for last name
97 function search_by_lName($sql, $search_string)
99 $lName = add_escape_custom($search_string);
100 $sql .= " WHERE lname LIKE '$lName%' ORDER BY lname, fname";
101 //print "SQL is $sql \n";
102 $result_array = $this->_db->GetAll($sql);
103 //print_r($result_array);
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 $result_array = $this->_db->GetAll($sql);
119 return $result_array;
123 * Function that returns an array containing the
124 * Results of a Full Name search
125 * @param string $sql base sql query
126 * @param string $search_string parsed for first, last and middle name
128 function search_by_FullName($sql, $search_string)
130 $name_array = explode(",", $search_string);
131 $lName = add_escape_custom($name_array[0]);
132 $fName = add_escape_custom(trim($name_array[1]));
133 $sql .= " WHERE fname LIKE '%$fName%' AND lname LIKE '$lName%' ORDER BY lname, fname";
134 //print "SQL is $sql \n";
135 $result_array = $this->_db->GetAll($sql);
136 return $result_array;