4 * This module shows relative insurance usage by unique patients
5 * that are seen within a given time period. Each patient that had
6 * a visit is counted only once, regardless of how many visits.
9 * @link http://www.open-emr.org
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("../../library/patient.inc");
18 use OpenEMR\Common\Csrf\CsrfUtils
;
19 use OpenEMR\Core\Header
;
22 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
23 CsrfUtils
::csrfNotVerified();
27 $form_from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
28 $form_to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
30 if (!empty($_POST['form_csvexport'])) {
31 header("Pragma: public");
33 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
34 header("Content-Type: application/force-download");
35 header("Content-Disposition: attachment; filename=insurance_distribution.csv");
36 header("Content-Description: File Transfer");
39 echo csvEscape("Insurance") . ',';
40 echo csvEscape("Charges") . ',';
41 echo csvEscape("Visits") . ',';
42 echo csvEscape("Patients") . ',';
43 echo csvEscape("Pt Pct") . "\n";
50 <title
><?php
echo xlt('Patient Insurance Distribution'); ?
></title
>
52 <?php Header
::setupHeader('datetime-picker'); ?
>
56 var win
= top
.printLogSetup ? top
: opener
.top
;
57 win
.printLogSetup(document
.getElementById('printbutton'));
59 $
('.datepicker').datetimepicker({
60 <?php
$datetimepicker_timepicker = false; ?
>
61 <?php
$datetimepicker_showseconds = false; ?
>
62 <?php
$datetimepicker_formatInput = true; ?
>
63 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
64 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
71 /* specifically include & exclude from printing */
77 #report_parameters_daterange {
81 #report_results table {
86 /* specifically exclude some from the screen */
88 #report_parameters_daterange {
97 <body
class="body_top">
99 <!-- Required
for the popup date selectors
-->
100 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
102 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Insurance Distribution'); ?
></span
>
104 <div id
="report_parameters_daterange">
105 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt("to{{Range}}") . " " . text(oeFormatShortDate($form_to_date)); ?
>
108 <form name
='theform' method
='post' action
='insurance_allocation_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
109 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
111 <div id
="report_parameters">
112 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
113 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
118 <div style
='float:left'>
122 <td
class='col-form-label'>
123 <?php
echo xlt('From'); ?
>:
126 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
128 <td
class='col-form-label'>
129 <?php
echo xlt('To{{Range}}'); ?
>:
132 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
140 <td
class='h-100' align
='left' valign
='middle'>
141 <table
class='w-100 h-100' style
='border-left:1px solid;'>
144 <div
class="text-center">
145 <div
class="btn-group" role
="group">
146 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#form_csvexport").val(""); $("#theform").submit();'>
147 <?php
echo xlt('Submit'); ?
>
149 <?php
if (!empty($_POST['form_refresh'])) { ?
>
150 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
151 <?php
echo xlt('Print'); ?
>
153 <a href
='#' class='btn btn-secondary btn-transmit' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
154 <?php
echo xlt('Export to CSV'); ?
>
167 </div
> <!-- end parameters
-->
169 <div id
="report_results">
170 <table
class='table'>
172 <thead
class='thead-light'>
173 <th align
='left'> <?php
echo xlt('Primary Insurance'); ?
> </th
>
174 <th align
='right'> <?php
echo xlt('Charges'); ?
> </th
>
175 <th align
='right'> <?php
echo xlt('Visits'); ?
> </th
>
176 <th align
='right'> <?php
echo xlt('Patients'); ?
> </th
>
177 <th align
='right'> <?php
echo xlt('Pt %'); ?
> </th
>
182 if (!empty($_POST['form_refresh']) ||
!empty($_POST['form_csvexport'])) {
183 $query = "SELECT b.pid, b.encounter, SUM(b.fee) AS charges, " .
184 "MAX(fe.date) AS date " .
185 "FROM form_encounter AS fe, billing AS b " .
186 "WHERE fe.date >= ? AND fe.date <= ? " .
187 "AND b.pid = fe.pid AND b.encounter = fe.encounter " .
188 "AND b.code_type != 'COPAY' AND b.activity > 0 AND b.fee != 0 " .
189 "GROUP BY b.pid, b.encounter ORDER BY b.pid, b.encounter";
191 $res = sqlStatement($query, array((!empty($form_from_date)) ?
$form_from_date : '0000-00-00', $form_to_date));
196 while ($row = sqlFetchArray($res)) {
197 $patient_id = $row['pid'];
198 $encounter_date = $row['date'];
199 $irow = sqlQuery("SELECT insurance_companies.name " .
200 "FROM insurance_data, insurance_companies WHERE " .
201 "insurance_data.pid = ? AND " .
202 "insurance_data.type = 'primary' AND " .
203 "(insurance_data.date <= ? OR insurance_data.date IS NULL) AND " .
204 "insurance_companies.id = insurance_data.provider " .
205 "ORDER BY insurance_data.date DESC LIMIT 1", array($patient_id, $encounter_date));
206 $plan = (!empty($irow['name'])) ?
$irow['name'] : '-- No Insurance --';
207 $insarr[$plan]['visits'] = $insarr[$plan]['visits'] ??
null;
208 $insarr[$plan]['visits'] +
= 1;
209 $insarr[$plan]['charges'] = $insarr[$plan]['charges'] ??
null;
210 $insarr[$plan]['charges'] +
= sprintf('%0.2f', $row['charges']);
211 if ($patient_id != $prev_pid) {
213 $insarr[$plan]['patients'] = $insarr[$plan]['patients'] ??
null;
214 $insarr[$plan]['patients'] +
= 1;
215 $prev_pid = $patient_id;
221 foreach ($insarr as $key => $val) {
222 if ($_POST['form_csvexport']) {
223 echo csvEscape($key) . ',';
224 echo csvEscape(oeFormatMoney($val['charges'])) . ',';
225 echo csvEscape($val['visits']) . ',';
226 echo csvEscape($val['patients']) . ',';
227 echo csvEscape(sprintf("%.1f", $val['patients'] * 100 / $patcount)) . "\n";
232 <?php
echo text($key); ?
>
235 <?php
echo text(oeFormatMoney($val['charges'])); ?
>
238 <?php
echo text($val['visits']); ?
>
241 <?php
echo text($val['patients']); ?
>
244 <?php
printf("%.1f", $val['patients'] * 100 / $patcount) ?
>
252 if (empty($_POST['form_csvexport'])) {
257 </div
> <!-- end of results
-->