Focus the search term on load
[openemr.git] / interface / reports / injury_overview_report.php
blob227f9d104d1d21c633a15df6a11ad56e0052a92e
1 <?php
2 // Copyright (C) 2007 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("../../library/patient.inc");
11 require_once("../../library/lists.inc");
12 require_once("../../library/acl.inc");
13 require_once("../../custom/code_types.inc.php");
15 // Might want something different here.
17 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
19 $from_date = fixDate($_POST['form_from_date']);
20 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
21 $form_issue_type = $_POST['form_issue_type'];
22 $form_squads = $_POST['form_squads']; // this is an array
24 /*********************************************************************
25 // Look up descriptions for one or more billing codes. This should
26 // probably be moved to an "include" file somewhere.
28 function lookup_code_descriptions($codes) {
29 global $code_types;
30 $code_text = '';
31 if (!empty($codes)) {
32 $relcodes = explode(';', $codes);
33 foreach ($relcodes as $codestring) {
34 if ($codestring === '') continue;
35 list($codetype, $code) = explode(':', $codestring);
36 $wheretype = "";
37 if (empty($code)) {
38 $code = $codetype;
39 } else {
40 $wheretype = "code_type = '" . $code_types[$codetype]['id'] . "' AND ";
42 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
43 "$wheretype code = '$code' ORDER BY id LIMIT 1");
44 if (!empty($crow['code_text'])) {
45 if ($code_text) $code_text .= '; ';
46 $code_text .= $crow['code_text'];
50 return $code_text;
52 *********************************************************************/
54 <html>
55 <head>
56 <?php html_header_show();?>
57 <title><?php xl('Injury Overview Report','e'); ?></title>
58 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
59 <style type="text/css">
60 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
61 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
62 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
63 </style>
64 <script type="text/javascript" src="../../library/topdialog.js"></script>
65 <script type="text/javascript" src="../../library/dialog.js"></script>
66 <script type="text/javascript" src="../../library/textformat.js"></script>
67 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
68 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
69 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
70 <script language="JavaScript">
72 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
74 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
76 // callback from add_edit_issue.php:
77 function refreshIssue(issue, title) {
78 top.restoreSession();
79 document.forms[0].submit();
82 // Process click on issue title.
83 function dopclick(id,pid) {
84 dlgopen('../patient_file/summary/add_edit_issue.php?issue=' + id + '&thispid=' + pid,
85 '_blank', 600, 475);
88 </script>
89 </head>
91 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
93 <center>
95 <h2><?php xl('Injury Overview Report','e'); ?></h2>
97 <form name='theform' method='post' action='injury_overview_report.php'
98 onsubmit='return top.restoreSession()'>
100 <table border='0' cellspacing='0' cellpadding='2'>
102 <tr>
103 <td valign='top' nowrap>
104 Issues:
105 </td>
106 <td valign='top'>
107 <select name='form_issue_type' title='Types of issues to show'>
108 <option value=''>All</option>
109 <?php
110 foreach ($ISSUE_TYPES as $key => $value) {
111 echo " <option value='$key'";
112 if ($key == $form_issue_type) echo " selected";
113 echo ">" . $value[0] . "</option>\n";
116 </select>
117 </td>
118 <td valign='top' rowspan='3' nowrap>
119 &nbsp;
120 Squads:
121 </td>
122 <td valign='top' rowspan='3'>
123 <select name='form_squads[]' size='4' multiple
124 title='<?php xl('Hold down Ctrl to select multiple squads','e'); ?>'>
125 <?php
126 $squads = acl_get_squads();
127 if ($squads) {
128 foreach ($squads as $key => $value) {
129 echo " <option value='$key'";
130 if (!is_array($form_squads) || in_array($key, $form_squads)) echo " selected";
131 echo ">" . $value[3] . "</option>\n";
135 </select>
136 </td>
137 <td valign='top' rowspan='3' nowrap>
138 &nbsp;
139 <input type='submit' name='form_refresh' value='<?php xl('Show Report','e'); ?>'
140 title='<?php xl('Click to generate the report','e'); ?>'>
141 </td>
142 </tr>
143 <tr>
144 <td valign='top' nowrap>
145 From:
146 </td>
147 <td valign='top' nowrap>
148 <input type='text' name='form_from_date' id='form_from_date' size='10' value='<?php echo $from_date ?>'
149 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='Start date yyyy-mm-dd'>
150 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
151 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
152 title='<?php xl('Click here to choose a date','e'); ?>'>
153 </td>
154 </tr>
155 <tr>
156 <td valign='top' nowrap>
158 </td>
159 <td valign='top' nowrap>
160 <input type='text' name='form_to_date' id='form_to_date' size='10' value='<?php echo $to_date ?>'
161 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='End date yyyy-mm-dd'>
162 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
163 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
164 title='<?php xl('Click here to choose a date','e'); ?>'>
165 </td>
166 </tr>
168 <tr>
169 <td height="1">
170 </td>
171 </tr>
173 </table>
175 <?php
176 if ($_POST['form_squads']) {
178 // fetch all the issues of the desired type and corresponding FIA
179 // data. We are reporting only values from issues (though often by FIA
180 // fields), so it seems we want to retain one array row per issue and
181 // discard extra FIA forms.
183 $issuetypematches = '';
184 if ($form_issue_type) {
185 $issuetypematches = " AND lists.type = '$form_issue_type'";
188 $squadmatches = '1 = 2'; // an always-false condition
189 foreach ($form_squads as $squad)
190 $squadmatches .= " OR pd.squad = '$squad'";
192 $query = "SELECT lists.id AS listid, lists.diagnosis, lists.pid, " .
193 "lists.extrainfo AS gmissed, lists.begdate, lists.enddate, " .
194 "lists.returndate, lists.title, lists.type, " .
195 "pd.lname, pd.fname, pd.mname, pd.fitness " .
196 "FROM lists " .
197 "JOIN patient_data AS pd ON pd.pid = lists.pid AND ( $squadmatches ) " .
198 "WHERE ( lists.enddate IS NULL OR lists.enddate >= '$from_date' ) AND " .
199 "( lists.begdate IS NULL OR lists.begdate <= '$to_date' )" .
200 "$issuetypematches " .
201 "ORDER BY pd.lname, pd.fname, pd.mname, lists.pid, lists.begdate";
203 // echo "\n<!-- $query -->\n"; // debugging
205 $res = sqlStatement($query);
207 $areport = array();
208 $last_listid = 0;
209 $last_pid = 0;
210 $last_endsecs = 0;
211 $encount = 0;
214 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
216 <tr bgcolor="#dddddd">
217 <td class="dehead">Player</td>
218 <td class="dehead">Fitness</td>
219 <td class="dehead">Issue</td>
220 <td class="dehead">Diagnosis</td>
221 <td class="dehead">Start Date</td>
222 <td class="dehead" align="right">Days Missed</td>
223 <td class="dehead" align="right">Games Missed</td>
224 <td class="dehead">Last Provider</td>
225 </tr>
227 <?php
228 while ($row = sqlFetchArray($res)) {
229 $listid = $row['listid'];
230 $thispid = $row['pid'];
231 $issue_title = trim($row['title']);
232 $ptname = '&nbsp;';
233 $fitness = '&nbsp;';
235 $issue_style = $ISSUE_TYPES[$row['type']][3];
237 // Compute days missed. Force non-overlap of multiple issues for the
238 // same player. This logic assumes sorting on begdate within pid.
240 $begsecs = $row['begdate'] ? strtotime($row['begdate']) : 0;
241 $endsecs = $row['returndate'] ? strtotime($row['returndate']) : time();
242 if ($thispid == $last_pid) {
243 if ($begsecs < $last_endsecs) {
244 $begsecs = $last_endsecs;
247 else {
248 $last_pid = $thispid;
249 $last_endsecs = 0;
250 $ptname = trim($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']);
251 if ($row['fitness']) $fitness = $PLAYER_FITNESSES[$row['fitness'] - 1];
252 $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd";
254 $daysmissed = '&nbsp;';
255 // if ($row['begdate'] && $issue_style == 0) { // huh? why?
256 if ($row['begdate']) {
257 if ($begsecs > $endsecs) $begsecs = $endsecs;
258 if ($last_endsecs < $endsecs) $last_endsecs = $endsecs;
259 $daysmissed = round(($endsecs - $begsecs) / (60 * 60 * 24));
262 // Get the name of the last provider for this issue.
263 $query = "SELECT users.lname, users.fname, users.mname " .
264 "FROM issue_encounter, forms, users WHERE " .
265 "issue_encounter.list_id = $listid AND " .
266 "forms.pid = issue_encounter.pid AND " .
267 "forms.encounter = issue_encounter.encounter AND " .
268 "users.username = forms.user " .
269 "ORDER BY forms.date DESC LIMIT 1";
270 $user = sqlQuery($query);
271 $provname = $user['lname'] ?
272 $user['lname'] . ', ' . $user['fname'] . ' ' . $user['mname'] :
273 '&nbsp;';
275 echo " <tr bgcolor='$bgcolor' onclick='dopclick($listid,$thispid)' style='cursor:pointer'>\n";
276 echo " <td class='detail'>$ptname</td>\n";
277 echo " <td class='detail'>$fitness</td>\n";
278 echo " <td class='detail'>$issue_title</td>\n";
279 echo " <td class='detail'>" . lookup_code_descriptions($row['diagnosis']) . "</td>\n";
280 echo " <td class='detail'>" . $row['begdate'] . "</td>\n";
281 echo " <td class='detail' align='right'>$daysmissed</td>\n";
282 echo " <td class='detail' align='right'>" . $row['gmissed'] . "</td>\n";
283 echo " <td class='detail'>$provname</td>\n";
285 echo " </tr>\n";
286 } // end while
289 </table>
291 <?php } // end of if ($_POST['form_refresh']) ?>
293 </form>
294 </center>
296 <script language='JavaScript'>
297 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
298 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
299 </script>
301 </body>
302 </html>