2 // Copyright (C) 2005-2015 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This is the Indigent Patients Report. It displays a summary of
10 // encounters within the specified time period for patients without
13 require_once("../globals.php");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/sql-ledger.inc");
16 require_once("$srcdir/formatting.inc.php");
20 function bucks($amount) {
21 if ($amount) return oeFormatMoney($amount);
25 $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01"));
26 $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d"));
28 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
30 if (!$INTEGRATED_AR) SLConnect();
34 <?php
html_header_show(); ?
>
35 <style type
="text/css">
37 /* specifically include & exclude from printing */
43 #report_parameters_daterange {
47 #report_results table {
52 /* specifically exclude some from the screen */
54 #report_parameters_daterange {
59 </style
><link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
60 <title
><?php
xl('Indigent Patients Report','e')?
></title
>
62 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
64 <script language
="JavaScript">
66 $
(document
).ready(function() {
67 var win
= top
.printLogSetup ? top
: opener
.top
;
68 win
.printLogSetup(document
.getElementById('printbutton'));
75 <body
class="body_top">
77 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Indigent Patients','e'); ?
></span
>
79 <form method
='post' action
='indigent_patients_report.php' id
='theform'>
81 <div id
="report_parameters">
83 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
88 <div style
='float:left'>
93 <?php
xl('Visits From','e'); ?
>:
96 <input type
='text' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo $form_start_date ?>'
97 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
98 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
99 id
='img_start_date' border
='0' alt
='[?]' style
='cursor:pointer'
100 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
103 <?php
xl('To','e'); ?
>:
106 <input type
='text' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo $form_end_date ?>'
107 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
108 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
109 id
='img_end_date' border
='0' alt
='[?]' style
='cursor:pointer'
110 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
118 <td align
='left' valign
='middle' height
="100%">
119 <table style
='border-left:1px solid; width:100%; height:100%' >
122 <div style
='margin-left:15px'>
123 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
125 <?php
xl('Submit','e'); ?
>
129 <?php
if ($_POST['form_refresh']) { ?
>
130 <a href
='#' class='css_button' id
='printbutton'>
132 <?php
xl('Print','e'); ?
>
143 </div
> <!-- end of parameters
-->
145 <div id
="report_results">
148 <thead bgcolor
="#dddddd">
150  
;<?php
xl('Patient','e')?
>
153  
;<?php
xl('SSN','e')?
>
156  
;<?php
xl('Invoice','e')?
>
159  
;<?php
xl('Svc Date','e')?
>
162  
;<?php
xl('Due Date','e')?
>
165 <?php
xl('Amount','e')?
> 
;
168 <?php
xl('Paid','e')?
> 
;
171 <?php
xl('Balance','e')?
> 
;
176 if ($_POST['form_search']) {
180 if ($form_start_date) {
181 $where .= " AND e.date >= '$form_start_date'";
183 if ($form_end_date) {
184 $where .= " AND e.date <= '$form_end_date'";
187 $rez = sqlStatement("SELECT " .
188 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
189 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
190 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
191 "AND i.provider = ''$where " .
192 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
198 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
199 $patient_id = $row['pid'];
200 $encounter_id = $row['encounter'];
201 $invnumber = $row['pid'] . "." . $row['encounter'];
203 if ($INTEGRATED_AR) {
205 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
206 "pid = '$patient_id' AND encounter = '$encounter_id'");
207 $inv_amount = $arow['amount'];
208 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
209 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
210 "activity = 1 AND code_type != 'COPAY'");
211 $inv_amount +
= $arow['amount'];
212 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
213 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
214 "activity = 1 AND code_type = 'COPAY'");
215 $inv_paid = 0 - $arow['amount'];
216 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
217 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
218 "pid = '$patient_id' AND encounter = '$encounter_id'");
219 $inv_paid +
= $arow['pay'];
220 $inv_amount -= $arow['adj'];
223 $ares = SLQuery("SELECT duedate, amount, paid FROM ar WHERE " .
224 "ar.invnumber = '$invnumber'");
225 if ($sl_err) die($sl_err);
226 if (SLRowCount($ares) == 0) continue;
227 $arow = SLGetRow($ares, 0);
228 $inv_amount = $arow['amount'];
229 $inv_paid = $arow['paid'];
230 $inv_duedate = $arow['duedate'];
232 $total_amount +
= bucks($inv_amount);
233 $total_paid +
= bucks($inv_paid);
235 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
237 <tr bgcolor
='<?php echo $bgcolor ?>'>
239  
;<?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
242  
;<?php
echo $row['ss'] ?
>
245  
;<?php
echo $invnumber ?
></a
>
248  
;<?php
echo oeFormatShortDate(substr($row['date'], 0, 10)) ?
>
251  
;<?php
echo oeFormatShortDate($inv_duedate) ?
>
253 <td
class="detail" align
="right">
254 <?php
echo bucks($inv_amount) ?
> 
;
256 <td
class="detail" align
="right">
257 <?php
echo bucks($inv_paid) ?
> 
;
259 <td
class="detail" align
="right">
260 <?php
echo bucks($inv_amount - $inv_paid) ?
> 
;
266 <tr bgcolor
='#dddddd'>
268  
;<?php
xl('Totals','e'); ?
>
282 <td
class="detail" align
="right">
283 <?php
echo bucks($total_amount) ?
> 
;
285 <td
class="detail" align
="right">
286 <?php
echo bucks($total_paid) ?
> 
;
288 <td
class="detail" align
="right">
289 <?php
echo bucks($total_amount - $total_paid) ?
> 
;
294 if (!$INTEGRATED_AR) SLClose();
304 echo "alert('$alertmsg');\n";
310 <!-- stuff
for the popup calendar
-->
311 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
312 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
313 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
314 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
315 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
316 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
318 <script language
="Javascript">
319 Calendar
.setup({inputField
:"form_start_date", ifFormat
:"%Y-%m-%d", button
:"img_start_date"});
320 Calendar
.setup({inputField
:"form_end_date", ifFormat
:"%Y-%m-%d", button
:"img_end_date"});