Refactor Fee Sheet Printing to support an array of patient IDs from the appointment...
[openemr.git] / interface / reports / appointments_report.php
blob23bcb47d2322a97145140ee734be8a42b6a492bd
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;
36 //$to_date = fixDate($_POST['form_to_date'], '');
37 $provider = $_POST['form_provider'];
38 $facility = $_POST['form_facility']; //(CHEMED) facility filter
39 $form_orderby = getComparisonOrder( $_REQUEST['form_orderby'] ) ? $_REQUEST['form_orderby'] : 'date';
43 <html>
45 <head>
46 <?php html_header_show();?>
48 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
50 <title><?php xl('Appointments Report','e'); ?></title>
52 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
53 <script type="text/javascript" src="../../library/textformat.js"></script>
54 <script type="text/javascript" src="../../library/dialog.js"></script>
55 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
57 <script type="text/javascript">
59 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
61 function dosort(orderby) {
62 var f = document.forms[0];
63 f.form_orderby.value = orderby;
64 f.submit();
65 return false;
68 function oldEvt(eventid) {
69 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 550, 270);
72 function refreshme() {
73 // location.reload();
74 document.forms[0].submit();
77 </script>
79 <style type="text/css">
80 /* specifically include & exclude from printing */
81 @media print {
82 #report_parameters {
83 visibility: hidden;
84 display: none;
86 #report_parameters_daterange {
87 visibility: visible;
88 display: inline;
90 #report_results table {
91 margin-top: 0px;
95 /* specifically exclude some from the screen */
96 @media screen {
97 #report_parameters_daterange {
98 visibility: hidden;
99 display: none;
102 </style>
103 </head>
105 <body class="body_top">
107 <!-- Required for the popup date selectors -->
108 <div id="overDiv"
109 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
111 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Appointments','e'); ?></span>
113 <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)); ?>
114 </div>
116 <form method='post' name='theform' id='theform' action='appointments_report.php'>
118 <div id="report_parameters">
120 <table>
121 <tr>
122 <td width='650px'>
123 <div style='float: left'>
125 <table class='text'>
126 <tr>
127 <td class='label'><?php xl('Facility','e'); ?>:</td>
128 <td><?php dropdown_facility(strip_escape_custom($facility), 'form_facility'); ?>
129 </td>
130 <td class='label'><?php xl('Provider','e'); ?>:</td>
131 <td><?php
133 // Build a drop-down list of providers.
136 $query = "SELECT id, lname, fname FROM users WHERE ".
137 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
139 $ures = sqlStatement($query);
141 echo " <select name='form_provider'>\n";
142 echo " <option value=''>-- " . xl('All') . " --\n";
144 while ($urow = sqlFetchArray($ures)) {
145 $provid = $urow['id'];
146 echo " <option value='$provid'";
147 if ($provid == $_POST['form_provider']) echo " selected";
148 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
151 echo " </select>\n";
153 ?></td>
154 <td><input type='checkbox' name='form_show_available'
155 title='<?php xl('Show Available Times','e'); ?>'
156 <?php if ( $show_available_times ) echo ' checked'; ?>> <?php xl( 'Show Available Times','e' ); ?>
157 </td>
158 </tr>
159 <tr>
160 <td class='label'><?php xl('From','e'); ?>:</td>
161 <td><input type='text' name='form_from_date' id="form_from_date"
162 size='10' value='<?php echo $form_from_date ?>'
163 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
164 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
165 align='absbottom' width='24' height='22' id='img_from_date'
166 border='0' alt='[?]' style='cursor: pointer'
167 title='<?php xl('Click here to choose a date','e'); ?>'></td>
168 <td class='label'><?php xl('To','e'); ?>:</td>
169 <td><input type='text' name='form_to_date' id="form_to_date"
170 size='10' value='<?php echo $form_to_date ?>'
171 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
172 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
173 align='absbottom' width='24' height='22' id='img_to_date'
174 border='0' alt='[?]' style='cursor: pointer'
175 title='<?php xl('Click here to choose a date','e'); ?>'></td>
176 </tr>
177 </table>
179 </div>
181 </td>
182 <td align='left' valign='middle' height="100%">
183 <table style='border-left: 1px solid; width: 100%; height: 100%'>
184 <tr>
185 <td>
186 <div style='margin-left: 15px'>
187 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
188 <span> <?php xl('Submit','e'); ?> </span> </a>
189 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
190 <a href='#' class='css_button' onclick='window.print()'>
191 <span> <?php xl('Print','e'); ?> </span> </a>
192 <a href='#' class='css_button' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")'>
193 <span> <?php xl('Superbills','e'); ?> </span> </a>
194 <?php } ?></div>
195 </td>
196 </tr>
197 <tr>&nbsp;&nbsp;<?php xl('Most column headers can be clicked to change sort order','e') ?></tr>
198 </table>
199 </td>
200 </tr>
201 </table>
203 </div>
204 <!-- end of search parameters --> <?php
205 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
207 <div id="report_results">
208 <table>
210 <thead>
211 <th><a href="nojs.php" onclick="return dosort('doctor')"
212 <?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php xl('Provider','e'); ?>
213 </a></th>
215 <th><a href="nojs.php" onclick="return dosort('date')"
216 <?php if ($form_orderby == "date") echo " style=\"color:#00cc00\"" ?>><?php xl('Date','e'); ?></a>
217 </th>
219 <th><a href="nojs.php" onclick="return dosort('time')"
220 <?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php xl('Time','e'); ?></a>
221 </th>
223 <th><a href="nojs.php" onclick="return dosort('patient')"
224 <?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php xl('Patient','e'); ?></a>
225 </th>
227 <th><a href="nojs.php" onclick="return dosort('pubpid')"
228 <?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php xl('ID','e'); ?></a>
229 </th>
231 <th><?php xl('Home','e'); //Sorting by phone# not really useful ?></th>
233 <th><?php xl('Cell','e'); //Sorting by phone# not really useful ?></th>
235 <th><a href="nojs.php" onclick="return dosort('type')"
236 <?php if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?>><?php xl('Type','e'); ?></a>
237 </th>
239 <th><a href="nojs.php" onclick="return dosort('comment')"
240 <?php if ($form_orderby == "comment") echo " style=\"color:#00cc00\"" ?>><?php xl('Comment','e'); ?></a>
241 </th>
243 </thead>
244 <tbody>
245 <!-- added for better print-ability -->
246 <?php
248 $lastdocname = "";
249 $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility );
251 if ( $show_available_times ) {
252 $availableSlots = getAvailableSlots( $from_date, $to_date, $provider, $facility );
253 $appointments = array_merge( $appointments, $availableSlots );
256 $appointments = sortAppointments( $appointments, $form_orderby );
257 $pid_list = array(); // Initialize list of PIDs for Superbill option
259 foreach ( $appointments as $appointment ) {
260 array_push($pid_list,$appointment['pid']);
261 $patient_id = $appointment['pid'];
262 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
264 $errmsg = "";
268 <tr bgcolor='<?php echo $bgcolor ?>'>
269 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : $docname ?>
270 </td>
272 <td class="detail"><?php echo oeFormatShortDate($appointment['pc_eventDate']) ?>
273 </td>
275 <td class="detail"><?php echo oeFormatTime($appointment['pc_startTime']) ?>
276 </td>
278 <td class="detail">&nbsp;<?php echo $appointment['fname'] . " " . $appointment['lname'] ?>
279 </td>
281 <td class="detail">&nbsp;<?php echo $appointment['pubpid'] ?></td>
283 <td class="detail">&nbsp;<?php echo $appointment['phone_home'] ?></td>
285 <td class="detail">&nbsp;<?php echo $appointment['phone_cell'] ?></td>
287 <td class="detail">&nbsp;<?php echo xl_appt_category($appointment['pc_catname']) ?>
288 </td>
290 <td class="detail">&nbsp;<?php echo $appointment['pc_hometext'] ?></td>
292 </tr>
294 <?php
295 $lastdocname = $docname;
297 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
298 $_SESSION['pidList'] = $pid_list;
300 </tbody>
301 </table>
302 </div>
303 <!-- end of search results --> <?php } else { ?>
304 <div class='text'><?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
305 </div>
306 <?php } ?> <input type="hidden" name="form_orderby"
307 value="<?php echo $form_orderby ?>" /> <input type="hidden"
308 name="patient" value="<?php echo $patient ?>" /> <input type='hidden'
309 name='form_refresh' id='form_refresh' value='' /></form>
311 <script type="text/javascript">
313 <?php
314 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
317 </script>
319 </body>
321 <!-- stuff for the popup calendar -->
322 <style type="text/css">
323 @import url(../../library/dynarch_calendar.css);
324 </style>
325 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
326 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
327 <script type="text/javascript"
328 src="../../library/dynarch_calendar_setup.js"></script>
329 <script type="text/javascript">
330 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
331 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
332 </script>
334 </html>