From 8c43a470f9eb871aced914f70280ca4d100ab631 Mon Sep 17 00:00:00 2001 From: Rod Roark Date: Sat, 4 Jun 2011 21:52:27 -0700 Subject: [PATCH] Changes for athletic teams related to weekly exposures --- interface/reports/players_report.php | 194 ++++++++++++++++++++++++++-- interface/reports/players_report_dialog.php | 32 ++++- library/ajax/left_nav_encounter_ajax.php | 62 +++++++-- library/js/ajtooltip.js | 3 +- library/spreadsheet.inc.php | 17 ++- sql/athletic_team_layout.sql | 6 + 6 files changed, 280 insertions(+), 34 deletions(-) diff --git a/interface/reports/players_report.php b/interface/reports/players_report.php index edf9f71d1..066556566 100644 --- a/interface/reports/players_report.php +++ b/interface/reports/players_report.php @@ -9,15 +9,24 @@ // This report lists all players/patients by name within squad. // It is applicable only for sports teams. +//SANITIZE ALL ESCAPES +$sanitize_all_escapes=true; +// + +//STOP FAKE REGISTER GLOBALS +$fake_register_globals=false; +// + require_once("../globals.php"); require_once("$srcdir/patient.inc"); require_once("$srcdir/acl.inc"); +require_once("$srcdir/lists.inc"); require_once("$srcdir/calendar_events.inc.php"); -// Temporary variable while new logic is being tested. +// Temporary variable while new "propagation" logic is being tested. // True means that missing days in the daily_fitness table default to // the previous entry's values, if there is one. -// Otherwise the default fitness level (Fully Fit) is used. +// Otherwise the default fitness level (Fully Fit) is used (old logic). $PROPLOGIC = true; $squads = acl_get_squads(); @@ -27,6 +36,18 @@ $alertmsg = ''; // not used yet but maybe later $form_date = fixDate($_POST['form_date'], date('Y-m-d')); +// Figure out the desired or default squad to select. +if (!empty($_POST['form_squad'])) { + $form_squad = $_POST['form_squad']; + $_SESSION['roster_squad'] = $form_squad; +} +else if (!empty($_SESSION['roster_squad'])) { + $form_squad = $_SESSION['roster_squad']; +} +else { + $form_squad = array_shift(array_keys($squads)); +} + // $now = time(); $now = mktime(0, 0, 0, substr($form_date, 5, 2), substr($form_date, 8, 2), substr($form_date, 0, 4)); @@ -36,6 +57,9 @@ $fdefault = sqlQuery("SELECT * FROM list_options WHERE " . "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1"); $query = "SELECT pid, squad, fitness, lname, fname FROM patient_data"; +if (!empty($form_squad)) { + $query .= " WHERE squad LIKE '$form_squad'"; +} $res = sqlStatement($query); // Sort the patients in squad priority order. @@ -110,10 +134,48 @@ if (empty($_GET['embed'])) echo " window.close();\n"; } function refreshme() { + top.restoreSession(); // location.reload(); document.forms[0].submit(); } + // Process click on issue title or [Add Issue]. + function openissue(pid, issue) { + dlgopen('../patient_file/summary/add_edit_issue.php?thispid=' + pid + '&issue=' + issue, '_blank', 800, 600); + return false; + } + + // callback from add_edit_issue.php: + function refreshIssue(issue, title) { + refreshme(); + } + + // Process click on Treatment Protocols form title. + function opentpform(id) { + dlgopen('../forms/treatment_protocols/new.php?popup=1&id=' + id, '_blank', 800, 600); + return false; + } + + // This is called from left_nav_encounter_ajax.php to create the new TP form. + function createtpform(encounter) { + dlgopen('../forms/treatment_protocols/new.php?popup=1&id=0&thisenc=' + encounter, '_blank', 800, 600); + return false; + } + + // Process click on [Add Rehab Form] to add a new encounter and TP form. + function newtpform(issue) { + top.restoreSession(); + $.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue + '&followup=createtpform'); + return false; + } + + // Process click on issue title to add a new encounter and switch to it and its patient. + function newvisit(issue) { + top.restoreSession(); + $.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue); + return false; + } + <?php xl('Weekly Exposures','e'); ?> @@ -142,6 +204,24 @@ if (empty($_GET['embed'])) echo " window.close();\n"; [?]'> + + + +   + + + +   '> @@ -157,9 +237,11 @@ if (empty($_GET['embed'])) echo " window.close();\n"; + @@ -187,9 +269,11 @@ foreach ($ordres as $row) { $patient_id = $row['pid']; ?> + @@ -209,6 +293,7 @@ foreach ($ordres as $row) { "ORDER BY df.date DESC LIMIT 1"); } else { + // This is obsolete. $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " . "FROM daily_fitness AS df " . "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " . @@ -220,8 +305,8 @@ foreach ($ordres as $row) { 'fitness' => $fdefault['option_id'], 'lf_title' => $fdefault['title'], 'lf_mapping' => $fdefault['mapping'], - // 'am' => '', - // 'pm' => '', + 'am' => '', + 'pm' => '', ); } @@ -247,25 +332,108 @@ foreach ($ordres as $row) { echo " \n"; - echo " \n"; $time += 60 * 60 * 24; diff --git a/interface/reports/players_report_dialog.php b/interface/reports/players_report_dialog.php index cb0cd904f..6ea8b8665 100644 --- a/interface/reports/players_report_dialog.php +++ b/interface/reports/players_report_dialog.php @@ -41,6 +41,12 @@ $form_to = formData('form_to'); $form_note = empty($_POST['form_note']) ? '' : $_POST['form_note']; if (get_magic_quotes_gpc()) $form_note = stripslashes($form_note); +$form_am = empty($_POST['form_am']) ? '' : $_POST['form_am']; +if (get_magic_quotes_gpc()) $form_am = stripslashes($form_am); + +$form_pm = empty($_POST['form_pm']) ? '' : $_POST['form_pm']; +if (get_magic_quotes_gpc()) $form_pm = stripslashes($form_pm); + function gen_list_options($list_id, $default='') { $res = sqlStatement("SELECT * FROM list_options WHERE " . "list_id = '$list_id' ORDER BY seq"); @@ -106,8 +112,8 @@ if ($_POST['form_save']) { if ($dfrow['date'] == $date) { sqlStatement("UPDATE daily_fitness SET " . "fitness = '$form_fitness', " . - // "am = '$form_am', " . - // "pm = '$form_pm', " . + "am = '$form_am', " . + "pm = '$form_pm', " . "issue_id = '$form_issue'" . "WHERE pid = '$plid' AND date = '$date'"); } @@ -116,8 +122,8 @@ if ($_POST['form_save']) { "pid = '$plid', " . "date = '$date', " . "fitness = '$form_fitness', " . - // "am = '$form_am', " . - // "pm = '$form_pm', " . + "am = '$form_am', " . + "pm = '$form_pm', " . "issue_id = '$form_issue'"); } @@ -315,6 +321,24 @@ while ($urow = sqlFetchArray($ures)) { + + + + + + + + + +
 
  \n"; if ($PROPLOGIC && (empty($dfrow['date']) || $dfrow['date'] != $date)) echo '' . $mapping[1] . ''; else - echo $mapping[1]; + echo $mapping[1]; // this is obsolete + // Append % fitness to this line. + if ($partmins < $eventmins) { + echo sprintf(" %d", $partmins * 100 / $eventmins) . '%'; + } + + // Write a line for each active issue, and below it enumerate the forms. + // Each form can be clicked to pop it up for editing, or the issue can be + // clicked to add a form. + // At end of forms for each issue, a line to add a new form. + // At end of issues, a line to add a new issue. + // + $ires = sqlStatement("SELECT id, type, title, begdate " . + "FROM lists WHERE pid = ? AND activity = 1 AND " . + "( type = 'football_injury' OR type = 'medical_problem' ) AND " . + "begdate <= ? AND ( enddate IS NULL OR enddate >= ? ) " . + "ORDER BY begdate, id", array($patient_id, $date, $date)); + while ($irow = sqlFetchArray($ires)) { + $issue_id = 0 + $irow['id']; + $tcode = $irow['type']; + if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2]; + echo "
