2 // Copyright (C) 2007-2009 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 // This module is for team sports use and reports on absences by
10 // injury type (diagnosis) for a given time period.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/acl.inc");
15 require_once("../../custom/code_types.inc.php");
16 require_once("$srcdir/calendar_events.inc.php");
18 // Might want something different here.
20 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
22 $from_date = fixDate($_POST['form_from_date']);
23 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
24 $form_by = $_POST['form_by'];
28 <?php
html_header_show();?
>
29 <title
><?php
xl('Absences by Diagnosis','e'); ?
></title
>
30 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
31 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
32 <script language
="JavaScript">
33 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
35 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
38 <body
class="body_top">
40 <!-- Required
for the popup date selectors
-->
41 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
45 <h2
><?php
xl('Days and Games Missed','e'); ?
></h2
>
47 <form name
='theform' method
='post' action
='absences_report.php'>
49 <table border
='0' cellpadding
='3'>
53 <?php
xl('By:','e'); ?
>
54 <input type
='radio' name
='form_by' value
='d'
55 <?php
echo ($form_by == 'p') ?
'' : 'checked' ?
> /><?php
xl('Diagnosis','e'); ?
> 
;
56 <input type
='radio' name
='form_by' value
='p'
57 <?php
echo ($form_by == 'p') ?
'checked' : '' ?
> /><?php
xl('Player','e'); ?
>  
;
58 <?php
xl('From:','e'); ?
>
59 <input type
='text' name
='form_from_date' id
='form_from_date' size
='10' value
='<?php echo $from_date ?>'
60 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
61 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
62 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
63 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
64  
;<?php
xl('To:','e'); ?
>
65 <input type
='text' name
='form_to_date' id
='form_to_date' size
='10' value
='<?php echo $to_date ?>'
66 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
67 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
68 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
69 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
71 <input type
='submit' name
='form_refresh' value
='<?php xl('Refresh
','e
'); ?>'>
82 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
84 <tr bgcolor
="#dddddd">
85 <?php
if ($form_by == 'p') { ?
>
87 <?php
xl('Name','e'); ?
>
91 <?php
xl('Code','e'); ?
>
94 <?php
xl('Description','e'); ?
>
98 <td
class='dehead' align
='right'>
99 <?php
xl('Issues','e'); ?
>
102 <td
class='dehead' align
='right'>
103 <?php
xl('Days Missed','e'); ?
>
105 <td
class='dehead' align
='right'>
106 <?php
xl('Games Missed','e'); ?
>
110 if ($_POST['form_refresh']) {
111 $from_date = fixDate($_POST['form_from_date']);
112 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
115 $eres = sqlStatement("SELECT e.pc_eid, e.pc_apptstatus, " .
116 "e.pc_eventDate, e.pc_endDate, e.pc_startTime, " .
117 "e.pc_duration, e.pc_recurrtype, e.pc_recurrspec, " .
119 "FROM openemr_postcalendar_events AS e " .
120 "JOIN openemr_postcalendar_categories AS c ON " .
121 "c.pc_catdesc LIKE 'Squad=%' AND c.pc_catid = e.pc_catid " .
122 "WHERE ((e.pc_endDate >= '$from_date' AND e.pc_eventDate <= '$to_date') OR " .
123 "(e.pc_endDate = '0000-00-00' AND e.pc_eventDate >= '$from_date' AND " .
124 "e.pc_eventDate <= '$to_date'))");
126 while ($erow = sqlFetchArray($eres)) {
127 $estart = $erow['pc_eventDate'];
128 if ($estart < $from_date) $estart = $from_date;
129 $eend = ($erow['pc_endDate'] > '0000-00-00') ?
$erow['pc_endDate'] : $erow['pc_eventDate'];
130 if ($eend > $to_date) $eend = $to_date;
131 $time = mktime(0, 0, 0, substr($estart, 5, 2),
132 substr($estart, 8, 2), substr($estart, 0, 4));
133 $endtime = mktime(0, 0, 0, substr($eend, 5, 2),
134 substr($eend, 8, 2), substr($eend, 0, 4)) +
(24 * 60 * 60);
136 $eid = $erow['pc_eid'];
137 $squad = substr($erow['pc_catdesc'], 6);
138 $duration = $erow['pc_duration'] / 60;
140 for (; $time < $endtime; $time +
= 24 * 60 * 60) {
141 $date = date('Y-m-d', $time);
142 if (!eventMatchesDay($erow, $date)) continue;
144 $pres = sqlStatement("SELECT pd.lname, pd.fname, pd.mname, " .
145 "pd.pid, pe.minutes, pe.fitness_related, df.issue_id, l.diagnosis " .
146 "FROM patient_data AS pd " .
147 "LEFT JOIN player_event AS pe ON pe.pid = pd.pid AND pe.date = '$date' AND pe.pc_eid = '$eid' " .
148 "LEFT JOIN daily_fitness AS df ON df.pid = pd.pid AND df.date = '$date' " .
149 "LEFT JOIN lists AS l ON l.id = df.issue_id " .
150 "WHERE pd.squad = '$squad'");
152 while ($prow = sqlFetchArray($pres)) {
154 // Each iteration of this loop is for a particular player and a
155 // particular event on a particular day.
157 // For each ($key,$date) accumulate event minutes and missed minutes.
158 // Then we can total fractions of days missed just before sorting.
160 $fitness_related = isset($prow['fitness_related']) ?
$prow['fitness_related'] :
161 !empty($prow['issue_id']);
163 if ($form_by == 'p') {
164 $key = trim($prow['lname'] . ', ' . $prow['fname'] . ' ' . $prow['mname']);
166 $key = $fitness_related ?
$prow['diagnosis'] : 'z';
168 if (empty($areport[$key])) {
169 $areport[$key] = array();
170 $areport[$key]['days'] = array();
171 $areport[$key]['gmissed'] = 0;
173 if (empty($areport[$key]['days'][$date])) {
174 $areport[$key]['days'][$date] = array();
175 $areport[$key]['days'][$date][0] = 0; // total event minutes
176 $areport[$key]['days'][$date][1] = 0; // missed event minutes
179 $missed = isset($prow['minutes']) ?
($duration - $prow['minutes']) : 0;
181 if ($duration && $erow['pc_apptstatus'] == 'G') { // if this is a game event
182 $areport[$key]['gmissed'] +
= $missed / $duration;
185 // echo "<!-- key='$key' eid='$eid' date='$date' duration='$duration' missed='$missed' -->\n"; // debugging
187 // Event minutes and those missed are totaled by day, so that we
188 // can later total up the fractions of days missed for each $key.
189 $areport[$key]['days'][$date][0] +
= $duration;
190 $areport[$key]['days'][$date][1] +
= $missed;
195 // echo "<!--\n"; // debugging
196 // print_r($areport);
199 foreach ($areport as $key => $arr) {
200 $areport[$key]['dmissed'] = 0;
201 foreach ($arr['days'] as $date => $pair) {
203 $areport[$key]['dmissed'] +
= $pair[1] / $pair[0];
206 unset($areport[$key]['days']);
209 /*******************************************************************
210 $query = "SELECT lists.diagnosis, lists.pid, lists.type, " .
211 "lists.extrainfo AS gmissed, " .
212 "lists.begdate, lists.enddate, lists.returndate, " .
213 "pd.lname, pd.fname, pd.mname " .
215 "JOIN patient_data AS pd ON pd.pid = lists.pid " .
216 "WHERE ( lists.returndate IS NULL OR lists.returndate >= '$from_date' ) AND " .
217 "( lists.begdate IS NULL OR lists.begdate <= '$to_date' )" .
218 "ORDER BY pd.lname, pd.fname, pd.mname, lists.pid, lists.begdate";
219 $res = sqlStatement($query);
226 while ($row = sqlFetchArray($res)) {
227 $thispid = $row['pid'];
228 // Compute days missed. Force non-overlap of multiple issues for the
229 // same player. This logic assumes sorting on begdate within pid.
230 $begsecs = $row['begdate'] ? strtotime($row['begdate']) : 0;
231 $endsecs = $row['returndate'] ? strtotime($row['returndate']) : time();
232 if ($thispid == $last_pid) {
233 if ($begsecs < $last_endsecs) {
234 $begsecs = $last_endsecs;
238 $last_pid = $thispid;
240 $ptname = trim($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']);
243 if ($row['begdate']) {
244 if ($begsecs > $endsecs) $begsecs = $endsecs;
245 if ($last_endsecs < $endsecs) $last_endsecs = $endsecs;
246 $daysmissed = round(($endsecs - $begsecs) / (60 * 60 * 24));
248 if ($form_by == 'p') {
251 $key = $row['diagnosis'];
253 if (empty($areport[$key])) {
254 $areport[$key] = array();
255 $areport[$key]['count'] = 0;
256 $areport[$key]['dmissed'] = 0;
257 $areport[$key]['gmissed'] = 0;
259 $areport[$key]['count'] += 1;
260 $areport[$key]['dmissed'] += $daysmissed;
261 $areport[$key]['gmissed'] += $row['gmissed'];
263 *******************************************************************/
267 foreach ($areport as $key => $row) {
271 <?php
if ($form_by == 'p') { ?
>
277 <?php
echo $key == 'z' ?
'' : $key; ?
>
282 echo xl('Undiagnosed');
283 else if ($key == 'z')
284 echo xl('No injury/illness');
286 echo lookup_code_descriptions($key);
291 <td
class='detail' align
='right'>
292 <?php
// echo $row['count'] ?>
295 <td
class='detail' align
='right'>
296 <?php
echo sprintf('%0.2f', $row['dmissed']) ?
>
298 <td
class='detail' align
='right'>
299 <?php
echo sprintf('%0.2f', $row['gmissed']) ?
>
311 <!-- stuff
for the popup calendar
-->
312 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
313 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
314 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
315 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
316 <script language
="Javascript">
317 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
318 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});