d0836a0decaade8b6b6281c3742d3c4197c6dd6e
[openemr.git] / interface / orders / orders_results.php
blobd0836a0decaade8b6b6281c3742d3c4197c6dd6e
1 <?php
2 // Copyright (C) 2010-2013 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 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/formdata.inc.php");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/formatting.inc.php");
14 require_once("../orders/lab_exchange_tools.php");
16 // Indicates if we are entering in batch mode.
17 $form_batch = empty($_GET['batch']) ? 0 : 1;
19 // Indicates if we are entering in review mode.
20 $form_review = empty($_GET['review']) ? 0 : 1;
22 // Check authorization.
23 $thisauth = acl_check('patients', 'med');
24 if (!$thisauth) die(xl('Not authorized'));
26 // Check authorization for pending review.
27 $reviewauth = acl_check('patients', 'sign');
28 if ($form_review and !$reviewauth and !$thisauth) die(xl('Not authorized'));
30 // Set pid for pending review.
31 if ($_GET['set_pid'] && $form_review) {
32 require_once("$srcdir/pid.inc");
33 require_once("$srcdir/patient.inc");
34 setpid($_GET['set_pid']);
36 $result = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
38 <script language='JavaScript'>
39 parent.left_nav.setPatient(<?php echo "'" . addslashes($result['fname']) . " " . addslashes($result['lname']) . "',$pid,'" . addslashes($result['pubpid']) . "','', ' " . xl('DOB') . ": " . oeFormatShortDate($result['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($result['DOB_YMD']) . "'"; ?>);
40 parent.left_nav.setRadio(window.name, 'orp');
41 </script>
42 <?php
45 if (!$form_batch && !$pid && !$form_review) die(xl('There is no current patient'));
47 function oresRawData($name, $index) {
48 $s = isset($_POST[$name][$index]) ? $_POST[$name][$index] : '';
49 return trim(strip_escape_custom($s));
52 function oresData($name, $index) {
53 $s = isset($_POST[$name][$index]) ? $_POST[$name][$index] : '';
54 return formDataCore($s, true);
57 function QuotedOrNull($fld) {
58 if (empty($fld)) return "NULL";
59 return "'$fld'";
62 $current_report_id = 0;
64 if ($_POST['form_submit'] && !empty($_POST['form_line'])) {
65 foreach ($_POST['form_line'] as $lino => $line_value) {
66 list($order_id, $order_seq, $report_id, $result_id) = explode(':', $line_value);
68 // Not using xl() here because this is for debugging only.
69 if (empty($order_id)) die("Order ID is missing from line $lino.");
71 // If report data exists for this line, save it.
72 $date_report = oresData("form_date_report", $lino);
74 if (!empty($date_report)) {
75 $sets =
76 "procedure_order_id = '$order_id', " .
77 "procedure_order_seq = '$order_seq', " .
78 "date_report = '$date_report', " .
79 "date_collected = " . QuotedOrNull(oresData("form_date_collected", $lino)) . ", " .
80 "specimen_num = '" . oresData("form_specimen_num", $lino) . "', " .
81 "report_status = '" . oresData("form_report_status", $lino) . "'";
83 // Set the review status to reviewed.
84 if ($form_review)
85 $sets .= ", review_status = 'reviewed'";
87 if ($report_id) { // Report already exists.
88 sqlStatement("UPDATE procedure_report SET $sets " .
89 "WHERE procedure_report_id = '$report_id'");
91 else { // Add new report.
92 $report_id = sqlInsert("INSERT INTO procedure_report SET $sets");
96 // If this line had report data entry fields, filled or not, set the
97 // "current report ID" which the following result data will link to.
98 if (isset($_POST["form_date_report"][$lino])) $current_report_id = $report_id;
100 // If there's a report, save corresponding results.
101 if ($current_report_id) {
102 // Comments and notes will be combined into one comments field.
103 $form_comments = oresRawData("form_comments", $lino);
104 $form_comments = str_replace("\n" ,'~' , $form_comments);
105 $form_comments = str_replace("\r" ,'' , $form_comments);
106 $form_notes = oresRawData("form_notes", $lino);
107 if ($form_notes !== '') {
108 $form_comments .= "\n" . $form_notes;
110 $sets =
111 "procedure_report_id = '$current_report_id', " .
112 "result_code = '" . oresData("form_result_code", $lino) . "', " .
113 "result_text = '" . oresData("form_result_text", $lino) . "', " .
114 "abnormal = '" . oresData("form_result_abnormal", $lino) . "', " .
115 "result = '" . oresData("form_result_result", $lino) . "', " .
116 "`range` = '" . oresData("form_result_range", $lino) . "', " .
117 "units = '" . oresData("form_result_units", $lino) . "', " .
118 "facility = '" . oresData("form_facility", $lino) . "', " .
119 "comments = '" . add_escape_custom($form_comments) . "', " .
120 "result_status = '" . oresData("form_result_status", $lino) . "'";
121 if ($result_id) { // result already exists
122 sqlStatement("UPDATE procedure_result SET $sets " .
123 "WHERE procedure_result_id = '$result_id'");
125 else { // Add new result.
126 $result_id = sqlInsert("INSERT INTO procedure_result SET $sets");
129 } // end foreach
132 <html>
134 <head>
135 <?php html_header_show();?>
137 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
138 <title><?php xl('Procedure Results','e'); ?></title>
140 <style>
142 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
143 tr.detail { font-size:10pt; }
144 a, a:visited, a:hover { color:#0000cc; }
146 .celltext {
147 font-size:10pt;
148 font-weight:normal;
149 border-style:solid;
150 border-top-width:0px;
151 border-bottom-width:0px;
152 border-left-width:0px;
153 border-right-width:0px;
154 border-color: #aaaaaa;
155 background-color:transparent;
156 width:100%;
157 color:#0000cc;
160 .celltextfw {
161 font-size:10pt;
162 font-weight:normal;
163 border-style:solid;
164 border-top-width:0px;
165 border-bottom-width:0px;
166 border-left-width:0px;
167 border-right-width:0px;
168 border-color: #aaaaaa;
169 background-color:transparent;
170 color:#0000cc;
173 .cellselect {
174 font-size:10pt;
175 background-color:transparent;
176 color:#0000cc;
179 .reccolor {
180 color:#008800;
183 </style>
185 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
186 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
187 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
188 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
190 <script type="text/javascript" src="../../library/dialog.js"></script>
191 <script type="text/javascript" src="../../library/textformat.js"></script>
193 <script language="JavaScript">
195 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
197 // This invokes the find-procedure-type popup.
198 var ptvarname;
199 function sel_proc_type(varname) {
200 var f = document.forms[0];
201 if (typeof varname == 'undefined') varname = 'form_proc_type';
202 ptvarname = varname;
203 dlgopen('types.php?popup=1&order=' + f[ptvarname].value, '_blank', 800, 500);
206 // This is for callback by the find-procedure-type popup.
207 // Sets both the selected type ID and its descriptive name.
208 function set_proc_type(typeid, typename) {
209 var f = document.forms[0];
210 f[ptvarname].value = typeid;
211 f[ptvarname + '_desc'].value = typename;
214 // Helper functions.
215 function extGetX(elem) {
216 var x = 0;
217 while(elem != null) {
218 x += elem.offsetLeft;
219 elem = elem.offsetParent;
221 return x;
223 function extGetY(elem) {
224 var y = 0;
225 while(elem != null) {
226 y += elem.offsetTop;
227 elem = elem.offsetParent;
229 return y;
232 // Show or hide the "extras" div for a result.
233 var extdiv = null;
234 function extShow(lino, show) {
235 var thisdiv = document.getElementById("ext_" + lino);
236 if (extdiv) {
237 extdiv.style.visibility = 'hidden';
238 extdiv.style.left = '-1000px';
239 extdiv.style.top = '0px';
241 if (show && thisdiv != extdiv) {
242 extdiv = thisdiv;
243 var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
244 x = dw - extdiv.offsetWidth;
245 if (x < 0) x = 0;
246 var y = extGetY(show) + show.offsetHeight;
247 extdiv.style.left = x;
248 extdiv.style.top = y;
249 extdiv.style.visibility = 'visible';
251 else {
252 extdiv = null;
256 // Helper function for validate.
257 function prDateRequired(rlino) {
258 var f = document.forms[0];
259 if (f['form_date_report['+rlino+']'].value.length < 10) {
260 alert('<?php xl('Missing report date','e') ?>');
261 if (f['form_date_report['+rlino+']'].focus)
262 f['form_date_report['+rlino+']'].focus();
263 return false;
265 return true;
268 // Validation at submit time.
269 function validate(f) {
270 var rlino = 0;
271 for (var lino = 0; f['form_line['+lino+']']; ++lino) {
272 if (f['form_date_report['+lino+']']) {
273 rlino = lino;
274 if (f['form_report_status['+rlino+']'].selectedIndex > 0) {
275 if (!prDateRequired(rlino)) return false;
278 var abnstat = f['form_result_abnormal['+lino+']'].selectedIndex > 0;
279 if (abnstat && !prDateRequired(rlino)) return false;
281 top.restoreSession();
282 return true;
285 </script>
287 </head>
289 <body class="body_top">
290 <form method='post' action='orders_results.php?batch=<?php echo $form_batch; ?>&review=<?php echo $form_review; ?>'
291 onsubmit='return validate(this)'>
293 <table>
294 <tr>
295 <td class='text'>
296 <?php
297 if ($form_batch) {
298 $form_from_date = formData('form_from_date','P',true);
299 $form_to_date = formData('form_to_date','P',true);
300 if (empty($form_to_date)) $form_to_date = $form_from_date;
301 $form_proc_type = formData('form_proc_type') + 0;
302 if (!$form_proc_type) $form_proc_type = -1;
303 $form_proc_type_desc = '';
304 if ($form_proc_type > 0) {
305 $ptrow = sqlQuery("SELECT name FROM procedure_type WHERE " .
306 "procedure_type_id = '$form_proc_type'");
307 $form_proc_type_desc = $ptrow['name'];
310 <?php xl('Procedure','e'); ?>:
311 <input type='text' size='30' name='form_proc_type_desc'
312 value='<?php echo addslashes($form_proc_type_desc) ?>'
313 onclick='sel_proc_type()' onfocus='this.blur()'
314 title='<?php xl('Click to select the desired procedure','e'); ?>'
315 style='cursor:pointer;cursor:hand' readonly />
316 <input type='hidden' name='form_proc_type' value='<?php echo $form_proc_type ?>' />
318 &nbsp;<?php xl('From','e'); ?>:
319 <input type='text' size='10' name='form_from_date' id='form_from_date'
320 value='<?php echo $form_from_date ?>'
321 title='<?php xl('yyyy-mm-dd','e'); ?>'
322 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
323 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
324 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
325 title='<?php xl('Click here to choose a date','e'); ?>' />
327 &nbsp;<?php xl('To','e'); ?>:
328 <input type='text' size='10' name='form_to_date' id='form_to_date'
329 value='<?php echo $form_to_date ?>'
330 title='<?php xl('yyyy-mm-dd','e'); ?>'
331 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
332 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
333 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
334 title='<?php xl('Click here to choose a date','e'); ?>' />
336 &nbsp;
337 <?php
338 } // end header for batch option
340 <!-- removed by jcw -- check/submit sequece too tedious. This is a quick fix -->
341 <!-- <input type='checkbox' name='form_all' value='1' <?php if ($_POST['form_all']) echo " checked"; ?>><?php xl('Include Completed','e') ?>
342 &nbsp;-->
343 <input type='submit' name='form_refresh' value=<?php xl('Refresh','e'); ?>>
344 </td>
345 </tr>
346 </table>
348 <?php if (!$form_batch || ($form_proc_type > 0 && $form_from_date)) { ?>
350 <table width='100%' cellpadding='1' cellspacing='2'>
352 <tr class='head'>
353 <td colspan='2'><?php echo $form_batch ? xl('Patient') : xl('Order'); ?></td>
354 <td colspan='4'><?php xl('Report','e'); ?></td>
355 <td colspan='7'><?php xl('Results and','e'); ?> <span class='reccolor''>
356 <?php xl('Recommendations','e'); ?></span></td>
357 </tr>
359 <tr class='head'>
360 <td><?php echo $form_batch ? xl('Name') : xl('Date'); ?></td>
361 <td><?php echo $form_batch ? xl('ID') : xl('Procedure Name'); ?></td>
362 <td><?php xl('Reported','e'); ?></td>
363 <td><?php xl('Ext Time Collected','e'); ?></td>
364 <td><?php xl('Specimen','e'); ?></td>
365 <td><?php xl('Status','e'); ?></td>
366 <td><?php xl('Code','e'); ?></td>
367 <td><?php xl('Name','e'); ?></td>
368 <td><?php xl('Abn','e'); ?></td>
369 <td><?php xl('Value','e'); ?></td>
370 <td><?php xl('Units', 'e'); ?></td>
371 <td><?php xl('Range','e'); ?></td>
372 <td><?php xl('?','e'); ?></td>
373 </tr>
375 <?php
376 $selects =
377 "po.procedure_order_id, po.date_ordered, pc.procedure_order_seq, " .
378 "pt1.procedure_type_id AS order_type_id, pc.procedure_name, " .
379 "pr.procedure_report_id, pr.date_report, pr.date_collected, pr.specimen_num, " .
380 "pr.report_status, pr.review_status";
382 $joins =
383 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
384 "LEFT JOIN procedure_type AS pt1 ON pt1.lab_id = po.lab_id AND pt1.procedure_code = pc.procedure_code " .
385 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
386 "pr.procedure_order_seq = pc.procedure_order_seq";
388 $orderby =
389 "po.date_ordered, po.procedure_order_id, " .
390 "pc.procedure_order_seq, pr.procedure_report_id";
392 // removed by jcw -- check/submit sequece too tedious. This is a quick fix
393 //$where = empty($_POST['form_all']) ?
394 // "( pr.report_status IS NULL OR pr.report_status = '' OR pr.report_status = 'prelim' )" :
395 // "1 = 1";
397 $where = "1 = 1";
399 if ($form_batch) {
400 $query = "SELECT po.patient_id, " .
401 "pd.fname, pd.mname, pd.lname, pd.pubpid, $selects " .
402 "FROM procedure_order AS po " .
403 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id $joins " .
404 "WHERE pt.procedure_type_id = '$form_proc_type' AND " .
405 "po.date_ordered >= '$form_from_date' AND po.date_ordered <= '$form_to_date' " .
406 "AND $where " .
407 "ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, $orderby";
409 else {
410 $query = "SELECT $selects " .
411 "FROM procedure_order AS po " .
412 "$joins " .
413 "WHERE po.patient_id = '$pid' AND $where " .
414 "ORDER BY $orderby";
417 $res = sqlStatement($query);
419 $lastpoid = -1;
420 $lastpcid = -1;
421 $lastprid = -1;
422 $encount = 0;
423 $lino = 0;
424 $extra_html = '';
425 $lastrcn = '';
426 $facilities = array();
428 while ($row = sqlFetchArray($res)) {
429 $order_type_id = empty($row['order_type_id' ]) ? 0 : ($row['order_type_id' ] + 0);
430 $order_id = empty($row['procedure_order_id' ]) ? 0 : ($row['procedure_order_id' ] + 0);
431 $order_seq = empty($row['procedure_order_seq']) ? 0 : ($row['procedure_order_seq'] + 0);
432 $report_id = empty($row['procedure_report_id']) ? 0 : ($row['procedure_report_id'] + 0);
433 $date_report = empty($row['date_report' ]) ? '' : $row['date_report'];
434 $date_collected = empty($row['date_collected' ]) ? '' : substr($row['date_collected'], 0, 16);
435 $specimen_num = empty($row['specimen_num' ]) ? '' : $row['specimen_num'];
436 $report_status = empty($row['report_status' ]) ? '' : $row['report_status'];
437 $review_status = empty($row['review_status' ]) ? 'received' : $row['review_status'];
439 // skip report_status = receive to make sure do not show the report before it reviewed and sign off by Physicians
440 if ($form_review) {
441 if ($review_status == "reviewed") continue;
443 else {
444 if ($review_status == "received") continue;
447 $selects = "pt2.procedure_type, pt2.procedure_code, pt2.units AS pt2_units, " .
448 "pt2.range AS pt2_range, pt2.procedure_type_id AS procedure_type_id, " .
449 "pt2.name AS name, pt2.description, pt2.seq AS seq, " .
450 "ps.procedure_result_id, ps.result_code AS result_code, ps.result_text, ps.abnormal, ps.result, " .
451 "ps.range, ps.result_status, ps.facility, ps.comments, ps.units, ps.comments";
453 // procedure_type_id for order:
454 $pt2cond = "pt2.parent = $order_type_id AND " .
455 "(pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%')";
457 // pr.procedure_report_id or 0 if none:
458 $pscond = "ps.procedure_report_id = $report_id";
460 $joincond = "ps.result_code = pt2.procedure_code";
462 // This union emulates a full outer join. The idea is to pick up all
463 // result types defined for this order type, as well as any actual
464 // results that do not have a matching result type.
465 $query = "(SELECT $selects FROM procedure_type AS pt2 " .
466 "LEFT JOIN procedure_result AS ps ON $pscond AND $joincond " .
467 "WHERE $pt2cond" .
468 ") UNION (" .
469 "SELECT $selects FROM procedure_result AS ps " .
470 "LEFT JOIN procedure_type AS pt2 ON $pt2cond AND $joincond " .
471 "WHERE $pscond) " .
472 "ORDER BY seq, name, procedure_type_id, result_code";
474 $rres = sqlStatement($query);
475 while ($rrow = sqlFetchArray($rres)) {
476 $restyp_code = empty($rrow['procedure_code' ]) ? '' : $rrow['procedure_code'];
477 $restyp_type = empty($rrow['procedure_type' ]) ? '' : $rrow['procedure_type'];
478 $restyp_name = empty($rrow['name' ]) ? '' : $rrow['name'];
479 $restyp_units = empty($rrow['pt2_units' ]) ? '' : $rrow['pt2_units'];
480 $restyp_range = empty($rrow['pt2_range' ]) ? '' : $rrow['pt2_range'];
482 $result_id = empty($rrow['procedure_result_id']) ? 0 : ($rrow['procedure_result_id'] + 0);
483 $result_code = empty($rrow['result_code' ]) ? $restyp_code : $rrow['result_code'];
484 $result_text = empty($rrow['result_text' ]) ? $restyp_name : $rrow['result_text'];
485 $result_abnormal = empty($rrow['abnormal' ]) ? '' : $rrow['abnormal'];
486 $result_result = empty($rrow['result' ]) ? '' : $rrow['result'];
487 $result_units = empty($rrow['units' ]) ? $restyp_units : $rrow['units'];
488 $result_facility = empty($rrow['facility' ]) ? '' : $rrow['facility'];
489 $result_comments = empty($rrow['comments' ]) ? '' : $rrow['comments'];
490 $result_range = empty($rrow['range' ]) ? $restyp_range : $rrow['range'];
491 $result_status = empty($rrow['result_status' ]) ? '' : $rrow['result_status'];
493 // If there is more than one line of comments, everything after that is "notes".
494 $result_notes = '';
495 $i = strpos($result_comments, "\n");
496 if ($i !== FALSE) {
497 $result_notes = trim(substr($result_comments, $i + 1));
498 $result_comments = substr($result_comments, 0, $i);
500 $result_comments = trim($result_comments);
502 if($result_facility <> "" && !in_array($result_facility, $facilities)) {
503 $facilities[] = $result_facility;
506 if ($lastpoid != $order_id || $lastpcid != $order_seq) {
507 ++$encount;
508 $lastrcn = '';
510 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
512 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
514 // Generate first 2 columns.
515 if ($lastpoid != $order_id || $lastpcid != $order_seq) {
516 $lastprid = -1; // force report fields on first line of each procedure
517 if ($form_batch) {
518 if ($lastpoid != $order_id) {
519 $tmp = $row['lname'];
520 if ($row['fname'] || $row['mname'])
521 $tmp .= ', ' . $row['fname'] . ' ' . $row['mname'];
522 echo " <td>" . htmlentities($tmp) . "</td>\n";
523 echo " <td>" . htmlentities($row['pubpid']) . "</td>\n";
525 else {
526 echo " <td colspan='2' style='background-color:transparent'>&nbsp;</td>";
529 else {
530 if ($lastpoid != $order_id) {
531 echo " <td>" . $row['date_ordered'] . "</td>\n";
533 else {
534 echo " <td style='background-color:transparent'>&nbsp;</td>";
536 echo " <td>" . htmlentities($row['procedure_name']) . "</td>\n";
539 else {
540 echo " <td colspan='2' style='background-color:transparent'>&nbsp;</td>";
543 // If this starts a new report or a new order, generate the report form
544 // fields. In the case of a new order with no report yet, the fields will
545 // have their blank/default values, and form_line (above) will indicate a
546 // report ID of 0.
548 // TBD: Also generate default report fields and another set of results if
549 // the previous report is marked "Preliminary".
551 if ($report_id != $lastprid) {
552 echo " <td nowrap>";
553 echo "<input type='text' size='8' name='form_date_report[$lino]'" .
554 " id='form_date_report[$lino]' class='celltextfw' value='" . attr($date_report) . "' " .
555 " title='" . xl('Date of this report') . "'" .
556 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'" .
557 " />";
558 echo "<span class='bold' id='q_date_report[$lino]' style='cursor:pointer' " .
559 "title='" . xl('Click here to choose a date') . "' />?</span>";
560 echo "</td>\n";
562 echo " <td nowrap>";
563 echo "<input type='text' size='13' name='form_date_collected[$lino]'" .
564 " id='form_date_collected[$lino]'" .
565 " class='celltextfw' value='" . attr($date_collected) . "' " .
566 " title='" . xl('Date and time of sample collection') . "'" .
567 " onkeyup='datekeyup(this,mypcc,true)' onblur='dateblur(this,mypcc,true)'" .
568 " />";
569 echo "<span class='bold' id='q_date_collected[$lino]' style='cursor:pointer' " .
570 "title='" . xl('Click here to choose a date and time') . "' />?</span>";
571 echo "</td>\n";
573 echo " <td>";
574 echo "<input type='text' size='8' name='form_specimen_num[$lino]'" .
575 " class='celltext' value='" . attr($specimen_num) . "' " .
576 " title='" . xl('Specimen number/identifier') . "'" .
577 " />";
578 echo "</td>\n";
580 echo " <td>";
581 echo generate_select_list("form_report_status[$lino]", 'proc_rep_status',
582 $report_status, xl('Report Status'), ' ', 'cellselect');
583 echo "</td>\n";
585 else {
586 echo " <td colspan='4' style='background-color:transparent'>&nbsp;</td>\n";
589 echo " <td nowrap>";
590 echo "<input type='text' size='6' name='form_result_code[$lino]'" .
591 " class='celltext' value='" . attr($result_code) . "' />" .
592 "</td>\n";
594 echo " <td>" .
595 "<input type='text' size='16' name='form_result_text[$lino]'" .
596 " class='celltext' value='" . attr($result_text) . "' />";
597 "</td>\n";
599 echo " <td>";
600 echo generate_select_list("form_result_abnormal[$lino]", 'proc_res_abnormal',
601 $result_abnormal, xl('Indicates abnormality'), ' ', 'cellselect');
602 echo "</td>\n";
604 echo " <td>";
605 if ($result_units == 'bool') {
606 echo "&nbsp;--";
608 else {
609 echo "<input type='text' size='7' name='form_result_result[$lino]'" .
610 " class='celltext' value='" . attr($result_result) . "' " .
611 " />";
613 echo "</td>\n";
615 echo " <td>";
616 echo "<input type='text' size='4' name='form_result_units[$lino]'" .
617 " class='celltext' value='" . attr($result_units) . "' " .
618 " title='" . xl('Units applicable to the result value') . "'" .
619 " />";
620 echo "</td>\n";
622 echo " <td>";
623 echo "<input type='text' size='8' name='form_result_range[$lino]'" .
624 " class='celltext' value='" . attr($result_range) . "' " .
625 " title='" . xl('Reference range of results') . "'" .
626 " />";
627 // Include a hidden form field containing all IDs for this line.
628 echo "<input type='hidden' name='form_line[$lino]' " .
629 "value='$order_id:$order_seq:$report_id:$result_id' />";
630 echo "</td>\n";
632 echo " <td class='bold' style='cursor:pointer' " .
633 "onclick='extShow($lino, this)' align='center' " .
634 "title='" . xl('Click here to view/edit more details') . "'>";
635 echo "&nbsp;?&nbsp;";
636 echo "</td>\n";
638 echo " </tr>\n";
640 // Create a floating div for additional attributes of this result.
641 $extra_html .= "<div id='ext_$lino' " .
642 "style='position:absolute;width:750px;border:1px solid black;" .
643 "padding:2px;background-color:#cccccc;visibility:hidden;" .
644 "z-index:1000;left:-1000px;top:0px;font-size:9pt;'>\n" .
645 "<table width='100%'>\n" .
646 "<tr><td class='bold' align='center' colspan='2' style='padding:4pt 0 4pt 0'>" .
647 htmlspecialchars($result_text) .
648 "</td></tr>\n" .
649 "<tr><td class='bold' width='1%' nowrap>" . xlt('Status') . ": </td>" .
650 "<td>" . generate_select_list("form_result_status[$lino]", 'proc_res_status',
651 $result_status, xl('Result Status'), '') . "</td></tr>\n" .
652 "<tr><td class='bold' nowrap>" . xlt('Facility') . ": </td>" .
653 "<td><input type='text' size='15' name='form_facility[$lino]'" .
654 " value='$result_facility' " .
655 " title='" . xla('Supplier facility name') . "'" .
656 " style='width:100%' /></td></tr>\n" .
657 "<tr><td class='bold' nowrap>" . xlt('Comments') . ": </td>" .
658 "<td><textarea rows='3' cols='15' name='form_comments[$lino]'" .
659 " title='" . xla('Comments for this result or recommendation') . "'" .
660 " style='width:100%' />" . htmlspecialchars($result_comments) .
661 "</textarea></td></tr>\n" .
662 "<tr><td class='bold' nowrap>" . xlt('Notes') . ": </td>" .
663 "<td><textarea rows='4' cols='15' name='form_notes[$lino]'" .
664 " title='" . xla('Additional notes for this result or recommendation') . "'" .
665 " style='width:100%' />" . htmlspecialchars($result_notes) .
666 "</textarea></td></tr>\n" .
667 "</table>\n" .
668 "<p><center><input type='button' value='" . xla('Close') . "' " .
669 "onclick='extShow($lino, false)' /></center></p>\n".
670 "</div>";
672 $lastpoid = $order_id;
673 $lastpcid = $order_seq;
674 $lastprid = $report_id;
675 ++$lino;
679 if (!empty($facilities)) {
680 // display facility information
681 $extra_html .= "<table>";
682 $extra_html .= "<tr><th>". xl('Performing Laboratory Facility') . "</th></tr>";
683 foreach($facilities as $facilityID) {
684 foreach(explode(":", $facilityID) as $lab_facility) {
685 $facility_array = getFacilityInfo($lab_facility);
686 if($facility_array) {
687 $extra_html .=
688 "<tr><td><hr></td></tr>" .
689 "<tr><td>". htmlspecialchars($facility_array['fname']) . " " . htmlspecialchars($facility_array['lname']) . ", " . htmlspecialchars($facility_array['title']). "</td></tr>" .
690 "<tr><td>". htmlspecialchars($facility_array['organization']) . "</td></tr>" .
691 "<tr><td>". htmlspecialchars($facility_array['street']) . " " .htmlspecialchars($facility_array['city']) . " " . htmlspecialchars($facility_array['state']) . "</td></tr>" .
692 "<tr><td>". htmlspecialchars(formatPhone($facility_array['phone'])) . "</td></tr>";
696 $extra_html .= "</table>\n";
700 </table>
702 <?php
703 if ($form_review) {
704 // if user authorized for pending review.
705 if ($reviewauth) {
707 <center><p>
708 <input type='submit' name='form_submit' value='<?php xl('Sign Results','e'); ?>' />
709 </p></center>
710 <?php
712 else {
714 <center><p>
715 <input type='button' name='form_submit' value='<?php xl('Sign Results','e'); ?>' onclick="alert('<?php xl('Not authorized','e') ?>');" />
716 </p></center>
717 <?php
720 else {
722 <center><p>
723 <input type='submit' name='form_submit' value='<?php xl('Save','e'); ?>' />
724 </p></center>
725 <?php
729 <?php } ?>
731 <?php echo $extra_html; ?>
733 <script language='JavaScript'>
735 <?php if ($form_batch) { ?>
736 // Initialize calendar widgets for "from" and "to" dates.
737 Calendar.setup({inputField:'form_from_date', ifFormat:'%Y-%m-%d',
738 button:'img_from_date'});
739 Calendar.setup({inputField:'form_to_date', ifFormat:'%Y-%m-%d',
740 button:'img_to_date'});
741 <?php } ?>
743 // Initialize calendar widgets for report dates and collection dates.
744 var f = document.forms[0];
745 for (var lino = 0; f['form_line['+lino+']']; ++lino) {
746 if (f['form_date_report['+lino+']']) {
747 Calendar.setup({inputField:'form_date_report['+lino+']', ifFormat:'%Y-%m-%d',
748 button:'q_date_report['+lino+']'});
749 Calendar.setup({inputField:'form_date_collected['+lino+']', ifFormat:'%Y-%m-%d %H:%M',
750 button:'q_date_collected['+lino+']', showsTime:true});
754 </script>
756 </form>
757 </body>
758 </html>