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 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../globals.php");
17 require_once("$srcdir/patient.inc");
19 use OpenEMR\Core\Header
;
23 function bucks($amount)
26 return oeFormatMoney($amount);
32 $form_start_date = (!empty($_POST['form_start_date'])) ?
DateToYYYYMMDD($_POST['form_start_date']) : date('Y-01-01');
33 $form_end_date = (!empty($_POST['form_end_date'])) ?
DateToYYYYMMDD($_POST['form_end_date']) : date('Y-m-d');
39 <style type
="text/css">
41 /* specifically include & exclude from printing */
47 #report_parameters_daterange {
51 #report_results table {
56 /* specifically exclude some from the screen */
58 #report_parameters_daterange {
66 <?php Header
::setupHeader('datetime-picker'); ?
>
68 <title
><?php
echo xlt('Indigent Patients Report')?
></title
>
70 <script language
="JavaScript">
72 $
(document
).ready(function() {
73 var win
= top
.printLogSetup ? top
: opener
.top
;
74 win
.printLogSetup(document
.getElementById('printbutton'));
76 $
('.datepicker').datetimepicker({
77 <?php
$datetimepicker_timepicker = false; ?
>
78 <?php
$datetimepicker_showseconds = false; ?
>
79 <?php
$datetimepicker_formatInput = true; ?
>
80 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
81 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
89 <body
class="body_top">
91 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Indigent Patients'); ?
></span
>
93 <form method
='post' action
='indigent_patients_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
94 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(collectCsrfToken()); ?>" />
96 <div id
="report_parameters">
98 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
103 <div style
='float:left'>
107 <td
class='control-label'>
108 <?php
echo xlt('Visits From'); ?
>:
111 <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)); ?>'>
113 <td
class='control-label'>
114 <?php
xl('To', 'e'); ?
>:
117 <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)); ?>'>
125 <td align
='left' valign
='middle' height
="100%">
126 <table style
='border-left:1px solid; width:100%; height:100%' >
129 <div
class="text-center">
130 <div
class="btn-group" role
="group">
131 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
132 <?php
echo xlt('Submit'); ?
>
134 <?php
if ($_POST['form_refresh']) { ?
>
135 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
136 <?php
echo xlt('Print'); ?
>
147 </div
> <!-- end of parameters
-->
149 <div id
="report_results">
152 <thead bgcolor
="#dddddd">
154  
;<?php
echo xlt('Patient'); ?
>
157  
;<?php
echo xlt('SSN'); ?
>
160  
;<?php
echo xlt('Invoice'); ?
>
163  
;<?php
echo xlt('Svc Date'); ?
>
166  
;<?php
echo xlt('Due Date'); ?
>
169 <?php
echo xlt('Amount'); ?
> 
;
172 <?php
echo xlt('Paid'); ?
> 
;
175 <?php
echo xlt('Balance'); ?
> 
;
180 if ($_POST['form_refresh']) {
181 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
186 $sqlBindArray = array();
188 if ($form_start_date) {
189 $where .= " AND e.date >= ?";
190 array_push($sqlBindArray, $form_start_date);
193 if ($form_end_date) {
194 $where .= " AND e.date <= ?";
195 array_push($sqlBindArray, $form_end_date);
198 $rez = sqlStatement("SELECT " .
199 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
200 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
201 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
202 "AND i.provider = ''$where " .
203 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date", $sqlBindArray);
208 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
209 $patient_id = $row['pid'];
210 $encounter_id = $row['encounter'];
211 $invnumber = $row['pid'] . "." . $row['encounter'];
213 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
214 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
215 $inv_amount = $arow['amount'];
216 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
217 "pid = ? AND encounter = ? AND " .
218 "activity = 1 AND code_type != 'COPAY'", array($patient_id, $encounter_id));
219 $inv_amount +
= $arow['amount'];
220 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
221 "pid = ? AND encounter = ? AND " .
222 "activity = 1 AND code_type = 'COPAY'", array($patient_id, $encounter_id));
223 $inv_paid = 0 - $arow['amount'];
224 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
225 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
226 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
227 $inv_paid +
= floatval($arow['pay']);
228 $inv_amount -= floatval($arow['adj']);
229 $total_amount +
= $inv_amount;
230 $total_paid +
= $inv_paid;
232 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
234 <tr bgcolor
='<?php echo $bgcolor ?>'>
236  
;<?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
>
239  
;<?php
echo text($row['ss']); ?
>
242  
;<?php
echo text($invnumber); ?
></a
>
245  
;<?php
echo text(oeFormatShortDate(substr($row['date'], 0, 10))); ?
>
248  
;<?php
echo text(oeFormatShortDate($inv_duedate)); ?
>
250 <td
class="detail" align
="right">
251 <?php
echo bucks($inv_amount); ?
> 
;
253 <td
class="detail" align
="right">
254 <?php
echo bucks($inv_paid); ?
> 
;
256 <td
class="detail" align
="right">
257 <?php
echo bucks($inv_amount - $inv_paid); ?
> 
;
263 <tr bgcolor
='#dddddd'>
265  
;<?php
echo xlt('Totals'); ?
>
279 <td
class="detail" align
="right">
280 <?php
echo bucks($total_amount); ?
> 
;
282 <td
class="detail" align
="right">
283 <?php
echo bucks($total_paid); ?
> 
;
285 <td
class="detail" align
="right">
286 <?php
echo bucks($total_amount - $total_paid); ?
> 
;
300 echo "alert('" . addslashes($alertmsg) . "');\n";