changed how the default provider is chosen for new single-provider events
[openemr.git] / interface / reports / football_injury_report.php
blobcbde66960333adfe8bae846293c3c66ddcea041d
1 <?php
2 // This module is for team sports use and reports on various attributes
3 // of injuries for a given time period and reporting key.
5 include_once("../globals.php");
6 include_once("../../library/patient.inc");
7 include_once("../../library/acl.inc");
8 include_once("../forms/football_injury_audit/fia.inc.php");
10 // Might want something different here.
12 // if (! acl_check('acct', 'rep')) die("Unauthorized access.");
14 $from_date = fixDate($_POST['form_from_date']);
15 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
16 $form_by = $_POST['form_by']; // this is a scalar
17 $form_show = $_POST['form_show']; // this is an array
18 $form_squads = $_POST['form_squads']; // this is an array
20 // One of these is chosen as the left column, or Y-axis, of the report.
22 $arr_by = array(
23 1 => xl('Activity Type'),
24 2 => xl('Body Region'),
25 3 => xl('Footwear Type'),
26 4 => xl('Game Period'),
27 5 => xl('Injury Mechanism'),
28 6 => xl('Injury Type'),
29 7 => xl('Player'),
30 8 => xl('Playing Position'),
31 9 => xl('Sanction Type'),
32 10 => xl('Surface Type'),
33 11 => xl('Training Type')
36 // A reported value is either scalar, or an array listed horizontally. If
37 // multiple items are chosen then each starts in the next available column.
39 $arr_show = array(
40 1 => array('Number of Injuries'),
41 2 => array('Days/Games Missed'),
42 3 => array('Body Region'),
43 4 => array('Injury Type'),
44 5 => array('Issue Title'),
47 $arr_regions_osics = array(
48 'A' => xl('Ankle + heel'),
49 'B' => xl('Buttock + S.I.'),
50 'C' => xl('Chest'),
51 'D' => xl('Thoracic spine'),
52 'E' => xl('Elbow'),
53 'F' => xl('Foot'),
54 'G' => xl('Hip + groin'),
55 'H' => xl('Head'),
56 'K' => xl('Knee'),
57 'L' => xl('Lumbar spine'),
58 'M' => xl('Medical problem'),
59 'N' => xl('Neck'),
60 'O' => xl('Abdominal'),
61 'P' => xl('Hand + fingers'),
62 'Q' => xl('Lower leg'),
63 'R' => xl('Forearm'),
64 'S' => xl('Shoulder + clavicle'),
65 'T' => xl('Thigh + hamstring'),
66 'U' => xl('Upper arm'),
67 'W' => xl('Wrist'),
68 'X' => xl('Multiple areas'),
69 'Z' => xl('Area not specified')
72 $arr_regions_ucsmc = array(
73 'AN' => xl('Ankle + heel'),
74 'AR' => xl('Upper arm'),
75 'BL' => xl('Medical problem'),
76 'CV' => xl('Medical problem'),
77 'DE' => xl('Medical problem'),
78 'EL' => xl('Elbow'),
79 'EN' => xl('Medical problem'),
80 'EV' => xl('Environmental'),
81 'FA' => xl('Forearm'),
82 'FE' => xl('Fluid and electrolyte problem'),
83 'FO' => xl('Foot'),
84 'GI' => xl('Abdominal'),
85 'GU' => xl('Medical problem'),
86 'HA' => xl('Hand + fingers'),
87 'HE' => xl('Head'),
88 'HI' => xl('Hip + groin'),
89 'ID' => xl('Medical problem'),
90 'KN' => xl('Knee'),
91 'LE' => xl('Lower leg'),
92 'LP' => xl('Lumbar spine'),
93 'NE' => xl('Neck'),
94 'NS' => xl('Medical problem'),
95 'PS' => xl('Medical problem'),
96 'RE' => xl('Medical problem'),
97 'RM' => xl('Medical problem'),
98 'SH' => xl('Shoulder + clavicle'),
99 'TH' => xl('Thigh + hamstring'),
100 'TR' => xl('Thoracic spine'),
101 'WR' => xl('Wrist')
104 $arr_types_osics = array(
105 'A' => xl('Arthritis / degen joint disease'),
106 'B' => xl('Developmental abnormality'),
107 'C' => xl('Cartilage / chondral / disc damage'),
108 'D' => xl('Dislocation'),
109 'E' => xl('Tumour'),
110 'F' => xl('Fracture'),
111 'G' => xl('Avulsion / avulsion fracture'),
112 'H' => xl('Haematoma / bruising'),
113 'I' => xl('Infection / Abscess'),
114 'J' => xl('Minor joint strain +/- synovitis'),
115 'K' => xl('Laceration / skin condition'),
116 'L' => xl('Ligament tear or sprain'),
117 'M' => xl('Strain of muscle'),
118 'N' => xl('Neural condition / nerve damage'),
119 'O' => xl('Visceral damage/trauma/surgery'),
120 'P' => xl('Chronic synovitis / effusion / joint pain / gout'),
121 'Q' => xl('Old fracture non / malunion'),
122 'R' => xl('Rupture'),
123 'S' => xl('Stress fracture'),
124 'T' => xl('Tendonitis / osis / bursitis'),
125 'U' => xl('Instability / subluxation'),
126 'V' => xl('Vascular condition'),
127 'X' => xl('Medical problem'),
128 'Y' => xl('Trigger point / compartment syndrome / DOMS / cramp'),
129 'Z' => xl('Undiagnosed')
132 $arr_types_ucsmc = array(
133 '01' => xl('Ligament tear or sprain'),
134 '02' => xl('Ligament tear or sprain'),
135 '03' => xl('Ligament tear or sprain'),
136 '07' => xl('Strain of muscle'),
137 '09' => xl('Rupture'),
138 '10' => xl('Dislocation'),
139 '11' => xl('Instability / subluxation'),
140 '12' => xl('Instability / subluxation'),
141 '13' => xl('Fracture'),
142 '14' => xl('Avulsion / avulsion fracture'),
143 '15' => xl('Old fracture non / malunion'),
144 '16' => xl('Fracture'),
145 '17' => xl('Cartilage / chondral / disc damage'),
146 '18' => xl('Stress fracture'),
147 '23' => xl('Haematoma / bruising'),
148 '24' => xl('Laceration / skin condition'),
149 '25' => xl('Haematoma / bruising'),
150 '26' => xl('Tendonitis / osis / bursitis'),
151 '27' => xl('Tendonitis / osis / bursitis'),
152 '28' => xl('Tendonitis / osis / bursitis'),
153 '29' => xl('Tendonitis / osis / bursitis'),
154 '33' => xl('Arthritis / degen joint diseas'),
155 '36' => xl('Trigger point / compartment syndrome / DOMS / cramp'),
156 '38' => xl('Infection / Abscess'),
157 '39' => xl('Medical problem'),
158 '40' => xl('Cartilage / chondral / disc damage'),
159 '42' => xl('Tumour'),
160 '44' => xl('Neural condition / nerve damage')
164 <html>
165 <head>
166 <? html_header_show();?>
167 <title><?php xl('Football Injury Report','e'); ?></title>
168 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
169 <style type="text/css">
170 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
171 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
172 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
173 </style>
174 <script type="text/javascript" src="../../library/textformat.js"></script>
175 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
176 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
177 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
178 <script language="JavaScript">
179 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
180 </script>
181 </head>
183 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
185 <center>
187 <h2><? xl('Football Injury Report','e'); ?></h2>
189 <form name='theform' method='post' action='football_injury_report.php'>
191 <table border='0' cellspacing='0' cellpadding='2'>
193 <tr>
194 <td valign='top' nowrap>
195 For each
196 </td>
197 <td valign='top'>
198 <select name='form_by' title='Left column of report'>
199 <?php
200 foreach ($arr_by as $key => $value) {
201 echo " <option value='$key'";
202 if ($key == $form_by) echo " selected";
203 echo ">" . $value . "</option>\n";
206 </select>
207 </td>
208 <td valign='top' rowspan='3' nowrap>
209 &nbsp;
210 <input type='submit' name='form_refresh' value='<?php xl('Show','e'); ?>' title='<?php xl('Click to generate the report','e'); ?>'> :
211 </td>
212 <td valign='top' rowspan='3'>
213 <select name='form_show[]' size='4' multiple
214 title='<?php xl('Hold down Ctrl to select multiple items','e'); ?>'>
215 <?php
216 foreach ($arr_show as $key => $value) {
217 echo " <option value='$key'";
218 if (is_array($form_show) && in_array($key, $form_show)) echo " selected";
219 echo ">" . $value[0] . "</option>\n";
222 </select>
223 </td>
224 <td valign='top' rowspan='3' nowrap>
225 &nbsp;
226 for:
227 </td>
228 <td valign='top' rowspan='3'>
229 <select name='form_squads[]' size='4' multiple
230 title='<?php xl('Hold down Ctrl to select multiple squads','e'); ?>'>
231 <?php
232 $squads = acl_get_squads();
233 if ($squads) {
234 foreach ($squads as $key => $value) {
235 echo " <option value='$key'";
236 if (!is_array($form_squads) || in_array($key, $form_squads)) echo " selected";
237 echo ">" . $value[3] . "</option>\n";
241 </select>
242 </td>
243 </tr>
244 <tr>
245 <td valign='top' nowrap>
246 from
247 </td>
248 <td valign='top' nowrap>
249 <input type='text' name='form_from_date' id='form_from_date' size='10' value='<?php echo $from_date ?>'
250 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='Start date yyyy-mm-dd'>
251 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
252 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
253 title='<?php xl('Click here to choose a date','e'); ?>'>
254 </td>
255 </tr>
256 <tr>
257 <td valign='top' nowrap>
259 </td>
260 <td valign='top' nowrap>
261 <input type='text' name='form_to_date' id='form_to_date' size='10' value='<?php echo $to_date ?>'
262 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='End date yyyy-mm-dd'>
263 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
264 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
265 title='<?php xl('Click here to choose a date','e'); ?>'>
266 </td>
267 </tr>
269 <tr>
270 <td height="1">
271 </td>
272 </tr>
274 </table>
276 <?php
277 if ($_POST['form_refresh']) {
279 // fetch all the issues that are medical problems and corresponding FIA
280 // data. We are reporting only values from issues (though often by FIA
281 // fields), so it seems we want to retain one array row per issue and
282 // discard extra FIA forms.
284 $squadmatches = '1 = 2'; // an always-false condition
285 foreach ($form_squads as $squad)
286 $squadmatches .= " OR pd.squad = '$squad'";
288 $query = "SELECT lists.id AS listid, lists.diagnosis, lists.pid, " .
289 "lists.extrainfo AS gmissed, lists.begdate, lists.enddate, " .
290 "lists.returndate, lists.title, fia.*, pd.lname, pd.fname, pd.mname " .
291 "FROM lists " .
292 "JOIN patient_data AS pd ON pd.pid = lists.pid AND ( $squadmatches ) " .
293 "JOIN issue_encounter AS ie ON ie.list_id = lists.id " .
294 "JOIN forms ON forms.pid = ie.pid AND forms.encounter = ie.encounter " .
295 "AND forms.formdir = 'football_injury_audit' " .
296 "JOIN form_football_injury_audit as fia ON fia.id = forms.form_id " .
297 "WHERE ( lists.enddate IS NULL OR lists.enddate >= '$from_date' ) AND " .
298 "lists.begdate <= '$to_date' AND " .
299 "lists.type = 'medical_problem' AND lists.title NOT LIKE '%Illness%'" .
300 "ORDER BY lists.pid, lists.begdate";
302 $res = sqlStatement($query);
304 $areport = array();
305 $arr_my_body_regions = array();
306 $arr_my_injury_types = array();
307 $arr_my_issue_titles = array();
309 $last_listid = 0;
310 $last_pid = 0;
311 $last_endsecs = 0;
313 while ($row = sqlFetchArray($res)) {
315 // Throw away extra injury forms.
316 if ($row['listid'] == $last_listid) continue;
317 $last_listid = $rows['listid'];
319 $body_region = 'Undiagnosed';
320 if (preg_match('/^(.)..$/', $row['diagnosis'], $matches)) {
321 $body_region = $arr_regions_osics[$matches[1]];
323 else if (preg_match('/^(..)\...\...$/', $row['diagnosis'], $matches)) {
324 $body_region = $arr_regions_ucsmc[$matches[1]];
327 $injury_type = 'Undiagnosed';
328 if (preg_match('/^.(.).$/', $row['diagnosis'], $matches)) {
329 $injury_type = $arr_types_osics[$matches[1]];
331 else if (preg_match('/^..\...\.(..)$/', $row['diagnosis'], $matches)) {
332 $injury_type = $arr_types_ucsmc[$matches[1]];
335 $issue_title = trim($row['title']);
337 $key = 'Unspecified';
339 if ($form_by == '1') { // Activity Type
340 if ($row['fimech_tackling'] || $row['fimech_tackled'] ||
341 $row['fimech_collision'] || $row['fimech_kicked'] ||
342 $row['fimech_elbow'] || $row['fimech_othercon'])
344 $key = 'Contact';
345 } else {
346 $key = 'Non-contact';
350 else if ($form_by == '2') { // Body Region
351 $key = $body_region;
354 else if ($form_by == '3') { // Footwear Type
355 if ($row['fifootwear']) $key = $arr_footwear[$row['fifootwear']];
358 else if ($form_by == '4') { // Game Period
359 if ($row['fiinjmin']) {
360 $key = 15 * (int)(($row['fiinjmin'] + 14) / 15);
364 else if ($form_by == '5') { // Injury Mechanism
365 foreach ($arr_activity as $imkey => $imvalue) {
366 if ($row["fimech_$imkey"]) {
367 $key = $imvalue;
368 break;
373 else if ($form_by == '6') { // Injury Type
374 $key = $injury_type;
377 else if ($form_by == '7') { // Player
378 $key = trim($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']);
381 else if ($form_by == '8') { // Playing Position
382 if ($row['fiposition']) $key = $arr_position[$row['fiposition']];
385 else if ($form_by == '9') { // Referee Sanction Type
386 foreach ($arr_sanction as $imkey => $imvalue) {
387 if ($row["fimech_$imkey"]) {
388 $key = $imvalue;
389 break;
394 else if ($form_by == '10') { // Surface Type
395 if ($row['fisurface']) $key = $arr_surface[$row['fisurface']];
398 else if ($form_by == '11') { // Training Type
399 if ($row['fiinjtime']) $key = $arr_injtime[$row['fiinjtime']];
402 // OK we now have the reporting key for this issue.
404 // If first instance of this key, initialize its arrays.
405 if (! $areport[$key]) {
406 $areport[$key] = array();
407 $areport[$key]['inj'] = 0; // number of injuries
408 $areport[$key]['dmissed'] = 0; // days missed
409 $areport[$key]['gmissed'] = 0; // games missed
410 $areport[$key]['br'] = array(); // body region array
411 $areport[$key]['it'] = array(); // injury type array
412 $areport[$key]['ti'] = array(); // issue title array
415 // Compute days missed. Force non-overlap of multiple issues for the
416 // same player. This logic assumes sorting on begdate within pid.
418 $begsecs = strtotime($row['begdate']);
419 $endsecs = $row['returndate'] ? strtotime($row['returndate']) : time();
420 if ($row['pid'] == $last_pid) {
421 if ($begsecs < $last_endsecs) {
422 $begsecs = $last_endsecs;
425 else {
426 $last_pid = $row['pid'];
427 $last_endsecs = 0;
429 if ($begsecs > $endsecs) $begsecs = $endsecs;
430 if ($last_endsecs < $endsecs) $last_endsecs = $endsecs;
431 $daysmissed = round(($endsecs - $begsecs) / (60 * 60 * 24));
433 // Store values that we might want to report on.
434 $areport[$key]['inj'] += 1; // count number of injuries
435 $areport[$key]['dmissed'] += $daysmissed; // count days missed
436 $areport[$key]['gmissed'] += $row['gmissed']; // count games missed
437 $areport[$key]['br'][$body_region] += 1; // count injuries to this body part
438 $areport[$key]['it'][$injury_type] += 1; // count injuries of this type
439 $areport[$key]['ti'][$issue_title] += 1; // count injuries with this title
441 // These track all body regions and injury types encountered.
442 $arr_my_body_regions[$body_region] += 1;
443 $arr_my_injury_types[$injury_type] += 1;
444 $arr_my_issue_titles[$issue_title] += 1;
446 } // end while
448 // Sort everything by key for reporting.
449 ksort($areport);
450 ksort($arr_my_body_regions);
451 ksort($arr_my_injury_types);
452 ksort($arr_my_issue_titles);
455 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
457 <tr bgcolor="#dddddd">
458 <td class="dehead">
459 <?php echo $arr_by[$form_by]; ?>
460 </td>
462 <?php
463 // Generate headings for values to be shown.
464 foreach ($form_show as $value) {
465 if ($value == '1') { // Number of injuries
466 echo " <td class='dehead' align='right'>Injuries</td>\n";
468 else if ($value == '2') { // days and games missed
469 echo " <td class='dehead' align='right'>Days Missed</td>\n";
470 echo " <td class='dehead' align='right'>Games Missed</td>\n";
472 else if ($value == '3') { // body region
473 foreach ($arr_my_body_regions as $br => $nothing) {
474 echo " <td class='dehead' align='right'>$br</td>\n";
477 else if ($value == '4') { // injury type
478 foreach ($arr_my_injury_types as $it => $nothing) {
479 echo " <td class='dehead' align='right'>$it</td>\n";
482 else if ($value == '5') { // issue titles
483 foreach ($arr_my_issue_titles as $ti => $nothing) {
484 echo " <td class='dehead' align='right'>$ti</td>\n";
489 echo " </tr>\n";
491 $encount = 0;
493 foreach ($areport as $key => $varr) {
494 $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd";
496 echo " <tr bgcolor='$bgcolor'>\n";
497 echo " <td class='detail'>$key</td>\n";
499 // Generate data for this row.
500 foreach ($form_show as $value) {
501 if ($value == '1') { // Number of injuries
502 echo " <td class='detail' align='right'>" . $areport[$key]['inj'] . "</td>\n";
504 else if ($value == '2') { // days and games missed
505 echo " <td class='detail' align='right'>" . $areport[$key]['dmissed'] . "</td>\n";
506 echo " <td class='detail' align='right'>" . $areport[$key]['gmissed'] . "</td>\n";
508 else if ($value == '3') { // body region
509 foreach ($arr_my_body_regions as $body_region => $nothing) {
510 echo " <td class='detail' align='right'>" . $areport[$key]['br'][$body_region] . "</td>\n";
513 else if ($value == '4') { // injury type
514 foreach ($arr_my_injury_types as $injury_type => $nothing) {
515 echo " <td class='detail' align='right'>" . $areport[$key]['it'][$injury_type] . "</td>\n";
518 else if ($value == '5') { // issue title
519 foreach ($arr_my_issue_titles as $issue_title => $nothing) {
520 echo " <td class='detail' align='right'>" . $areport[$key]['ti'][$issue_title] . "</td>\n";
525 echo " </tr>\n";
526 } // end foreach
529 </table>
531 <?php } // end of if ($_POST['form_refresh']) ?>
533 </form>
534 </center>
536 <script language='JavaScript'>
537 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
538 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
539 </script>
541 </body>
542 </html>