Minor cosmetic tweaking of the weekly exposures page.
[openemr.git] / interface / reports / players_report.php
blobe2ec034579c660af60290a8ec995afcc3ebb10d7
1 <?php
2 // Copyright (C) 2005-2011 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 // This report lists all players/patients by name within squad.
10 // It is applicable only for sports teams.
12 //SANITIZE ALL ESCAPES
13 $sanitize_all_escapes=true;
16 //STOP FAKE REGISTER GLOBALS
17 $fake_register_globals=false;
20 require_once("../globals.php");
21 require_once("$srcdir/patient.inc");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/lists.inc");
24 require_once("$srcdir/calendar_events.inc.php");
26 // Temporary variable while new "propagation" logic is being tested.
27 // True means that missing days in the daily_fitness table default to
28 // the previous entry's values, if there is one.
29 // Otherwise the default fitness level (Fully Fit) is used (old logic).
30 $PROPLOGIC = true;
32 $squads = acl_get_squads();
33 $auth_notes_a = acl_check('encounters', 'notes_a');
35 $alertmsg = ''; // not used yet but maybe later
37 $form_date = fixDate($_POST['form_date'], date('Y-m-d'));
39 // Figure out the desired or default squad to select.
40 if (!empty($_POST['form_squad'])) {
41 $form_squad = $_POST['form_squad'];
42 $_SESSION['roster_squad'] = $form_squad;
44 else if (!empty($_SESSION['roster_squad'])) {
45 $form_squad = $_SESSION['roster_squad'];
47 else {
48 $form_squad = array_shift(array_keys($squads));
51 // $now = time();
52 $now = mktime(0, 0, 0, substr($form_date, 5, 2),
53 substr($form_date, 8, 2), substr($form_date, 0, 4));
55 // Get attributes of the default fitless level.
56 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
57 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
59 $query = "SELECT pid, squad, fitness, lname, fname FROM patient_data";
60 if (!empty($form_squad)) {
61 $query .= " WHERE squad LIKE '$form_squad'";
63 $res = sqlStatement($query);
65 // Sort the patients in squad priority order.
66 function patient_compare($a, $b) {
67 global $squads;
68 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
69 if ($a['lname'] == $b['lname']) {
70 return ($a['fname'] < $b['fname']) ? -1 : 1;
72 return ($a['lname'] < $b['lname']) ? -1 : 1;
74 // The squads are different so compare their order attributes,
75 // or unassigned squads sort last.
76 if (! $squads[$a['squad']][3]) return 1;
77 if (! $squads[$b['squad']][3]) return -1;
78 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ? -1 : 1;
81 $ordres = array();
82 if ($res) {
83 while ($row = sqlFetchArray($res)) $ordres[] = $row;
84 usort($ordres, "patient_compare");
87 <html>
88 <head>
89 <?php html_header_show(); ?>
90 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
92 <style type="text/css">
93 </style>
95 <?php if (empty($_GET['embed'])) { ?>
96 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
97 <?php } ?>
98 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
99 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
100 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/ajtooltip.js"></script>
101 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
103 <script language="JavaScript">
104 <?php if (empty($_GET['embed'])) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
106 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
108 function gopid(pid) {
109 <?php
110 $maintop = $_GET['embed'] ? "top" : "opener.top";
111 echo " $maintop.restoreSession();\n";
112 if ($GLOBALS['concurrent_layout']) {
113 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
114 // echo " $maintop.left_nav.forceDual();\n"; // Decided not to do this.
115 } else {
116 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
118 if (empty($_GET['embed'])) echo " window.close();\n";
122 // Process click to pop up the dialog window.
123 function rosdlgclick(pid, date) {
124 cascwin('players_report_dialog.php?plid=' + pid + '&date=' + date,
125 '_blank', 850, 550, "resizable=1,scrollbars=1");
128 function mov1(elem, plid) {
129 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid);
132 function mov2(elem, plid, date) {
133 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid + "&date=" + date);
136 function refreshme() {
137 top.restoreSession();
138 // location.reload();
139 document.forms[0].submit();
142 // Process click on issue title or [Add Issue].
143 function openissue(pid, issue) {
144 dlgopen('../patient_file/summary/add_edit_issue.php?thispid=' + pid + '&issue=' + issue, '_blank', 800, 600);
145 return false;
148 // callback from add_edit_issue.php:
149 function refreshIssue(issue, title) {
150 refreshme();
153 // Process click on Treatment Protocols form title.
154 function opentpform(id) {
155 dlgopen('../forms/treatment_protocols/new.php?popup=1&id=' + id, '_blank', 800, 600);
156 return false;
159 // This is called from left_nav_encounter_ajax.php to create the new TP form.
160 function createtpform(encounter) {
161 dlgopen('../forms/treatment_protocols/new.php?popup=1&id=0&thisenc=' + encounter, '_blank', 800, 600);
162 return false;
165 // Process click on [Add Rehab Form] to add a new encounter and TP form.
166 function newtpform(issue) {
167 top.restoreSession();
168 $.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue + '&followup=createtpform');
169 return false;
172 // Process click on issue title to add a new encounter and switch to it and its patient.
173 function newvisit(issue) {
174 top.restoreSession();
175 $.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue);
176 return false;
179 </script>
181 <title><?php xl('Weekly Exposures','e'); ?></title>
182 </head>
184 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
185 <center>
187 <form method='post' action='players_report.php<?php if (!empty($_GET['embed'])) echo "?embed=1"; ?>'>
189 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
191 <tr>
192 <td height="1" colspan="2">
193 </td>
194 </tr>
196 <tr bgcolor='#ddddff'>
197 <td align='left'>
198 <h2><?php xl('Weekly Exposures','e'); ?></h2>
199 </td>
200 <td align='right'>
201 <b><?php echo date('l, F j, Y', $now) ?></b>&nbsp;
202 <input type='text' name='form_date' id='form_date' size='10' value='<?php echo date('Y-m-d', $now) ?>'
203 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
204 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
205 id='img_date' border='0' alt='[?]' style='cursor:pointer'
206 title='<?php xl('Click here to choose a start date','e'); ?>'>
210 &nbsp;
211 <select name='form_squad' title='<?php xl('Select desired squad','e'); ?>'>
212 <?php
213 if ($squads) {
214 foreach ($squads as $key => $value) {
215 echo " <option value='$key'";
216 if (!empty($form_squad) && $form_squad == $key) echo " selected";
217 echo ">" . $value[3] . "</option>\n";
221 </select>
225 &nbsp;
226 <input type='submit' name='form_refresh' value='<?php xl('Refresh','e'); ?>'>
227 </td>
228 </tr>
230 <tr>
231 <td height="1" colspan="2">
232 </td>
233 </tr>
235 </table>
237 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
239 <tr bgcolor="#dddddd">
240 <!--
241 <td class="dehead">
242 &nbsp;<?php xl('Squad','e'); ?>
243 </td>
245 <td class="dehead">
246 &nbsp;<?php xl('Player','e'); ?>
247 </td>
249 <?php
250 $time = $now;
251 for ($day = 0; $day < 8; ++$day) {
252 echo " <td class='dehead' colspan='2' align='center'>";
253 echo date('D', $time);
254 echo "</td>\n";
255 $time += 60 * 60 * 24;
258 </tr>
259 <?php
260 $lastsquad = '';
261 foreach ($ordres as $row) {
262 $squadvalue = $row['squad'];
263 $squadname = $squads[$squadvalue][3];
264 if ($squadname) {
265 if (! acl_check('squads', $squadvalue)) continue;
266 } else {
267 $squadname = "None";
269 $patient_id = $row['pid'];
271 <tr>
272 <!--
273 <td class="detail">
274 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
275 </td>
277 <td class="detail">
278 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
279 </td>
280 <?php
281 $time = $now;
282 for ($day = 0; $day < 8; ++$day) {
283 $date = date('Y-m-d', $time);
284 $ymd = date('Ymd', $time);
286 if ($PROPLOGIC) {
287 // For a given date, fitness info is the last on or before that date,
288 // or if there is none then the defaults apply.
289 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
290 "FROM daily_fitness AS df " .
291 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
292 "WHERE df.pid = '$patient_id' AND df.date <= '$date' " .
293 "ORDER BY df.date DESC LIMIT 1");
295 else {
296 // This is obsolete.
297 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
298 "FROM daily_fitness AS df " .
299 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
300 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
303 if (empty($dfrow)) {
304 $dfrow = array(
305 'fitness' => $fdefault['option_id'],
306 'lf_title' => $fdefault['title'],
307 'lf_mapping' => $fdefault['mapping'],
308 'am' => '',
309 'pm' => '',
313 $mapping = explode(':', $dfrow['lf_mapping']);
314 $bgcolor = $mapping[0];
316 // Compute percentage of participation.
317 $eventmins = 0;
318 $partmins = 0;
319 $eres = getSquadEvents($date, $squadvalue, $patient_id);
321 while ($erow = sqlFetchArray($eres)) {
322 if (!eventMatchesDay($erow, $date)) continue;
323 $duration = (int) ($erow['pc_duration'] / 60);
324 $eventmins += $duration;
325 if (empty($erow['pid']) || $erow['minutes'] > $duration) {
326 $partmins += $duration;
328 else {
329 $partmins += $erow['minutes'];
333 echo " <td class='detail' " .
334 "bgcolor='$bgcolor' " .
335 // "onclick='rosdlgclick($patient_id,$ymd)' " .
336 // "onmouseover='mov1(this,$patient_id)' " .
337 // "onmouseout='ttMouseOut()' " .
338 "valign='top' " .
339 // "nowrap" .
340 ">\n";
341 if ($PROPLOGIC && (empty($dfrow['date']) || $dfrow['date'] != $date))
342 echo '<i>' . $mapping[1] . '</i>';
343 else
344 echo $mapping[1]; // this is obsolete
345 // Append % fitness to this line.
346 if ($partmins < $eventmins) {
347 echo sprintf(" %d", $partmins * 100 / $eventmins) . '%';
350 // Write a line for each active issue, and below it enumerate the forms.
351 // Each form can be clicked to pop it up for editing, or the issue can be
352 // clicked to add a form.
353 // At end of forms for each issue, a line to add a new form.
354 // At end of issues, a line to add a new issue.
356 $ires = sqlStatement("SELECT id, type, title, begdate " .
357 "FROM lists WHERE pid = ? AND activity = 1 AND " .
358 "( type = 'football_injury' OR type = 'medical_problem' ) AND " .
359 "begdate <= ? AND ( enddate IS NULL OR enddate >= ? ) " .
360 "ORDER BY begdate, id", array($patient_id, $date, $date));
361 while ($irow = sqlFetchArray($ires)) {
362 $issue_id = 0 + $irow['id'];
363 $tcode = $irow['type'];
364 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
365 echo "<br />";
366 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,$issue_id)'>";
367 echo "<a href='javascript:;' class='link' onclick='return newvisit($issue_id)' title='" .
368 xl('Click to add new consultation') . "'>";
369 echo "<b>$tcode</b>: " . htmlspecialchars($irow['title'], ENT_NOQUOTES);
370 echo "</a>\n";
371 $fres = sqlStatement("SELECT f.date, f.encounter, f.form_id, tp.value FROM " .
372 "issue_encounter AS ie, forms AS f , form_treatment_protocols AS tp WHERE " .
373 "ie.pid = ? AND ie.list_id = ? AND " .
374 "f.pid = ie.pid AND f.encounter = ie.encounter AND " .
375 "f.formdir = 'treatment_protocols' AND f.deleted = 0 AND " .
376 "tp.id = f.form_id AND tp.rownbr = -1 AND tp.colnbr = -1 AND " .
377 "SUBSTR(tp.value,3,10) <= ? " . // TBD: implement form end date also
378 "ORDER BY f.encounter DESC, f.id DESC",
379 array($patient_id, $irow['id'], $date));
380 $form_id = 0;
381 while ($frow = sqlFetchArray($fres)) {
382 $form_id = 0 + $frow['form_id'];
383 list($form_completed, $start_date, $template_name) = explode('|', $frow['value'], 3);
384 echo "<br />";
385 echo "<a href='javascript:;' class='link' onclick='return opentpform($form_id)'>";
386 echo "&nbsp;&nbsp;";
387 echo "$start_date ";
388 echo htmlspecialchars($template_name, ENT_NOQUOTES);
389 echo "</a>\n";
391 // If there were no rehab forms, insert a link for adding one. In this case the link will
392 // create a new encounter but will not switch to it.
393 if (!$form_id) {
394 echo "<br /><a href='javascript:;' class='link' onclick='return newtpform($issue_id)'>";
395 echo "&nbsp;&nbsp;";
396 echo htmlspecialchars('[' . xl('Add Rehab') . ']', ENT_NOQUOTES);
397 echo "</a>\n";
400 // echo "<br /><a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
401 // echo htmlspecialchars('[' . xl('Add Issue') . ']', ENT_NOQUOTES);
402 // echo "</a>\n";
403 echo " </td>\n";
405 echo " <td " .
406 // "class='detail' " .
407 // "class='small' " .
408 // "align='right' " .
409 "bgcolor='$bgcolor' " .
410 // "style='width:20pt;font-size:70%;' " .
411 "style='font-size:70%;' " .
412 "onclick='rosdlgclick($patient_id,$ymd)' " .
413 "onmouseover='mov2(this,$patient_id,$ymd)' " .
414 "onmouseout='ttMouseOut()' " .
415 "valign='top' " .
416 // "nowrap" .
417 ">\n";
418 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
419 // echo htmlspecialchars('[' . xl('New')) . '&nbsp;' . htmlspecialchars(xl('Inj/Rehab') . ']', ENT_NOQUOTES);
420 // echo "</a>\n";
421 // echo "<a href='javascript:;' class='link' " .
422 // "onclick='return rosdlgclick($patient_id,$ymd)'>";
423 if (!empty($dfrow['am'])) {
424 // echo "<br />";
425 echo '<b>' . htmlspecialchars(xl('AM'), ENT_NOQUOTES) . '</b>: ';
426 echo htmlspecialchars($dfrow['am'], ENT_NOQUOTES);
428 if (!empty($dfrow['pm'])) {
429 if (!empty($dfrow['am'])) echo "<br />";
430 echo '<b>' . htmlspecialchars(xl('PM'), ENT_NOQUOTES) . '</b>: ';
431 echo htmlspecialchars($dfrow['pm'], ENT_NOQUOTES);
433 if (empty($dfrow['am']) && empty($dfrow['pm'])) {
434 // echo "<br />";
435 echo htmlspecialchars('[' . xl('New Inj/Status') . ']', ENT_NOQUOTES);
437 // echo "</a>\n";
438 echo " </td>\n";
440 $time += 60 * 60 * 24;
443 </tr>
444 <?php
445 $lastsquad = $squadname;
449 </table>
451 </form>
452 </center>
454 <div id='tooltipdiv'
455 style='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
456 ></div>
458 <script>
459 <?php
460 if ($alertmsg) {
461 echo " alert('$alertmsg');\n";
464 </script>
465 <!-- stuff for the popup calendar -->
466 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
467 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
468 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
469 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
470 <script language="Javascript">
471 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
472 </script>
473 </body>
474 </html>