Feature to add drug-drug interaction checking for the
[openemr.git] / interface / billing / indigent_patients_report.php
blob81d0edc21b21a680fc371fe53a7403e0a5a72ac9
1 <?php
2 // Copyright (C) 2005-2015 Rod Roark <rod@sunsetsystems.com>
3 //
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
11 // insurance.
13 require_once("../globals.php");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/formatting.inc.php");
17 $alertmsg = '';
19 function bucks($amount) {
20 if ($amount) return oeFormatMoney($amount);
21 return "";
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"));
28 <html>
29 <head>
30 <?php html_header_show(); ?>
31 <style type="text/css">
33 /* specifically include & exclude from printing */
34 @media print {
35 #report_parameters {
36 visibility: hidden;
37 display: none;
39 #report_parameters_daterange {
40 visibility: visible;
41 display: inline;
43 #report_results table {
44 margin-top: 0px;
48 /* specifically exclude some from the screen */
49 @media screen {
50 #report_parameters_daterange {
51 visibility: hidden;
52 display: none;
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'));
65 });
67 </script>
69 </head>
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=''/>
81 <table>
82 <tr>
83 <td width='410px'>
84 <div style='float:left'>
86 <table class='text'>
87 <tr>
88 <td class='label'>
89 <?php xl('Visits From','e'); ?>:
90 </td>
91 <td>
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'); ?>'>
97 </td>
98 <td class='label'>
99 <?php xl('To','e'); ?>:
100 </td>
101 <td>
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'); ?>'>
107 </td>
108 </tr>
109 </table>
111 </div>
113 </td>
114 <td align='left' valign='middle' height="100%">
115 <table style='border-left:1px solid; width:100%; height:100%' >
116 <tr>
117 <td>
118 <div style='margin-left:15px'>
119 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
120 <span>
121 <?php xl('Submit','e'); ?>
122 </span>
123 </a>
125 <?php if ($_POST['form_refresh']) { ?>
126 <a href='#' class='css_button' id='printbutton'>
127 <span>
128 <?php xl('Print','e'); ?>
129 </span>
130 </a>
131 <?php } ?>
132 </div>
133 </td>
134 </tr>
135 </table>
136 </td>
137 </tr>
138 </table>
139 </div> <!-- end of parameters -->
141 <div id="report_results">
142 <table>
144 <thead bgcolor="#dddddd">
145 <th>
146 &nbsp;<?php xl('Patient','e')?>
147 </th>
148 <th>
149 &nbsp;<?php xl('SSN','e')?>
150 </th>
151 <th>
152 &nbsp;<?php xl('Invoice','e')?>
153 </th>
154 <th>
155 &nbsp;<?php xl('Svc Date','e')?>
156 </th>
157 <th>
158 &nbsp;<?php xl('Due Date','e')?>
159 </th>
160 <th align="right">
161 <?php xl('Amount','e')?>&nbsp;
162 </th>
163 <th align="right">
164 <?php xl('Paid','e')?>&nbsp;
165 </th>
166 <th align="right">
167 <?php xl('Balance','e')?>&nbsp;
168 </th>
169 </thead>
171 <?php
172 if ($_POST['form_refresh']) {
174 $where = "";
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"
191 $total_amount = 0;
192 $total_paid = 0;
194 for ($irow = 0; $row = sqlFetchArray($rez); ++$irow) {
195 $patient_id = $row['pid'];
196 $encounter_id = $row['encounter'];
197 $invnumber = $row['pid'] . "." . $row['encounter'];
198 $inv_duedate = '';
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 ?>'>
221 <td class="detail">
222 &nbsp;<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
223 </td>
224 <td class="detail">
225 &nbsp;<?php echo $row['ss'] ?>
226 </td>
227 <td class="detail">
228 &nbsp;<?php echo $invnumber ?></a>
229 </td>
230 <td class="detail">
231 &nbsp;<?php echo oeFormatShortDate(substr($row['date'], 0, 10)) ?>
232 </td>
233 <td class="detail">
234 &nbsp;<?php echo oeFormatShortDate($inv_duedate) ?>
235 </td>
236 <td class="detail" align="right">
237 <?php echo bucks($inv_amount) ?>&nbsp;
238 </td>
239 <td class="detail" align="right">
240 <?php echo bucks($inv_paid) ?>&nbsp;
241 </td>
242 <td class="detail" align="right">
243 <?php echo bucks($inv_amount - $inv_paid) ?>&nbsp;
244 </td>
245 </tr>
246 <?php
249 <tr bgcolor='#dddddd'>
250 <td class="detail">
251 &nbsp;<?php xl('Totals','e'); ?>
252 </td>
253 <td class="detail">
254 &nbsp;
255 </td>
256 <td class="detail">
257 &nbsp;
258 </td>
259 <td class="detail">
260 &nbsp;
261 </td>
262 <td class="detail">
263 &nbsp;
264 </td>
265 <td class="detail" align="right">
266 <?php echo bucks($total_amount) ?>&nbsp;
267 </td>
268 <td class="detail" align="right">
269 <?php echo bucks($total_paid) ?>&nbsp;
270 </td>
271 <td class="detail" align="right">
272 <?php echo bucks($total_amount - $total_paid) ?>&nbsp;
273 </td>
274 </tr>
275 <?php
279 </table>
280 </div>
282 </form>
283 <script>
284 <?php
285 if ($alertmsg) {
286 echo "alert('$alertmsg');\n";
289 </script>
290 </body>
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"});
303 </script>
305 </html>