more organization of autoloaded files (#424)
[openemr.git] / library / ajax / find_patients.php
blobdcd602c4bcbea6d1dacf9abac4597106a4f463cc
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");
19 function myGetValue($fldname) {
20 $val = formData($fldname, 'G', true);
21 if ($val == 'undefined') $val = '';
22 return $val;
25 function myQueryPatients($where) {
26 $sql = "SELECT count(*) AS count FROM patient_data WHERE $where";
27 $row = sqlQuery($sql);
28 return $row['count'];
31 $fname = myGetValue('fname');
32 $mname = myGetValue('mname');
33 $lname = myGetValue('lname');
34 $pubpid = myGetValue('pubpid');
35 $ss = myGetValue('ss');
37 $error = 0;
38 $message = '';
40 if ($pubpid) {
41 if (myQueryPatients("pubpid LIKE '$pubpid'")) {
42 $error = 2;
43 $message = xl('A patient with this ID already exists.');
44 $fname = $mname = $lname = $ss = '';
48 if (!$error && $ss) {
49 if (myQueryPatients("ss LIKE '$ss'")) {
50 $error = 2;
51 $message = xl('A patient with this SS already exists.');
52 $fname = $mname = $lname = $pubpid = '';
56 $nametest = "fname LIKE '$fname' AND lname LIKE '$lname'";
57 if ($mname != '') $nametest .= " AND mname LIKE '$mname'";
59 if (!$error && ($fname || $lname || $mname)) {
60 if (myQueryPatients("$nametest")) {
61 $error = 1;
62 $message = xl('A patient with this name already exists.');
63 $pubpid = $ss = '';
67 if ($error) {
68 if ($error == 1) {
69 echo "force_submit = true;\n";
70 echo "f.create.value = '" . xl('Force Create New Patient') . "';\n";
72 $message = addslashes($message);
73 echo "show_matches('$fname', '$mname', '$lname', '$pubpid', '$ss', '$message')\n";
75 else {
76 echo "f.submit()\n";