2 // Copyright (C) 2005-2010 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">
70 <body
class="body_top">
72 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Indigent Patients','e'); ?
></span
>
74 <form method
='post' action
='indigent_patients_report.php' id
='theform'>
76 <div id
="report_parameters">
78 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
83 <div style
='float:left'>
88 <?php
xl('Visits From','e'); ?
>:
91 <input type
='text' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo $form_start_date ?>'
92 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
93 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
94 id
='img_start_date' border
='0' alt
='[?]' style
='cursor:pointer'
95 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
98 <?php
xl('To','e'); ?
>:
101 <input type
='text' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo $form_end_date ?>'
102 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
103 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
104 id
='img_end_date' border
='0' alt
='[?]' style
='cursor:pointer'
105 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
113 <td align
='left' valign
='middle' height
="100%">
114 <table style
='border-left:1px solid; width:100%; height:100%' >
117 <div style
='margin-left:15px'>
118 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
120 <?php
xl('Submit','e'); ?
>
124 <?php
if ($_POST['form_refresh']) { ?
>
125 <a href
='#' class='css_button' onclick
='window.print()'>
127 <?php
xl('Print','e'); ?
>
138 </div
> <!-- end of parameters
-->
140 <div id
="report_results">
143 <thead bgcolor
="#dddddd">
145  
;<?php
xl('Patient','e')?
>
148  
;<?php
xl('SSN','e')?
>
151  
;<?php
xl('Invoice','e')?
>
154  
;<?php
xl('Svc Date','e')?
>
157  
;<?php
xl('Due Date','e')?
>
160 <?php
xl('Amount','e')?
> 
;
163 <?php
xl('Paid','e')?
> 
;
166 <?php
xl('Balance','e')?
> 
;
171 if ($_POST['form_search']) {
175 if ($form_start_date) {
176 $where .= " AND e.date >= '$form_start_date'";
178 if ($form_end_date) {
179 $where .= " AND e.date <= '$form_end_date'";
182 $rez = sqlStatement("SELECT " .
183 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
184 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
185 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
186 "AND i.provider = ''$where " .
187 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
193 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
194 $patient_id = $row['pid'];
195 $encounter_id = $row['encounter'];
196 $invnumber = $row['pid'] . "." . $row['encounter'];
198 if ($INTEGRATED_AR) {
200 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
201 "pid = '$patient_id' AND encounter = '$encounter_id'");
202 $inv_amount = $arow['amount'];
203 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
204 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
205 "activity = 1 AND code_type != 'COPAY'");
206 $inv_amount +
= $arow['amount'];
207 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
208 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
209 "activity = 1 AND code_type = 'COPAY'");
210 $inv_paid = 0 - $arow['amount'];
211 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
212 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
213 "pid = '$patient_id' AND encounter = '$encounter_id'");
214 $inv_paid +
= $arow['pay'];
215 $inv_amount -= $arow['adj'];
218 $ares = SLQuery("SELECT duedate, amount, paid FROM ar WHERE " .
219 "ar.invnumber = '$invnumber'");
220 if ($sl_err) die($sl_err);
221 if (SLRowCount($ares) == 0) continue;
222 $arow = SLGetRow($ares, 0);
223 $inv_amount = $arow['amount'];
224 $inv_paid = $arow['paid'];
225 $inv_duedate = $arow['duedate'];
227 $total_amount +
= bucks($inv_amount);
228 $total_paid +
= bucks($inv_paid);
230 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
232 <tr bgcolor
='<?php echo $bgcolor ?>'>
234  
;<?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
237  
;<?php
echo $row['ss'] ?
>
240  
;<?php
echo $invnumber ?
></a
>
243  
;<?php
echo oeFormatShortDate(substr($row['date'], 0, 10)) ?
>
246  
;<?php
echo oeFormatShortDate($inv_duedate) ?
>
248 <td
class="detail" align
="right">
249 <?php
echo bucks($inv_amount) ?
> 
;
251 <td
class="detail" align
="right">
252 <?php
echo bucks($inv_paid) ?
> 
;
254 <td
class="detail" align
="right">
255 <?php
echo bucks($inv_amount - $inv_paid) ?
> 
;
261 <tr bgcolor
='#dddddd'>
263  
;<?php
xl('Totals','e'); ?
>
277 <td
class="detail" align
="right">
278 <?php
echo bucks($total_amount) ?
> 
;
280 <td
class="detail" align
="right">
281 <?php
echo bucks($total_paid) ?
> 
;
283 <td
class="detail" align
="right">
284 <?php
echo bucks($total_amount - $total_paid) ?
> 
;
289 if (!$INTEGRATED_AR) SLClose();
299 echo "alert('$alertmsg');\n";
305 <!-- stuff
for the popup calendar
-->
306 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
307 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
308 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
309 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
310 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
311 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
313 <script language
="Javascript">
314 Calendar
.setup({inputField
:"form_start_date", ifFormat
:"%Y-%m-%d", button
:"img_start_date"});
315 Calendar
.setup({inputField
:"form_end_date", ifFormat
:"%Y-%m-%d", button
:"img_end_date"});