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/formatting.inc.php");
19 function bucks($amount) {
20 if ($amount) return oeFormatMoney($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"));
30 <?php
html_header_show(); ?
>
31 <style type
="text/css">
33 /* specifically include & exclude from printing */
39 #report_parameters_daterange {
43 #report_results table {
48 /* specifically exclude some from the screen */
50 #report_parameters_daterange {
55 </style
><link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
56 <title
><?php
xl('Indigent Patients Report','e')?
></title
>
58 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script
>
60 <script language
="JavaScript">
62 $
(document
).ready(function() {
63 var win
= top
.printLogSetup ? top
: opener
.top
;
64 win
.printLogSetup(document
.getElementById('printbutton'));
71 <body
class="body_top">
73 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Indigent Patients','e'); ?
></span
>
75 <form method
='post' action
='indigent_patients_report.php' id
='theform'>
77 <div id
="report_parameters">
79 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
84 <div style
='float:left'>
89 <?php
xl('Visits From','e'); ?
>:
92 <input type
='text' name
='form_start_date' id
="form_start_date" size
='10' value
='<?php echo $form_start_date ?>'
93 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
94 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
95 id
='img_start_date' border
='0' alt
='[?]' style
='cursor:pointer'
96 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
99 <?php
xl('To','e'); ?
>:
102 <input type
='text' name
='form_end_date' id
="form_end_date" size
='10' value
='<?php echo $form_end_date ?>'
103 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
104 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
105 id
='img_end_date' border
='0' alt
='[?]' style
='cursor:pointer'
106 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
114 <td align
='left' valign
='middle' height
="100%">
115 <table style
='border-left:1px solid; width:100%; height:100%' >
118 <div style
='margin-left:15px'>
119 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
121 <?php
xl('Submit','e'); ?
>
125 <?php
if ($_POST['form_refresh']) { ?
>
126 <a href
='#' class='css_button' id
='printbutton'>
128 <?php
xl('Print','e'); ?
>
139 </div
> <!-- end of parameters
-->
141 <div id
="report_results">
144 <thead bgcolor
="#dddddd">
146  
;<?php
xl('Patient','e')?
>
149  
;<?php
xl('SSN','e')?
>
152  
;<?php
xl('Invoice','e')?
>
155  
;<?php
xl('Svc Date','e')?
>
158  
;<?php
xl('Due Date','e')?
>
161 <?php
xl('Amount','e')?
> 
;
164 <?php
xl('Paid','e')?
> 
;
167 <?php
xl('Balance','e')?
> 
;
172 if ($_POST['form_refresh']) {
176 if ($form_start_date) {
177 $where .= " AND e.date >= '$form_start_date'";
179 if ($form_end_date) {
180 $where .= " AND e.date <= '$form_end_date'";
183 $rez = sqlStatement("SELECT " .
184 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
185 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
186 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
187 "AND i.provider = ''$where " .
188 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
194 for ($irow = 0; $row = sqlFetchArray($rez); ++
$irow) {
195 $patient_id = $row['pid'];
196 $encounter_id = $row['encounter'];
197 $invnumber = $row['pid'] . "." . $row['encounter'];
199 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
200 "pid = '$patient_id' AND encounter = '$encounter_id'");
201 $inv_amount = $arow['amount'];
202 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
203 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
204 "activity = 1 AND code_type != 'COPAY'");
205 $inv_amount +
= $arow['amount'];
206 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
207 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
208 "activity = 1 AND code_type = 'COPAY'");
209 $inv_paid = 0 - $arow['amount'];
210 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
211 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
212 "pid = '$patient_id' AND encounter = '$encounter_id'");
213 $inv_paid +
= $arow['pay'];
214 $inv_amount -= $arow['adj'];
215 $total_amount +
= bucks($inv_amount);
216 $total_paid +
= bucks($inv_paid);
218 $bgcolor = (($irow & 1) ?
"#ffdddd" : "#ddddff");
220 <tr bgcolor
='<?php echo $bgcolor ?>'>
222  
;<?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
225  
;<?php
echo $row['ss'] ?
>
228  
;<?php
echo $invnumber ?
></a
>
231  
;<?php
echo oeFormatShortDate(substr($row['date'], 0, 10)) ?
>
234  
;<?php
echo oeFormatShortDate($inv_duedate) ?
>
236 <td
class="detail" align
="right">
237 <?php
echo bucks($inv_amount) ?
> 
;
239 <td
class="detail" align
="right">
240 <?php
echo bucks($inv_paid) ?
> 
;
242 <td
class="detail" align
="right">
243 <?php
echo bucks($inv_amount - $inv_paid) ?
> 
;
249 <tr bgcolor
='#dddddd'>
251  
;<?php
xl('Totals','e'); ?
>
265 <td
class="detail" align
="right">
266 <?php
echo bucks($total_amount) ?
> 
;
268 <td
class="detail" align
="right">
269 <?php
echo bucks($total_paid) ?
> 
;
271 <td
class="detail" align
="right">
272 <?php
echo bucks($total_amount - $total_paid) ?
> 
;
286 echo "alert('$alertmsg');\n";
292 <!-- stuff
for the popup calendar
-->
293 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
294 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
295 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
296 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
297 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
298 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script
>
300 <script language
="Javascript">
301 Calendar
.setup({inputField
:"form_start_date", ifFormat
:"%Y-%m-%d", button
:"img_start_date"});
302 Calendar
.setup({inputField
:"form_end_date", ifFormat
:"%Y-%m-%d", button
:"img_end_date"});