2 // Copyright (C) 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 lists referrals for a given date range.
11 include_once("../globals.php");
12 include_once("$srcdir/patient.inc");
14 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
15 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
16 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
20 <?php
html_header_show();?
>
21 <title
><?php
xl('Referrals','e'); ?
></title
>
23 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
25 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
26 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
27 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
28 <script type
="text/javascript" src
="../../library/dynarch_calendar_en.js"></script
>
29 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
30 <script language
="JavaScript">
32 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
34 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
36 // The OnClick handler for referral display.
37 function show_referral(transid
) {
38 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid
,
45 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
46 <style type
="text/css">
48 /* specifically include & exclude from printing */
50 #referreport_parameters {
54 #referreport_parameters_daterange {
60 /* specifically exclude some from the screen */
62 #referreport_parameters_daterange {
68 #referreport_parameters {
70 background
-color
: #ddf;
72 #referreport_parameters table {
74 border
-collapse
: collapse
;
76 #referreport_parameters table td {
80 #referreport_results {
84 #referreport_results table {
85 border
: 1px solid black
;
87 border
-collapse
: collapse
;
89 #referreport_results table thead {
90 display
: table
-header
-group
;
91 background
-color
: #ddd;
93 #referreport_results table th {
94 border
-bottom
: 1px solid black
;
97 #referreport_results table td {
100 border
-bottom
: 1px solid
#eee;
103 .referreport_totals td
{
104 background
-color
: #77ff77;
110 <body
class="body_top">
114 <h2
><?php
xl('Referrals','e'); ?
></h2
>
116 <div id
="referreport_parameters_daterange">
117 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
120 <div id
="referreport_parameters">
121 <form name
='theform' method
='post' action
='referrals_report.php'>
126 // Build a drop-down list of facilities.
128 $query = "SELECT id, name FROM facility ORDER BY name";
129 $fres = sqlStatement($query);
130 echo " <select name='form_facility'>\n";
131 echo " <option value=''>-- " . xl('All Facilities') . " --\n";
132 while ($frow = sqlFetchArray($fres)) {
133 $facid = $frow['id'];
134 echo " <option value='$facid'";
135 if ($facid == $form_facility) echo " selected";
136 echo ">" . $frow['name'] . "\n";
138 echo " <option value='0'";
139 if ($form_facility === '0') echo " selected";
140 echo ">-- " . xl('Unspecified') . " --\n";
143  
;<?php
xl('From','e'); ?
>:
144 <input type
='text' size
='10' name
='form_from_date' id
='form_from_date'
145 value
='<?php echo $from_date ?>'
146 title
='<?php xl('yyyy
-mm
-dd
','e
'); ?>'
147 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
148 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
149 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
150 title
='<?php xl('Click here to choose a date
','e
'); ?>' />
151  
;<?php
xl('To','e'); ?
>:
152 <input type
='text' size
='10' name
='form_to_date' id
='form_to_date'
153 value
='<?php echo $to_date ?>'
154 title
='<?php xl('yyyy
-mm
-dd
','e
'); ?>'
155 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
156 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
157 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
158 title
='<?php xl('Click here to choose a date
','e
'); ?>' />
160 <input type
='submit' name
='form_refresh' value
=<?php
xl('Refresh','e'); ?
>>
162 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='window.print()' />
166 </div
> <!-- end of parameters
-->
169 <div id
="referreport_results">
172 <th
> <?php
xl('Refer To','e'); ?
> </th
>
173 <th
> <?php
xl('Refer Date','e'); ?
> </th
>
174 <th
> <?php
xl('Reply Date','e'); ?
> </th
>
175 <th
> <?php
xl('Patient','e'); ?
> </th
>
176 <th
> <?php
xl('ID','e'); ?
> </th
>
177 <th
> <?php
xl('Reason','e'); ?
> </th
>
181 if ($_POST['form_refresh']) {
182 $query = "SELECT t.id, t.refer_date, t.reply_date, t.body, " .
183 "ut.organization, uf.facility_id, p.pubpid, " .
184 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
185 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
186 "FROM transactions AS t " .
187 "LEFT OUTER JOIN patient_data AS p ON p.pid = t.pid " .
188 "LEFT OUTER JOIN users AS ut ON ut.id = t.refer_to " .
189 "LEFT OUTER JOIN users AS uf ON uf.id = t.refer_from " .
190 "WHERE t.title = 'Referral' AND " .
191 "t.refer_date >= '$from_date' AND t.refer_date <= '$to_date' " .
192 "ORDER BY ut.organization, t.refer_date, t.id";
194 // echo "<!-- $query -->\n"; // debugging
195 $res = sqlStatement($query);
197 while ($row = sqlFetchArray($res)) {
198 // If a facility is specified, ignore rows that do not match.
199 if ($form_facility !== '') {
200 if ($form_facility) {
201 if ($row['facility_id'] != $form_facility) continue;
204 if (!empty($row['facility_id'])) continue;
210 <?php
echo $row['organization'] ?
>
213 <a href
='#' onclick
="return show_referral(<?php echo $row['id']; ?>)">
214 <?php
echo $row['refer_date']; ?
> 
;
218 <?php
echo $row['reply_date'] ?
>
221 <?php
echo $row['patient_name'] ?
>
224 <?php
echo $row['pubpid'] ?
>
227 <?php
echo $row['body'] ?
>
236 </div
> <!-- end of results
-->
240 <script language
='JavaScript'>
241 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
242 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});