Add back popup dialogs for tabs U.I. (#1434)
[openemr.git] / interface / reports / custom_report_range.php
blob430677f13cd6f92472c10699e214b5463c0c9c10
1 <?php
2 /**
3 * Superbill Report
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 require_once(dirname(__file__)."/../globals.php");
13 require_once("$srcdir/forms.inc");
14 require_once("$srcdir/billing.inc");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/report.inc");
18 use OpenEMR\Services\FacilityService;
20 $facilityService = new FacilityService();
22 $startdate = $enddate = "";
23 if (empty($_POST['start']) || empty($_POST['end'])) {
24 // set some default dates
25 $startdate = date('Y-m-d', (time() - 30*24*60*60));
26 $enddate = date('Y-m-d', time());
27 } else {
28 // set dates
29 $startdate = DateToYYYYMMDD($_POST['start']);
30 $enddate = DateToYYYYMMDD($_POST['end']);
33 //Patient related stuff
34 if ($_POST["form_patient"]) {
35 $form_patient = isset($_POST['form_patient']) ? $_POST['form_patient'] : '';
38 $form_pid = isset($_POST['form_pid']) ? $_POST['form_pid'] : '';
39 if ($form_patient == '') {
40 $form_pid = '';
43 <html>
45 <head>
46 <?php html_header_show();?>
48 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
49 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
51 <style>
53 @media print {
54 .title {
55 visibility: hidden;
57 .pagebreak {
58 page-break-after: always;
59 border: none;
60 visibility: hidden;
63 #superbill_description {
64 visibility: hidden;
67 #report_parameters {
68 visibility: hidden;
70 #superbill_results {
71 margin-top: -30px;
75 @media screen {
76 .title {
77 visibility: visible;
79 #superbill_description {
80 visibility: visible;
82 .pagebreak {
83 width: 100%;
84 border: 2px dashed black;
86 #report_parameters {
87 visibility: visible;
90 #superbill_description {
91 margin: 10px;
93 #superbill_startingdate {
94 margin: 10px;
96 #superbill_endingdate {
97 margin: 10px;
100 #superbill_patientdata {
102 #superbill_patientdata h1 {
103 font-weight: bold;
104 font-size: 1.2em;
105 margin: 0px;
106 padding: 5px;
107 width: 100%;
108 background-color: #eee;
109 border: 1px solid black;
111 #superbill_insurancedata {
112 margin-top: 10px;
114 #superbill_insurancedata h1 {
115 font-weight: bold;
116 font-size: 1.2em;
117 margin: 0px;
118 padding: 5px;
119 width: 100%;
120 background-color: #eee;
121 border: 1px solid black;
123 #superbill_insurancedata h2 {
124 font-weight: bold;
125 font-size: 1.0em;
126 margin: 0px;
127 padding: 0px;
128 width: 100%;
129 background-color: #eee;
131 #superbill_billingdata {
132 margin-top: 10px;
134 #superbill_billingdata h1 {
135 font-weight: bold;
136 font-size: 1.2em;
137 margin: 0px;
138 padding: 5px;
139 width: 100%;
140 background-color: #eee;
141 border: 1px solid black;
143 #superbill_signature {
145 #superbill_logo {
147 </style>
148 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
149 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
150 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
152 <script language="Javascript">
153 $(document).ready(function() {
154 var win = top.printLogSetup ? top : opener.top;
155 win.printLogSetup(document.getElementById('printbutton'));
157 $('.datepicker').datetimepicker({
158 <?php $datetimepicker_timepicker = false; ?>
159 <?php $datetimepicker_showseconds = false; ?>
160 <?php $datetimepicker_formatInput = true; ?>
161 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
162 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
166 // CapMinds :: invokes find-patient popup.
167 function sel_patient() {
168 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
171 // CapMinds :: callback by the find-patient popup.
172 function setpatient(pid, lname, fname, dob) {
173 var f = document.theform;
174 f.form_patient.value = lname + ', ' + fname;
175 f.form_pid.value = pid;
178 </script>
179 </head>
181 <body class="body_top">
183 <span class='title'><?php echo xlt('Reports'); ?> - <?php echo xlt('Superbill'); ?></span>
185 <div id="superbill_description" class='text'>
186 <?php echo xlt('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.'); ?>
187 </div>
189 <div id="report_parameters">
191 <form method="post" name="theform" id='theform' action="custom_report_range.php">
192 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
193 <table>
194 <tr>
195 <td width='650px'>
196 <div style='float:left'>
198 <table class='text'>
199 <tr>
200 <td class='label_custom'>
201 <?php echo xlt('Start Date'); ?>:
202 </td>
203 <td>
204 <input type='text' class='datepicker' name='start' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($startdate)); ?>'>
205 </td>
206 <td class='label_custom'>
207 <?php echo xlt('End Date'); ?>:
208 </td>
209 <td>
210 <input type='text' class='datepicker' name='end' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($enddate)); ?>'>
211 </td>
213 <td>
214 &nbsp;&nbsp;<span class='text'><?php echo xlt('Patient'); ?>: </span>
215 </td>
216 <td>
217 <input type='text' size='20' name='form_patient' style='width:100%;cursor:pointer;cursor:hand' value='<?php echo ($form_patient) ? attr($form_patient) : xla('Click To Select'); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' />
218 <input type='hidden' name='form_pid' value='<?php echo attr($form_pid); ?>' />
219 </td>
220 </tr>
221 <tr><td>
222 </tr>
223 </table>
225 </div>
227 </td>
228 <td align='left' valign='middle' height="100%">
229 <table style='border-left:1px solid; width:100%; height:100%' >
230 <tr>
231 <td>
232 <div style='margin-left:15px'>
233 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
234 <span>
235 <?php echo xlt('Submit'); ?>
236 </span>
237 </a>
239 <?php if ($_POST['form_refresh']) { ?>
240 <a href='#' class='css_button' id='printbutton'>
241 <span>
242 <?php echo xlt('Print'); ?>
243 </span>
244 </a>
245 <?php } ?>
246 </div>
247 </td>
248 </tr>
249 </table>
250 </td>
251 </tr>
252 </table>
253 </div> <!-- end of parameters -->
255 </form>
257 <div id="superbill_results">
259 <?php
260 if (!(empty($_POST['start']) || empty($_POST['end']))) {
261 $facility = $facilityService->getPrimaryBillingLocation();
264 <h2><?php echo text($facility['name'])?></h2>
265 <?php echo text($facility['street'])?><br>
266 <?php echo text($facility['city'])?>, <?php echo text($facility['state'])?> <?php echo text($facility['postal_code'])?><br>
268 </p>
269 <?php
270 $sqlBindArray = array();
271 $res_query = "select * from forms where " .
272 "form_name = 'New Patient Encounter' and " .
273 "date between ? and ? " ;
274 array_push($sqlBindArray, $startdate, $enddate);
275 if ($form_pid) {
276 $res_query.= " and pid=? ";
277 array_push($sqlBindArray, $form_pid);
280 $res_query.= " order by date DESC" ;
281 $res =sqlStatement($res_query, $sqlBindArray);
283 while ($result = sqlFetchArray($res)) {
284 if ($result{"form_name"} == "New Patient Encounter") {
285 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
286 $pids[] = $result{"pid"};
290 $N = 6;
292 function postToGet($newpatient, $pids)
294 $getstring="";
295 $serialnewpatient = serialize($newpatient);
296 $serialpids = serialize($pids);
297 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
299 return $getstring;
302 $iCounter = 0;
303 if (empty($newpatient)) {
304 $newpatient = array();
307 foreach ($newpatient as $patient) {
309 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
310 while($result = sqlFetchArray($inclookupres)) {
311 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
315 print "<div id='superbill_patientdata'>";
316 print "<h1>".xlt('Patient Data').":</h1>";
317 printRecDataOne($patient_data_array, getRecPatientData($pids[$iCounter]), $N);
318 print "</div>";
320 print "<div id='superbill_insurancedata'>";
321 print "<h1>".xlt('Insurance Data').":</h1>";
322 print "<h2>".xlt('Primary').":</h2>";
323 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "primary"), $N);
324 print "<h2>".xlt('Secondary').":</h2>";
325 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "secondary"), $N);
326 print "<h2>".xlt('Tertiary').":</h2>";
327 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "tertiary"), $N);
328 print "</div>";
330 print "<div id='superbill_billingdata'>";
331 print "<h1>".xlt('Billing Information').":</h1>";
332 if (count($patient) > 0) {
333 $billings = array();
334 echo "<table width='100%'>";
335 echo "<tr>";
336 echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
337 echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
338 echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
339 echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
340 $total = 0.00;
341 $copays = 0.00;
342 //foreach ($patient as $be) {
344 $ta = explode(":", $patient);
345 $billing = getPatientBillingEncounter($pids[$iCounter], $ta[1]);
347 $billings[] = $billing;
348 foreach ($billing as $b) {
349 // grab the date to reformat it in the output
350 $bdate = strtotime($b['date']);
352 echo "<tr>\n";
353 echo "<td class='text' style='font-size: 0.8em'>" . text(oeFormatShortDate(date("Y-m-d", $bdate))) . "<BR>" . date("h:i a", $bdate) . "</td>";
354 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
355 echo "<td class='text'>";
356 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;";
357 echo "</td>\n";
358 echo "<td class='text'>";
359 echo oeFormatMoney($b['fee']);
360 echo "</td>\n";
361 echo "</tr>\n";
362 $total += $b['fee'];
365 // Calculate the copay for the encounter
366 $copays = getPatientCopay($pids[$iCounter], $ta[1]);
368 echo "<tr><td>&nbsp;</td></tr>";
369 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
370 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
371 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
372 echo "</table>";
373 echo "<pre>";
374 //print_r($billings);
375 echo "</pre>";
378 echo "</div>";
380 ++$iCounter;
381 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
382 print "<hr class='pagebreak' />";
386 </div>
388 </body>
390 </html>