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());
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 == '') {
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">
58 page
-break-after
: always
;
63 #superbill_description {
79 #superbill_description {
84 border
: 2px dashed black
;
90 #superbill_description {
93 #superbill_startingdate {
96 #superbill_endingdate {
100 #superbill_patientdata {
102 #superbill_patientdata h1 {
108 background
-color
: #eee;
109 border
: 1px solid black
;
111 #superbill_insurancedata {
114 #superbill_insurancedata h1 {
120 background
-color
: #eee;
121 border
: 1px solid black
;
123 #superbill_insurancedata h2 {
129 background
-color
: #eee;
131 #superbill_billingdata {
134 #superbill_billingdata h1 {
140 background
-color
: #eee;
141 border
: 1px solid black
;
143 #superbill_signature {
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
;
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.'); ?
>
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
=''/>
196 <div style
='float:left'>
200 <td
class='label_custom'>
201 <?php
echo xlt('Start Date'); ?
>:
204 <input type
='text' class='datepicker' name
='start' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($startdate)); ?>'>
206 <td
class='label_custom'>
207 <?php
echo xlt('End Date'); ?
>:
210 <input type
='text' class='datepicker' name
='end' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($enddate)); ?>'>
214  
; 
;<span
class='text'><?php
echo xlt('Patient'); ?
>: </span
>
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); ?>' />
228 <td align
='left' valign
='middle' height
="100%">
229 <table style
='border-left:1px solid; width:100%; height:100%' >
232 <div style
='margin-left:15px'>
233 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
235 <?php
echo xlt('Submit'); ?
>
239 <?php
if ($_POST['form_refresh']) { ?
>
240 <a href
='#' class='css_button' id
='printbutton'>
242 <?php
echo xlt('Print'); ?
>
253 </div
> <!-- end of parameters
-->
257 <div id
="superbill_results">
260 if (!(empty($_POST['start']) ||
empty($_POST['end']))) {
261 $facility = $facilityService->getPrimaryBillingLocation();
264 <h2
><?php
text($facility['name'])?
></h2
>
265 <?php
text($facility['street'])?
><br
>
266 <?php
text($facility['city'])?
>, <?php
text($facility['state'])?
> <?php
text($facility['postal_code'])?
><br
>
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);
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"};
292 function postToGet($newpatient, $pids)
295 $serialnewpatient = serialize($newpatient);
296 $serialpids = serialize($pids);
297 $getstring = "newpatient=".urlencode($serialnewpatient)."&pids=".urlencode($serialpids);
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);
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);
330 print "<div id='superbill_billingdata'>";
331 print "<h1>".xlt('Billing Information').":</h1>";
332 if (count($patient) > 0) {
334 echo "<table width='100%'>";
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";
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']);
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']) . " ". text($b['modifier']) . " " . text($b['code_text']) . " ";
358 echo "<td class='text'>";
359 echo oeFormatMoney($b['fee']);
365 // Calculate the copay for the encounter
366 $copays = getPatientCopay($pids[$iCounter], $ta[1]);
368 echo "<tr><td> </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>";
374 //print_r($billings);
381 print "<br/><br/>".xlt('Physician Signature').": _______________________________________________";
382 print "<hr class='pagebreak' />";