4 * This report lists referrals for a given date range.
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2008-2016 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
13 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/patient.inc.php");
19 require_once "$srcdir/options.inc.php";
21 use OpenEMR\Common\Acl\AclMain
;
22 use OpenEMR\Common\Csrf\CsrfUtils
;
23 use OpenEMR\Common\Twig\TwigContainer
;
24 use OpenEMR\Core\Header
;
26 if (!AclMain
::aclCheckCore('patients', 'med')) {
27 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Referrals")]);
32 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
33 CsrfUtils
::csrfNotVerified();
37 $form_from_date = (isset($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
38 $form_to_date = (isset($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
39 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
43 <title
><?php
echo xlt('Referrals'); ?
></title
>
45 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
48 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
51 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
52 var win
= top
.printLogSetup ? top
: opener
.top
;
53 win
.printLogSetup(document
.getElementById('printbutton'));
55 $
('.datepicker').datetimepicker({
56 <?php
$datetimepicker_timepicker = false; ?
>
57 <?php
$datetimepicker_showseconds = false; ?
>
58 <?php
$datetimepicker_formatInput = true; ?
>
59 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
60 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
64 // The OnClick handler for referral display.
66 function show_referral(transid
) {
67 dlgopen('../patient_file/transaction/print_referral.php?transid=' +
encodeURIComponent(transid
),
68 '_blank', 550, 400,true); // Force new window rather than iframe because of the dynamic generation of the content in print_referral.php
74 /* specifically include & exclude from printing */
80 #report_parameters_daterange {
84 #report_results table {
89 /* specifically exclude some from the screen */
91 #report_parameters_daterange {
99 <body
class="body_top">
101 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Referrals'); ?
></span
>
103 <div id
="report_parameters_daterange">
104 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($form_to_date)); ?
>
107 <form name
='theform' id
='theform' method
='post' action
='referrals_report.php' onsubmit
='return top.restoreSession()'>
108 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
110 <div id
="report_parameters">
111 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
115 <div style
='float:left'>
119 <td
class='col-form-label'>
120 <?php
echo xlt('Facility'); ?
>:
123 <?php
dropdown_facility(($form_facility), 'form_facility', true); ?
>
125 <td
class='col-form-label'>
126 <?php
echo xlt('From'); ?
>:
129 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'
130 class='datepicker form-control'>
132 <td
class='col-form-label'>
133 <?php
echo xlt('To{{Range}}'); ?
>:
136 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'
137 class='datepicker form-control'>
145 <td
class='h-100' align
='left' valign
='middle'>
146 <table
class='w-100 h-100' style
='border-left:1px solid;'>
149 <div
class="text-center">
150 <div
class="btn-group" role
="group">
151 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
152 <?php
echo xlt('Submit'); ?
>
154 <?php
if (!empty($_POST['form_refresh'])) { ?
>
155 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
156 <?php
echo xlt('Print'); ?
>
167 </div
> <!-- end of parameters
-->
170 if (!empty($_POST['form_refresh'])) {
172 <div id
="report_results">
173 <table
class='table' width
='98%' id
='mymaintable'>
174 <thead
class='thead-light'>
175 <th
> <?php
echo xlt('Refer To'); ?
> </th
>
176 <th
> <?php
echo xlt('Refer Date'); ?
> </th
>
177 <th
> <?php
echo xlt('Reply Date'); ?
> </th
>
178 <th
> <?php
echo xlt('Patient'); ?
> </th
>
179 <th
> <?php
echo xlt('ID'); ?
> </th
>
180 <th
> <?php
echo xlt('Reason'); ?
> </th
>
184 if ($_POST['form_refresh']) {
185 $query = "SELECT t.id, t.pid, " .
186 "d1.field_value AS refer_date, " .
187 "d3.field_value AS reply_date, " .
188 "d4.field_value AS body, " .
189 "ut.organization, uf.facility_id, p.pubpid, " .
190 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
191 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
192 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
193 "FROM transactions AS t " .
194 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
195 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
196 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
197 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
198 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
199 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
200 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
201 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
202 "WHERE t.title = 'LBTref' AND " .
203 "d1.field_value >= ? AND d1.field_value <= ? " .
204 "ORDER BY ut.organization, d1.field_value, t.id";
205 $res = sqlStatement($query, array($form_from_date, $form_to_date));
207 while ($row = sqlFetchArray($res)) {
208 // If a facility is specified, ignore rows that do not match.
209 if ($form_facility !== '') {
210 if ($form_facility) {
211 if ($row['facility_id'] != $form_facility) {
215 if (!empty($row['facility_id'])) {
225 if ($row['organization'] != null ||
$row['organization'] != '') {
226 echo text($row['organization']);
228 echo text($row['referer_to']);
233 <a href
='#' onclick
="return show_referral(<?php echo js_escape($row['id']); ?>)">
234 <?php
echo text(oeFormatShortDate($row['refer_date'])); ?
> 
;
238 <?php
echo text(oeFormatShortDate($row['reply_date'])) ?
>
241 <?php
echo text($row['patient_name']) ?
>
244 <?php
echo text($row['pubpid']) ?
>
247 <?php
echo text($row['body']) ?
>
256 </div
> <!-- end of results
-->
259 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>