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.
8 * @link http://www.open-emr.org
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 include_once("../globals.php");
15 include_once("../../library/patient.inc");
16 include_once("../../library/acl.inc");
18 use OpenEMR\Core\Header
;
20 // Might want something different here.
22 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
24 $form_from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
25 $form_to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
27 if ($_POST['form_csvexport']) {
28 header("Pragma: public");
30 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
31 header("Content-Type: application/force-download");
32 header("Content-Disposition: attachment; filename=insurance_distribution.csv");
33 header("Content-Description: File Transfer");
40 echo '"Pt Pct"' . "\n";
47 <title
><?php
echo xlt('Patient Insurance Distribution'); ?
></title
>
49 <?php Header
::setupHeader('datetime-picker'); ?
>
51 <script language
="JavaScript">
52 $
(document
).ready(function() {
53 var win
= top
.printLogSetup ? top
: opener
.top
;
54 win
.printLogSetup(document
.getElementById('printbutton'));
56 $
('.datepicker').datetimepicker({
57 <?php
$datetimepicker_timepicker = false; ?
>
58 <?php
$datetimepicker_showseconds = false; ?
>
59 <?php
$datetimepicker_formatInput = true; ?
>
60 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
61 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
66 <style type
="text/css">
68 /* specifically include & exclude from printing */
74 #report_parameters_daterange {
78 #report_results table {
83 /* specifically exclude some from the screen */
85 #report_parameters_daterange {
94 <body
class="body_top">
96 <!-- Required
for the popup date selectors
-->
97 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
99 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Insurance Distribution'); ?
></span
>
101 <div id
="report_parameters_daterange">
102 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt("to") . " ". text(oeFormatShortDate($form_to_date)); ?
>
105 <form name
='theform' method
='post' action
='insurance_allocation_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
107 <div id
="report_parameters">
108 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
109 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
114 <div style
='float:left'>
118 <td
class='control-label'>
119 <?php
echo xlt('From'); ?
>:
122 <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)); ?>'>
124 <td
class='control-label'>
125 <?php
echo xlt('To'); ?
>:
128 <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)); ?>'>
136 <td align
='left' valign
='middle' height
="100%">
137 <table style
='border-left:1px solid; width:100%; height:100%' >
140 <div
class="text-center">
141 <div
class="btn-group" role
="group">
142 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#form_csvexport").val(""); $("#theform").submit();'>
143 <?php
echo xlt('Submit'); ?
>
145 <?php
if ($_POST['form_refresh']) { ?
>
146 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
147 <?php
echo xlt('Print'); ?
>
149 <a href
='#' class='btn btn-default btn-transmit' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
150 <?php
echo xlt('Export to CSV'); ?
>
163 </div
> <!-- end parameters
-->
165 <div id
="report_results">
169 <th align
='left'> <?php
echo xlt('Primary Insurance'); ?
> </th
>
170 <th align
='right'> <?php
echo xlt('Charges'); ?
> </th
>
171 <th align
='right'> <?php
echo xlt('Visits'); ?
> </th
>
172 <th align
='right'> <?php
echo xlt('Patients'); ?
> </th
>
173 <th align
='right'> <?php
echo xlt('Pt %'); ?
> </th
>
178 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
179 $query = "SELECT b.pid, b.encounter, SUM(b.fee) AS charges, " .
180 "MAX(fe.date) AS date " .
181 "FROM form_encounter AS fe, billing AS b " .
182 "WHERE fe.date >= ? AND fe.date <= ? " .
183 "AND b.pid = fe.pid AND b.encounter = fe.encounter " .
184 "AND b.code_type != 'COPAY' AND b.activity > 0 AND b.fee != 0 " .
185 "GROUP BY b.pid, b.encounter ORDER BY b.pid, b.encounter";
187 $res = sqlStatement($query, array((!empty($form_from_date)) ?
$form_from_date : '0000-00-00', $form_to_date));
192 while ($row = sqlFetchArray($res)) {
193 $patient_id = $row['pid'];
194 $encounter_date = $row['date'];
195 $irow = sqlQuery("SELECT insurance_companies.name " .
196 "FROM insurance_data, insurance_companies WHERE " .
197 "insurance_data.pid = ? AND " .
198 "insurance_data.type = 'primary' AND " .
199 "insurance_data.date <= ? AND " .
200 "insurance_companies.id = insurance_data.provider " .
201 "ORDER BY insurance_data.date DESC LIMIT 1", array($patient_id, $encounter_date));
202 $plan = $irow['name'] ?
$irow['name'] : '-- No Insurance --';
203 $insarr[$plan]['visits'] +
= 1;
204 $insarr[$plan]['charges'] +
= sprintf('%0.2f', $row['charges']);
205 if ($patient_id != $prev_pid) {
207 $insarr[$plan]['patients'] +
= 1;
208 $prev_pid = $patient_id;
214 while (list($key, $val) = each($insarr)) {
215 if ($_POST['form_csvexport']) {
216 echo '"' . $key . '",';
217 echo '"' . oeFormatMoney($val['charges']) . '",';
218 echo '"' . $val['visits'] . '",';
219 echo '"' . $val['patients'] . '",';
220 echo '"' . sprintf("%.1f", $val['patients'] * 100 / $patcount) . '"' . "\n";
225 <?php
echo text($key); ?
>
228 <?php
echo oeFormatMoney($val['charges']); ?
>
231 <?php
echo text($val['visits']); ?
>
234 <?php
echo text($val['patients']); ?
>
237 <?php
printf("%.1f", $val['patients'] * 100 / $patcount) ?
>
245 if (! $_POST['form_csvexport']) {
250 </div
> <!-- end of results
-->