avoid unescaped quotes when updating database
[openemr.git] / interface / reports / insurance_allocation_report.php
blob62c955817fd5eb23461ee8a86cf214d2fd0084c5
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>Patient Insurance Distribution</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>Patient Insurance Distribution</h2>
37 <form name='theform' method='post' action='insurance_allocation_report.php'>
39 <table border='0' cellpadding='3'>
41 <tr>
42 <td>
43 From:
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="Click here to choose a date"
48 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
49 &nbsp;To:
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="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='Refresh'>
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 Primary Insurance
72 </td>
73 <td class='dehead' align='right'>
74 Patients
75 </td>
76 <td class='dehead' align='right'>
77 Percent
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 billing.pid, insurance_companies.name " .
86 "FROM billing " .
87 "LEFT OUTER JOIN insurance_data ON " .
88 "insurance_data.pid = billing.pid AND " .
89 "insurance_data.type = 'primary' " .
90 "LEFT OUTER JOIN insurance_companies ON " .
91 "insurance_companies.id = insurance_data.provider " .
92 "WHERE " .
93 "billing.date >= '$from_date' AND " .
94 "billing.date <= '$to_date' " .
95 "ORDER BY insurance_companies.name, billing.pid";
97 // echo "<!-- $query -->\n"; // debugging
98 $res = sqlStatement($query);
99 $insarr = array();
101 while ($row = sqlFetchArray($res)) {
102 // echo "<!-- " . $row['name'] . " / " . $row['pid'] . " -->\n"; // debugging
103 $plan = $row['name'] ? $row['name'] : '-- No Insurance --';
104 $insarr[$plan] += 1;
105 $inscount += 1;
108 while (list($key, $val) = each($insarr)) {
110 <tr>
111 <td class='detail'>
112 <? echo $key ?>
113 </td>
114 <td class='detail' align='right'>
115 <? echo $val ?>
116 </td>
117 <td class='detail' align='right'>
118 <? printf("%.1f", $val * 100 / $inscount) ?>
119 </td>
120 </tr>
126 </table>
127 </form>
128 </center>
129 </body>
130 </html>