3 * This module shows relative insurance usage by unique patients
4 * that are seen within a given time period. Each patient that had
5 * a visit is counted only once, regardless of how many visits.
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Brady Miller <brady.g.miller@gmail.com>
20 * @link http://www.open-emr.org
24 include_once("../globals.php");
25 include_once("../../library/patient.inc");
26 include_once("../../library/acl.inc");
27 require_once("../../library/formatting.inc.php");
29 // Might want something different here.
31 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
33 $from_date = fixDate($_POST['form_from_date']);
34 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
36 if ($_POST['form_csvexport']) {
37 header("Pragma: public");
39 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
40 header("Content-Type: application/force-download");
41 header("Content-Disposition: attachment; filename=insurance_distribution.csv");
42 header("Content-Description: File Transfer");
49 echo '"Pt Pct"' . "\n";
56 <?php
html_header_show();?
>
57 <title
><?php
xl('Patient Insurance Distribution','e'); ?
></title
>
59 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
60 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
61 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
62 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
64 <script language
="JavaScript">
65 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
67 $
(document
).ready(function() {
68 var win
= top
.printLogSetup ? top
: opener
.top
;
69 win
.printLogSetup(document
.getElementById('printbutton'));
71 $
('.datepicker').datetimepicker({
72 <?php
$datetimepicker_timepicker = false; ?
>
73 <?php
$datetimepicker_formatInput = false; ?
>
74 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
75 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
81 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
82 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
84 <style type
="text/css">
86 /* specifically include & exclude from printing */
92 #report_parameters_daterange {
96 #report_results table {
101 /* specifically exclude some from the screen */
103 #report_parameters_daterange {
112 <body
class="body_top">
114 <!-- Required
for the popup date selectors
-->
115 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
117 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient Insurance Distribution','e'); ?
></span
>
119 <div id
="report_parameters_daterange">
120 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
123 <form name
='theform' method
='post' action
='insurance_allocation_report.php' id
='theform'>
125 <div id
="report_parameters">
126 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
127 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
132 <div style
='float:left'>
137 <?php
xl('From','e'); ?
>:
140 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
144 <?php
xl('To','e'); ?
>:
147 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
156 <td align
='left' valign
='middle' height
="100%">
157 <table style
='border-left:1px solid; width:100%; height:100%' >
160 <div style
='margin-left:15px'>
161 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
163 <?php
xl('Submit','e'); ?
>
167 <?php
if ($_POST['form_refresh']) { ?
>
168 <a href
='#' class='css_button' id
='printbutton'>
170 <?php
xl('Print','e'); ?
>
173 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
175 <?php
xl('Export to CSV','e'); ?
>
188 </div
> <!-- end parameters
-->
190 <div id
="report_results">
194 <th align
='left'> <?php
xl('Primary Insurance','e'); ?
> </th
>
195 <th align
='right'> <?php
xl('Charges','e'); ?
> </th
>
196 <th align
='right'> <?php
xl('Visits','e'); ?
> </th
>
197 <th align
='right'> <?php
xl('Patients','e'); ?
> </th
>
198 <th align
='right'> <?php
xl('Pt %','e'); ?
> </th
>
203 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
205 $from_date = fixDate($_POST['form_from_date']);
206 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
208 $query = "SELECT b.pid, b.encounter, SUM(b.fee) AS charges, " .
209 "MAX(fe.date) AS date " .
210 "FROM form_encounter AS fe, billing AS b " .
211 "WHERE fe.date >= '$from_date' AND fe.date <= '$to_date' " .
212 "AND b.pid = fe.pid AND b.encounter = fe.encounter " .
213 "AND b.code_type != 'COPAY' AND b.activity > 0 AND b.fee != 0 " .
214 "GROUP BY b.pid, b.encounter ORDER BY b.pid, b.encounter";
216 $res = sqlStatement($query);
221 while ($row = sqlFetchArray($res)) {
222 $patient_id = $row['pid'];
223 $encounter_date = $row['date'];
224 $irow = sqlQuery("SELECT insurance_companies.name " .
225 "FROM insurance_data, insurance_companies WHERE " .
226 "insurance_data.pid = $patient_id AND " .
227 "insurance_data.type = 'primary' AND " .
228 "insurance_data.date <= '$encounter_date' AND " .
229 "insurance_companies.id = insurance_data.provider " .
230 "ORDER BY insurance_data.date DESC LIMIT 1");
231 $plan = $irow['name'] ?
$irow['name'] : '-- No Insurance --';
232 $insarr[$plan]['visits'] +
= 1;
233 $insarr[$plan]['charges'] +
= sprintf('%0.2f', $row['charges']);
234 if ($patient_id != $prev_pid) {
236 $insarr[$plan]['patients'] +
= 1;
237 $prev_pid = $patient_id;
243 while (list($key, $val) = each($insarr)) {
244 if ($_POST['form_csvexport']) {
245 echo '"' . $key . '",';
246 echo '"' . oeFormatMoney($val['charges']) . '",';
247 echo '"' . $val['visits'] . '",';
248 echo '"' . $val['patients'] . '",';
249 echo '"' . sprintf("%.1f", $val['patients'] * 100 / $patcount) . '"' . "\n";
258 <?php
echo oeFormatMoney($val['charges']) ?
>
261 <?php
echo $val['visits'] ?
>
264 <?php
echo $val['patients'] ?
>
267 <?php
printf("%.1f", $val['patients'] * 100 / $patcount) ?
>
275 if (! $_POST['form_csvexport']) {
280 </div
> <!-- end of results
-->