acknowledgments update
[openemr.git] / interface / reports / custom_report_range.php
blob5e51a0c8ea2a25386ce7224799d1cd00c6ee3830
1 <?php
2 /**
3 *
4 * Superbill Report
6 * LICENSE: This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @package OpenEMR
18 * @author Brady Miller <brady@sparmy.com>
19 * @link http://www.open-emr.org
22 $fake_register_globals=false;
23 $sanitize_all_escapes=true;
25 require_once(dirname(__file__)."/../globals.php");
26 require_once("$srcdir/forms.inc");
27 require_once("$srcdir/billing.inc");
28 require_once("$srcdir/patient.inc");
29 require_once("$srcdir/report.inc");
30 require_once("$srcdir/classes/Document.class.php");
31 require_once("$srcdir/classes/Note.class.php");
32 require_once("$srcdir/formatting.inc.php");
34 $startdate = $enddate = "";
35 if(empty($_POST['start']) || empty($_POST['end'])) {
36 // set some default dates
37 $startdate = date('Y-m-d', (time() - 30*24*60*60));
38 $enddate = date('Y-m-d', time());
40 else {
41 // set dates
42 $startdate = $_POST['start'];
43 $enddate = $_POST['end'];
46 <html>
48 <head>
49 <?php html_header_show();?>
51 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
52 <style>
54 @media print {
55 .title {
56 visibility: hidden;
58 .pagebreak {
59 page-break-after: always;
60 border: none;
61 visibility: hidden;
64 #superbill_description {
65 visibility: hidden;
68 #report_parameters {
69 visibility: hidden;
71 #superbill_results {
72 margin-top: -30px;
76 @media screen {
77 .title {
78 visibility: visible;
80 #superbill_description {
81 visibility: visible;
83 .pagebreak {
84 width: 100%;
85 border: 2px dashed black;
87 #report_parameters {
88 visibility: visible;
91 #superbill_description {
92 margin: 10px;
94 #superbill_startingdate {
95 margin: 10px;
97 #superbill_endingdate {
98 margin: 10px;
101 #superbill_patientdata {
103 #superbill_patientdata h1 {
104 font-weight: bold;
105 font-size: 1.2em;
106 margin: 0px;
107 padding: 5px;
108 width: 100%;
109 background-color: #eee;
110 border: 1px solid black;
112 #superbill_insurancedata {
113 margin-top: 10px;
115 #superbill_insurancedata h1 {
116 font-weight: bold;
117 font-size: 1.2em;
118 margin: 0px;
119 padding: 5px;
120 width: 100%;
121 background-color: #eee;
122 border: 1px solid black;
124 #superbill_insurancedata h2 {
125 font-weight: bold;
126 font-size: 1.0em;
127 margin: 0px;
128 padding: 0px;
129 width: 100%;
130 background-color: #eee;
132 #superbill_billingdata {
133 margin-top: 10px;
135 #superbill_billingdata h1 {
136 font-weight: bold;
137 font-size: 1.2em;
138 margin: 0px;
139 padding: 5px;
140 width: 100%;
141 background-color: #eee;
142 border: 1px solid black;
144 #superbill_signature {
146 #superbill_logo {
148 </style>
150 </head>
152 <body class="body_top">
154 <span class='title'><?php echo xlt('Reports'); ?> - <?php echo xlt('Superbill'); ?></span>
156 <div id="superbill_description" class='text'>
157 <?php echo xlt('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.'); ?>
158 </div>
160 <div id="report_parameters">
162 <form method="post" id='theform' action="custom_report_range.php">
163 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
164 <table>
165 <tr>
166 <td width='450px'>
167 <div style='float:left'>
169 <table class='text'>
170 <tr>
171 <td class='label'>
172 <?php echo xlt('Start Date'); ?>:
173 </td>
174 <td>
175 <input type='text' name='start' id="form_from_date" size='10' value='<?php echo attr($startdate) ?>'
176 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
177 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
178 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
179 title='<?php echo xla('Click here to choose a date'); ?>'>
180 </td>
181 <td class='label'>
182 <?php echo xlt('End Date'); ?>:
183 </td>
184 <td>
185 <input type='text' name='end' id="form_to_date" size='10' value='<?php echo attr($enddate) ?>'
186 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
187 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
188 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
189 title='<?php echo xla('Click here to choose a date'); ?>'>
190 </td>
191 </tr>
192 </table>
194 </div>
196 </td>
197 <td align='left' valign='middle' height="100%">
198 <table style='border-left:1px solid; width:100%; height:100%' >
199 <tr>
200 <td>
201 <div style='margin-left:15px'>
202 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
203 <span>
204 <?php echo xlt('Submit'); ?>
205 </span>
206 </a>
208 <?php if ($_POST['form_refresh']) { ?>
209 <a href='#' class='css_button' onclick='window.print()'>
210 <span>
211 <?php echo xlt('Print'); ?>
212 </span>
213 </a>
214 <?php } ?>
215 </div>
216 </td>
217 </tr>
218 </table>
219 </td>
220 </tr>
221 </table>
222 </div> <!-- end of parameters -->
224 </form>
226 <div id="superbill_results">
228 <?php
229 if( !(empty($_POST['start']) || empty($_POST['end']))) {
230 $sql = "select * from facility where billing_location = 1";
231 $db = $GLOBALS['adodb']['db'];
232 $results = $db->Execute($sql);
233 $facility = array();
234 if (!$results->EOF) {
235 $facility = $results->fields;
238 <h2><?php text($facility['name'])?></h2>
239 <?php text($facility['street'])?><br>
240 <?php text($facility['city'])?>, <?php text($facility['state'])?> <?php text($facility['postal_code'])?><br>
242 </p>
243 <?php
246 $res = sqlStatement("select * from forms where " .
247 "form_name = 'New Patient Encounter' and " .
248 "date between ? and ? " .
249 "order by date DESC", array($startdate,$enddate) );
250 while($result = sqlFetchArray($res)) {
251 if ($result{"form_name"} == "New Patient Encounter") {
252 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
253 $pids[] = $result{"pid"};
256 $N = 6;
258 function postToGet($newpatient, $pids) {
259 $getstring="";
260 $serialnewpatient = serialize($newpatient);
261 $serialpids = serialize($pids);
262 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
264 return $getstring;
267 $iCounter = 0;
268 if(empty($newpatient)){ $newpatient = array(); }
269 foreach($newpatient as $patient){
271 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
272 while($result = sqlFetchArray($inclookupres)) {
273 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
277 print "<div id='superbill_patientdata'>";
278 print "<h1>".xlt('Patient Data').":</h1>";
279 printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
280 print "</div>";
282 print "<div id='superbill_insurancedata'>";
283 print "<h1>".xlt('Insurance Data').":</h1>";
284 print "<h2>".xlt('Primary').":</h2>";
285 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
286 print "<h2>".xlt('Secondary').":</h2>";
287 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
288 print "<h2>".xlt('Tertiary').":</h2>";
289 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
290 print "</div>";
292 print "<div id='superbill_billingdata'>";
293 print "<h1>".xlt('Billing Information').":</h1>";
294 if (count($patient) > 0) {
295 $billings = array();
296 echo "<table width='100%'>";
297 echo "<tr>";
298 echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
299 echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
300 echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
301 echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
302 $total = 0.00;
303 $copays = 0.00;
304 //foreach ($patient as $be) {
306 $ta = split(":",$patient);
307 $billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);
309 $billings[] = $billing;
310 foreach ($billing as $b) {
311 // grab the date to reformat it in the output
312 $bdate = strtotime($b['date']);
314 echo "<tr>\n";
315 echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
316 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
317 echo "<td class='text'>";
318 echo text($b['code_type']) . ":\t" . text($b['code']) . "&nbsp;". text($b['modifier']) . "&nbsp;&nbsp;&nbsp;" . text($b['code_text']) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
319 echo "</td>\n";
320 echo "<td class='text'>";
321 echo oeFormatMoney($b['fee']);
322 echo "</td>\n";
323 echo "</tr>\n";
324 $total += $b['fee'];
325 if ($b['code_type'] == "COPAY") {
326 $copays += $b['fee'];
330 echo "<tr><td>&nbsp;</td></tr>";
331 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
332 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
333 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
334 echo "</table>";
335 echo "<pre>";
336 //print_r($billings);
337 echo "</pre>";
339 echo "</div>";
341 ++$iCounter;
342 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
343 print "<hr class='pagebreak' />";
347 </div>
349 </body>
351 <!-- stuff for the popup calendar -->
352 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
353 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
354 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
355 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
356 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
358 <script language="Javascript">
359 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
360 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
361 </script>
362 </html>