major improvements for keeping a history of claims, and to save and use prior insuran...
[openemr.git] / interface / reports / insurance_allocation_report.php
blobbe639ff0e8683349272b92fe4fa92ce245f1547e
1 <?
2 // This module shows relative insurance usage by unique patients
3 // that are seen within a given time period. Each patient that had
4 // a visit is counted only once, regardless of how many visits.
6 include_once("../globals.php");
7 include_once("../../library/patient.inc");
8 include_once("../../library/acl.inc");
10 // Might want something different here.
12 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
14 $from_date = fixDate($_POST['form_from_date']);
15 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
17 <html>
18 <head>
19 <title><? xl('Patient Insurance Distribution','e'); ?></title>
20 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
21 <script type="text/javascript" src="../../library/calendar.js"></script>
22 <script type="text/javascript" src="../../library/textformat.js"></script>
23 <script language="JavaScript">
24 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
25 </script>
26 </head>
28 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
30 <!-- Required for the popup date selectors -->
31 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
33 <center>
35 <h2><? xl('Patient Insurance Distribution','e'); ?></h2>
37 <form name='theform' method='post' action='insurance_allocation_report.php'>
39 <table border='0' cellpadding='3'>
41 <tr>
42 <td>
43 <? xl('From','e'); ?>:
44 <input type='text' name='form_from_date' size='10' value='<? echo $from_date ?>'
45 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
46 <a href="javascript:show_calendar('theform.form_from_date')"
47 title=".xl('Click here to choose a date')"
48 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
49 &nbsp;<? xl('To','e'); ?>:
50 <input type='text' name='form_to_date' size='10' value='<? echo $to_date ?>'
51 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
52 <a href="javascript:show_calendar('theform.form_to_date')"
53 title=".xl('Click here to choose a date')"
54 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
55 &nbsp;
56 <input type='submit' name='form_refresh' value=<? xl('Refresh','e'); ?>>
57 </td>
58 </tr>
60 <tr>
61 <td height="1">
62 </td>
63 </tr>
65 </table>
67 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
69 <tr bgcolor="#dddddd">
70 <td class="dehead">
71 <? xl('Primary Insurance','e'); ?>
72 </td>
73 <td class='dehead' align='right'>
74 <? xl('Patients','e'); ?>
75 </td>
76 <td class='dehead' align='right'>
77 <? xl('Percent','e'); ?>
78 </td>
79 </tr>
81 if ($_POST['form_refresh']) {
82 $from_date = fixDate($_POST['form_from_date']);
83 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
85 $query = "SELECT DISTINCT c.name, b.pid, i.date " .
86 "FROM billing AS b " .
87 "LEFT OUTER JOIN insurance_data AS i ON " .
88 "i.pid = b.pid AND " .
89 "i.type = 'primary' AND " .
90 "i.date <= b.date " .
91 "LEFT OUTER JOIN insurance_companies AS c ON " .
92 "c.id = i.provider " .
93 "WHERE " .
94 "b.date >= '$from_date' AND " .
95 "b.date <= '$to_date' " .
96 "ORDER BY c.name ASC, b.pid ASC, i.date DESC";
98 // echo "<!-- $query -->\n"; // debugging
99 $res = sqlStatement($query);
100 $insarr = array();
102 $prevplan = '';
103 $prevpid = 0;
104 while ($row = sqlFetchArray($res)) {
105 // echo "<!-- " . $row['name'] . " / " . $row['pid'] . " -->\n"; // debugging
106 $plan = $row['name'] ? $row['name'] : '-- No Insurance --';
107 if (strcmp($plan, $prevplan) == 0 && $row['pid'] == $prevpid) continue;
108 $prevplan = $plan;
109 $prevpid = $row['pid'];
110 $insarr[$plan] += 1;
111 $inscount += 1;
114 while (list($key, $val) = each($insarr)) {
116 <tr>
117 <td class='detail'>
118 <? echo $key ?>
119 </td>
120 <td class='detail' align='right'>
121 <? echo $val ?>
122 </td>
123 <td class='detail' align='right'>
124 <? printf("%.1f", $val * 100 / $inscount) ?>
125 </td>
126 </tr>
132 </table>
133 </form>
134 </center>
135 </body>
136 </html>