Enhance Photo and Patient ID card handling with a widget that supports thumnails...
[openemr.git] / library / ajax / find_patients.php
blob22c2f18b255838f28bbd90984abb67e5b7f8737d
1 <?php
2 // Copyright (C) 2009 Jason Morrill <jason@italktech.net>
3 // Rewritten by Rod Roark <rod@sunsetsystems.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This file is used to find patient(s) that match the given
11 // criteria passed in
13 // OUTPUT is varied and based on the returntype parameter
15 // Important - Ensure that display_errors=Off in php.ini settings.
17 require_once("../../interface/globals.php");
18 require_once("{$GLOBALS['srcdir']}/sql.inc");
19 require_once("{$GLOBALS['srcdir']}/formdata.inc.php");
21 function myGetValue($fldname) {
22 $val = formData($fldname, 'G', true);
23 if ($val == 'undefined') $val = '';
24 return $val;
27 function myQueryPatients($where) {
28 $sql = "SELECT count(*) AS count FROM patient_data WHERE $where";
29 $row = sqlQuery($sql);
30 return $row['count'];
33 $fname = myGetValue('fname');
34 $mname = myGetValue('mname');
35 $lname = myGetValue('lname');
36 $pubpid = myGetValue('pubpid');
37 $ss = myGetValue('ss');
39 $error = 0;
40 $message = '';
42 if ($pubpid) {
43 if (myQueryPatients("pubpid LIKE '$pubpid'")) {
44 $error = 2;
45 $message = xl('A patient with this ID already exists.');
46 $fname = $mname = $lname = $ss = '';
50 if (!$error && $ss) {
51 if (myQueryPatients("ss LIKE '$ss'")) {
52 $error = 2;
53 $message = xl('A patient with this SS already exists.');
54 $fname = $mname = $lname = $pubpid = '';
58 $nametest = "fname LIKE '$fname' AND lname LIKE '$lname'";
59 if ($mname != '') $nametest .= " AND mname LIKE '$mname'";
61 if (!$error && ($fname || $lname || $mname)) {
62 if (myQueryPatients("$nametest")) {
63 $error = 1;
64 $message = xl('A patient with this name already exists.');
65 $pubpid = $ss = '';
69 if ($error) {
70 if ($error == 1) {
71 echo "force_submit = true;\n";
72 echo "f.create.value = '" . xl('Force Create New Patient') . "';\n";
74 $message = addslashes($message);
75 echo "show_matches('$fname', '$mname', '$lname', '$pubpid', '$ss', '$message')\n";
77 else {
78 echo "f.submit()\n";