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
'] ?>';
52 $
(document
).ready(function() {
53 var win
= top
.printLogSetup ? top
: opener
.top
;
54 win
.printLogSetup(document
.getElementById('printbutton'));
59 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
60 <style type
="text/css">
62 /* specifically include & exclude from printing */
68 #report_parameters_daterange {
72 #report_results table {
77 /* specifically exclude some from the screen */
79 #report_parameters_daterange {
88 <body
class="body_top">
90 <!-- Required
for the popup date selectors
-->
91 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
93 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient Insurance Distribution','e'); ?
></span
>
95 <div id
="report_parameters_daterange">
96 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
99 <form name
='theform' method
='post' action
='insurance_allocation_report.php' id
='theform'>
101 <div id
="report_parameters">
102 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
103 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
108 <div style
='float:left'>
113 <?php
xl('From','e'); ?
>:
116 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
117 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
118 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
119 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
120 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
123 <?php
xl('To','e'); ?
>:
126 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
127 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
128 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
129 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
130 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
138 <td align
='left' valign
='middle' height
="100%">
139 <table style
='border-left:1px solid; width:100%; height:100%' >
142 <div style
='margin-left:15px'>
143 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
145 <?php
xl('Submit','e'); ?
>
149 <?php
if ($_POST['form_refresh']) { ?
>
150 <a href
='#' class='css_button' id
='printbutton'>
152 <?php
xl('Print','e'); ?
>
155 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
157 <?php
xl('Export to CSV','e'); ?
>
170 </div
> <!-- end parameters
-->
172 <div id
="report_results">
176 <th align
='left'> <?php
xl('Primary Insurance','e'); ?
> </th
>
177 <th align
='right'> <?php
xl('Charges','e'); ?
> </th
>
178 <th align
='right'> <?php
xl('Visits','e'); ?
> </th
>
179 <th align
='right'> <?php
xl('Patients','e'); ?
> </th
>
180 <th align
='right'> <?php
xl('Pt %','e'); ?
> </th
>
185 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
187 $from_date = fixDate($_POST['form_from_date']);
188 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
190 $query = "SELECT b.pid, b.encounter, SUM(b.fee) AS charges, " .
191 "MAX(fe.date) AS date " .
192 "FROM form_encounter AS fe, billing AS b " .
193 "WHERE fe.date >= '$from_date' AND fe.date <= '$to_date' " .
194 "AND b.pid = fe.pid AND b.encounter = fe.encounter " .
195 "AND b.code_type != 'COPAY' AND b.activity > 0 AND b.fee != 0 " .
196 "GROUP BY b.pid, b.encounter ORDER BY b.pid, b.encounter";
198 $res = sqlStatement($query);
203 while ($row = sqlFetchArray($res)) {
204 $patient_id = $row['pid'];
205 $encounter_date = $row['date'];
206 $irow = sqlQuery("SELECT insurance_companies.name " .
207 "FROM insurance_data, insurance_companies WHERE " .
208 "insurance_data.pid = $patient_id AND " .
209 "insurance_data.type = 'primary' AND " .
210 "insurance_data.date <= '$encounter_date' AND " .
211 "insurance_companies.id = insurance_data.provider " .
212 "ORDER BY insurance_data.date DESC LIMIT 1");
213 $plan = $irow['name'] ?
$irow['name'] : '-- No Insurance --';
214 $insarr[$plan]['visits'] +
= 1;
215 $insarr[$plan]['charges'] +
= sprintf('%0.2f', $row['charges']);
216 if ($patient_id != $prev_pid) {
218 $insarr[$plan]['patients'] +
= 1;
219 $prev_pid = $patient_id;
225 while (list($key, $val) = each($insarr)) {
226 if ($_POST['form_csvexport']) {
227 echo '"' . $key . '",';
228 echo '"' . oeFormatMoney($val['charges']) . '",';
229 echo '"' . $val['visits'] . '",';
230 echo '"' . $val['patients'] . '",';
231 echo '"' . sprintf("%.1f", $val['patients'] * 100 / $patcount) . '"' . "\n";
240 <?php
echo oeFormatMoney($val['charges']) ?
>
243 <?php
echo $val['visits'] ?
>
246 <?php
echo $val['patients'] ?
>
249 <?php
printf("%.1f", $val['patients'] * 100 / $patcount) ?
>
257 if (! $_POST['form_csvexport']) {
262 </div
> <!-- end of results
-->
266 <!-- stuff
for the popup calendar
-->
267 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
268 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
269 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
270 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
271 <script language
="Javascript">
272 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
273 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});