3 * This is the Indigent Patients Report. It displays a summary of
4 * encounters within the specified time period for patients without
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2005-2015 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2017-2019 Brady Miller <brady.g.miller@gmail.com>
13 * @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\Core\Header
;
24 function bucks($amount)
27 return oeFormatMoney($amount);
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');
40 <style type
="text/css">
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
>
71 <script language
="JavaScript">
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(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='control-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='control-label'>
115 <?php
xl('To', 'e'); ?
>:
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 align
='left' valign
='middle' height
="100%">
127 <table style
='border-left:1px solid; width:100%; height:100%' >
130 <div
class="text-center">
131 <div
class="btn-group" role
="group">
132 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
133 <?php
echo xlt('Submit'); ?
>
135 <?php
if ($_POST['form_refresh']) { ?
>
136 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
137 <?php
echo xlt('Print'); ?
>
148 </div
> <!-- end of parameters
-->
150 <div id
="report_results">
153 <thead bgcolor
="#dddddd">
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 ($_POST['form_refresh']) {
182 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
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'];
225 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
226 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
227 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
228 $inv_paid +
= floatval($arow['pay']);
229 $inv_amount -= floatval($arow['adj']);
230 $total_amount +
= $inv_amount;
231 $total_paid +
= $inv_paid;
233 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
235 <tr bgcolor
='<?php echo $bgcolor ?>'>
237  
;<?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
>
240  
;<?php
echo text($row['ss']); ?
>
243  
;<?php
echo text($invnumber); ?
></a
>
246  
;<?php
echo text(oeFormatShortDate(substr($row['date'], 0, 10))); ?
>
249  
;<?php
echo text(oeFormatShortDate($inv_duedate)); ?
>
251 <td
class="detail" align
="right">
252 <?php
echo bucks($inv_amount); ?
> 
;
254 <td
class="detail" align
="right">
255 <?php
echo bucks($inv_paid); ?
> 
;
257 <td
class="detail" align
="right">
258 <?php
echo bucks($inv_amount - $inv_paid); ?
> 
;
264 <tr bgcolor
='#dddddd'>
266  
;<?php
echo xlt('Totals'); ?
>
280 <td
class="detail" align
="right">
281 <?php
echo bucks($total_amount); ?
> 
;
283 <td
class="detail" align
="right">
284 <?php
echo bucks($total_paid); ?
> 
;
286 <td
class="detail" align
="right">
287 <?php
echo bucks($total_amount - $total_paid); ?
> 
;
301 echo "alert(" . js_escape($alertmsg) . ");\n";