migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / library / ajax / find_patients.php
blob0c2e413999c73f1c7a543cb91175cfbe4efca2e7
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");
20 function myGetValue($fldname) {
21 $val = formData($fldname, 'G', true);
22 if ($val == 'undefined') $val = '';
23 return $val;
26 function myQueryPatients($where) {
27 $sql = "SELECT count(*) AS count FROM patient_data WHERE $where";
28 $row = sqlQuery($sql);
29 return $row['count'];
32 $fname = myGetValue('fname');
33 $mname = myGetValue('mname');
34 $lname = myGetValue('lname');
35 $pubpid = myGetValue('pubpid');
36 $ss = myGetValue('ss');
38 $error = 0;
39 $message = '';
41 if ($pubpid) {
42 if (myQueryPatients("pubpid LIKE '$pubpid'")) {
43 $error = 2;
44 $message = xl('A patient with this ID already exists.');
45 $fname = $mname = $lname = $ss = '';
49 if (!$error && $ss) {
50 if (myQueryPatients("ss LIKE '$ss'")) {
51 $error = 2;
52 $message = xl('A patient with this SS already exists.');
53 $fname = $mname = $lname = $pubpid = '';
57 $nametest = "fname LIKE '$fname' AND lname LIKE '$lname'";
58 if ($mname != '') $nametest .= " AND mname LIKE '$mname'";
60 if (!$error && ($fname || $lname || $mname)) {
61 if (myQueryPatients("$nametest")) {
62 $error = 1;
63 $message = xl('A patient with this name already exists.');
64 $pubpid = $ss = '';
68 if ($error) {
69 if ($error == 1) {
70 echo "force_submit = true;\n";
71 echo "f.create.value = '" . xl('Force Create New Patient') . "';\n";
73 $message = addslashes($message);
74 echo "show_matches('$fname', '$mname', '$lname', '$pubpid', '$ss', '$message')\n";
76 else {
77 echo "f.submit()\n";