2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 // This module shows relative insurance usage by unique patients
8 // that are seen within a given time period. Each patient that had
9 // a visit is counted only once, regardless of how many visits.
11 include_once("../globals.php");
12 include_once("../../library/patient.inc");
13 include_once("../../library/acl.inc");
14 require_once("../../library/formatting.inc.php");
16 // Might want something different here.
18 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
20 $from_date = fixDate($_POST['form_from_date']);
21 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
23 if ($_POST['form_csvexport']) {
24 header("Pragma: public");
26 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
27 header("Content-Type: application/force-download");
28 header("Content-Disposition: attachment; filename=insurance_distribution.csv");
29 header("Content-Description: File Transfer");
36 echo '"Pt Pct"' . "\n";
43 <?php
html_header_show();?
>
44 <title
><?php
xl('Patient Insurance Distribution','e'); ?
></title
>
45 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
46 <script type
="text/javascript" src
="../../library/calendar.js"></script
>
47 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
48 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
49 <script language
="JavaScript">
50 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
53 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
54 <style type
="text/css">
56 /* specifically include & exclude from printing */
62 #report_parameters_daterange {
66 #report_results table {
71 /* specifically exclude some from the screen */
73 #report_parameters_daterange {
82 <body
class="body_top">
84 <!-- Required
for the popup date selectors
-->
85 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
87 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient Insurance Distribution','e'); ?
></span
>
89 <div id
="report_parameters_daterange">
90 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
93 <form name
='theform' method
='post' action
='insurance_allocation_report.php' id
='theform'>
95 <div id
="report_parameters">
96 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
97 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
102 <div style
='float:left'>
107 <?php
xl('From','e'); ?
>:
110 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
111 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
112 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
113 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
114 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
117 <?php
xl('To','e'); ?
>:
120 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
121 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
122 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
123 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
124 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
132 <td align
='left' valign
='middle' height
="100%">
133 <table style
='border-left:1px solid; width:100%; height:100%' >
136 <div style
='margin-left:15px'>
137 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
139 <?php
xl('Submit','e'); ?
>
143 <?php
if ($_POST['form_refresh']) { ?
>
144 <a href
='#' class='css_button' onclick
='window.print()'>
146 <?php
xl('Print','e'); ?
>
149 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
151 <?php
xl('Export to CSV','e'); ?
>
164 </div
> <!-- end parameters
-->
166 <div id
="report_results">
170 <th align
='left'> <?php
xl('Primary Insurance','e'); ?
> </th
>
171 <th align
='right'> <?php
xl('Charges','e'); ?
> </th
>
172 <th align
='right'> <?php
xl('Visits','e'); ?
> </th
>
173 <th align
='right'> <?php
xl('Patients','e'); ?
> </th
>
174 <th align
='right'> <?php
xl('Pt %','e'); ?
> </th
>
179 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
181 $from_date = fixDate($_POST['form_from_date']);
182 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
184 $query = "SELECT b.pid, b.encounter, SUM(b.fee) AS charges, " .
185 "MAX(fe.date) AS date " .
186 "FROM form_encounter AS fe, billing AS b " .
187 "WHERE fe.date >= '$from_date' AND fe.date <= '$to_date' " .
188 "AND b.pid = fe.pid AND b.encounter = fe.encounter " .
189 "AND b.code_type != 'COPAY' AND b.activity > 0 AND b.fee != 0 " .
190 "GROUP BY b.pid, b.encounter ORDER BY b.pid, b.encounter";
192 $res = sqlStatement($query);
197 while ($row = sqlFetchArray($res)) {
198 $patient_id = $row['pid'];
199 $encounter_date = $row['date'];
200 $irow = sqlQuery("SELECT insurance_companies.name " .
201 "FROM insurance_data, insurance_companies WHERE " .
202 "insurance_data.pid = $patient_id AND " .
203 "insurance_data.type = 'primary' AND " .
204 "insurance_data.date <= '$encounter_date' AND " .
205 "insurance_companies.id = insurance_data.provider " .
206 "ORDER BY insurance_data.date DESC LIMIT 1");
207 $plan = $irow['name'] ?
$irow['name'] : '-- No Insurance --';
208 $insarr[$plan]['visits'] +
= 1;
209 $insarr[$plan]['charges'] +
= sprintf('%0.2f', $row['charges']);
210 if ($patient_id != $prev_pid) {
212 $insarr[$plan]['patients'] +
= 1;
213 $prev_pid = $patient_id;
219 while (list($key, $val) = each($insarr)) {
220 if ($_POST['form_csvexport']) {
221 echo '"' . $key . '",';
222 echo '"' . oeFormatMoney($val['charges']) . '",';
223 echo '"' . $val['visits'] . '",';
224 echo '"' . $val['patients'] . '",';
225 echo '"' . sprintf("%.1f", $val['patients'] * 100 / $patcount) . '"' . "\n";
234 <?php
echo oeFormatMoney($val['charges']) ?
>
237 <?php
echo $val['visits'] ?
>
240 <?php
echo $val['patients'] ?
>
243 <?php
printf("%.1f", $val['patients'] * 100 / $patcount) ?
>
251 if (! $_POST['form_csvexport']) {
256 </div
> <!-- end of results
-->
260 <!-- stuff
for the popup calendar
-->
261 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
262 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
263 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
264 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
265 <script language
="Javascript">
266 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
267 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});