Focus the search term on load
[openemr.git] / interface / main / calendar / find_patient.php
blob5aca22c466c9ae3e5b08c4c1db361cab21c208d4
1 <?php
3 //SANITIZE ALL ESCAPES
4 $sanitize_all_escapes=true;
5 //
7 //STOP FAKE REGISTER GLOBALS
8 $fake_register_globals=false;
9 //
11 include_once("../../globals.php");
12 include_once("$srcdir/calendar.inc");
13 include_once("$srcdir/patient.inc");
15 //the maximum number of patient records to display:
16 $M = 100;
18 if (isset($_POST["mode"]) && ($_POST["mode"] == "editappt")) {
19 //echo "saved appt";
20 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
21 $year = $_POST["year"];
22 $month = $_POST["month"];
23 $day = $_POST["day"];
24 $hour = $_POST["hour"];
25 $minute = $_POST["minute"];
26 if ($_POST["ampm"] == "pm") {
27 $hour += 12;
29 $timesave = "$year-$month-$day $hour:$minute";
30 //echo $timesave;
31 $providerres = sqlQuery("select name from groups where user=? limit 1", array($_POST["provider"]) );
33 saveCalendarUpdate($_POST["calid"],$_POST["pid"],$timesave,$_POST["reason"],$_POST["provider"],$providerres{"name"});
35 elseif (isset($_POST["mode"]) && ($_POST["mode"] == "deleteappt")) {
36 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
38 deleteCalendarItem($_POST["calid"],$_POST["pid"]);
40 elseif (isset($_POST["mode"]) && ($_POST["mode"] == "saveappt")) {
41 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
42 $year = $_POST["year"];
43 $month = $_POST["month"];
44 $day = $_POST["day"];
45 $hour = $_POST["hour"];
46 $minute = $_POST["minute"];
47 if ($_POST["ampm"] == "pm") {
48 $hour += 12;
50 $timesave = "$year-$month-$day $hour:$minute";
51 $providerres = sqlQuery("select name from groups where user=? limit 1", array($_POST["provider"]) );
52 newCalendarItem($_POST["pid"],$timesave,$_POST["reason"],$_POST["provider"],$providerres{"name"});
53 } else {
54 $body_code = "";
55 $category = $_GET["event_category"];
56 if(empty($category))
58 $category = $_POST['category'];
62 if (isset($_GET["mode"]) && ($_GET["mode"] == "reset")) {
63 $_SESSION["lastname"] = "";
64 $_SESSION["firstname"] = "";
65 //$_SESSION["category"] = $_POST["category"];
66 $category = $_POST["category"];
69 if (isset($_POST["mode"]) && ($_POST["mode"] == "findpatient")) {
70 $_SESSION["findby"] = $_POST["findBy"];
71 $_SESSION["lastname"] = $_POST["lastname"];
72 $_SESSION["firstname"] = $_POST["firstname"];
73 $category = $_POST["category"];
76 $findby = $_SESSION["findby"];
77 $lastname = $_SESSION["lastname"];
78 $firstname = $_SESSION["firstname"];
80 // do the search, if we have some good criteria
81 if (isset($lastname) && $lastname != "") {
82 if ($findby == "Last") {
83 $result = getPatientLnames("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
84 } elseif ($findby == "ID") {
85 $result = getPatientId("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
86 } elseif ($findby == "DOB") {
87 $result = getPatientDOB("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
88 } elseif ($findby == "SSN") {
89 $result = getPatientSSN("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
90 } elseif ($searchby == "Phone") { //(CHEMED) Search by phone number
91 $result = getPatientPhone("$searchparm","*");
96 <html>
97 <head>
98 <?php html_header_show();?>
100 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
101 <style>
102 form {
103 padding: 0px;
104 margin: 0px;
106 #searchCriteria {
107 text-align: center;
108 width: 100%;
109 font-size: 0.8em;
110 background-color: #ddddff;
111 font-weight: bold;
112 padding: 3px;
113 margin: 0px;
114 display: inline;
116 #searchCriteria form {
117 /* this is to fix some odd thing with Firefox,
118 or is it something odd with IE ?! crazy */
119 background-color: #ddddff;
121 #searchResultsHeader {
122 width: 100%;
123 background-color: lightgrey;
125 #searchResultsHeader table {
126 width: 96%; /* not 100% because the 'searchResults' table has a scrollbar */
127 border-collapse: collapse;
129 #searchResultsHeader th {
130 font-size: 0.7em;
132 #searchResults {
133 width: 100%;
134 overflow: auto;
137 .srName { width: 30%; }
138 .srPhone { width: 21%; }
139 .srSS { width: 17%; }
140 .srDOB { width: 17%; }
141 .srID { width: 15%; }
143 #searchResults table {
144 width: 100%;
145 border-collapse: collapse;
146 background-color: white;
148 #searchResults tr {
149 cursor: hand;
150 cursor: pointer;
152 #searchResults td {
153 font-size: 0.7em;
154 border-bottom: 1px solid #eee;
156 .oneResult { }
157 .billing { color: red; font-weight: bold; }
158 /* for search results or 'searching' notification */
159 #searchstatus {
160 font-size: 0.8em;
161 font-weight: bold;
162 padding: 1px 1px 10px 1px;
163 font-style: italic;
164 color: black;
165 text-align: center;
167 .noResults { background-color: #ccc; }
168 .tooManyResults { background-color: #fc0; }
169 .howManyResults { background-color: #9f6; }
170 #searchspinner {
171 display: inline;
172 visibility: hidden;
175 .highlight {
176 background-color: #336699;
177 color: white;
179 </style>
181 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
182 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script>
184 <script language='JavaScript'>
186 // This is called from the event editor popup to refresh the display.
187 function refreshme() {
188 var cf = parent.frames[0].frames[0]; // calendar frame
189 if (cf && cf.refreshme) cf.refreshme();
192 // Cloned from interface/main/calendar/.../views/day/default.html:
193 function newEvt(startampm, starttimeh, starttimem, eventdate, providerid, patientid) {
194 dlgopen('add_edit_event.php?startampm=' + startampm +
195 '&starttimeh=' + starttimeh + '&starttimem=' + starttimem +
196 //'&date=' + eventdate + '&userid=' + providerid +
197 '&date=' + eventdate +
198 '&patientid=' + patientid,
199 '_blank', 550, 310);
202 </script>
204 </head>
205 <body class="body_bottom" <?php $body_code;?>>
207 <span class='bold'><?php echo htmlspecialchars( xl('Patient Appointment'), ENT_NOQUOTES); ?></span>
208 <?php if ($userauthorized == 1) { ?>
209 <a class="more" style="font-size:8pt;"
210 href="../authorizations/authorizations.php"
211 name="Authorizations"><?php echo htmlspecialchars( xl('(Notes and Authorizations)'), ENT_NOQUOTES); ?></a>
212 <?php } else { ?>
213 <a class="more" style="font-size:8pt;"
214 href="../authorizations/authorizations.php"
215 name="Authorizations"><?php echo htmlspecialchars( xl('(Patient Notes)'), ENT_NOQUOTES); ?></a>
216 <?php } ?>
218 <div id="searchCriteria">
219 <form method='post' id="theform" name='findpatientform' action='find_patient.php?no_nav=1'>
220 <input type='hidden' name='mode' value="findpatient">
221 <?php echo htmlspecialchars( xl('Search by:'), ENT_NOQUOTES); ?>
222 <select name='findBy'>
223 <option value="Last"><?php echo htmlspecialchars( xl('Name'), ENT_NOQUOTES); ?></option>
224 <!-- (CHEMED) Search by phone number -->
225 <option value="Phone"<?php if ($searchby == 'Phone') echo ' selected' ?>><?php echo htmlspecialchars( xl('Phone'), ENT_NOQUOTES); ?></option>
226 <option value="ID"<?php if ($searchby == 'ID') echo ' selected' ?>><?php echo htmlspecialchars( xl('ID'), ENT_NOQUOTES); ?></option>
227 <option value="SSN"<?php if ($searchby == 'SSN') echo ' selected' ?>><?php echo htmlspecialchars( xl('SSN'), ENT_NOQUOTES); ?></option>
228 <option value="DOB"<?php if ($searchby == 'DOB') echo ' selected' ?>><?php echo htmlspecialchars( xl('DOB'), ENT_NOQUOTES); ?></option>
229 </select>
230 <?php echo htmlspecialchars( xl('for:'), ENT_NOQUOTES); ?>
231 <input type='text' id='lastname' name='lastname' size='12' value='<?php echo htmlspecialchars( $_REQUEST['lastname'], ENT_QUOTES); ?>' title='<?php echo htmlspecialchars( xl('If name, any part of lastname or lastname,firstname'), ENT_QUOTES); ?>'>
232 &nbsp;
233 <input type='submit' id="submitbtn" value='<?php echo htmlspecialchars( xl('Search'), ENT_QUOTES); ?>'>
234 <div id="searchspinner"><img src="<?php echo $GLOBALS['webroot'] ?>/interface/pic/ajax-loader.gif"></div>
236 <?php if (! isset($_REQUEST['lastname'])): ?>
237 <div id="searchstatus"><?php echo htmlspecialchars( xl('Enter your search criteria above'), ENT_NOQUOTES); ?></div>
238 <?php elseif (count($result) == 0): ?>
239 <div id="searchstatus" class="noResults"><?php echo htmlspecialchars( xl('No records found. Please expand your search criteria.'), ENT_NOQUOTES); ?></div>
240 <?php elseif (count($result)>=100): ?>
241 <div id="searchstatus" class="tooManyResults"><?php echo htmlspecialchars( xl('More than 100 records found. Please narrow your search criteria.'), ENT_NOQUOTES); ?></div>
242 <?php elseif (count($result)<100): ?>
243 <div id="searchstatus" class="howManyResults"><?php echo htmlspecialchars( count($result)." ".xl('records found'), ENT_NOQUOTES); ?>.</div>
244 <?php endif; ?>
246 <a class='text' href="../../new/new_patient.php" target="_top"><?php echo htmlspecialchars( xl('(New Patient)'), ENT_NOQUOTES); ?></a>
248 </form>
249 </div>
252 <?php if (isset($result)): ?> <!-- we have results -->
254 <div id="searchResultsHeader">
255 <table>
256 <tr>
257 <th class="srName"><?php echo htmlspecialchars( xl('Name'), ENT_NOQUOTES); ?></th>
258 <th class="srPhone"><?php echo htmlspecialchars( xl('Phone'), ENT_NOQUOTES); ?></th> <!-- (CHEMED) Search by phone number -->
259 <th class="srSS"><?php echo htmlspecialchars( xl('SS'), ENT_NOQUOTES); ?></th>
260 <th class="srDOB"><?php echo htmlspecialchars( xl('DOB'), ENT_NOQUOTES); ?></th>
261 <th class="srID"><?php echo htmlspecialchars( xl('ID'), ENT_NOQUOTES); ?></th>
262 </tr>
263 </table>
264 </div>
266 <div id="searchResults">
267 <table>
268 <?php
269 //set ampm default for find patient results links event_startampm
270 $ampm = 1;
271 if (date("H") >= 12) { $ampm = 2; }
273 foreach ($result as $iter) {
274 if ($total > 100) { break; }
276 $iterpid = $iter['pid'];
277 $iterproviderid = $iter['providerID'];
278 $iterlname = $iter['lname'];
279 $iterfname = $iter['fname'];
280 $itermname = $iter['mname'];
281 $iterdob = $iter['DOB'];
283 // the special genericname2 of 'Billing' means something, but I'm not sure
284 // what, regardless it gets special coloring and an extra line of output
285 // in the 'name' column -- JRM
286 $trClass = "oneresult";
287 if ($iter['genericname2'] == 'Billing') { $trClass .= " billing"; }
289 $trTitle = xl("Make new appointment for") . " " . $iterfname . " " . $iterlname;
291 echo " <tr class='".$trClass."' id='".htmlspecialchars( $iterpid."~".$iterproviderid, ENT_QUOTES)."' title='".htmlspecialchars( $trTitle, ENT_QUOTES)."'>";
292 echo " <td class='srName'>".htmlspecialchars( $iterlname.", ".$iterfname." ".$itermname, ENT_NOQUOTES);
293 if ($iter['genericname2'] == 'Billing') { echo "<br>".htmlspecialchars( $iter['genericval2'], ENT_NOQUOTES); }
294 echo "</td>\n";
295 echo " <td class='srPhone'>" . htmlspecialchars( $iter['phone_home'], ENT_NOQUOTES) . "</td>\n"; //(CHEMED) Search by phone number
296 echo " <td class='srSS'>" . htmlspecialchars( $iter['ss'], ENT_NOQUOTES) . "</td>\n";
297 echo " <td class='srDOB'>" . htmlspecialchars( $iter['DOB'], ENT_NOQUOTES) . "</td>\n";
298 echo " <td class='srID'>" . htmlspecialchars( $iter['pubpid'], ENT_NOQUOTES) . "</td>\n";
299 echo " </tr>";
304 <?php endif; ?> <!-- end of results -->
305 </table>
306 </div> <!-- end search results DIV -->
308 </body>
310 <script language="javascript">
312 // jQuery stuff to make the page a little easier to use
314 $(document).ready(function(){
315 $("#lastname").focus();
316 $(".oneresult").mouseover(function() { $(this).toggleClass("highlight"); });
317 $(".oneresult").mouseout(function() { $(this).toggleClass("highlight"); });
318 $(".oneresult").click(function() { SelectPatient(this); });
319 $("#theform").submit(function() { SubmitForm(this); });
322 // show the 'searching...' status and submit the form
323 var SubmitForm = function(eObj) {
324 $("#submitbtn").css("disabled", "true");
325 $("#searchspinner").css("visibility", "visible");
326 return true;
329 // another way to select a patient from the list of results
330 // parts[] ==> 0=PID, 1=ProviderID
331 var SelectPatient = function (eObj) {
332 objID = eObj.id;
333 var parts = objID.split("~");
334 ampm = '<?php echo $ampm ?>';
335 starth = '<?php date("H") ?>';
336 startdate = '<?php date("Ymd") ?>';
337 return newEvt(ampm, starth , 0, startdate, parts[1], parts[0]);
340 var Showme = function (eObj) { alert("showme"); };
342 </script>
343 </html>