sql upgrade error is corrected.
[openemr.git] / interface / reports / custom_report_range.php
blobf84795c206233db362643eb63ee59e9f0536c9f2
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once(dirname(__file__)."/../globals.php");
8 require_once("$srcdir/forms.inc");
9 require_once("$srcdir/billing.inc");
10 require_once("$srcdir/pnotes.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/report.inc");
13 require_once("$srcdir/classes/Document.class.php");
14 require_once("$srcdir/classes/Note.class.php");
15 require_once("$srcdir/formatting.inc.php");
17 $startdate = $enddate = "";
18 if(empty($_POST['start']) || empty($_POST['end'])) {
19 // set some default dates
20 $startdate = date('Y-m-d', (time() - 30*24*60*60));
21 $enddate = date('Y-m-d', time());
23 else {
24 // set dates
25 $startdate = $_POST['start'];
26 $enddate = $_POST['end'];
29 <html>
31 <head>
32 <?php html_header_show();?>
34 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
35 <style>
37 @media print {
38 .title {
39 visibility: hidden;
41 .pagebreak {
42 page-break-after: always;
43 border: none;
44 visibility: hidden;
47 #superbill_description {
48 visibility: hidden;
51 #report_parameters {
52 visibility: hidden;
54 #superbill_results {
55 margin-top: -30px;
59 @media screen {
60 .title {
61 visibility: visible;
63 #superbill_description {
64 visibility: visible;
66 .pagebreak {
67 width: 100%;
68 border: 2px dashed black;
70 #report_parameters {
71 visibility: visible;
74 #superbill_description {
75 margin: 10px;
77 #superbill_startingdate {
78 margin: 10px;
80 #superbill_endingdate {
81 margin: 10px;
84 #superbill_patientdata {
86 #superbill_patientdata h1 {
87 font-weight: bold;
88 font-size: 1.2em;
89 margin: 0px;
90 padding: 5px;
91 width: 100%;
92 background-color: #eee;
93 border: 1px solid black;
95 #superbill_insurancedata {
96 margin-top: 10px;
98 #superbill_insurancedata h1 {
99 font-weight: bold;
100 font-size: 1.2em;
101 margin: 0px;
102 padding: 5px;
103 width: 100%;
104 background-color: #eee;
105 border: 1px solid black;
107 #superbill_insurancedata h2 {
108 font-weight: bold;
109 font-size: 1.0em;
110 margin: 0px;
111 padding: 0px;
112 width: 100%;
113 background-color: #eee;
115 #superbill_billingdata {
116 margin-top: 10px;
118 #superbill_billingdata h1 {
119 font-weight: bold;
120 font-size: 1.2em;
121 margin: 0px;
122 padding: 5px;
123 width: 100%;
124 background-color: #eee;
125 border: 1px solid black;
127 #superbill_signature {
129 #superbill_logo {
131 </style>
133 </head>
135 <body class="body_top">
137 <span class='title'><?php xl('Reports','e'); ?> - <?php xl('Superbill','e'); ?></span>
139 <div id="superbill_description" class='text'>
140 <?php xl('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.','e'); ?>
141 </div>
143 <div id="report_parameters">
145 <form method="post" id='theform' action="custom_report_range.php">
146 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
147 <table>
148 <tr>
149 <td width='450px'>
150 <div style='float:left'>
152 <table class='text'>
153 <tr>
154 <td class='label'>
155 <?php xl('Start Date','e'); ?>:
156 </td>
157 <td>
158 <input type='text' name='start' id="form_from_date" size='10' value='<?php echo $startdate ?>'
159 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
160 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
161 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
162 title='<?php xl('Click here to choose a date','e'); ?>'>
163 </td>
164 <td class='label'>
165 <?php xl('End Date','e'); ?>:
166 </td>
167 <td>
168 <input type='text' name='end' id="form_to_date" size='10' value='<?php echo $enddate ?>'
169 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
170 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
171 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
172 title='<?php xl('Click here to choose a date','e'); ?>'>
173 </td>
174 </tr>
175 </table>
177 </div>
179 </td>
180 <td align='left' valign='middle' height="100%">
181 <table style='border-left:1px solid; width:100%; height:100%' >
182 <tr>
183 <td>
184 <div style='margin-left:15px'>
185 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
186 <span>
187 <?php xl('Submit','e'); ?>
188 </span>
189 </a>
191 <?php if ($_POST['form_refresh']) { ?>
192 <a href='#' class='css_button' onclick='window.print()'>
193 <span>
194 <?php xl('Print','e'); ?>
195 </span>
196 </a>
197 <?php } ?>
198 </div>
199 </td>
200 </tr>
201 </table>
202 </td>
203 </tr>
204 </table>
205 </div> <!-- end of parameters -->
207 </form>
209 <div id="superbill_results">
211 <?php
212 if( !(empty($_POST['start']) || empty($_POST['end']))) {
213 $sql = "select * from facility where billing_location = 1";
214 $db = $GLOBALS['adodb']['db'];
215 $results = $db->Execute($sql);
216 $facility = array();
217 if (!$results->EOF) {
218 $facility = $results->fields;
221 <h2><?php $facility['name']?></h2>
222 <?php $facility['street']?><br>
223 <?php $facility['city']?>, <?php $facility['state']?> <?php $facility['postal_code']?><br>
225 </p>
226 <?php
229 $res = sqlStatement("select * from forms where " .
230 "form_name = 'New Patient Encounter' and " .
231 "date between '$startdate' and '$enddate' " .
232 "order by date DESC");
233 while($result = sqlFetchArray($res)) {
234 if ($result{"form_name"} == "New Patient Encounter") {
235 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
236 $pids[] = $result{"pid"};
239 $N = 6;
241 function postToGet($newpatient, $pids) {
242 $getstring="";
243 $serialnewpatient = serialize($newpatient);
244 $serialpids = serialize($pids);
245 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
247 return $getstring;
250 $iCounter = 0;
251 if(empty($newpatient)){ $newpatient = array(); }
252 foreach($newpatient as $patient){
254 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
255 while($result = sqlFetchArray($inclookupres)) {
256 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
260 print "<div id='superbill_patientdata'>";
261 print "<h1>".xl('Patient Data').":</h1>";
262 printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
263 print "</div>";
265 print "<div id='superbill_insurancedata'>";
266 print "<h1>".xl('Insurance Data').":</h1>";
267 print "<h2>".xl('Primary').":</h2>";
268 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
269 print "<h2>".xl('Secondary').":</h2>";
270 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
271 print "<h2>".xl('Tertiary').":</h2>";
272 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
273 print "</div>";
275 print "<div id='superbill_billingdata'>";
276 print "<h1>".xl('Billing Information').":</h1>";
277 if (count($patient) > 0) {
278 $billings = array();
279 echo "<table width='100%'>";
280 echo "<tr>";
281 echo "<td class='bold' width='10%'>".xl('Date')."</td>";
282 echo "<td class='bold' width='20%'>".xl('Provider')."</td>";
283 echo "<td class='bold' width='40%'>".xl('Code')."</td>";
284 echo "<td class='bold' width='10%'>".xl('Fee')."</td></tr>\n";
285 $total = 0.00;
286 $copays = 0.00;
287 //foreach ($patient as $be) {
289 $ta = split(":",$patient);
290 $billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);
292 $billings[] = $billing;
293 foreach ($billing as $b) {
294 // grab the date to reformat it in the output
295 $bdate = strtotime($b['date']);
297 echo "<tr>\n";
298 echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
299 echo "<td class='text'>" . $b['provider_name'] . "</td>";
300 echo "<td class='text'>";
301 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;". $b['modifier'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
302 echo "</td>\n";
303 echo "<td class='text'>";
304 echo oeFormatMoney($b['fee']);
305 echo "</td>\n";
306 echo "</tr>\n";
307 $total += $b['fee'];
308 if ($b['code_type'] == "COPAY") {
309 $copays += $b['fee'];
313 echo "<tr><td>&nbsp;</td></tr>";
314 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xl('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
315 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xl('Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
316 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xl('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
317 echo "</table>";
318 echo "<pre>";
319 //print_r($billings);
320 echo "</pre>";
322 echo "</div>";
324 ++$iCounter;
325 print "<br/><br/>".xl('Physician Signature').": _______________________________________________";
326 print "<hr class='pagebreak' />";
330 </div>
332 </body>
334 <!-- stuff for the popup calendar -->
335 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
336 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
337 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
338 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
339 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
341 <script language="Javascript">
342 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
343 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
344 </script>
345 </html>