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");
20 use OpenEMR\Common\Csrf\CsrfUtils
;
21 use OpenEMR\Core\Header
;
25 function bucks($amount)
28 return oeFormatMoney($amount);
34 $form_start_date = (!empty($_POST['form_start_date'])) ?
DateToYYYYMMDD($_POST['form_start_date']) : date('Y-01-01');
35 $form_end_date = (!empty($_POST['form_end_date'])) ?
DateToYYYYMMDD($_POST['form_end_date']) : date('Y-m-d');
43 /* specifically include & exclude from printing */
49 #report_parameters_daterange {
53 #report_results table {
58 /* specifically exclude some from the screen */
60 #report_parameters_daterange {
68 <?php Header
::setupHeader('datetime-picker'); ?
>
70 <title
><?php
echo xlt('Indigent Patients Report')?
></title
>
75 var win
= top
.printLogSetup ? top
: opener
.top
;
76 win
.printLogSetup(document
.getElementById('printbutton'));
78 $
('.datepicker').datetimepicker({
79 <?php
$datetimepicker_timepicker = false; ?
>
80 <?php
$datetimepicker_showseconds = false; ?
>
81 <?php
$datetimepicker_formatInput = true; ?
>
82 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
83 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
91 <body
class="body_top">
93 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Indigent Patients'); ?
></span
>
95 <form method
='post' action
='indigent_patients_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
96 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
98 <div id
="report_parameters">
100 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
105 <div style
='float: left'>
109 <td
class='col-form-label'>
110 <?php
echo xlt('Visits From'); ?
>:
113 <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)); ?>'>
115 <td
class='col-form-label'>
116 <?php
echo xlt('To{{Range}}'); ?
>:
119 <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)); ?>'>
127 <td
class='h-100' align
='left' valign
='middle'>
128 <table
class='w-100 h-100' style
='border-left: 1px solid;'>
131 <div
class="text-center">
132 <div
class="btn-group" role
="group">
133 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
134 <?php
echo xlt('Submit'); ?
>
136 <?php
if ($_POST['form_refresh']) { ?
>
137 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
138 <?php
echo xlt('Print'); ?
>
149 </div
> <!-- end of parameters
-->
151 <div id
="report_results">
152 <table
class='table'>
154 <thead
class="thead-light">
156  
;<?php
echo xlt('Patient'); ?
>
159  
;<?php
echo xlt('SSN'); ?
>
162  
;<?php
echo xlt('Invoice'); ?
>
165  
;<?php
echo xlt('Svc Date'); ?
>
168  
;<?php
echo xlt('Due Date'); ?
>
171 <?php
echo xlt('Amount'); ?
> 
;
174 <?php
echo xlt('Paid'); ?
> 
;
177 <?php
echo xlt('Balance'); ?
> 
;
182 if ($_POST['form_refresh']) {
183 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
184 CsrfUtils
::csrfNotVerified();
188 $sqlBindArray = array();
190 if ($form_start_date) {
191 $where .= " AND e.date >= ?";
192 array_push($sqlBindArray, $form_start_date);
195 if ($form_end_date) {
196 $where .= " AND e.date <= ?";
197 array_push($sqlBindArray, $form_end_date);
200 $rez = sqlStatement("SELECT " .
201 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
202 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
203 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
204 "AND i.provider = ''$where " .
205 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date", $sqlBindArray);
210 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
211 $patient_id = $row['pid'];
212 $encounter_id = $row['encounter'];
213 $invnumber = $row['pid'] . "." . $row['encounter'];
215 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
216 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
217 $inv_amount = $arow['amount'];
218 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
219 "pid = ? AND encounter = ? AND " .
220 "activity = 1 AND code_type != 'COPAY'", array($patient_id, $encounter_id));
221 $inv_amount +
= $arow['amount'];
222 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
223 "pid = ? AND encounter = ? AND " .
224 "activity = 1 AND code_type = 'COPAY'", array($patient_id, $encounter_id));
225 $inv_paid = 0 - $arow['amount'];
227 "SELECT SUM(pay_amount) AS pay, sum(adj_amount) AS adj " .
228 "FROM ar_activity WHERE pid = ? AND encounter = ? AND deleted IS NULL",
229 array($patient_id, $encounter_id)
231 $inv_paid +
= floatval($arow['pay']);
232 $inv_amount -= floatval($arow['adj']);
233 $total_amount +
= $inv_amount;
234 $total_paid +
= $inv_paid;
236 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
238 <tr bgcolor
='<?php echo $bgcolor ?>'>
240  
;<?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
>
243  
;<?php
echo text($row['ss']); ?
>
246  
;<?php
echo text($invnumber); ?
></a
>
249  
;<?php
echo text(oeFormatShortDate(substr($row['date'], 0, 10))); ?
>
252  
;<?php
echo text(oeFormatShortDate($inv_duedate)); ?
>
254 <td
class="detail" align
="right">
255 <?php
echo bucks($inv_amount); ?
> 
;
257 <td
class="detail" align
="right">
258 <?php
echo bucks($inv_paid); ?
> 
;
260 <td
class="detail" align
="right">
261 <?php
echo bucks($inv_amount - $inv_paid); ?
> 
;
267 <tr
class="table-light">
269  
;<?php
echo xlt('Totals'); ?
>
283 <td
class="detail" align
="right">
284 <?php
echo bucks($total_amount); ?
> 
;
286 <td
class="detail" align
="right">
287 <?php
echo bucks($total_paid); ?
> 
;
289 <td
class="detail" align
="right">
290 <?php
echo bucks($total_amount - $total_paid); ?
> 
;
304 echo "alert(" . js_escape($alertmsg) . ");\n";