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