Fixed bug: https://sourceforge.net/p/openemr/bugs/416/
[openemr.git] / interface / reports / custom_report_range.php
blobade0c70bfec5c3b9d20772b79195ff1d718ce271
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'];
45 //Patient related stuff
46 if ($_POST["form_patient"])
47 $form_patient = isset($_POST['form_patient']) ? $_POST['form_patient'] : '';
48 $form_pid = isset($_POST['form_pid']) ? $_POST['form_pid'] : '';
49 if ($form_patient == '' ) $form_pid = '';
51 <html>
53 <head>
54 <?php html_header_show();?>
56 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
57 <style>
59 @media print {
60 .title {
61 visibility: hidden;
63 .pagebreak {
64 page-break-after: always;
65 border: none;
66 visibility: hidden;
69 #superbill_description {
70 visibility: hidden;
73 #report_parameters {
74 visibility: hidden;
76 #superbill_results {
77 margin-top: -30px;
81 @media screen {
82 .title {
83 visibility: visible;
85 #superbill_description {
86 visibility: visible;
88 .pagebreak {
89 width: 100%;
90 border: 2px dashed black;
92 #report_parameters {
93 visibility: visible;
96 #superbill_description {
97 margin: 10px;
99 #superbill_startingdate {
100 margin: 10px;
102 #superbill_endingdate {
103 margin: 10px;
106 #superbill_patientdata {
108 #superbill_patientdata h1 {
109 font-weight: bold;
110 font-size: 1.2em;
111 margin: 0px;
112 padding: 5px;
113 width: 100%;
114 background-color: #eee;
115 border: 1px solid black;
117 #superbill_insurancedata {
118 margin-top: 10px;
120 #superbill_insurancedata h1 {
121 font-weight: bold;
122 font-size: 1.2em;
123 margin: 0px;
124 padding: 5px;
125 width: 100%;
126 background-color: #eee;
127 border: 1px solid black;
129 #superbill_insurancedata h2 {
130 font-weight: bold;
131 font-size: 1.0em;
132 margin: 0px;
133 padding: 0px;
134 width: 100%;
135 background-color: #eee;
137 #superbill_billingdata {
138 margin-top: 10px;
140 #superbill_billingdata h1 {
141 font-weight: bold;
142 font-size: 1.2em;
143 margin: 0px;
144 padding: 5px;
145 width: 100%;
146 background-color: #eee;
147 border: 1px solid black;
149 #superbill_signature {
151 #superbill_logo {
153 </style>
154 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
155 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
157 <script language="Javascript">
158 $(document).ready(function() {
159 var win = top.printLogSetup ? top : opener.top;
160 win.printLogSetup(document.getElementById('printbutton'));
163 // CapMinds :: invokes find-patient popup.
164 function sel_patient() {
165 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
168 // CapMinds :: callback by the find-patient popup.
169 function setpatient(pid, lname, fname, dob) {
170 var f = document.theform;
171 f.form_patient.value = lname + ', ' + fname;
172 f.form_pid.value = pid;
175 </script>
176 </head>
178 <body class="body_top">
180 <span class='title'><?php echo xlt('Reports'); ?> - <?php echo xlt('Superbill'); ?></span>
182 <div id="superbill_description" class='text'>
183 <?php echo xlt('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.'); ?>
184 </div>
186 <div id="report_parameters">
188 <form method="post" name="theform" id='theform' action="custom_report_range.php">
189 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
190 <table>
191 <tr>
192 <td width='650px'>
193 <div style='float:left'>
195 <table class='text'>
196 <tr>
197 <td class='label'>
198 <?php echo xlt('Start Date'); ?>:
199 </td>
200 <td>
201 <input type='text' name='start' id="form_from_date" size='10' value='<?php echo attr($startdate) ?>'
202 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
203 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
204 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
205 title='<?php echo xla('Click here to choose a date'); ?>'>
206 </td>
207 <td class='label'>
208 <?php echo xlt('End Date'); ?>:
209 </td>
210 <td>
211 <input type='text' name='end' id="form_to_date" size='10' value='<?php echo attr($enddate) ?>'
212 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
213 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
214 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
215 title='<?php echo xla('Click here to choose a date'); ?>'>
216 </td>
218 <td>
219 &nbsp;&nbsp;<span class='text'><?php echo xlt('Patient'); ?>: </span>
220 </td>
221 <td>
222 <input type='text' size='20' name='form_patient' style='width:100%;cursor:pointer;cursor:hand' value='<?php echo attr($form_patient) ? attr($form_patient) : xla('Click To Select'); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' />
223 <input type='hidden' name='form_pid' value='<?php echo attr($form_pid); ?>' />
224 </td>
225 </tr>
226 <tr><td>
227 </tr>
228 </table>
230 </div>
232 </td>
233 <td align='left' valign='middle' height="100%">
234 <table style='border-left:1px solid; width:100%; height:100%' >
235 <tr>
236 <td>
237 <div style='margin-left:15px'>
238 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
239 <span>
240 <?php echo xlt('Submit'); ?>
241 </span>
242 </a>
244 <?php if ($_POST['form_refresh']) { ?>
245 <a href='#' class='css_button' id='printbutton'>
246 <span>
247 <?php echo xlt('Print'); ?>
248 </span>
249 </a>
250 <?php } ?>
251 </div>
252 </td>
253 </tr>
254 </table>
255 </td>
256 </tr>
257 </table>
258 </div> <!-- end of parameters -->
260 </form>
262 <div id="superbill_results">
264 <?php
265 if( !(empty($_POST['start']) || empty($_POST['end']))) {
266 $sql = "select * from facility where billing_location = 1";
267 $db = $GLOBALS['adodb']['db'];
268 $results = $db->Execute($sql);
269 $facility = array();
270 if (!$results->EOF) {
271 $facility = $results->fields;
274 <h2><?php text($facility['name'])?></h2>
275 <?php text($facility['street'])?><br>
276 <?php text($facility['city'])?>, <?php text($facility['state'])?> <?php text($facility['postal_code'])?><br>
278 </p>
279 <?php
281 $sqlBindArray = array();
282 $res_query = "select * from forms where " .
283 "form_name = 'New Patient Encounter' and " .
284 "date between ? and ? " ;
285 array_push($sqlBindArray,$startdate,$enddate);
286 if($form_pid) {
287 $res_query.= " and pid=? ";
288 array_push($sqlBindArray,$form_pid);
290 $res_query.= " order by date DESC" ;
291 $res =sqlStatement($res_query,$sqlBindArray);
293 while($result = sqlFetchArray($res)) {
294 if ($result{"form_name"} == "New Patient Encounter") {
295 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
296 $pids[] = $result{"pid"};
299 $N = 6;
301 function postToGet($newpatient, $pids) {
302 $getstring="";
303 $serialnewpatient = serialize($newpatient);
304 $serialpids = serialize($pids);
305 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
307 return $getstring;
310 $iCounter = 0;
311 if(empty($newpatient)){ $newpatient = array(); }
312 foreach($newpatient as $patient){
314 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
315 while($result = sqlFetchArray($inclookupres)) {
316 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
320 print "<div id='superbill_patientdata'>";
321 print "<h1>".xlt('Patient Data').":</h1>";
322 printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
323 print "</div>";
325 print "<div id='superbill_insurancedata'>";
326 print "<h1>".xlt('Insurance Data').":</h1>";
327 print "<h2>".xlt('Primary').":</h2>";
328 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
329 print "<h2>".xlt('Secondary').":</h2>";
330 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
331 print "<h2>".xlt('Tertiary').":</h2>";
332 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
333 print "</div>";
335 print "<div id='superbill_billingdata'>";
336 print "<h1>".xlt('Billing Information').":</h1>";
337 if (count($patient) > 0) {
338 $billings = array();
339 echo "<table width='100%'>";
340 echo "<tr>";
341 echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
342 echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
343 echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
344 echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
345 $total = 0.00;
346 $copays = 0.00;
347 //foreach ($patient as $be) {
349 $ta = explode(":",$patient);
350 $billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);
352 $billings[] = $billing;
353 foreach ($billing as $b) {
354 // grab the date to reformat it in the output
355 $bdate = strtotime($b['date']);
357 echo "<tr>\n";
358 echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
359 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
360 echo "<td class='text'>";
361 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;";
362 echo "</td>\n";
363 echo "<td class='text'>";
364 echo oeFormatMoney($b['fee']);
365 echo "</td>\n";
366 echo "</tr>\n";
367 $total += $b['fee'];
369 // Calculate the copay for the encounter
370 $copays = getPatientCopay($pids[$iCounter],$ta[1]);
372 echo "<tr><td>&nbsp;</td></tr>";
373 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
374 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
375 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
376 echo "</table>";
377 echo "<pre>";
378 //print_r($billings);
379 echo "</pre>";
381 echo "</div>";
383 ++$iCounter;
384 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
385 print "<hr class='pagebreak' />";
389 </div>
391 </body>
393 <!-- stuff for the popup calendar -->
394 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
395 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
396 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
397 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
399 <script language="Javascript">
400 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
401 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
403 </script>
404 </html>