misc cosmetic cleanups for sports team use
[openemr.git] / interface / reports / absences_report.php
blobe677eabbd158d265d1fd6a8153d2b5fc6af4b496
1 <?
2 // This module is for team sports use and reports on absences by
3 // injury type (diagnosis) for a given time period.
5 include_once("../globals.php");
6 include_once("../../library/patient.inc");
7 include_once("../../library/acl.inc");
9 // Might want something different here.
11 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
13 $from_date = fixDate($_POST['form_from_date']);
14 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
15 $form_by = $_POST['form_by'];
17 <html>
18 <head>
19 <title>Absences by Diagnosis</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>Days and Games Missed</h2>
37 <form name='theform' method='post' action='absences_report.php'>
39 <table border='0' cellpadding='3'>
41 <tr>
42 <td>
43 By:
44 <input type='radio' name='form_by' value='d'
45 <? echo ($form_by == 'p') ? '' : 'checked' ?> />Diagnosis&nbsp;
46 <input type='radio' name='form_by' value='p'
47 <? echo ($form_by == 'p') ? 'checked' : '' ?> />Player &nbsp;
48 From:
49 <input type='text' name='form_from_date' size='10' value='<? echo $from_date ?>'
50 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
51 <a href="javascript:show_calendar('theform.form_from_date')"
52 title="Click here to choose a date"
53 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
54 &nbsp;To:
55 <input type='text' name='form_to_date' size='10' value='<? echo $to_date ?>'
56 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
57 <a href="javascript:show_calendar('theform.form_to_date')"
58 title="Click here to choose a date"
59 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
60 &nbsp;
61 <input type='submit' name='form_refresh' value='Refresh'>
62 </td>
63 </tr>
65 <tr>
66 <td height="1">
67 </td>
68 </tr>
70 </table>
72 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
74 <tr bgcolor="#dddddd">
75 <? if ($form_by == 'p') { ?>
76 <td class="dehead">
77 Name
78 </td>
79 <? } else { ?>
80 <td class="dehead">
81 Code
82 </td>
83 <td class="dehead">
84 Description
85 </td>
86 <? } ?>
87 <td class='dehead' align='right'>
88 Issues
89 </td>
90 <td class='dehead' align='right'>
91 Days
92 </td>
93 <td class='dehead' align='right'>
94 Games
95 </td>
96 </tr>
98 if ($_POST['form_refresh']) {
99 $form_doctor = $_POST['form_doctor'];
100 $from_date = fixDate($_POST['form_from_date']);
101 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
103 if ($form_by == 'p') {
104 $query = "SELECT patient_data.lname, patient_data.fname, patient_data.mname, " .
105 "count(*) AS count, " .
106 "SUM(lists.extrainfo) AS gmissed, " .
107 "SUM(TO_DAYS(LEAST(IFNULL(lists.enddate,CURRENT_DATE),'$to_date')) - TO_DAYS(GREATEST(lists.begdate,'$from_date'))) AS dmissed " .
108 "FROM lists, patient_data WHERE " .
109 "(lists.enddate IS NULL OR lists.enddate >= '$from_date') AND lists.begdate <= '$to_date' AND " .
110 "patient_data.pid = lists.pid " .
111 "GROUP BY lname, fname, mname";
113 else {
114 $query = "SELECT lists.diagnosis, codes.code_text, count(*) AS count, " .
115 "SUM(lists.extrainfo) AS gmissed, " .
116 "SUM(TO_DAYS(LEAST(IFNULL(lists.enddate,CURRENT_DATE),'$to_date')) - TO_DAYS(GREATEST(lists.begdate,'$from_date'))) AS dmissed " .
117 "FROM lists " .
118 "LEFT OUTER JOIN codes " .
119 "ON codes.code = lists.diagnosis AND " .
120 "(codes.code_type = 2 OR codes.code_type = 4 OR codes.code_type = 5 OR codes.code_type = 8) " .
121 "WHERE " .
122 "(lists.enddate IS NULL OR lists.enddate >= '$from_date') AND lists.begdate <= '$to_date' " .
123 "GROUP BY lists.diagnosis";
126 echo "<!-- $query -->\n"; // debugging
128 $res = sqlStatement($query);
130 while ($row = sqlFetchArray($res)) {
133 <tr>
134 <? if ($form_by == 'p') { ?>
135 <td class='detail'>
136 <? echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
137 </td>
138 <? } else { ?>
139 <td class='detail'>
140 <? echo $row['diagnosis'] ?>
141 </td>
142 <td class='detail'>
143 <? echo $row['code_text'] ?>
144 </td>
145 <? } ?>
146 <td class='detail' align='right'>
147 <? echo $row['count'] ?>
148 </td>
149 <td class='detail' align='right'>
150 <? echo $row['dmissed'] ?>
151 </td>
152 <td class='detail' align='right'>
153 <? echo $row['gmissed'] ?>
154 </td>
155 </tr>
161 </table>
162 </form>
163 </center>
164 </body>
165 </html>