Filter appointment report by category
[openemr.git] / interface / reports / appointments_report.php
blob76b47f57e3d8a23ed1fb19e21849ad1f06955af3
1 <?php
2 // Copyright (C) 2005-2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report shows upcoming appointments with filtering and
10 // sorting by patient, practitioner, appointment type, and date.
11 // 2012-01-01 - Added display of home and cell phone and fixed header
13 require_once("../globals.php");
14 require_once("../../library/patient.inc");
15 require_once("$srcdir/formatting.inc.php");
16 require_once "$srcdir/options.inc.php";
17 require_once "$srcdir/formdata.inc.php";
18 require_once "$srcdir/appointments.inc.php";
20 $alertmsg = ''; // not used yet but maybe later
21 $patient = $_REQUEST['patient'];
23 if ($patient && ! $_POST['form_from_date']) {
24 // If a specific patient, default to 2 years ago.
25 $tmp = date('Y') - 2;
26 $from_date = date("$tmp-m-d");
27 } else {
28 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
29 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
32 $show_available_times = false;
33 if ( $_POST['form_show_available'] ) {
34 $show_available_times = true;
37 $chk_with_out_provider = false;
38 if ( $_POST['with_out_provider'] ) {
39 $chk_with_out_provider = true;
42 $chk_with_out_facility = false;
43 if ( $_POST['with_out_facility'] ) {
44 $chk_with_out_facility = true;
47 //$to_date = fixDate($_POST['form_to_date'], '');
48 $provider = $_POST['form_provider'];
49 $facility = $_POST['form_facility']; //(CHEMED) facility filter
50 $form_orderby = getComparisonOrder( $_REQUEST['form_orderby'] ) ? $_REQUEST['form_orderby'] : 'date';
54 <html>
56 <head>
57 <?php html_header_show();?>
59 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
61 <title><?php xl('Appointments Report','e'); ?></title>
63 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
64 <script type="text/javascript" src="../../library/textformat.js"></script>
65 <script type="text/javascript" src="../../library/dialog.js"></script>
66 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
68 <script type="text/javascript">
70 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
72 function dosort(orderby) {
73 var f = document.forms[0];
74 f.form_orderby.value = orderby;
75 f.submit();
76 return false;
79 function oldEvt(eventid) {
80 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 550, 270);
83 function refreshme() {
84 // location.reload();
85 document.forms[0].submit();
88 </script>
90 <style type="text/css">
91 /* specifically include & exclude from printing */
92 @media print {
93 #report_parameters {
94 visibility: hidden;
95 display: none;
97 #report_parameters_daterange {
98 visibility: visible;
99 display: inline;
101 #report_results table {
102 margin-top: 0px;
106 /* specifically exclude some from the screen */
107 @media screen {
108 #report_parameters_daterange {
109 visibility: hidden;
110 display: none;
113 </style>
114 </head>
116 <body class="body_top">
118 <!-- Required for the popup date selectors -->
119 <div id="overDiv"
120 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
122 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Appointments','e'); ?></span>
124 <div id="report_parameters_daterange"><?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
125 </div>
127 <form method='post' name='theform' id='theform' action='appointments_report.php'>
129 <div id="report_parameters">
131 <table>
132 <tr>
133 <td width='650px'>
134 <div style='float: left'>
136 <table class='text'>
137 <tr>
138 <td class='label'><?php xl('Facility','e'); ?>:</td>
139 <td><?php dropdown_facility(strip_escape_custom($facility), 'form_facility'); ?>
140 </td>
141 <td class='label'><?php xl('Provider','e'); ?>:</td>
142 <td><?php
144 // Build a drop-down list of providers.
147 $query = "SELECT id, lname, fname FROM users WHERE ".
148 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
150 $ures = sqlStatement($query);
152 echo " <select name='form_provider'>\n";
153 echo " <option value=''>-- " . xl('All') . " --\n";
155 while ($urow = sqlFetchArray($ures)) {
156 $provid = $urow['id'];
157 echo " <option value='$provid'";
158 if ($provid == $_POST['form_provider']) echo " selected";
159 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
162 echo " </select>\n";
164 ?></td>
165 <td><input type='checkbox' name='form_show_available'
166 title='<?php xl('Show Available Times','e'); ?>'
167 <?php if ( $show_available_times ) echo ' checked'; ?>> <?php xl( 'Show Available Times','e' ); ?>
168 </td>
169 </tr>
170 <tr>
171 <td class='label'><?php xl('From','e'); ?>:</td>
172 <td><input type='text' name='form_from_date' id="form_from_date"
173 size='10' value='<?php echo $form_from_date ?>'
174 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
175 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
176 align='absbottom' width='24' height='22' id='img_from_date'
177 border='0' alt='[?]' style='cursor: pointer'
178 title='<?php xl('Click here to choose a date','e'); ?>'></td>
179 <td class='label'><?php xl('To','e'); ?>:</td>
180 <td><input type='text' name='form_to_date' id="form_to_date"
181 size='10' value='<?php echo $form_to_date ?>'
182 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
183 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
184 align='absbottom' width='24' height='22' id='img_to_date'
185 border='0' alt='[?]' style='cursor: pointer'
186 title='<?php xl('Click here to choose a date','e'); ?>'></td>
187 </tr>
189 <tr>
190 <td class='label'><?php xl('Status','e'); ?>:</td>
191 <td><?php generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'),$_POST['form_apptstatus']);?></td>
192 <td><?php echo xlt('Category')?></td>
193 <td>
194 <select id="form_apptcat" name="form_apptcat">
195 <?php
196 $categories=fetchAppointmentCategories();
197 echo "<option value='ALL'>".xlt("All")."</option>";
198 while($cat=sqlFetchArray($categories))
200 echo "<option value='".attr($cat['id'])."'";
201 if($cat['id']==$_POST['form_apptcat'])
203 echo " selected='true' ";
205 echo ">".text(xl_appt_category($cat['category']))."</option>";
208 </select>
209 </td>
210 </tr>
212 <tr>
213 <td colspan="2"><input type="checkbox" name="with_out_provider" id="with_out_provider" <?php if($chk_with_out_provider) echo "checked";?>>&nbsp;<?php xl('Without Provider','e'); ?></td>
214 <td colspan="2"><input type="checkbox" name="with_out_facility" id="with_out_facility" <?php if($chk_with_out_facility) echo "checked";?>>&nbsp;<?php xl('Without Facility','e'); ?></td>
215 </tr>
217 </table>
219 </div>
221 </td>
222 <td align='left' valign='middle' height="100%">
223 <table style='border-left: 1px solid; width: 100%; height: 100%'>
224 <tr>
225 <td>
226 <div style='margin-left: 15px'>
227 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
228 <span> <?php xl('Submit','e'); ?> </span> </a>
229 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
230 <a href='#' class='css_button' onclick='window.print()'>
231 <span> <?php xl('Print','e'); ?> </span> </a>
232 <a href='#' class='css_button' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")'>
233 <span> <?php xl('Superbills','e'); ?> </span> </a>
234 <?php } ?></div>
235 </td>
236 </tr>
237 <tr>&nbsp;&nbsp;<?php xl('Most column headers can be clicked to change sort order','e') ?></tr>
238 </table>
239 </td>
240 </tr>
241 </table>
243 </div>
244 <!-- end of search parameters --> <?php
245 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
247 <div id="report_results">
248 <table>
250 <thead>
251 <th><a href="nojs.php" onclick="return dosort('doctor')"
252 <?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php xl('Provider','e'); ?>
253 </a></th>
255 <th><a href="nojs.php" onclick="return dosort('date')"
256 <?php if ($form_orderby == "date") echo " style=\"color:#00cc00\"" ?>><?php xl('Date','e'); ?></a>
257 </th>
259 <th><a href="nojs.php" onclick="return dosort('time')"
260 <?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php xl('Time','e'); ?></a>
261 </th>
263 <th><a href="nojs.php" onclick="return dosort('patient')"
264 <?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php xl('Patient','e'); ?></a>
265 </th>
267 <th><a href="nojs.php" onclick="return dosort('pubpid')"
268 <?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php xl('ID','e'); ?></a>
269 </th>
271 <th><?php xl('Home','e'); //Sorting by phone# not really useful ?></th>
273 <th><?php xl('Cell','e'); //Sorting by phone# not really useful ?></th>
275 <th><a href="nojs.php" onclick="return dosort('type')"
276 <?php if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?>><?php xl('Type','e'); ?></a>
277 </th>
279 <th><a href="nojs.php" onclick="return dosort('status')"
280 <?php if ($form_orderby == "status") echo " style=\"color:#00cc00\"" ?>><?php xl('Status','e'); ?></a>
281 </th>
283 <th><a href="nojs.php" onclick="return dosort('comment')"
284 <?php if ($form_orderby == "comment") echo " style=\"color:#00cc00\"" ?>><?php xl('Comment','e'); ?></a>
285 </th>
287 </thead>
288 <tbody>
289 <!-- added for better print-ability -->
290 <?php
292 $lastdocname = "";
293 //Appointment Status Checking
294 $form_apptstatus = $_POST['form_apptstatus'];
295 $form_apptcat=null;
296 if(isset($_POST['form_apptcat']))
298 if($form_apptcat!="ALL")
300 $form_apptcat=intval($_POST['form_apptcat']);
304 //Without provider and facility data checking
305 $with_out_provider = null;
306 $with_out_facility = null;
308 if( isset($_POST['with_out_provider']) ){
309 $with_out_provider = $_POST['with_out_provider'];
312 if( isset($_POST['with_out_facility']) ){
313 $with_out_facility = $_POST['with_out_facility'];
315 $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility,$form_apptcat );
317 if ( $show_available_times ) {
318 $availableSlots = getAvailableSlots( $from_date, $to_date, $provider, $facility );
319 $appointments = array_merge( $appointments, $availableSlots );
322 $appointments = sortAppointments( $appointments, $form_orderby );
323 $pid_list = array(); // Initialize list of PIDs for Superbill option
324 $totalAppontments = count($appointments);
326 foreach ( $appointments as $appointment ) {
327 array_push($pid_list,$appointment['pid']);
328 $patient_id = $appointment['pid'];
329 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
331 $errmsg = "";
332 $pc_apptstatus = $appointment['pc_apptstatus'];
336 <tr bgcolor='<?php echo $bgcolor ?>'>
337 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : $docname ?>
338 </td>
340 <td class="detail"><?php echo oeFormatShortDate($appointment['pc_eventDate']) ?>
341 </td>
343 <td class="detail"><?php echo oeFormatTime($appointment['pc_startTime']) ?>
344 </td>
346 <td class="detail">&nbsp;<?php echo $appointment['fname'] . " " . $appointment['lname'] ?>
347 </td>
349 <td class="detail">&nbsp;<?php echo $appointment['pubpid'] ?></td>
351 <td class="detail">&nbsp;<?php echo $appointment['phone_home'] ?></td>
353 <td class="detail">&nbsp;<?php echo $appointment['phone_cell'] ?></td>
355 <td class="detail">&nbsp;<?php echo xl_appt_category($appointment['pc_catname']) ?></td>
357 <td class="detail">&nbsp;
358 <?php
359 //Appointment Status
360 if($pc_apptstatus != ""){
361 $frow['data_type']=1;
362 $frow['list_id']='apptstat';
363 generate_print_field($frow, $pc_apptstatus);
366 </td>
368 <td class="detail">&nbsp;<?php echo $appointment['pc_hometext'] ?></td>
370 </tr>
372 <?php
373 $lastdocname = $docname;
375 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
376 $_SESSION['pidList'] = $pid_list;
378 <tr>
379 <td colspan="10" align="left"><?php xl('Total number of appointments','e'); ?>:&nbsp;<?php echo $totalAppontments;?></td>
380 </tr>
381 </tbody>
382 </table>
383 </div>
384 <!-- end of search results --> <?php } else { ?>
385 <div class='text'><?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
386 </div>
387 <?php } ?> <input type="hidden" name="form_orderby"
388 value="<?php echo $form_orderby ?>" /> <input type="hidden"
389 name="patient" value="<?php echo $patient ?>" /> <input type='hidden'
390 name='form_refresh' id='form_refresh' value='' /></form>
392 <script type="text/javascript">
394 <?php
395 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
398 </script>
400 </body>
402 <!-- stuff for the popup calendar -->
403 <style type="text/css">
404 @import url(../../library/dynarch_calendar.css);
405 </style>
406 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
407 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
408 <script type="text/javascript"
409 src="../../library/dynarch_calendar_setup.js"></script>
410 <script type="text/javascript">
411 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
412 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
413 </script>
415 </html>