"; + // echo ""; + echo ""; + echo "$tcode: " . htmlspecialchars($irow['title'], ENT_NOQUOTES); + echo "\n"; + $fres = sqlStatement("SELECT f.date, f.encounter, f.form_id, tp.value FROM " . + "issue_encounter AS ie, forms AS f , form_treatment_protocols AS tp WHERE " . + "ie.pid = ? AND ie.list_id = ? AND " . + "f.pid = ie.pid AND f.encounter = ie.encounter AND " . + "f.formdir = 'treatment_protocols' AND f.deleted = 0 AND " . + "tp.id = f.form_id AND tp.rownbr = -1 AND tp.colnbr = -1 AND " . + "SUBSTR(tp.value,3,10) <= ? " . // TBD: implement form end date also + "ORDER BY f.encounter DESC, f.id DESC", + array($patient_id, $irow['id'], $date)); + $form_id = 0; + while ($frow = sqlFetchArray($fres)) { + $form_id = 0 + $frow['form_id']; + list($form_completed, $start_date, $template_name) = explode('|', $frow['value'], 3); + echo "
"; + echo ""; + echo "  "; + echo "$start_date "; + echo htmlspecialchars($template_name, ENT_NOQUOTES); + echo "\n"; + } + // If there were no rehab forms, insert a link for adding one. In this case the link will + // create a new encounter but will not switch to it. + if (!$form_id) { + echo "
"; + echo "  "; + echo htmlspecialchars('[' . xl('Add') . ']', ENT_NOQUOTES); + echo "\n"; + } + } + // echo "
"; + // echo htmlspecialchars('[' . xl('Add Issue') . ']', ENT_NOQUOTES); + // echo "\n"; echo "
\n"; - if ($partmins < $eventmins) { - echo ((int)($partmins * 100 / $eventmins)) . "%\n"; + "valign='top' " . + // "nowrap" . + ">\n"; + // echo ""; + // echo htmlspecialchars('[' . xl('New')) . ' ' . htmlspecialchars(xl('Inj/Rehab') . ']', ENT_NOQUOTES); + // echo "\n"; + // echo ""; + if (!empty($dfrow['am'])) { + // echo "
"; + echo '' . htmlspecialchars(xl('AM'), ENT_NOQUOTES) . ': '; + echo htmlspecialchars($dfrow['am'], ENT_NOQUOTES); + } + if (!empty($dfrow['pm'])) { + if (!empty($dfrow['am'])) echo "
"; + echo '' . htmlspecialchars(xl('PM'), ENT_NOQUOTES) . ': '; + echo htmlspecialchars($dfrow['pm'], ENT_NOQUOTES); + } + if (empty($dfrow['am']) && empty($dfrow['pm'])) { + // echo "
"; + echo htmlspecialchars('[' . xl('New Inj/Status') . ']', ENT_NOQUOTES); } + // echo "
\n"; echo "
+ + + +
+ + + +

