2 // Copyright (C) 2005-2008 Rod Roark <rod@sunsetsystems.com>
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.
12 include_once("../globals.php");
13 include_once("../../library/patient.inc");
15 $alertmsg = ''; // not used yet but maybe later
17 // For each sorting option, specify the ORDER BY argument.
21 'doctor' => 'lower(u.lname), lower(u.fname), pc_eventDate, pc_startTime',
22 'patient' => 'lower(p.lname), lower(p.fname), pc_eventDate, pc_startTime',
23 'pubpid' => 'lower(p.pubpid), pc_eventDate, pc_startTime',
24 'time' => 'pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)',
25 'type' => 'pc_catname, pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)'
28 function bucks($amount) {
29 if ($amount) printf("%.2f", $amount);
32 $patient = $_REQUEST['patient'];
34 if ($patient && ! $_POST['form_from_date']) {
35 // If a specific patient, default to 2 years ago.
37 $from_date = date("$tmp-m-d");
39 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
40 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
43 //$to_date = fixDate($_POST['form_to_date'], '');
44 $provider = $_POST['form_provider'];
45 $facility = $_POST['form_facility']; //(CHEMED) facility filter
47 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ?
$_REQUEST['form_orderby'] : 'time';
49 $orderby = $ORDERHASH[$form_orderby];
51 $where = "e.pc_pid != '' AND e.pc_eventDate >= '$from_date'";
53 if ($to_date ) $where .= " AND e.pc_eventDate <= '$to_date'";
54 if ($provider) $where .= " AND e.pc_aid = '$provider'";
56 //(CHEMED) facility filter
57 $facility_filter = '';
59 $event_facility_filter = " AND e.pc_facility = '$facility'";
60 $provider_facility_filter = " AND users.facility_id = '$facility'";
64 if ($patient ) $where .= " AND e.pc_pid = '$patient'";
70 "e.pc_eventDate, e.pc_startTime, e.pc_catid, e.pc_eid, " .
71 "p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
72 "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, " .
74 "FROM openemr_postcalendar_events AS e " .
75 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
76 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
77 "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " .
78 "WHERE $where $event_facility_filter ORDER BY $orderby"; //(CHEMED) facility filter
80 $res = sqlStatement($query);
87 <?php
html_header_show();?
>
89 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
91 <title
><?php
xl('Appointments Report','e'); ?
></title
>
93 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
94 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
95 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
97 <script LANGUAGE
="JavaScript">
99 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
101 function dosort(orderby
) {
102 var f
= document
.forms
[0];
103 f
.form_orderby
.value
= orderby
;
108 function oldEvt(eventid
) {
109 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid
, 'blank', 550, 270);
112 function refreshme() {
113 // location.reload();
114 document
.forms
[0].submit();
120 /* specifically include & exclude from printing */
122 #apptreport_parameters {
126 #apptreport_parameters_daterange {
132 /* specifically exclude some from the screen */
134 #apptreport_parameters_daterange {
140 #apptreport_parameters {
143 background
-color
: #ddf;
145 #apptreport_parameters table {
147 border
-collapse
: collapse
;
149 #apptreport_parameters table td {
153 #apptreport_results {
157 #apptreport_results table {
158 border
: 1px solid black
;
160 border
-collapse
: collapse
;
162 #apptreport_results table thead {
163 display
: table
-header
-group
;
164 background
-color
: #ddd;
166 #apptreport_results table th {
167 border
-bottom
: 1px solid black
;
169 #apptreport_results table td {
177 <body
class="body_top">
179 <!-- Required
for the popup date selectors
-->
180 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
184 <h2
><?php
xl('Appointments Report','e'); ?
></h2
>
185 <div id
="apptreport_parameters_daterange">
186 <?php
echo date("d F Y", strtotime($from_date)) ." to ". date("d F Y", strtotime($to_date)); ?
>
189 <form method
='post' name
='theform' action
='appointments_report.php'>
191 <div id
="apptreport_parameters">
196 <?php
//(CHEMED) Facility filter
200 // Build a drop-down list of facilities.
203 $query = "SELECT id, name FROM facility WHERE " .
204 "service_location = 1 ORDER BY name ";
206 $ures = sqlStatement($query);
208 echo " <select name='form_facility' onChange='document.all.theform.submit()'>\n";
209 echo " <option value=''>-- All --\n";
211 while ($urow = sqlFetchArray($ures)) {
213 echo " <option value='$fid'";
214 if ($fid == $_POST['form_facility']) echo " selected";
215 echo ">" . $urow['name'] . "\n";
219 //END (CHEMED) Facility filter
222 <?php
xl('Provider','e'); ?
>:
226 // Build a drop-down list of providers.
229 $query = "SELECT id, lname, fname FROM users WHERE ".
230 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
232 $ures = sqlStatement($query);
234 echo " <select name='form_provider'>\n";
235 echo " <option value=''>-- All --\n";
237 while ($urow = sqlFetchArray($ures)) {
238 $provid = $urow['id'];
239 echo " <option value='$provid'";
240 if ($provid == $_POST['form_provider']) echo " selected";
241 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
248  
;<?php
xl('From','e'); ?
>:
250 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $from_date ?>'
251 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
252 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
253 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
254 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
256  
;<?php
xl('To','e'); ?
>:
258 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $to_date ?>'
259 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
260 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
261 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
262 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
265 <input type
='submit' name
='form_refresh' value
='<?php xl('Refresh
','e
'); ?>'>
267 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='window.print()' />
278 </div
> <!-- end of search parameters
-->
280 <div id
="apptreport_results">
285 <a href
="nojs.php" onclick
="return dosort('doctor')"
286 <?php
if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Provider','e'); ?
> </a
>
290 <a href
="nojs.php" onclick
="return dosort('time')"
291 <?php
if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Time','e'); ?
></a
>
295 <a href
="nojs.php" onclick
="return dosort('patient')"
296 <?php
if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Patient','e'); ?
></a
>
300 <a href
="nojs.php" onclick
="return dosort('pubpid')"
301 <?php
if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?
>><?php
xl('ID','e'); ?
></a
>
305 <a href
="nojs.php" onclick
="return dosort('type')"
306 <?php
if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Type','e'); ?
></a
>
310 <tbody
> <!-- added
for better
print-ability
-->
316 while ($row = sqlFetchArray($res)) {
317 $patient_id = $row['pid'];
318 $docname = $row['ulname'] . ', ' . $row['ufname'] . ' ' . $row['umname'];
323 <tr bgcolor
='<?php echo $bgcolor ?>'>
325  
;<?php
echo ($docname == $lastdocname) ?
"" : $docname ?
>
329 <?php
echo $row['pc_eventDate'] . ' ' . substr($row['pc_startTime'], 0, 5) ?
>
331  
;<a href
='javascript:oldEvt(<?php echo $row['pc_eid
'] ?>)'>
337  
;<?php
echo $row['fname'] . " " . $row['lname'] ?
>
341  
;<?php
echo $row['pubpid'] ?
>
345  
;<?php
echo $row['pc_catname'] ?
>
351 $lastdocname = $docname;
357 </div
> <!-- end of search results
-->
359 <input type
="hidden" name
="form_orderby" value
="<?php echo $form_orderby ?>" />
360 <input type
="hidden" name
="patient" value
="<?php echo $patient ?>" />
369 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
376 <!-- stuff
for the popup calendar
-->
377 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
378 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
379 <script type
="text/javascript" src
="../../library/dynarch_calendar_en.js"></script
>
380 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
381 <script language
="Javascript">
382 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
383 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});