Updated documentation.
[openemr.git] / interface / main / calendar / find_patient.php
blob7597e47174db9236f8d935ce9540f1361fc2f0af
1 <?php
2 include_once("../../globals.php");
3 include_once("$srcdir/calendar.inc");
4 include_once("$srcdir/patient.inc");
6 //the maximum number of patient records to display:
7 $M = 100;
9 if (isset($_POST["mode"]) && ($_POST["mode"] == "editappt")) {
10 //echo "saved appt";
11 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
12 $year = $_POST["year"];
13 $month = $_POST["month"];
14 $day = $_POST["day"];
15 $hour = $_POST["hour"];
16 $minute = $_POST["minute"];
17 if ($_POST["ampm"] == "pm") {
18 $hour += 12;
20 $timesave = "$year-$month-$day $hour:$minute";
21 //echo $timesave;
22 $providerres = sqlQuery("select name from groups where user='".$_POST["provider"]."' limit 1");
24 saveCalendarUpdate($_POST["calid"],$_POST["pid"],$timesave,$_POST["reason"],$_POST["provider"],$providerres{"name"});
26 elseif (isset($_POST["mode"]) && ($_POST["mode"] == "deleteappt")) {
27 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
29 deleteCalendarItem($_POST["calid"],$_POST["pid"]);
31 elseif (isset($_POST["mode"]) && ($_POST["mode"] == "saveappt")) {
32 $body_code = ' onload="javascript:parent.Calendar.location.href=parent.Calendar.location.href;" ';
33 $year = $_POST["year"];
34 $month = $_POST["month"];
35 $day = $_POST["day"];
36 $hour = $_POST["hour"];
37 $minute = $_POST["minute"];
38 if ($_POST["ampm"] == "pm") {
39 $hour += 12;
41 $timesave = "$year-$month-$day $hour:$minute";
42 $providerres = sqlQuery("select name from groups where user='".$_POST["provider"]."' limit 1");
43 newCalendarItem($_POST["pid"],$timesave,$_POST["reason"],$_POST["provider"],$providerres{"name"});
44 } else {
45 $body_code = "";
46 $category = $_GET["event_category"];
47 if(empty($category))
49 $category = $_POST['category'];
53 if (isset($_GET["mode"]) && ($_GET["mode"] == "reset")) {
54 $_SESSION["lastname"] = "";
55 $_SESSION["firstname"] = "";
56 //$_SESSION["category"] = $_POST["category"];
57 $category = $_POST["category"];
60 if (isset($_POST["mode"]) && ($_POST["mode"] == "findpatient")) {
61 $_SESSION["findby"] = $_POST["findBy"];
62 $_SESSION["lastname"] = $_POST["lastname"];
63 $_SESSION["firstname"] = $_POST["firstname"];
64 $category = $_POST["category"];
67 $findby = $_SESSION["findby"];
68 $lastname = $_SESSION["lastname"];
69 $firstname = $_SESSION["firstname"];
71 // do the search, if we have some good criteria
72 if (isset($lastname) && $lastname != "") {
73 if ($findby == "Last") {
74 $result = getPatientLnames("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
75 } elseif ($findby == "ID") {
76 $result = getPatientId("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
77 } elseif ($findby == "DOB") {
78 $result = getPatientDOB("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
79 } elseif ($findby == "SSN") {
80 $result = getPatientSSN("$lastname","*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
81 } elseif ($searchby == "Phone") { //(CHEMED) Search by phone number
82 $result = getPatientPhone("$searchparm","*");
87 <html>
88 <head>
89 <?php html_header_show();?>
91 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
92 <style>
93 form {
94 padding: 0px;
95 margin: 0px;
97 #searchCriteria {
98 text-align: center;
99 width: 100%;
100 font-size: 0.8em;
101 background-color: #ddddff;
102 font-weight: bold;
103 padding: 3px;
104 margin: 0px;
105 display: inline;
107 #searchCriteria form {
108 /* this is to fix some odd thing with Firefox,
109 or is it something odd with IE ?! crazy */
110 background-color: #ddddff;
112 #searchResultsHeader {
113 width: 100%;
114 background-color: lightgrey;
116 #searchResultsHeader table {
117 width: 96%; /* not 100% because the 'searchResults' table has a scrollbar */
118 border-collapse: collapse;
120 #searchResultsHeader th {
121 font-size: 0.7em;
123 #searchResults {
124 width: 100%;
125 overflow: auto;
128 .srName { width: 30%; }
129 .srPhone { width: 21%; }
130 .srSS { width: 17%; }
131 .srDOB { width: 17%; }
132 .srID { width: 15%; }
134 #searchResults table {
135 width: 100%;
136 border-collapse: collapse;
137 background-color: white;
139 #searchResults tr {
140 cursor: hand;
141 cursor: pointer;
143 #searchResults td {
144 font-size: 0.7em;
145 border-bottom: 1px solid #eee;
147 .oneResult { }
148 .billing { color: red; font-weight: bold; }
149 /* for search results or 'searching' notification */
150 #searchstatus {
151 font-size: 0.8em;
152 font-weight: bold;
153 padding: 1px 1px 10px 1px;
154 font-style: italic;
155 color: black;
156 text-align: center;
158 .noResults { background-color: #ccc; }
159 .tooManyResults { background-color: #fc0; }
160 .howManyResults { background-color: #9f6; }
161 #searchspinner {
162 display: inline;
163 visibility: hidden;
166 .highlight {
167 background-color: #336699;
168 color: white;
170 </style>
172 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
173 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script>
175 <script language='JavaScript'>
177 // This is called from the event editor popup to refresh the display.
178 function refreshme() {
179 var cf = parent.frames[0].frames[0]; // calendar frame
180 if (cf && cf.refreshme) cf.refreshme();
183 // Cloned from interface/main/calendar/.../views/day/default.html:
184 function newEvt(startampm, starttimeh, starttimem, eventdate, providerid, patientid) {
185 dlgopen('add_edit_event.php?startampm=' + startampm +
186 '&starttimeh=' + starttimeh + '&starttimem=' + starttimem +
187 //'&date=' + eventdate + '&userid=' + providerid +
188 '&date=' + eventdate +
189 '&patientid=' + patientid,
190 '_blank', 550, 270);
193 </script>
195 </head>
196 <body class="body_bottom" <?php $body_code;?>>
198 <span class='bold'><?php xl('Patient Appointment','e'); ?></span>
199 <?php if ($userauthorized == 1) { ?>
200 <a class="more" style="font-size:8pt;"
201 href="../authorizations/authorizations.php"
202 name="Authorizations"><?php xl('(Notes and Authorizations)','e'); ?></a>
203 <?php } else { ?>
204 <a class="more" style="font-size:8pt;"
205 href="../authorizations/authorizations.php"
206 name="Authorizations"><?php xl('(Patient Notes)','e'); ?></a>
207 <?php } ?>
209 <div id="searchCriteria">
210 <form method='post' id="theform" name='findpatientform' action='find_patient.php?no_nav=1'>
211 <input type='hidden' name='mode' value="findpatient">
212 <?php xl('Search by:','e'); ?>
213 <select name='findBy'>
214 <option value="Last"><?php xl ('Name','e'); ?></option>
215 <!-- (CHEMED) Search by phone number -->
216 <option value="Phone"<?php if ($searchby == 'Phone') echo ' selected' ?>><?php xl ('Phone','e'); ?></option>
217 <option value="ID"<?php if ($searchby == 'ID') echo ' selected' ?>><?php xl ('ID','e'); ?></option>
218 <option value="SSN"<?php if ($searchby == 'SSN') echo ' selected' ?>><?php xl ('SSN','e'); ?></option>
219 <option value="DOB"<?php if ($searchby == 'DOB') echo ' selected' ?>><?php xl ('DOB','e'); ?></option>
220 </select>
221 <?php xl('for:','e'); ?>
222 <input type='text' id='lastname' name='lastname' size='12' value='<?php echo $_REQUEST['lastname']; ?>' title='<?php xl('If name, any part of lastname or lastname,firstname','e'); ?>'>
223 &nbsp;
224 <input type='submit' id="submitbtn" value='<?php xl('Search','e'); ?>'>
225 <div id="searchspinner"><img src="<?php echo $GLOBALS['webroot'] ?>/interface/pic/ajax-loader.gif"></div>
227 <?php if (! isset($_REQUEST['lastname'])): ?>
228 <div id="searchstatus">Enter your search criteria above</div>
229 <?php elseif (count($result) == 0): ?>
230 <div id="searchstatus" class="noResults">No records found. Please expand your search criteria.</div>
231 <?php elseif (count($result)>=100): ?>
232 <div id="searchstatus" class="tooManyResults">More than 100 records found. Please narrow your search criteria.</div>
233 <?php elseif (count($result)<100): ?>
234 <div id="searchstatus" class="howManyResults"><?php echo count($result); ?> records found.</div>
235 <?php endif; ?>
237 <a class='text' href="../../new/new_patient.php" target="_top"><?php xl ('(New Patient)','e'); ?></a>
239 </form>
240 </div>
243 <?php if (isset($result)): ?> <!-- we have results -->
245 <div id="searchResultsHeader">
246 <table>
247 <tr>
248 <th class="srName"><?php xl ('Name','e'); ?></th>
249 <th class="srPhone"><?php xl ('Phone','e'); ?></th> <!-- (CHEMED) Search by phone number -->
250 <th class="srSS"><?php xl ('SS','e'); ?></th>
251 <th class="srDOB"><?php xl ('DOB','e'); ?></th>
252 <th class="srID"><?php xl ('ID','e'); ?></th>
253 </tr>
254 </table>
255 </div>
257 <div id="searchResults">
258 <table>
259 <?php
260 //set ampm default for find patient results links event_startampm
261 $ampm = 1;
262 if (date("H") >= 12) { $ampm = 2; }
264 //get the categories so you can get the details of the default category
265 $dbconn = $GLOBALS['adodb']['db'];
267 $sql = "SELECT pc_catid,pc_catname,pc_catcolor,pc_catdesc, " .
268 "pc_recurrtype,pc_recurrspec,pc_recurrfreq,pc_duration, " .
269 "pc_dailylimit,pc_end_date_flag,pc_end_date_type,pc_end_date_freq, " .
270 "pc_end_all_day FROM openemr_postcalendar_categories " .
271 "WHERE pc_catid = " . $GLOBALS['default_category'];
272 $catresult = $dbconn->Execute($sql);
274 $event_dur_minutes = ($catresult->fields['pc_duration']%(60 * 60))/60;
275 $event_dur_hours = ($catresult->fields['pc_duration']/(60 * 60));
276 $event_title = $catresult->fields['pc_catname'];
278 foreach ($result as $iter) {
279 if ($total > 100) { break; }
281 $iterpid = $iter['pid'];
282 $iterproviderid = $iter['providerID'];
283 $iterlname = addslashes($iter['lname']);
284 $iterfname = addslashes($iter['fname']);
285 $itermname = addslashes($iter['mname']);
286 $iterdob = $iter['DOB'];
288 // the special genericname2 of 'Billing' means something, but I'm not sure
289 // what, regardless it gets special coloring and an extra line of output
290 // in the 'name' column -- JRM
291 $trClass = "oneresult";
292 if ($iter['genericname2'] == 'Billing') { $trClass .= " billing"; }
294 $trTitle = "Make new appointment for ".$iterfname. " ". $iterlname;
296 echo " <tr class='".$trClass."' id='".$iterpid."~".$iterproviderid."' title='".$trTitle."'>";
297 echo " <td class='srName'>$iterlname, $iterfname $itermname";
298 if ($iter['genericname2'] == 'Billing') { echo "<br>".$iter['genericval2']; }
299 echo "</td>\n";
300 echo " <td class='srPhone'>" . $iter['phone_home'] . "</td>\n"; //(CHEMED) Search by phone number
301 echo " <td class='srSS'>" . $iter['ss'] . "</td>\n";
302 echo " <td class='srDOB'>" . $iter['DOB'] . "</td>\n";
303 echo " <td class='srID'>" . $iter['pubpid'] . "</td>\n";
304 echo " </tr>";
309 <?php endif; ?> <!-- end of results -->
310 </table>
311 </div> <!-- end search results DIV -->
313 </body>
315 <script language="javascript">
317 // jQuery stuff to make the page a little easier to use
319 $(document).ready(function(){
320 $("#lastname").focus();
321 $(".oneresult").mouseover(function() { $(this).toggleClass("highlight"); });
322 $(".oneresult").mouseout(function() { $(this).toggleClass("highlight"); });
323 $(".oneresult").click(function() { SelectPatient(this); });
324 $("#theform").submit(function() { SubmitForm(this); });
327 // show the 'searching...' status and submit the form
328 var SubmitForm = function(eObj) {
329 $("#submitbtn").css("disabled", "true");
330 $("#searchspinner").css("visibility", "visible");
331 return true;
334 // another way to select a patient from the list of results
335 // parts[] ==> 0=PID, 1=ProviderID
336 var SelectPatient = function (eObj) {
337 objID = eObj.id;
338 var parts = objID.split("~");
339 ampm = '<?php echo $ampm ?>';
340 starth = '<?php date("H") ?>';
341 startdate = '<?php date("Ymd") ?>';
342 return newEvt(ampm, starth , 0, startdate, parts[1], parts[0]);
345 var Showme = function (eObj) { alert("showme"); };
347 </script>
348 </html>