2 // Copyright (C) 2005, 2008 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("../../library/patient.inc");
15 require_once("../../library/sql-ledger.inc");
19 function bucks($amount) {
20 if ($amount) return sprintf("%.2f", $amount);
24 $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01"));
25 $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d"));
27 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
29 if (!$INTEGRATED_AR) SLConnect();
33 <?
html_header_show();?
>
34 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
35 <title
><?php
xl('Indigent Patients Report','e')?
></title
>
37 <script language
="JavaScript">
43 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
46 <h3
>Indigent Patients Report
</h3
>
48 <form method
='post' action
='indigent_patients_report.php'>
50 <table border
='0' cellpadding
='5' cellspacing
='0'>
53 <td height
="1" colspan
="10">
57 <tr bgcolor
='#ddddff'>
59 <?php
xl('Start Date:','e')?
>
62 <input type
='text' name
='form_start_date' size
='10' value
='<?php echo $form_start_date ?>'
63 title
='<?php xl("Beginning date of service yyyy-mm-dd","e")?>'>
66 <?php
xl('End Date:','e')?
>
69 <input type
='text' name
='form_end_date' size
='10' value
='<?php echo $form_end_date ?>'
70 title
='<?php xl("Ending date of service yyyy-mm-dd","e")?>'>
73 <input type
='submit' name
='form_search' value
='<?php xl("Search","e")?>'>
78 <td height
="1" colspan
="10">
84 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
86 <tr bgcolor
="#dddddd">
88  
;<?php
xl('Patient','e')?
>
91  
;<?php
xl('SSN','e')?
>
94  
;<?php
xl('Invoice','e')?
>
97  
;<?php
xl('Svc Date','e')?
>
100  
;<?php
xl('Due Date','e')?
>
102 <td
class="dehead" align
="right">
103 <?php
xl('Amount','e')?
> 
;
105 <td
class="dehead" align
="right">
106 <?php
xl('Paid','e')?
> 
;
108 <td
class="dehead" align
="right">
109 <?php
xl('Balance','e')?
> 
;
113 if ($_POST['form_search']) {
117 if ($form_start_date) {
118 $where .= " AND e.date >= '$form_start_date'";
120 if ($form_end_date) {
121 $where .= " AND e.date <= '$form_end_date'";
124 $rez = sqlStatement("SELECT " .
125 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
126 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
127 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
128 "AND i.provider = ''$where " .
129 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
135 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
136 $patient_id = $row['pid'];
137 $encounter_id = $row['encounter'];
138 $invnumber = $row['pid'] . "." . $row['encounter'];
140 if ($INTEGRATED_AR) {
142 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
143 "pid = '$patient_id' AND encounter = '$encounter_id'");
144 $inv_amount = $arow['amount'];
145 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
146 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
147 "activity = 1 AND code_type != 'COPAY'");
148 $inv_amount +
= $arow['amount'];
149 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
150 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
151 "activity = 1 AND code_type = 'COPAY'");
152 $inv_paid = 0 - $arow['amount'];
153 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
154 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
155 "pid = '$patient_id' AND encounter = '$encounter_id'");
156 $inv_paid +
= $arow['pay'];
157 $inv_amount -= $arow['adj'];
160 $ares = SLQuery("SELECT duedate, amount, paid FROM ar WHERE " .
161 "ar.invnumber = '$invnumber'");
162 if ($sl_err) die($sl_err);
163 if (SLRowCount($ares) == 0) continue;
164 $arow = SLGetRow($ares, 0);
165 $inv_amount = $arow['amount'];
166 $inv_paid = $arow['paid'];
167 $inv_duedate = $arow['duedate'];
169 $total_amount +
= bucks($inv_amount);
170 $total_paid +
= bucks($inv_paid);
172 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
174 <tr bgcolor
='<?php echo $bgcolor ?>'>
176  
;<?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
179  
;<?php
echo $row['ss'] ?
>
182  
;<?php
echo $invnumber ?
></a
>
185  
;<?php
echo substr($row['date'], 0, 10) ?
>
188  
;<?php
echo $inv_duedate ?
>
190 <td
class="detail" align
="right">
191 <?php
echo bucks($inv_amount) ?
> 
;
193 <td
class="detail" align
="right">
194 <?php
echo bucks($inv_paid) ?
> 
;
196 <td
class="detail" align
="right">
197 <?php
echo bucks($inv_amount - $inv_paid) ?
> 
;
203 <tr bgcolor
='#dddddd'>
219 <td
class="detail" align
="right">
220 <?php
echo bucks($total_amount) ?
> 
;
222 <td
class="detail" align
="right">
223 <?php
echo bucks($total_paid) ?
> 
;
225 <td
class="detail" align
="right">
226 <?php
echo bucks($total_amount - $total_paid) ?
> 
;
231 if (!$INTEGRATED_AR) SLClose();
241 echo "alert('$alertmsg');\n";