new datepicker in encounter
[openemr.git] / interface / reports / insurance_allocation_report.php
blobc2b9cd6867198b07194ed91d6783c71bf13db6f6
1 <?php
2 /**
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>;.
18 * @package OpenEMR
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");
38 header("Expires: 0");
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");
43 // CSV headers:
44 if (true) {
45 echo '"Insurance",';
46 echo '"Charges",';
47 echo '"Visits",';
48 echo '"Patients",';
49 echo '"Pt Pct"' . "\n";
52 else {
54 <html>
55 <head>
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 ?>
76 });
77 });
79 </script>
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 */
87 @media print {
88 #report_parameters {
89 visibility: hidden;
90 display: none;
92 #report_parameters_daterange {
93 visibility: visible;
94 display: inline;
96 #report_results table {
97 margin-top: 0px;
101 /* specifically exclude some from the screen */
102 @media screen {
103 #report_parameters_daterange {
104 visibility: hidden;
105 display: none;
109 </style>
110 </head>
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)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
121 </div>
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=''/>
129 <table>
130 <tr>
131 <td width='410px'>
132 <div style='float:left'>
134 <table class='text'>
135 <tr>
136 <td class='label'>
137 <?php xl('From','e'); ?>:
138 </td>
139 <td>
140 <input type='text' class='datepicker' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
141 title='yyyy-mm-dd'>
142 </td>
143 <td class='label'>
144 <?php xl('To','e'); ?>:
145 </td>
146 <td>
147 <input type='text' class='datepicker' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
148 title='yyyy-mm-dd'>
149 </td>
150 </tr>
151 </table>
153 </div>
155 </td>
156 <td align='left' valign='middle' height="100%">
157 <table style='border-left:1px solid; width:100%; height:100%' >
158 <tr>
159 <td>
160 <div style='margin-left:15px'>
161 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
162 <span>
163 <?php xl('Submit','e'); ?>
164 </span>
165 </a>
167 <?php if ($_POST['form_refresh']) { ?>
168 <a href='#' class='css_button' id='printbutton'>
169 <span>
170 <?php xl('Print','e'); ?>
171 </span>
172 </a>
173 <a href='#' class='css_button' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
174 <span>
175 <?php xl('Export to CSV','e'); ?>
176 </span>
177 </a>
178 <?php } ?>
179 </div>
180 </td>
181 </tr>
182 </table>
183 </td>
184 </tr>
185 </table>
187 </form>
188 </div> <!-- end parameters -->
190 <div id="report_results">
191 <table>
193 <thead>
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>
199 </thead>
200 <tbody>
201 <?php
202 } // end not export
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);
217 $insarr = array();
218 $prev_pid = 0;
219 $patcount = 0;
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) {
235 ++$patcount;
236 $insarr[$plan]['patients'] += 1;
237 $prev_pid = $patient_id;
241 ksort($insarr);
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";
251 else {
253 <tr>
254 <td>
255 <?php echo $key ?>
256 </td>
257 <td align='right'>
258 <?php echo oeFormatMoney($val['charges']) ?>
259 </td>
260 <td align='right'>
261 <?php echo $val['visits'] ?>
262 </td>
263 <td align='right'>
264 <?php echo $val['patients'] ?>
265 </td>
266 <td align='right'>
267 <?php printf("%.1f", $val['patients'] * 100 / $patcount) ?>
268 </td>
269 </tr>
270 <?php
271 } // end not export
272 } // end while
273 } // end if
275 if (! $_POST['form_csvexport']) {
278 </tbody>
279 </table>
280 </div> <!-- end of results -->
282 </body>
284 </html>
285 <?php
286 } // end not export