diff --git a/library/ajax/left_nav_encounter_ajax.php b/library/ajax/left_nav_encounter_ajax.php index c8d9d7721..41fcc83e4 100644 --- a/library/ajax/left_nav_encounter_ajax.php +++ b/library/ajax/left_nav_encounter_ajax.php @@ -11,6 +11,8 @@ $fake_register_globals = false; require_once("../../interface/globals.php"); require_once("$srcdir/forms.inc"); +require_once("$srcdir/patient.inc"); +require_once("$srcdir/formatting.inc.php"); /********************************************************************* // Get the patient's encounter ID for today, if it exists. @@ -63,34 +65,68 @@ function todaysEncounter($patient_id, $reason='') { $issue = $_GET['issue']; $today = date('Y-m-d'); -$irow = sqlQuery("SELECT title FROM lists WHERE id = ?", array($issue)); +$irow = sqlQuery("SELECT title, pid FROM lists WHERE id = ?", array($issue)); + +$thispid = $irow['pid']; +if (empty($thispid)) die("Error fetching issue $issue"); // Check if an encounter already exists for today. // If yes, select the latest one. // If not, create one and give it a title of the issue title. -$thisenc = todaysEncounter($pid, $irow['title']); +$thisenc = todaysEncounter($thispid, $irow['title']); // If the encounter is not already linked to the specified issue, link it. $tmp = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " . "pid = ? AND list_id = ? AND encounter = ?", - array($pid, $issue, $thisenc)); + array($thispid, $issue, $thisenc)); if (empty($tmp['count'])) { sqlStatement("INSERT INTO issue_encounter " . "( pid, list_id, encounter ) VALUES ( ?, ?, ? )", - array($pid, $issue, $thisenc)); + array($thispid, $issue, $thisenc)); } - -// Write JavaScript to open the selected encounter as the active encounter. -// Logic cloned from encounters.php. ?> + +// alert('pid = thispid = '); // debugging + top.restoreSession(); var enc = ; - -setEncounter('', enc, 'RBot'); -setRadio('RBot', 'enc'); -loadFrame2('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc); - + +// The JavaScript part of switching to the new pid. Cloned from demographics.php. +top.left_nav.setPatient(); +// TBD: ForceDual? Maybe load demographics.php into the top frame? + +top.left_nav.setEncounter('', enc, 'RBot'); +top.left_nav.setRadio('RBot', 'enc'); +top.left_nav.loadFrame2('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc); + top.Title.location.href = '../encounter/encounter_title.php?set_encounter=' + enc; top.Main.location.href = '../encounter/patient_encounter.php?set_encounter=' + enc; - + diff --git a/library/js/ajtooltip.js b/library/js/ajtooltip.js index 4c6c77d2f..fd38cbc3a 100644 --- a/library/js/ajtooltip.js +++ b/library/js/ajtooltip.js @@ -54,7 +54,8 @@ function ttMake() { // var y = ttGetY(ttElem) - ttobject.offsetHeight - 10; // if (y < 0) y = ttGetY(ttElem) + ttElem.offsetHeight + 10; var dh = window.innerHeight ? window.innerHeight : document.body.clientHeight; - var y = ttGetY(ttElem) + ttobject.offsetHeight + 10; + // var y = ttGetY(ttElem) + ttobject.offsetHeight + 10; + var y = ttGetY(ttElem) + ttElem.offsetHeight; if (y + 40 > dh) y = 0; ttobject.style.left = x; ttobject.style.top = y; diff --git a/library/spreadsheet.inc.php b/library/spreadsheet.inc.php index 06b410166..a954f997f 100644 --- a/library/spreadsheet.inc.php +++ b/library/spreadsheet.inc.php @@ -48,6 +48,9 @@ if (empty($spreadsheet_title)) $spreadsheet_title = 'Injury Log'; // Putting an error message in here will result in a javascript alert. $alertmsg = ''; +// Determine the encounter that we are working with. +$thisenc = empty($_GET['thisenc']) ? $encounter : $_GET['thisenc'] + 0; + // If we are invoked as a popup (not in an encounter): $popup = $_GET['popup']; @@ -115,6 +118,9 @@ if ($_POST['bn_save_form'] || $_POST['bn_save_template']) { } // If adding a new form... else { + $tmprow = sqlQuery("SELECT pid FROM form_encounter WHERE encounter = ? ORDER BY id DESC LIMIT 1", + array($thisenc)); + $thispid = $tmprow['pid']; sqlStatement("LOCK TABLES form_$spreadsheet_form_name WRITE, log WRITE"); $tmprow = sqlQuery("SELECT MAX(id) AS maxid FROM form_$spreadsheet_form_name"); $formid = $tmprow['maxid'] + 1; @@ -126,8 +132,8 @@ if ($_POST['bn_save_form'] || $_POST['bn_save_template']) { "'$form_completed|$start_date|$template_name' " . ")"); sqlStatement("UNLOCK TABLES"); - addForm($encounter, $spreadsheet_title, $formid, "$spreadsheet_form_name", - $pid, $userauthorized); + addForm($thisenc, $spreadsheet_title, $formid, "$spreadsheet_form_name", + $thispid, $userauthorized); } $saveid = $formid; } @@ -282,6 +288,11 @@ $num_virtual_cols = $num_used_cols ? $num_used_cols + 5 : 10; var ssChanged = false; // if they have changed anything in the spreadsheet var startDate = ''; + // In case we are a popup (top level) window, handle top.restoreSession() calls. + function restoreSession() { + return opener.top.restoreSession(); + } + // Helper function to set the contents of a block. function setBlockContent(id, content) { if (document.getElementById) { @@ -527,7 +538,7 @@ $num_virtual_cols = $num_used_cols ? $num_used_cols + 5 : 10; -

" +" onsubmit="return top.restoreSession()">
diff --git a/sql/athletic_team_layout.sql b/sql/athletic_team_layout.sql index 3838f08dc..ddf5f860c 100644 --- a/sql/athletic_team_layout.sql +++ b/sql/athletic_team_layout.sql @@ -271,3 +271,9 @@ INSERT INTO layout_options (form_id, field_id, group_name, title, seq, data_type INSERT INTO layout_options (form_id, field_id, group_name, title, seq, data_type, uor, fld_length, max_length, list_id, titlecols, datacols, edit_options) VALUES ('LBFfms','imping_r_2','1','' ,34,1,1,1,1,'boolean',0,2,''); INSERT INTO layout_options (form_id, field_id, group_name, title, seq, data_type, uor, fld_length, max_length, list_id, titlecols, datacols, edit_options) VALUES ('LBFfms','total' ,'1','Sum of Scores' ,35,2,1,3,3,'',2,2,'G'); +-- Added 2011-05-25: + +ALTER TABLE daily_fitness + ADD `am` text NOT NULL DEFAULT '', + ADD `pm` text NOT NULL DEFAULT ''; + -- 2.11.4.GIT