3 * This report lists referrals for a given date range.
5 * Copyright (C) 2008-2016 Rod Roark <rod@sunsetsystems.com>
6 * Copyright (C) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @author Rod Roark <rod@sunsetsystems.com>
21 * @author Roberto Vasquez <robertogagliotta@gmail.com>
22 * @link http://www.open-emr.org
25 $fake_register_globals=false;
26 $sanitize_all_escapes=true;
28 require_once("../globals.php");
29 require_once("$srcdir/patient.inc");
30 require_once("$srcdir/formatting.inc.php");
31 require_once "$srcdir/options.inc.php";
32 require_once "$srcdir/formdata.inc.php";
34 $from_date = (isset($_POST['form_from_date'])) ?
fixDate($_POST['form_from_date'], date('Y-m-d')) : '';
35 $form_from_date = $from_date;
36 $to_date = (isset($_POST['form_to_date'])) ?
fixDate($_POST['form_to_date'], date('Y-m-d')) : '';;
37 $form_to_date = $to_date;
38 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
42 <?php
html_header_show();?
>
43 <title
><?php
echo xlt('Referrals'); ?
></title
>
45 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
47 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
48 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
49 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
50 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
51 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
52 <script type
="text/javascript" src
="../../library/js/jquery-1.9.1.min.js"></script
>
53 <script type
="text/javascript" src
="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script
>
54 <script language
="JavaScript">
56 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
58 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
60 $
(document
).ready(function() {
61 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
62 var win
= top
.printLogSetup ? top
: opener
.top
;
63 win
.printLogSetup(document
.getElementById('printbutton'));
66 // The OnClick handler for referral display.
68 function show_referral(transid
) {
69 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid
,
76 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
77 <style type
="text/css">
79 /* specifically include & exclude from printing */
85 #report_parameters_daterange {
89 #report_results table {
94 /* specifically exclude some from the screen */
96 #report_parameters_daterange {
104 <script language
="JavaScript">
110 <body
class="body_top">
112 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Referrals'); ?
></span
>
114 <div id
="report_parameters_daterange">
115 <?php
echo text(date("d F Y", strtotime($form_from_date))) ." to ". text(date("d F Y", strtotime($form_to_date))); ?
>
118 <form name
='theform' id
='theform' method
='post' action
='referrals_report.php'>
120 <div id
="report_parameters">
121 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
125 <div style
='float:left'>
130 <?php
echo xlt('Facility'); ?
>:
133 <?php
dropdown_facility(($form_facility), 'form_facility', true); ?
>
136 <?php
echo xlt('From'); ?
>:
139 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date) ?>'
140 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='<?php echo xla('yyyy
-mm
-dd
') ?>'>
141 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
142 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
143 title
='<?php echo xla('Click here to choose a date
'); ?>'>
146 <?php
echo xlt('To'); ?
>:
149 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>'
150 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='<?php echo xla('yyyy
-mm
-dd
') ?>'>
151 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
152 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
153 title
='<?php echo xla('Click here to choose a date
'); ?>'>
161 <td align
='left' valign
='middle' height
="100%">
162 <table style
='border-left:1px solid; width:100%; height:100%' >
165 <div style
='margin-left:15px'>
166 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
168 <?php
echo xlt('Submit'); ?
>
172 <?php
if ($_POST['form_refresh']) { ?
>
173 <a href
='#' class='css_button' id
='printbutton'>
175 <?php
echo xlt('Print'); ?
>
186 </div
> <!-- end of parameters
-->
189 if ($_POST['form_refresh']) {
191 <div id
="report_results">
192 <table width
='98%' id
='mymaintable'>
194 <th
> <?php
echo xlt('Refer To'); ?
> </th
>
195 <th
> <?php
echo xlt('Refer Date'); ?
> </th
>
196 <th
> <?php
echo xlt('Reply Date'); ?
> </th
>
197 <th
> <?php
echo xlt('Patient'); ?
> </th
>
198 <th
> <?php
echo xlt('ID'); ?
> </th
>
199 <th
> <?php
echo xlt('Reason'); ?
> </th
>
203 if ($_POST['form_refresh']) {
204 $query = "SELECT t.id, t.pid, " .
205 "d1.field_value AS refer_date, " .
206 "d3.field_value AS reply_date, " .
207 "d4.field_value AS body, " .
208 "ut.organization, uf.facility_id, p.pubpid, " .
209 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
210 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
211 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
212 "FROM transactions AS t " .
213 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
214 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
215 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
216 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
217 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
218 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
219 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
220 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
221 "WHERE t.title = 'LBTref' AND " .
222 "d1.field_value >= ? AND d1.field_value <= ? " .
223 "ORDER BY ut.organization, d1.field_value, t.id";
224 $res = sqlStatement($query, array($from_date, $to_date));
226 while ($row = sqlFetchArray($res)) {
227 // If a facility is specified, ignore rows that do not match.
228 if ($form_facility !== '') {
229 if ($form_facility) {
230 if ($row['facility_id'] != $form_facility) continue;
233 if (!empty($row['facility_id'])) continue;
240 <?php
if($row['organization']!=NULL ||
$row['organization']!='') {
241 echo text($row['organization']);
244 echo text($row['referer_to']);
250 <a href
='#' onclick
="return show_referral(<?php echo attr($row['id']); ?>)">
251 <?php
echo text(oeFormatShortDate($row['refer_date'])); ?
> 
;
255 <?php
echo text(oeFormatShortDate($row['reply_date'])) ?
>
258 <?php
echo text($row['patient_name']) ?
>
261 <?php
echo text($row['pubpid']) ?
>
264 <?php
echo text($row['body']) ?
>
273 </div
> <!-- end of results
-->
276 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
281 <script language
='JavaScript'>
282 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
283 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});