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>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Roberto Vasquez <robertogagliotta@gmail.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
27 $fake_register_globals=false;
29 require_once("../globals.php");
30 require_once("$srcdir/patient.inc");
31 require_once "$srcdir/options.inc.php";
33 $from_date = (isset($_POST['form_from_date'])) ?
fixDate($_POST['form_from_date'], date('Y-m-d')) : '';
34 $form_from_date = $from_date;
35 $to_date = (isset($_POST['form_to_date'])) ?
fixDate($_POST['form_to_date'], date('Y-m-d')) : '';;
36 $form_to_date = $to_date;
37 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
41 <?php
html_header_show();?
>
42 <title
><?php
echo xlt('Referrals'); ?
></title
>
44 <?php
$include_standard_style_js = array("datetimepicker","report_helper.js"); ?
>
45 <?php
require "{$GLOBALS['srcdir']}/templates/standard_header_template.php"; ?
>
47 <script language
="JavaScript">
49 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
51 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
53 $
(document
).ready(function() {
54 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
55 var win
= top
.printLogSetup ? top
: opener
.top
;
56 win
.printLogSetup(document
.getElementById('printbutton'));
58 $
('.datepicker').datetimepicker({
59 <?php
$datetimepicker_timepicker = false; ?
>
60 <?php
$datetimepicker_showseconds = false; ?
>
61 <?php
$datetimepicker_formatInput = false; ?
>
62 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
63 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
67 // The OnClick handler for referral display.
69 function show_referral(transid
) {
70 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid
,
71 '_blank', 550, 400,true); // Force new window rather than iframe because of the dynamic generation of the content in print_referral.php
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' onsubmit
='return top.restoreSession()'>
120 <div id
="report_parameters">
121 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
125 <div style
='float:left'>
129 <td
class='control-label'>
130 <?php
echo xlt('Facility'); ?
>:
133 <?php
dropdown_facility(($form_facility), 'form_facility', true); ?
>
135 <td
class='control-label'>
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 class='datepicker form-control'
141 title
='<?php echo xla('yyyy
-mm
-dd
') ?>'>
143 <td
class='control-label'>
144 <?php
echo xlt('To'); ?
>:
147 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>'
148 class='datepicker form-control'
149 title
='<?php echo xla('yyyy
-mm
-dd
') ?>'>
157 <td align
='left' valign
='middle' height
="100%">
158 <table style
='border-left:1px solid; width:100%; height:100%' >
161 <div
class="text-center">
162 <div
class="btn-group" role
="group">
163 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
164 <?php
echo xlt('Submit'); ?
>
166 <?php
if ($_POST['form_refresh']) { ?
>
167 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
168 <?php
echo xlt('Print'); ?
>
179 </div
> <!-- end of parameters
-->
182 if ($_POST['form_refresh']) {
184 <div id
="report_results">
185 <table width
='98%' id
='mymaintable'>
187 <th
> <?php
echo xlt('Refer To'); ?
> </th
>
188 <th
> <?php
echo xlt('Refer Date'); ?
> </th
>
189 <th
> <?php
echo xlt('Reply Date'); ?
> </th
>
190 <th
> <?php
echo xlt('Patient'); ?
> </th
>
191 <th
> <?php
echo xlt('ID'); ?
> </th
>
192 <th
> <?php
echo xlt('Reason'); ?
> </th
>
196 if ($_POST['form_refresh']) {
197 $query = "SELECT t.id, t.pid, " .
198 "d1.field_value AS refer_date, " .
199 "d3.field_value AS reply_date, " .
200 "d4.field_value AS body, " .
201 "ut.organization, uf.facility_id, p.pubpid, " .
202 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
203 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
204 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
205 "FROM transactions AS t " .
206 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
207 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
208 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
209 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
210 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
211 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
212 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
213 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
214 "WHERE t.title = 'LBTref' AND " .
215 "d1.field_value >= ? AND d1.field_value <= ? " .
216 "ORDER BY ut.organization, d1.field_value, t.id";
217 $res = sqlStatement($query, array($from_date, $to_date));
219 while ($row = sqlFetchArray($res)) {
220 // If a facility is specified, ignore rows that do not match.
221 if ($form_facility !== '') {
222 if ($form_facility) {
223 if ($row['facility_id'] != $form_facility) continue;
226 if (!empty($row['facility_id'])) continue;
233 <?php
if($row['organization']!=NULL ||
$row['organization']!='') {
234 echo text($row['organization']);
237 echo text($row['referer_to']);
243 <a href
='#' onclick
="return show_referral(<?php echo attr($row['id']); ?>)">
244 <?php
echo text(oeFormatShortDate($row['refer_date'])); ?
> 
;
248 <?php
echo text(oeFormatShortDate($row['reply_date'])) ?
>
251 <?php
echo text($row['patient_name']) ?
>
254 <?php
echo text($row['pubpid']) ?
>
257 <?php
echo text($row['body']) ?
>
266 </div
> <!-- end of results
-->
269 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>