translation patches from Dr. Bosman and his crew
[openemr.git] / interface / reports / football_injury_report.php
blobdd088ff2b17b1b15fbb24a96b6be74c41c35443c
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 <title><?php xl('Football Injury Report','e'); ?></title>
167 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
168 <style type="text/css">
169 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
170 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
171 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
172 </style>
173 <script type="text/javascript" src="../../library/textformat.js"></script>
174 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
175 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
176 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
177 <script language="JavaScript">
178 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
179 </script>
180 </head>
182 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
184 <center>
186 <h2><? xl('Football Injury Report','e'); ?></h2>
188 <form name='theform' method='post' action='football_injury_report.php'>
190 <table border='0' cellspacing='0' cellpadding='2'>
192 <tr>
193 <td valign='top' nowrap>
194 For each
195 </td>
196 <td valign='top'>
197 <select name='form_by' title='Left column of report'>
198 <?php
199 foreach ($arr_by as $key => $value) {
200 echo " <option value='$key'";
201 if ($key == $form_by) echo " selected";
202 echo ">" . $value . "</option>\n";
205 </select>
206 </td>
207 <td valign='top' rowspan='3' nowrap>
208 &nbsp;
209 <input type='submit' name='form_refresh' value='<?php xl('Show','e'); ?>' title='<?php xl('Click to generate the report','e'); ?>'> :
210 </td>
211 <td valign='top' rowspan='3'>
212 <select name='form_show[]' size='4' multiple
213 title='<?php xl('Hold down Ctrl to select multiple items','e'); ?>'>
214 <?php
215 foreach ($arr_show as $key => $value) {
216 echo " <option value='$key'";
217 if (is_array($form_show) && in_array($key, $form_show)) echo " selected";
218 echo ">" . $value[0] . "</option>\n";
221 </select>
222 </td>
223 <td valign='top' rowspan='3' nowrap>
224 &nbsp;
225 for:
226 </td>
227 <td valign='top' rowspan='3'>
228 <select name='form_squads[]' size='4' multiple
229 title='<?php xl('Hold down Ctrl to select multiple squads','e'); ?>'>
230 <?php
231 $squads = acl_get_squads();
232 if ($squads) {
233 foreach ($squads as $key => $value) {
234 echo " <option value='$key'";
235 if (!is_array($form_squads) || in_array($key, $form_squads)) echo " selected";
236 echo ">" . $value[3] . "</option>\n";
240 </select>
241 </td>
242 </tr>
243 <tr>
244 <td valign='top' nowrap>
245 from
246 </td>
247 <td valign='top' nowrap>
248 <input type='text' name='form_from_date' id='form_from_date' size='10' value='<?php echo $from_date ?>'
249 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='Start date yyyy-mm-dd'>
250 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
251 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
252 title='<?php xl('Click here to choose a date','e'); ?>'>
253 </td>
254 </tr>
255 <tr>
256 <td valign='top' nowrap>
258 </td>
259 <td valign='top' nowrap>
260 <input type='text' name='form_to_date' id='form_to_date' size='10' value='<?php echo $to_date ?>'
261 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='End date yyyy-mm-dd'>
262 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
263 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
264 title='<?php xl('Click here to choose a date','e'); ?>'>
265 </td>
266 </tr>
268 <tr>
269 <td height="1">
270 </td>
271 </tr>
273 </table>
275 <?php
276 if ($_POST['form_refresh']) {
278 // fetch all the issues that are medical problems and corresponding FIA
279 // data. We are reporting only values from issues (though often by FIA
280 // fields), so it seems we want to retain one array row per issue and
281 // discard extra FIA forms.
283 $squadmatches = '1 = 2'; // an always-false condition
284 foreach ($form_squads as $squad)
285 $squadmatches .= " OR pd.squad = '$squad'";
287 $query = "SELECT lists.id AS listid, lists.diagnosis, lists.pid, " .
288 "lists.extrainfo AS gmissed, lists.begdate, lists.enddate, " .
289 "lists.returndate, lists.title, fia.*, pd.lname, pd.fname, pd.mname " .
290 "FROM lists " .
291 "JOIN patient_data AS pd ON pd.pid = lists.pid AND ( $squadmatches ) " .
292 "JOIN issue_encounter AS ie ON ie.list_id = lists.id " .
293 "JOIN forms ON forms.pid = ie.pid AND forms.encounter = ie.encounter " .
294 "AND forms.formdir = 'football_injury_audit' " .
295 "JOIN form_football_injury_audit as fia ON fia.id = forms.form_id " .
296 "WHERE ( lists.enddate IS NULL OR lists.enddate >= '$from_date' ) AND " .
297 "lists.begdate <= '$to_date' AND " .
298 "lists.type = 'medical_problem' AND lists.title NOT LIKE '%Illness%'" .
299 "ORDER BY lists.pid, lists.begdate";
301 $res = sqlStatement($query);
303 $areport = array();
304 $arr_my_body_regions = array();
305 $arr_my_injury_types = array();
306 $arr_my_issue_titles = array();
308 $last_listid = 0;
309 $last_pid = 0;
310 $last_endsecs = 0;
312 while ($row = sqlFetchArray($res)) {
314 // Throw away extra injury forms.
315 if ($row['listid'] == $last_listid) continue;
316 $last_listid = $rows['listid'];
318 $body_region = 'Undiagnosed';
319 if (preg_match('/^(.)..$/', $row['diagnosis'], $matches)) {
320 $body_region = $arr_regions_osics[$matches[1]];
322 else if (preg_match('/^(..)\...\...$/', $row['diagnosis'], $matches)) {
323 $body_region = $arr_regions_ucsmc[$matches[1]];
326 $injury_type = 'Undiagnosed';
327 if (preg_match('/^.(.).$/', $row['diagnosis'], $matches)) {
328 $injury_type = $arr_types_osics[$matches[1]];
330 else if (preg_match('/^..\...\.(..)$/', $row['diagnosis'], $matches)) {
331 $injury_type = $arr_types_ucsmc[$matches[1]];
334 $issue_title = trim($row['title']);
336 $key = 'Unspecified';
338 if ($form_by == '1') { // Activity Type
339 if ($row['fimech_tackling'] || $row['fimech_tackled'] ||
340 $row['fimech_collision'] || $row['fimech_kicked'] ||
341 $row['fimech_elbow'] || $row['fimech_othercon'])
343 $key = 'Contact';
344 } else {
345 $key = 'Non-contact';
349 else if ($form_by == '2') { // Body Region
350 $key = $body_region;
353 else if ($form_by == '3') { // Footwear Type
354 if ($row['fifootwear']) $key = $arr_footwear[$row['fifootwear']];
357 else if ($form_by == '4') { // Game Period
358 if ($row['fiinjmin']) {
359 $key = 15 * (int)(($row['fiinjmin'] + 14) / 15);
363 else if ($form_by == '5') { // Injury Mechanism
364 foreach ($arr_activity as $imkey => $imvalue) {
365 if ($row["fimech_$imkey"]) {
366 $key = $imvalue;
367 break;
372 else if ($form_by == '6') { // Injury Type
373 $key = $injury_type;
376 else if ($form_by == '7') { // Player
377 $key = trim($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']);
380 else if ($form_by == '8') { // Playing Position
381 if ($row['fiposition']) $key = $arr_position[$row['fiposition']];
384 else if ($form_by == '9') { // Referee Sanction Type
385 foreach ($arr_sanction as $imkey => $imvalue) {
386 if ($row["fimech_$imkey"]) {
387 $key = $imvalue;
388 break;
393 else if ($form_by == '10') { // Surface Type
394 if ($row['fisurface']) $key = $arr_surface[$row['fisurface']];
397 else if ($form_by == '11') { // Training Type
398 if ($row['fiinjtime']) $key = $arr_injtime[$row['fiinjtime']];
401 // OK we now have the reporting key for this issue.
403 // If first instance of this key, initialize its arrays.
404 if (! $areport[$key]) {
405 $areport[$key] = array();
406 $areport[$key]['inj'] = 0; // number of injuries
407 $areport[$key]['dmissed'] = 0; // days missed
408 $areport[$key]['gmissed'] = 0; // games missed
409 $areport[$key]['br'] = array(); // body region array
410 $areport[$key]['it'] = array(); // injury type array
411 $areport[$key]['ti'] = array(); // issue title array
414 // Compute days missed. Force non-overlap of multiple issues for the
415 // same player. This logic assumes sorting on begdate within pid.
417 $begsecs = strtotime($row['begdate']);
418 $endsecs = $row['returndate'] ? strtotime($row['returndate']) : time();
419 if ($row['pid'] == $last_pid) {
420 if ($begsecs < $last_endsecs) {
421 $begsecs = $last_endsecs;
424 else {
425 $last_pid = $row['pid'];
426 $last_endsecs = 0;
428 if ($begsecs > $endsecs) $begsecs = $endsecs;
429 if ($last_endsecs < $endsecs) $last_endsecs = $endsecs;
430 $daysmissed = round(($endsecs - $begsecs) / (60 * 60 * 24));
432 // Store values that we might want to report on.
433 $areport[$key]['inj'] += 1; // count number of injuries
434 $areport[$key]['dmissed'] += $daysmissed; // count days missed
435 $areport[$key]['gmissed'] += $row['gmissed']; // count games missed
436 $areport[$key]['br'][$body_region] += 1; // count injuries to this body part
437 $areport[$key]['it'][$injury_type] += 1; // count injuries of this type
438 $areport[$key]['ti'][$issue_title] += 1; // count injuries with this title
440 // These track all body regions and injury types encountered.
441 $arr_my_body_regions[$body_region] += 1;
442 $arr_my_injury_types[$injury_type] += 1;
443 $arr_my_issue_titles[$issue_title] += 1;
445 } // end while
447 // Sort everything by key for reporting.
448 ksort($areport);
449 ksort($arr_my_body_regions);
450 ksort($arr_my_injury_types);
451 ksort($arr_my_issue_titles);
454 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
456 <tr bgcolor="#dddddd">
457 <td class="dehead">
458 <?php echo $arr_by[$form_by]; ?>
459 </td>
461 <?php
462 // Generate headings for values to be shown.
463 foreach ($form_show as $value) {
464 if ($value == '1') { // Number of injuries
465 echo " <td class='dehead' align='right'>Injuries</td>\n";
467 else if ($value == '2') { // days and games missed
468 echo " <td class='dehead' align='right'>Days Missed</td>\n";
469 echo " <td class='dehead' align='right'>Games Missed</td>\n";
471 else if ($value == '3') { // body region
472 foreach ($arr_my_body_regions as $br => $nothing) {
473 echo " <td class='dehead' align='right'>$br</td>\n";
476 else if ($value == '4') { // injury type
477 foreach ($arr_my_injury_types as $it => $nothing) {
478 echo " <td class='dehead' align='right'>$it</td>\n";
481 else if ($value == '5') { // issue titles
482 foreach ($arr_my_issue_titles as $ti => $nothing) {
483 echo " <td class='dehead' align='right'>$ti</td>\n";
488 echo " </tr>\n";
490 $encount = 0;
492 foreach ($areport as $key => $varr) {
493 $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd";
495 echo " <tr bgcolor='$bgcolor'>\n";
496 echo " <td class='detail'>$key</td>\n";
498 // Generate data for this row.
499 foreach ($form_show as $value) {
500 if ($value == '1') { // Number of injuries
501 echo " <td class='detail' align='right'>" . $areport[$key]['inj'] . "</td>\n";
503 else if ($value == '2') { // days and games missed
504 echo " <td class='detail' align='right'>" . $areport[$key]['dmissed'] . "</td>\n";
505 echo " <td class='detail' align='right'>" . $areport[$key]['gmissed'] . "</td>\n";
507 else if ($value == '3') { // body region
508 foreach ($arr_my_body_regions as $body_region => $nothing) {
509 echo " <td class='detail' align='right'>" . $areport[$key]['br'][$body_region] . "</td>\n";
512 else if ($value == '4') { // injury type
513 foreach ($arr_my_injury_types as $injury_type => $nothing) {
514 echo " <td class='detail' align='right'>" . $areport[$key]['it'][$injury_type] . "</td>\n";
517 else if ($value == '5') { // issue title
518 foreach ($arr_my_issue_titles as $issue_title => $nothing) {
519 echo " <td class='detail' align='right'>" . $areport[$key]['ti'][$issue_title] . "</td>\n";
524 echo " </tr>\n";
525 } // end foreach
528 </table>
530 <?php } // end of if ($_POST['form_refresh']) ?>
532 </form>
533 </center>
535 <script language='JavaScript'>
536 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
537 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
538 </script>
540 </body>
541 </html>