7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once(dirname(__file__
) . "/../globals.php");
14 require_once("$srcdir/forms.inc.php");
15 require_once("$srcdir/patient.inc.php");
16 require_once("$srcdir/report.inc.php");
18 use OpenEMR\Common\Acl\AclMain
;
19 use OpenEMR\Billing\BillingUtilities
;
20 use OpenEMR\Common\Csrf\CsrfUtils
;
21 use OpenEMR\Common\Twig\TwigContainer
;
22 use OpenEMR\Core\Header
;
23 use OpenEMR\Services\FacilityService
;
25 if (!AclMain
::aclCheckCore('encounters', 'coding_a')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Superbill")]);
31 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
32 CsrfUtils
::csrfNotVerified();
36 $facilityService = new FacilityService();
38 $startdate = $enddate = "";
39 if (empty($_POST['start']) ||
empty($_POST['end'])) {
40 // set some default dates
41 $startdate = date('Y-m-d', (time() - 30 * 24 * 60 * 60));
42 $enddate = date('Y-m-d', time());
45 $startdate = DateToYYYYMMDD($_POST['start']);
46 $enddate = DateToYYYYMMDD($_POST['end']);
49 //Patient related stuff
50 if (!empty($_POST["form_patient"])) {
51 $form_patient = isset($_POST['form_patient']) ?
$_POST['form_patient'] : '';
54 $form_pid = isset($_POST['form_pid']) ?
$_POST['form_pid'] : '';
55 if (empty($form_patient)) {
63 <?php Header
::setupHeader('datetime-picker'); ?
>
72 page
-break-after
: always
;
77 #superbill_description {
93 #superbill_description {
98 border
: 2px dashed
var(--black
);
104 #superbill_description,
105 #superbill_startingdate,
106 #superbill_endingdate {
109 #superbill_patientdata h1 {
115 background
-color
: var(--gray200
);
116 border
: 1px solid
var(--black
);
118 #superbill_insurancedata {
121 #superbill_insurancedata h1 {
127 background
-color
: var(--gray200
);
128 border
: 1px solid
var(--black
);
130 #superbill_insurancedata h2 {
136 background
-color
: var(--gray200
);
138 #superbill_billingdata {
141 #superbill_billingdata h1 {
147 background
-color
: var(--gray200
);
148 border
: 1px solid
var(--black
);
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
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
193 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
197 <div style
='float: left'>
201 <td
class='label_custom'>
202 <?php
echo xlt('Start Date'); ?
>:
205 <input type
='text' class='form-control datepicker' name
='start' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($startdate)); ?>' />
207 <td
class='label_custom'>
208 <?php
echo xlt('End Date'); ?
>:
211 <input type
='text' class='form-control datepicker' name
='end' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($enddate)); ?>' />
215  
; 
;<span
class='text'><?php
echo xlt('Patient'); ?
>: </span
>
218 <input type
='text' class='form-control' size
='20' name
='form_patient' style
='width:100%;cursor:pointer;' value
='<?php echo (!empty($form_patient)) ? attr($form_patient) : xla('Click To Select
'); ?>' onclick
='sel_patient()' title
='<?php echo xla('Click to select patient
'); ?>' />
219 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
229 <td
class='h-100' align
='left' valign
='middle'>
230 <table
class="w-100 h-100" style
='border-left:1px solid;' >
233 <div style
='margin-left:15px'>
234 <a href
='#' class='btn btn-primary' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
236 <?php
echo xlt('Submit'); ?
>
240 <?php
if (!empty($_POST['form_refresh'])) { ?
>
241 <a href
='#' class='btn btn-primary' id
='printbutton'>
243 <?php
echo xlt('Print'); ?
>
254 </div
> <!-- end of parameters
-->
258 <div id
="superbill_results">
261 if (!(empty($_POST['start']) ||
empty($_POST['end']))) {
262 $facility = $facilityService->getPrimaryBillingLocation();
265 <h2
><?php
echo text($facility['name'] ??
'')?
></h2
>
266 <?php
echo text($facility['street'] ??
'')?
><br
/>
267 <?php
echo text($facility['city'] ??
'')?
>, <?php
echo text($facility['state'] ??
'')?
> <?php
echo text($facility['postal_code'] ??
'')?
><br
/>
271 $sqlBindArray = array();
272 $res_query = "select * from forms where " .
273 "form_name = 'New Patient Encounter' and " .
274 "date between ? and ? " ;
275 array_push($sqlBindArray, $startdate, $enddate);
277 $res_query .= " and pid=? ";
278 array_push($sqlBindArray, $form_pid);
281 $res_query .= " order by date DESC" ;
282 $res = sqlStatement($res_query, $sqlBindArray);
284 while ($result = sqlFetchArray($res)) {
285 if ($result["form_name"] == "New Patient Encounter") {
286 $newpatient[] = $result["form_id"] . ":" . $result["encounter"];
287 $pids[] = $result["pid"];
293 function postToGet($newpatient, $pids)
296 $serialnewpatient = serialize($newpatient);
297 $serialpids = serialize($pids);
298 $getstring = "newpatient=" . urlencode($serialnewpatient) . "&pids=" . urlencode($serialpids);
304 if (empty($newpatient)) {
305 $newpatient = array();
308 foreach ($newpatient as $patient) {
310 $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
311 while($result = sqlFetchArray($inclookupres)) {
312 include_once("{$GLOBALS['incdir']}/forms/" . $result["formdir"] . "/report.php");
316 print "<div id='superbill_patientdata'>";
317 print "<h1>" . xlt('Patient Data') . ":</h1>";
318 printRecDataOne($patient_data_array, getRecPatientData($pids[$iCounter]), $N);
321 print "<div id='superbill_insurancedata'>";
322 print "<h1>" . xlt('Insurance Data') . ":</h1>";
323 print "<h2>" . xlt('Primary') . ":</h2>";
324 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "primary"), $N);
325 print "<h2>" . xlt('Secondary') . ":</h2>";
326 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "secondary"), $N);
327 print "<h2>" . xlt('Tertiary') . ":</h2>";
328 printRecDataOne($insurance_data_array, getRecInsuranceData($pids[$iCounter], "tertiary"), $N);
331 print "<div id='superbill_billingdata'>";
332 print "<h1>" . xlt('Billing Information') . ":</h1>";
333 if (!empty($patient)) {
335 echo "<table class='table w-100'>";
337 echo "<td class='bold' width='10%'>" . xlt('Date') . "</td>";
338 echo "<td class='bold' width='20%'>" . xlt('Provider') . "</td>";
339 echo "<td class='bold' width='40%'>" . xlt('Code') . "</td>";
340 echo "<td class='bold' width='10%'>" . xlt('Fee') . "</td></tr>\n";
343 //foreach ($patient as $be) {
345 $ta = explode(":", $patient);
346 $billing = getPatientBillingEncounter($pids[$iCounter], $ta[1]);
348 $billings[] = $billing;
349 foreach ($billing as $b) {
350 // grab the date to reformat it in the output
351 $bdate = strtotime($b['date']);
354 echo "<td class='text' style='font-size: 0.8em'>" . text(oeFormatShortDate(date("Y-m-d", $bdate))) . "<BR>" . date("h:i a", $bdate) . "</td>";
355 echo "<td class='text'>" . text($b['provider_name']) . "</td>";
356 echo "<td class='text'>";
357 echo text($b['code_type']) . ":\t" . text($b['code']) . " " . text($b['modifier']) . " " . text($b['code_text']) . " ";
359 echo "<td class='text'>";
360 echo oeFormatMoney($b['fee']);
366 // Calculate the copay for the encounter
367 $copays = BillingUtilities
::getPatientCopay($pids[$iCounter], $ta[1]);
369 echo "<tr><td> </td></tr>";
370 echo "<tr><td class='font-weight-bold text-right' colspan='3'>" . xlt('Sub-Total') . "</td><td class='text'>" . text(oeFormatMoney($total +
abs($copays))) . "</td></tr>";
371 echo "<tr><td class='font-weight-bold text-right' colspan='3'>" . xlt('Copay Paid') . "</td><td class='text'>" . text(oeFormatMoney(abs($copays))) . "</td></tr>";
372 echo "<tr><td class='font-weight-bold text-right' colspan='3'>" . xlt('Total') . "</td><td class='text'>" . text(oeFormatMoney($total)) . "</td></tr>";
375 //print_r($billings);
382 print "<br/><br/>" . xlt('Physician Signature') . ": _______________________________________________";
383 print "<hr class='pagebreak' />";