2 // Copyright (C) 2007 Rod Roark <rod@sunsetsystems.com>
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) {
32 $relcodes = explode(';', $codes);
33 foreach ($relcodes as $codestring) {
34 if ($codestring === '') continue;
35 list($codetype, $code) = explode(':', $codestring);
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'];
52 *********************************************************************/
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 }
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
) {
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
,
91 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
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'>
103 <td valign
='top' nowrap
>
107 <select name
='form_issue_type' title
='Types of issues to show'>
108 <option value
=''>All
</option
>
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";
118 <td valign
='top' rowspan
='3' nowrap
>
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
'); ?>'>
126 $squads = acl_get_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";
137 <td valign
='top' rowspan
='3' nowrap
>
139 <input type
='submit' name
='form_refresh' value
='<?php xl('Show Report
','e
'); ?>'
140 title
='<?php xl('Click to generate the report
','e
'); ?>'>
144 <td valign
='top' nowrap
>
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
'); ?>'>
156 <td valign
='top' nowrap
>
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
'); ?>'>
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 " .
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);
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
>
228 while ($row = sqlFetchArray($res)) {
229 $listid = $row['listid'];
230 $thispid = $row['pid'];
231 $issue_title = trim($row['title']);
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;
248 $last_pid = $thispid;
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 = ' ';
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'] :
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";
291 <?php
} // end of if ($_POST['form_refresh']) ?>
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"});