added new datepicker to amendments gui
[openemr.git] / interface / reports / custom_report_range.php
blob9c1f0cd9f76ffef39c377c76c4648cf5f314301f
1 <?php
2 /**
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/formatting.inc.php");
32 $startdate = $enddate = "";
33 if(empty($_POST['start']) || empty($_POST['end'])) {
34 // set some default dates
35 $startdate = date('Y-m-d', (time() - 30*24*60*60));
36 $enddate = date('Y-m-d', time());
38 else {
39 // set dates
40 $startdate = $_POST['start'];
41 $enddate = $_POST['end'];
43 //Patient related stuff
44 if ($_POST["form_patient"])
45 $form_patient = isset($_POST['form_patient']) ? $_POST['form_patient'] : '';
46 $form_pid = isset($_POST['form_pid']) ? $_POST['form_pid'] : '';
47 if ($form_patient == '' ) $form_pid = '';
49 <html>
51 <head>
52 <?php html_header_show();?>
54 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
55 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.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?v=<?php echo $v_js_includes; ?>"></script>
155 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
156 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
158 <script language="Javascript">
159 $(document).ready(function() {
160 var win = top.printLogSetup ? top : opener.top;
161 win.printLogSetup(document.getElementById('printbutton'));
163 $('.datepicker').datetimepicker({
164 <?php $datetimepicker_timepicker = false; ?>
165 <?php $datetimepicker_formatInput = false; ?>
166 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
167 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
171 // CapMinds :: invokes find-patient popup.
172 function sel_patient() {
173 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
176 // CapMinds :: callback by the find-patient popup.
177 function setpatient(pid, lname, fname, dob) {
178 var f = document.theform;
179 f.form_patient.value = lname + ', ' + fname;
180 f.form_pid.value = pid;
183 </script>
184 </head>
186 <body class="body_top">
188 <span class='title'><?php echo xlt('Reports'); ?> - <?php echo xlt('Superbill'); ?></span>
190 <div id="superbill_description" class='text'>
191 <?php echo xlt('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.'); ?>
192 </div>
194 <div id="report_parameters">
196 <form method="post" name="theform" id='theform' action="custom_report_range.php">
197 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
198 <table>
199 <tr>
200 <td width='650px'>
201 <div style='float:left'>
203 <table class='text'>
204 <tr>
205 <td class='label'>
206 <?php echo xlt('Start Date'); ?>:
207 </td>
208 <td>
209 <input type='text' class='datepicker' name='start' id="form_from_date" size='10' value='<?php echo attr($startdate) ?>'
210 title='yyyy-mm-dd'>
211 </td>
212 <td class='label'>
213 <?php echo xlt('End Date'); ?>:
214 </td>
215 <td>
216 <input type='text' class='datepicker' name='end' id="form_to_date" size='10' value='<?php echo attr($enddate) ?>'
217 title='yyyy-mm-dd'>
218 </td>
220 <td>
221 &nbsp;&nbsp;<span class='text'><?php echo xlt('Patient'); ?>: </span>
222 </td>
223 <td>
224 <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'); ?>' />
225 <input type='hidden' name='form_pid' value='<?php echo attr($form_pid); ?>' />
226 </td>
227 </tr>
228 <tr><td>
229 </tr>
230 </table>
232 </div>
234 </td>
235 <td align='left' valign='middle' height="100%">
236 <table style='border-left:1px solid; width:100%; height:100%' >
237 <tr>
238 <td>
239 <div style='margin-left:15px'>
240 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
241 <span>
242 <?php echo xlt('Submit'); ?>
243 </span>
244 </a>
246 <?php if ($_POST['form_refresh']) { ?>
247 <a href='#' class='css_button' id='printbutton'>
248 <span>
249 <?php echo xlt('Print'); ?>
250 </span>
251 </a>
252 <?php } ?>
253 </div>
254 </td>
255 </tr>
256 </table>
257 </td>
258 </tr>
259 </table>
260 </div> <!-- end of parameters -->
262 </form>
264 <div id="superbill_results">
266 <?php
267 if( !(empty($_POST['start']) || empty($_POST['end']))) {
268 $sql = "select * from facility where billing_location = 1";
269 $db = $GLOBALS['adodb']['db'];
270 $results = $db->Execute($sql);
271 $facility = array();
272 if (!$results->EOF) {
273 $facility = $results->fields;
276 <h2><?php text($facility['name'])?></h2>
277 <?php text($facility['street'])?><br>
278 <?php text($facility['city'])?>, <?php text($facility['state'])?> <?php text($facility['postal_code'])?><br>
280 </p>
281 <?php
283 $sqlBindArray = array();
284 $res_query = "select * from forms where " .
285 "form_name = 'New Patient Encounter' and " .
286 "date between ? and ? " ;
287 array_push($sqlBindArray,$startdate,$enddate);
288 if($form_pid) {
289 $res_query.= " and pid=? ";
290 array_push($sqlBindArray,$form_pid);
292 $res_query.= " order by date DESC" ;
293 $res =sqlStatement($res_query,$sqlBindArray);
295 while($result = sqlFetchArray($res)) {
296 if ($result{"form_name"} == "New Patient Encounter") {
297 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
298 $pids[] = $result{"pid"};
301 $N = 6;
303 function postToGet($newpatient, $pids) {
304 $getstring="";
305 $serialnewpatient = serialize($newpatient);
306 $serialpids = serialize($pids);
307 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
309 return $getstring;
312 $iCounter = 0;
313 if(empty($newpatient)){ $newpatient = array(); }
314 foreach($newpatient as $patient){
316 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
317 while($result = sqlFetchArray($inclookupres)) {
318 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
322 print "<div id='superbill_patientdata'>";
323 print "<h1>".xlt('Patient Data').":</h1>";
324 printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
325 print "</div>";
327 print "<div id='superbill_insurancedata'>";
328 print "<h1>".xlt('Insurance Data').":</h1>";
329 print "<h2>".xlt('Primary').":</h2>";
330 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
331 print "<h2>".xlt('Secondary').":</h2>";
332 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
333 print "<h2>".xlt('Tertiary').":</h2>";
334 printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
335 print "</div>";
337 print "<div id='superbill_billingdata'>";
338 print "<h1>".xlt('Billing Information').":</h1>";
339 if (count($patient) > 0) {
340 $billings = array();
341 echo "<table width='100%'>";
342 echo "<tr>";
343 echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
344 echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
345 echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
346 echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
347 $total = 0.00;
348 $copays = 0.00;
349 //foreach ($patient as $be) {
351 $ta = explode(":",$patient);
352 $billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);
354 $billings[] = $billing;
355 foreach ($billing as $b) {
356 // grab the date to reformat it in the output
357 $bdate = strtotime($b['date']);
359 echo "<tr>\n";
360 echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
361 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
362 echo "<td class='text'>";
363 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;";
364 echo "</td>\n";
365 echo "<td class='text'>";
366 echo oeFormatMoney($b['fee']);
367 echo "</td>\n";
368 echo "</tr>\n";
369 $total += $b['fee'];
371 // Calculate the copay for the encounter
372 $copays = getPatientCopay($pids[$iCounter],$ta[1]);
374 echo "<tr><td>&nbsp;</td></tr>";
375 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
376 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
377 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
378 echo "</table>";
379 echo "<pre>";
380 //print_r($billings);
381 echo "</pre>";
383 echo "</div>";
385 ++$iCounter;
386 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
387 print "<hr class='pagebreak' />";
391 </div>
393 </body>
395 </html>