3 * This is the Indigent Patients Report. It displays a summary of
4 * encounters within the specified time period for patients without
7 * Copyright (C) 2005-2015 Rod Roark <rod@sunsetsystems.com>
8 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
28 require_once("../globals.php");
29 require_once("$srcdir/patient.inc");
33 function bucks($amount) {
34 if ($amount) return oeFormatMoney($amount);
38 $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01"));
39 $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d"));
44 <?php
html_header_show(); ?
>
45 <style type
="text/css">
47 /* specifically include & exclude from printing */
53 #report_parameters_daterange {
57 #report_results table {
62 /* specifically exclude some from the screen */
64 #report_parameters_daterange {
70 </style
><link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
71 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
73 <title
><?php
xl('Indigent Patients Report','e')?
></title
>
75 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
76 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
78 <script language
="JavaScript">
80 $
(document
).ready(function() {
81 var win
= top
.printLogSetup ? top
: opener
.top
;
82 win
.printLogSetup(document
.getElementById('printbutton'));
84 $
('.datepicker').datetimepicker({
85 <?php
$datetimepicker_timepicker = false; ?
>
86 <?php
$datetimepicker_showseconds = false; ?
>
87 <?php
$datetimepicker_formatInput = false; ?
>
88 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
89 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
97 <body
class="body_top">
99 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Indigent Patients','e'); ?
></span
>
101 <form method
='post' action
='indigent_patients_report.php' id
='theform'>
103 <div id
="report_parameters">
105 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
110 <div style
='float:left'>
115 <?php
xl('Visits From','e'); ?
>:
118 <input type
='text' class='datepicker' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo $form_start_date ?>'
122 <?php
xl('To','e'); ?
>:
125 <input type
='text' class='datepicker' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo $form_end_date ?>'
134 <td align
='left' valign
='middle' height
="100%">
135 <table style
='border-left:1px solid; width:100%; height:100%' >
138 <div style
='margin-left:15px'>
139 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
141 <?php
xl('Submit','e'); ?
>
145 <?php
if ($_POST['form_refresh']) { ?
>
146 <a href
='#' class='css_button' id
='printbutton'>
148 <?php
xl('Print','e'); ?
>
159 </div
> <!-- end of parameters
-->
161 <div id
="report_results">
164 <thead bgcolor
="#dddddd">
166  
;<?php
xl('Patient','e')?
>
169  
;<?php
xl('SSN','e')?
>
172  
;<?php
xl('Invoice','e')?
>
175  
;<?php
xl('Svc Date','e')?
>
178  
;<?php
xl('Due Date','e')?
>
181 <?php
xl('Amount','e')?
> 
;
184 <?php
xl('Paid','e')?
> 
;
187 <?php
xl('Balance','e')?
> 
;
192 if ($_POST['form_refresh']) {
196 if ($form_start_date) {
197 $where .= " AND e.date >= '$form_start_date'";
199 if ($form_end_date) {
200 $where .= " AND e.date <= '$form_end_date'";
203 $rez = sqlStatement("SELECT " .
204 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
205 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
206 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
207 "AND i.provider = ''$where " .
208 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
214 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
215 $patient_id = $row['pid'];
216 $encounter_id = $row['encounter'];
217 $invnumber = $row['pid'] . "." . $row['encounter'];
219 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
220 "pid = '$patient_id' AND encounter = '$encounter_id'");
221 $inv_amount = $arow['amount'];
222 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
223 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
224 "activity = 1 AND code_type != 'COPAY'");
225 $inv_amount +
= $arow['amount'];
226 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
227 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
228 "activity = 1 AND code_type = 'COPAY'");
229 $inv_paid = 0 - $arow['amount'];
230 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
231 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
232 "pid = '$patient_id' AND encounter = '$encounter_id'");
233 $inv_paid +
= $arow['pay'];
234 $inv_amount -= $arow['adj'];
235 $total_amount +
= bucks($inv_amount);
236 $total_paid +
= bucks($inv_paid);
238 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
240 <tr bgcolor
='<?php echo $bgcolor ?>'>
242  
;<?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
245  
;<?php
echo $row['ss'] ?
>
248  
;<?php
echo $invnumber ?
></a
>
251  
;<?php
echo oeFormatShortDate(substr($row['date'], 0, 10)) ?
>
254  
;<?php
echo oeFormatShortDate($inv_duedate) ?
>
256 <td
class="detail" align
="right">
257 <?php
echo bucks($inv_amount) ?
> 
;
259 <td
class="detail" align
="right">
260 <?php
echo bucks($inv_paid) ?
> 
;
262 <td
class="detail" align
="right">
263 <?php
echo bucks($inv_amount - $inv_paid) ?
> 
;
269 <tr bgcolor
='#dddddd'>
271  
;<?php
xl('Totals','e'); ?
>
285 <td
class="detail" align
="right">
286 <?php
echo bucks($total_amount) ?
> 
;
288 <td
class="detail" align
="right">
289 <?php
echo bucks($total_paid) ?
> 
;
291 <td
class="detail" align
="right">
292 <?php
echo bucks($total_amount - $total_paid) ?
> 
;
306 echo "alert('$alertmsg');\n";