change eligibility batch from ssn to policy number, minor fix to filename with extra...
[openemr.git] / library / ajax / find_patients.php
blob632edf713f6dc042369a935eae3fe9adf42f1455
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)
21 $val = formData($fldname, 'G', true);
22 if ($val == 'undefined') {
23 $val = '';
26 return $val;
29 function myQueryPatients($where)
31 $sql = "SELECT count(*) AS count FROM patient_data WHERE $where";
32 $row = sqlQuery($sql);
33 return $row['count'];
36 $fname = myGetValue('fname');
37 $mname = myGetValue('mname');
38 $lname = myGetValue('lname');
39 $pubpid = myGetValue('pubpid');
40 $ss = myGetValue('ss');
42 $error = 0;
43 $message = '';
45 if ($pubpid) {
46 if (myQueryPatients("pubpid LIKE '$pubpid'")) {
47 $error = 2;
48 $message = xl('A patient with this ID already exists.');
49 $fname = $mname = $lname = $ss = '';
53 if (!$error && $ss) {
54 if (myQueryPatients("ss LIKE '$ss'")) {
55 $error = 2;
56 $message = xl('A patient with this SS already exists.');
57 $fname = $mname = $lname = $pubpid = '';
61 $nametest = "fname LIKE '$fname' AND lname LIKE '$lname'";
62 if ($mname != '') {
63 $nametest .= " AND mname LIKE '$mname'";
66 if (!$error && ($fname || $lname || $mname)) {
67 if (myQueryPatients("$nametest")) {
68 $error = 1;
69 $message = xl('A patient with this name already exists.');
70 $pubpid = $ss = '';
74 if ($error) {
75 if ($error == 1) {
76 echo "force_submit = true;\n";
77 echo "f.create.value = '" . xl('Force Create New Patient') . "';\n";
80 $message = addslashes($message);
81 echo "show_matches('$fname', '$mname', '$lname', '$pubpid', '$ss', '$message')\n";
82 } else {
83 echo "f.submit()\n";