switch to explode since split deprecated
[openemr.git] / interface / reports / players_report.php
blob273febfe73643bc51d6fc272f695eb085efa3ab9
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&createvisit=1');
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' => '',
312 else if ($dfrow['date'] != $date) {
313 // As of 2012-07-12 am/pm are not propagated.
314 $dfrow['am'] = '';
315 $dfrow['pm'] = '';
318 $mapping = explode(':', $dfrow['lf_mapping']);
319 $bgcolor = $mapping[0];
321 // Compute percentage of participation.
322 $eventmins = 0;
323 $partmins = 0;
324 $eres = getSquadEvents($date, $squadvalue, $patient_id);
326 while ($erow = sqlFetchArray($eres)) {
327 if (!eventMatchesDay($erow, $date)) continue;
328 $duration = (int) ($erow['pc_duration'] / 60);
329 $eventmins += $duration;
330 if (empty($erow['pid']) || $erow['minutes'] > $duration) {
331 $partmins += $duration;
333 else {
334 $partmins += $erow['minutes'];
338 echo " <td class='detail' " .
339 "bgcolor='$bgcolor' " .
340 // "onclick='rosdlgclick($patient_id,$ymd)' " .
341 // "onmouseover='mov1(this,$patient_id)' " .
342 // "onmouseout='ttMouseOut()' " .
343 "valign='top' " .
344 // "nowrap" .
345 ">\n";
346 if ($PROPLOGIC && (empty($dfrow['date']) || $dfrow['date'] != $date))
347 echo '<i>' . $mapping[1] . '</i>';
348 else
349 echo $mapping[1]; // this is obsolete
350 // Append % fitness to this line.
351 if ($partmins < $eventmins) {
352 echo sprintf(" %d", $partmins * 100 / $eventmins) . '%';
355 // Write a line for each active issue, and below it enumerate the forms.
356 // Each form can be clicked to pop it up for editing, or the issue can be
357 // clicked to add a form.
358 // At end of forms for each issue, a line to add a new form.
359 // At end of issues, a line to add a new issue.
361 $ires = sqlStatement("SELECT id, type, title, begdate " .
362 "FROM lists WHERE pid = ? AND activity = 1 AND " .
363 "( type = 'football_injury' OR type = 'medical_problem' ) AND " .
364 "begdate <= ? AND ( enddate IS NULL OR enddate >= ? ) " .
365 "ORDER BY begdate, id", array($patient_id, $date, $date));
366 while ($irow = sqlFetchArray($ires)) {
367 $issue_id = 0 + $irow['id'];
368 $tcode = $irow['type'];
369 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
370 echo "<br />";
371 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,$issue_id)'>";
372 echo "<a href='javascript:;' class='link' onclick='return newvisit($issue_id)' title='" .
373 xl('Click to add new consultation') . "'>";
374 echo "<b>$tcode</b>: " . htmlspecialchars($irow['title'], ENT_NOQUOTES);
375 echo "</a>\n";
376 $fres = sqlStatement("SELECT f.date, f.encounter, f.form_id, tp.value FROM " .
377 "issue_encounter AS ie, forms AS f , form_treatment_protocols AS tp WHERE " .
378 "ie.pid = ? AND ie.list_id = ? AND " .
379 "f.pid = ie.pid AND f.encounter = ie.encounter AND " .
380 "f.formdir = 'treatment_protocols' AND f.deleted = 0 AND " .
381 "tp.id = f.form_id AND tp.rownbr = -1 AND tp.colnbr = -1 AND " .
382 "SUBSTR(tp.value,3,10) <= ? " . // TBD: implement form end date also
383 "ORDER BY f.encounter DESC, f.id DESC",
384 array($patient_id, $irow['id'], $date));
385 $form_id = 0;
386 while ($frow = sqlFetchArray($fres)) {
387 $form_id = 0 + $frow['form_id'];
388 list($form_completed, $start_date, $template_name) = explode('|', $frow['value'], 3);
389 echo "<br />";
390 echo "<a href='javascript:;' class='link' onclick='return opentpform($form_id)'>";
391 echo "&nbsp;&nbsp;";
392 echo "$start_date ";
393 echo htmlspecialchars($template_name, ENT_NOQUOTES);
394 echo "</a>\n";
396 // If there were no rehab forms, insert a link for adding one. In this case the link will
397 // create a new encounter but will not switch to it.
398 if (!$form_id) {
399 echo "<br /><a href='javascript:;' class='link' onclick='return newtpform($issue_id)'>";
400 echo "&nbsp;&nbsp;";
401 echo htmlspecialchars('[' . xl('Add Rehab') . ']', ENT_NOQUOTES);
402 echo "</a>\n";
405 // echo "<br /><a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
406 // echo htmlspecialchars('[' . xl('Add Issue') . ']', ENT_NOQUOTES);
407 // echo "</a>\n";
408 echo " </td>\n";
410 echo " <td " .
411 // "class='detail' " .
412 // "class='small' " .
413 // "align='right' " .
414 "bgcolor='$bgcolor' " .
415 // "style='width:20pt;font-size:70%;' " .
416 "style='font-size:70%;' " .
417 "onclick='rosdlgclick($patient_id,$ymd)' " .
418 "onmouseover='mov2(this,$patient_id,$ymd)' " .
419 "onmouseout='ttMouseOut()' " .
420 "valign='top' " .
421 // "nowrap" .
422 ">\n";
423 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
424 // echo htmlspecialchars('[' . xl('New')) . '&nbsp;' . htmlspecialchars(xl('Inj/Rehab') . ']', ENT_NOQUOTES);
425 // echo "</a>\n";
426 // echo "<a href='javascript:;' class='link' " .
427 // "onclick='return rosdlgclick($patient_id,$ymd)'>";
428 if (!empty($dfrow['am'])) {
429 // echo "<br />";
430 echo '<b>' . htmlspecialchars(xl('AM'), ENT_NOQUOTES) . '</b>: ';
431 echo htmlspecialchars($dfrow['am'], ENT_NOQUOTES);
433 if (!empty($dfrow['pm'])) {
434 if (!empty($dfrow['am'])) echo "<br />";
435 echo '<b>' . htmlspecialchars(xl('PM'), ENT_NOQUOTES) . '</b>: ';
436 echo htmlspecialchars($dfrow['pm'], ENT_NOQUOTES);
438 if (empty($dfrow['am']) && empty($dfrow['pm'])) {
439 // echo "<br />";
440 echo htmlspecialchars('[' . xl('New Inj/Status') . ']', ENT_NOQUOTES);
442 // echo "</a>\n";
443 echo " </td>\n";
445 $time += 60 * 60 * 24;
448 </tr>
449 <?php
450 $lastsquad = $squadname;
454 </table>
456 </form>
457 </center>
459 <div id='tooltipdiv'
460 style='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
461 ></div>
463 <script>
464 <?php
465 if ($alertmsg) {
466 echo " alert('$alertmsg');\n";
469 </script>
470 <!-- stuff for the popup calendar -->
471 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
472 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
473 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
474 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
475 <script language="Javascript">
476 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
477 </script>
478 </body>
479 </html>