4 * This is the Indigent Patients Report. It displays a summary of
5 * encounters within the specified time period for patients without
9 * @link http://www.open-emr.org
10 * @author Rod Roark <rod@sunsetsystems.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2005-2015, 2020 Rod Roark <rod@sunsetsystems.com>
13 * @copyright Copyright (c) 2017-2020 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");
20 use OpenEMR\Common\Acl\AclMain
;
21 use OpenEMR\Common\Csrf\CsrfUtils
;
22 use OpenEMR\Common\Twig\TwigContainer
;
23 use OpenEMR\Common\Utils\FormatMoney
;
24 use OpenEMR\Core\Header
;
26 if (!AclMain
::aclCheckCore('acct', 'rep_a')) {
27 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Indigent Patients Report")]);
33 $form_start_date = (!empty($_POST['form_start_date'])) ?
DateToYYYYMMDD($_POST['form_start_date']) : date('Y-01-01');
34 $form_end_date = (!empty($_POST['form_end_date'])) ?
DateToYYYYMMDD($_POST['form_end_date']) : date('Y-m-d');
42 /* specifically include & exclude from printing */
48 #report_parameters_daterange {
52 #report_results table {
57 /* specifically exclude some from the screen */
59 #report_parameters_daterange {
67 <?php Header
::setupHeader('datetime-picker'); ?
>
69 <title
><?php
echo xlt('Indigent Patients Report')?
></title
>
74 var win
= top
.printLogSetup ? top
: opener
.top
;
75 win
.printLogSetup(document
.getElementById('printbutton'));
77 $
('.datepicker').datetimepicker({
78 <?php
$datetimepicker_timepicker = false; ?
>
79 <?php
$datetimepicker_showseconds = false; ?
>
80 <?php
$datetimepicker_formatInput = true; ?
>
81 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
82 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
90 <body
class="body_top">
92 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Indigent Patients'); ?
></span
>
94 <form method
='post' action
='indigent_patients_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
95 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
97 <div id
="report_parameters">
99 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
104 <div style
='float: left'>
108 <td
class='col-form-label'>
109 <?php
echo xlt('Visits From'); ?
>:
112 <input type
='text' class='datepicker form-control' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_start_date)); ?>'>
114 <td
class='col-form-label'>
115 <?php
echo xlt('To{{Range}}'); ?
>:
118 <input type
='text' class='datepicker form-control' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_end_date)); ?>'>
126 <td
class='h-100' align
='left' valign
='middle'>
127 <table
class='w-100 h-100' style
='border-left: 1px solid;'>
130 <div
class="text-center">
131 <div
class="btn-group" role
="group">
132 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
133 <?php
echo xlt('Submit'); ?
>
135 <?php
if (!empty($_POST['form_refresh'])) { ?
>
136 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
137 <?php
echo xlt('Print'); ?
>
148 </div
> <!-- end of parameters
-->
150 <div id
="report_results">
151 <table
class='table'>
153 <thead
class="thead-light">
155  
;<?php
echo xlt('Patient'); ?
>
158  
;<?php
echo xlt('SSN'); ?
>
161  
;<?php
echo xlt('Invoice'); ?
>
164  
;<?php
echo xlt('Svc Date'); ?
>
167  
;<?php
echo xlt('Due Date'); ?
>
170 <?php
echo xlt('Amount'); ?
> 
;
173 <?php
echo xlt('Paid'); ?
> 
;
176 <?php
echo xlt('Balance'); ?
> 
;
181 if (!empty($_POST['form_refresh'])) {
182 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
183 CsrfUtils
::csrfNotVerified();
187 $sqlBindArray = array();
189 if ($form_start_date) {
190 $where .= " AND e.date >= ?";
191 array_push($sqlBindArray, $form_start_date);
194 if ($form_end_date) {
195 $where .= " AND e.date <= ?";
196 array_push($sqlBindArray, $form_end_date);
199 $rez = sqlStatement("SELECT " .
200 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
201 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
202 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
203 "AND i.provider = ''$where " .
204 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date", $sqlBindArray);
209 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
210 $patient_id = $row['pid'];
211 $encounter_id = $row['encounter'];
212 $invnumber = $row['pid'] . "." . $row['encounter'];
214 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
215 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
216 $inv_amount = $arow['amount'];
217 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
218 "pid = ? AND encounter = ? AND " .
219 "activity = 1 AND code_type != 'COPAY'", array($patient_id, $encounter_id));
220 $inv_amount +
= $arow['amount'];
221 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
222 "pid = ? AND encounter = ? AND " .
223 "activity = 1 AND code_type = 'COPAY'", array($patient_id, $encounter_id));
224 $inv_paid = 0 - $arow['amount'];
226 "SELECT SUM(pay_amount) AS pay, sum(adj_amount) AS adj " .
227 "FROM ar_activity WHERE pid = ? AND encounter = ? AND deleted IS NULL",
228 array($patient_id, $encounter_id)
230 $inv_paid +
= floatval($arow['pay']);
231 $inv_amount -= floatval($arow['adj']);
232 $total_amount +
= $inv_amount;
233 $total_paid +
= $inv_paid;
235 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
237 <tr bgcolor
='<?php echo $bgcolor ?>'>
239  
;<?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
>
242  
;<?php
echo text($row['ss']); ?
>
245  
;<?php
echo text($invnumber); ?
></a
>
248  
;<?php
echo text(oeFormatShortDate(substr($row['date'], 0, 10))); ?
>
251  
;<?php
echo text(oeFormatShortDate($inv_duedate)); ?
>
253 <td
class="detail" align
="right">
254 <?php
echo FormatMoney
::getBucks($inv_amount); ?
> 
;
256 <td
class="detail" align
="right">
257 <?php
echo FormatMoney
::getBucks($inv_paid); ?
> 
;
259 <td
class="detail" align
="right">
260 <?php
echo FormatMoney
::getBucks($inv_amount - $inv_paid); ?
> 
;
266 <tr
class="table-light">
268  
;<?php
echo xlt('Totals'); ?
>
282 <td
class="detail" align
="right">
283 <?php
echo FormatMoney
::getBucks($total_amount); ?
> 
;
285 <td
class="detail" align
="right">
286 <?php
echo FormatMoney
::getBucks($total_paid); ?
> 
;
288 <td
class="detail" align
="right">
289 <?php
echo FormatMoney
::getBucks($total_amount - $total_paid); ?
> 
;
303 echo "alert(" . js_escape($alertmsg) . ");\n";