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>;.
18 * @author Brady Miller <brady.g.miller@gmail.com>
19 * @link http://www.open-emr.org
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");
31 use OpenEMR\Services\FacilityService
;
33 $facilityService = new FacilityService();
35 $startdate = $enddate = "";
36 if (empty($_POST['start']) ||
empty($_POST['end'])) {
37 // set some default dates
38 $startdate = date('Y-m-d', (time() - 30*24*60*60));
39 $enddate = date('Y-m-d', time());
42 $startdate = $_POST['start'];
43 $enddate = $_POST['end'];
46 //Patient related stuff
47 if ($_POST["form_patient"]) {
48 $form_patient = isset($_POST['form_patient']) ?
$_POST['form_patient'] : '';
51 $form_pid = isset($_POST['form_pid']) ?
$_POST['form_pid'] : '';
52 if ($form_patient == '') {
59 <?php
html_header_show();?
>
61 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
62 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
71 page
-break-after
: always
;
76 #superbill_description {
92 #superbill_description {
97 border
: 2px dashed black
;
103 #superbill_description {
106 #superbill_startingdate {
109 #superbill_endingdate {
113 #superbill_patientdata {
115 #superbill_patientdata h1 {
121 background
-color
: #eee;
122 border
: 1px solid black
;
124 #superbill_insurancedata {
127 #superbill_insurancedata h1 {
133 background
-color
: #eee;
134 border
: 1px solid black
;
136 #superbill_insurancedata h2 {
142 background
-color
: #eee;
144 #superbill_billingdata {
147 #superbill_billingdata h1 {
153 background
-color
: #eee;
154 border
: 1px solid black
;
156 #superbill_signature {
161 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
162 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
163 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
165 <script language
="Javascript">
166 $
(document
).ready(function() {
167 var win
= top
.printLogSetup ? top
: opener
.top
;
168 win
.printLogSetup(document
.getElementById('printbutton'));
170 $
('.datepicker').datetimepicker({
171 <?php
$datetimepicker_timepicker = false; ?
>
172 <?php
$datetimepicker_showseconds = false; ?
>
173 <?php
$datetimepicker_formatInput = false; ?
>
174 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
175 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
179 // CapMinds :: invokes find-patient popup.
180 function sel_patient() {
181 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
184 // CapMinds :: callback by the find-patient popup.
185 function setpatient(pid
, lname
, fname
, dob
) {
186 var f
= document
.theform
;
187 f
.form_patient
.value
= lname +
', ' + fname
;
188 f
.form_pid
.value
= pid
;
194 <body
class="body_top">
196 <span
class='title'><?php
echo xlt('Reports'); ?
> - <?php
echo xlt('Superbill'); ?
></span
>
198 <div id
="superbill_description" class='text'>
199 <?php
echo xlt('Superbills, sometimes referred to as Encounter Forms or Routing Slips, are an essential part of most medical practices.'); ?
>
202 <div id
="report_parameters">
204 <form method
="post" name
="theform" id
='theform' action
="custom_report_range.php">
205 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
209 <div style
='float:left'>
213 <td
class='label_custom'>
214 <?php
echo xlt('Start Date'); ?
>:
217 <input type
='text' class='datepicker' name
='start' id
="form_from_date" size
='10' value
='<?php echo attr($startdate) ?>'
220 <td
class='label_custom'>
221 <?php
echo xlt('End Date'); ?
>:
224 <input type
='text' class='datepicker' name
='end' id
="form_to_date" size
='10' value
='<?php echo attr($enddate) ?>'
229  
; 
;<span
class='text'><?php
echo xlt('Patient'); ?
>: </span
>
232 <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
'); ?>' />
233 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
243 <td align
='left' valign
='middle' height
="100%">
244 <table style
='border-left:1px solid; width:100%; height:100%' >
247 <div style
='margin-left:15px'>
248 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
250 <?php
echo xlt('Submit'); ?
>
254 <?php
if ($_POST['form_refresh']) { ?
>
255 <a href
='#' class='css_button' id
='printbutton'>
257 <?php
echo xlt('Print'); ?
>
268 </div
> <!-- end of parameters
-->
272 <div id
="superbill_results">
275 if (!(empty($_POST['start']) ||
empty($_POST['end']))) {
276 $facility = $facilityService->getPrimaryBillingLocation();
279 <h2
><?php
text($facility['name'])?
></h2
>
280 <?php
text($facility['street'])?
><br
>
281 <?php
text($facility['city'])?
>, <?php
text($facility['state'])?
> <?php
text($facility['postal_code'])?
><br
>
285 $sqlBindArray = array();
286 $res_query = "select * from forms where " .
287 "form_name = 'New Patient Encounter' and " .
288 "date between ? and ? " ;
289 array_push($sqlBindArray, $startdate, $enddate);
291 $res_query.= " and pid=? ";
292 array_push($sqlBindArray, $form_pid);
295 $res_query.= " order by date DESC" ;
296 $res =sqlStatement($res_query, $sqlBindArray);
298 while ($result = sqlFetchArray($res)) {
299 if ($result{"form_name"} == "New Patient Encounter") {
300 $newpatient[] = $result{"form_id"}.":".$result{"encounter"};
301 $pids[] = $result{"pid"};
307 function postToGet($newpatient, $pids)
310 $serialnewpatient = serialize($newpatient);
311 $serialpids = serialize($pids);
312 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
318 if (empty($newpatient)) {
319 $newpatient = array();
322 foreach ($newpatient as $patient) {
324 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
325 while($result = sqlFetchArray($inclookupres)) {
326 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
330 print "<div id='superbill_patientdata'>";
331 print "<h1>".xlt('Patient Data').":</h1>";
332 printRecDataOne($patient_data_array, getRecPatientData($pids[$iCounter]), $N);
335 print "<div id='superbill_insurancedata'>";
336 print "<h1>".xlt('Insurance Data').":</h1>";
337 print "<h2>".xlt('Primary').":</h2>";
338 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "primary"), $N);
339 print "<h2>".xlt('Secondary').":</h2>";
340 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "secondary"), $N);
341 print "<h2>".xlt('Tertiary').":</h2>";
342 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "tertiary"), $N);
345 print "<div id='superbill_billingdata'>";
346 print "<h1>".xlt('Billing Information').":</h1>";
347 if (count($patient) > 0) {
349 echo "<table width='100%'>";
351 echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
352 echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
353 echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
354 echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
357 //foreach ($patient as $be) {
359 $ta = explode(":", $patient);
360 $billing = getPatientBillingEncounter($pids[$iCounter], $ta[1]);
362 $billings[] = $billing;
363 foreach ($billing as $b) {
364 // grab the date to reformat it in the output
365 $bdate = strtotime($b['date']);
368 echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d", $bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
369 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
370 echo "<td class='text'>";
371 echo text($b['code_type']) . ":\t" . text($b['code']) . " ". text($b['modifier']) . " " . text($b['code_text']) . " ";
373 echo "<td class='text'>";
374 echo oeFormatMoney($b['fee']);
380 // Calculate the copay for the encounter
381 $copays = getPatientCopay($pids[$iCounter], $ta[1]);
383 echo "<tr><td> </td></tr>";
384 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total +
abs($copays)) . "</td></tr>";
385 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
386 echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
389 //print_r($billings);
396 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
397 print "<hr class='pagebreak' />";