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 use OpenEMR\Core\Header
;
18 require_once("../globals.php");
19 require_once("$srcdir/patient.inc");
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()'>
95 <div id
="report_parameters">
97 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
102 <div style
='float:left'>
106 <td
class='control-label'>
107 <?php
echo xlt('Visits From'); ?
>:
110 <input type
='text' class='datepicker form-control' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo oeFormatShortDate($form_start_date); ?>'>
112 <td
class='control-label'>
113 <?php
xl('To', 'e'); ?
>:
116 <input type
='text' class='datepicker form-control' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo oeFormatShortDate($form_end_date); ?>'>
124 <td align
='left' valign
='middle' height
="100%">
125 <table style
='border-left:1px solid; width:100%; height:100%' >
128 <div
class="text-center">
129 <div
class="btn-group" role
="group">
130 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
131 <?php
echo xlt('Submit'); ?
>
133 <?php
if ($_POST['form_refresh']) { ?
>
134 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
135 <?php
echo xlt('Print'); ?
>
146 </div
> <!-- end of parameters
-->
148 <div id
="report_results">
151 <thead bgcolor
="#dddddd">
153  
;<?php
echo xlt('Patient'); ?
>
156  
;<?php
echo xlt('SSN'); ?
>
159  
;<?php
echo xlt('Invoice'); ?
>
162  
;<?php
echo xlt('Svc Date'); ?
>
165  
;<?php
echo xlt('Due Date'); ?
>
168 <?php
echo xlt('Amount'); ?
> 
;
171 <?php
echo xlt('Paid'); ?
> 
;
174 <?php
echo xlt('Balance'); ?
> 
;
179 if ($_POST['form_refresh']) {
181 $sqlBindArray = array();
183 if ($form_start_date) {
184 $where .= " AND e.date >= ?";
185 array_push($sqlBindArray, $form_start_date);
188 if ($form_end_date) {
189 $where .= " AND e.date <= ?";
190 array_push($sqlBindArray, $form_end_date);
193 $rez = sqlStatement("SELECT " .
194 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
195 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
196 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
197 "AND i.provider = ''$where " .
198 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date", $sqlBindArray);
203 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
204 $patient_id = $row['pid'];
205 $encounter_id = $row['encounter'];
206 $invnumber = $row['pid'] . "." . $row['encounter'];
208 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
209 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
210 $inv_amount = $arow['amount'];
211 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
212 "pid = ? AND encounter = ? AND " .
213 "activity = 1 AND code_type != 'COPAY'", array($patient_id, $encounter_id));
214 $inv_amount +
= $arow['amount'];
215 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
216 "pid = ? AND encounter = ? AND " .
217 "activity = 1 AND code_type = 'COPAY'", array($patient_id, $encounter_id));
218 $inv_paid = 0 - $arow['amount'];
219 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
220 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
221 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
222 $inv_paid +
= $arow['pay'];
223 $inv_amount -= $arow['adj'];
224 $total_amount +
= bucks($inv_amount);
225 $total_paid +
= bucks($inv_paid);
227 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
229 <tr bgcolor
='<?php echo $bgcolor ?>'>
231  
;<?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
>
234  
;<?php
echo text($row['ss']); ?
>
237  
;<?php
echo text($invnumber); ?
></a
>
240  
;<?php
echo oeFormatShortDate(substr($row['date'], 0, 10)); ?
>
243  
;<?php
echo oeFormatShortDate($inv_duedate); ?
>
245 <td
class="detail" align
="right">
246 <?php
echo bucks($inv_amount); ?
> 
;
248 <td
class="detail" align
="right">
249 <?php
echo bucks($inv_paid); ?
> 
;
251 <td
class="detail" align
="right">
252 <?php
echo bucks($inv_amount - $inv_paid); ?
> 
;
258 <tr bgcolor
='#dddddd'>
260  
;<?php
echo xlt('Totals'); ?
>
274 <td
class="detail" align
="right">
275 <?php
echo bucks($total_amount); ?
> 
;
277 <td
class="detail" align
="right">
278 <?php
echo bucks($total_paid); ?
> 
;
280 <td
class="detail" align
="right">
281 <?php
echo bucks($total_amount - $total_paid); ?
> 
;
295 echo "alert('" . addslashes($alertmsg) . "');\n";