various bugs (#4331)
[openemr.git] / interface / orders / single_order_results.inc.php
blobd1ad173998f9eaedc92942e852aed720f116a5f1
1 <?php
3 /**
4 * Script to display results for a given procedure order.
6 * Copyright (C) 2013-2016 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2018-2019 Jerry Padgett <sjpadgett@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
20 * @package OpenEMR
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Jerry Padgett <sjpadgett@gmail.com>
25 require_once($GLOBALS["srcdir"] . "/options.inc.php");
27 use OpenEMR\Common\Acl\AclMain;
29 function getListItem($listid, $value)
31 $lrow = sqlQuery(
32 "SELECT title FROM list_options " .
33 "WHERE list_id = ? AND option_id = ? AND activity = 1",
34 array($listid, $value)
36 $tmp = xl_list_label($lrow['title'] ?? '');
37 if (empty($tmp)) {
38 $tmp = (($value === '') ? '' : "($value)");
41 return $tmp;
44 function myCellText($s)
46 $s = trim($s);
47 if ($s === '') {
48 return '&nbsp;';
51 return text($s);
54 // Check if the given string already exists in the $aNotes array.
55 // If not, stores it as a new entry.
56 // Either way, returns the corresponding key which is a small integer.
57 function storeNote($s)
59 global $aNotes;
60 $key = array_search($s, $aNotes);
61 if ($key !== false) {
62 return $key;
65 $key = count($aNotes);
66 $aNotes[$key] = $s;
67 return $key;
70 // Display a single row of output including order, report and result information.
71 function generate_result_row(&$ctx, &$row, &$rrow, $priors_omitted = false)
73 $lab_id = empty($row['lab_id']) ? 0 : ($row['lab_id'] + 0);
74 $order_type_id = empty($row['order_type_id']) ? 0 : ($row['order_type_id'] + 0);
75 $order_seq = empty($row['procedure_order_seq']) ? 0 : ($row['procedure_order_seq'] + 0);
76 $report_id = empty($row['procedure_report_id']) ? 0 : ($row['procedure_report_id'] + 0);
77 $procedure_code = empty($row['procedure_code']) ? '' : $row['procedure_code'];
78 $diagnosis = empty($row['diagnoses']) ? '' : $row['diagnoses'];
79 $procedure_name = empty($row['procedure_name']) ? '' : $row['procedure_name'];
80 $date_report = empty($row['date_report']) ? '' : substr($row['date_report'], 0, 16);
81 $date_report_suf = empty($row['date_report_tz']) ? '' : (' ' . $row['date_report_tz']);
82 $date_collected = empty($row['date_collected']) ? '' : substr($row['date_collected'], 0, 16);
83 $date_collected_suf = empty($row['date_collected_tz']) ? '' : (' ' . $row['date_collected_tz']);
84 $specimen_num = empty($row['specimen_num']) ? '' : $row['specimen_num'];
85 $report_status = empty($row['report_status']) ? '' : $row['report_status'];
86 $review_status = empty($row['review_status']) ? 'received' : $row['review_status'];
88 $report_noteid = '';
89 if ($report_id && !isset($ctx['seen_report_ids'][$report_id])) {
90 $ctx['seen_report_ids'][$report_id] = true;
91 if ($review_status != 'reviewed') {
92 if ($ctx['sign_list']) {
93 $ctx['sign_list'] .= ',';
96 $ctx['sign_list'] .= $report_id;
99 // Allowing for multiple report notes separated by newlines.
100 if (!empty($row['report_notes'])) {
101 $notes = explode("\n", $row['report_notes']);
102 foreach ($notes as $note) {
103 if ($note === '') {
104 continue;
107 if ($report_noteid) {
108 $report_noteid .= ', ';
111 $report_noteid .= 1 + storeNote($note);
116 // allow for 0 to be displayed as a result value
117 $rrow['result'] = $rrow['result'] ?? '';
118 if ($rrow['result'] == '' && $rrow['result'] !== 0 && $rrow['result'] !== '0') {
119 $result_result = '';
120 } else {
121 $result_result = $rrow['result'];
122 if ($result_result == 'DNR' || $result_result == 'DNRTNP') {
123 return;
127 $result_code = empty($rrow['result_code']) ? '' : $rrow['result_code'];
128 $result_text = empty($rrow['result_text']) ? '' : $rrow['result_text'];
129 $result_abnormal = empty($rrow['abnormal']) ? '' : $rrow['abnormal'];
130 $result_units = empty($rrow['units']) ? '' : $rrow['units'];
131 $result_facility = empty($rrow['facility']) ? '' : $rrow['facility'];
132 $result_comments = empty($rrow['comments']) ? '' : $rrow['comments'];
133 $result_range = empty($rrow['range']) ? '' : $rrow['range'];
134 $result_status = empty($rrow['result_status']) ? '' : $rrow['result_status'];
135 $result_document_id = empty($rrow['document_id']) ? '' : $rrow['document_id'];
137 // Someone changed the delimiter in result comments from \n to \r.
138 // Have to make sure results are consistent with those before that change.
139 $result_comments = str_replace("\r", "\n", $result_comments);
141 if ($i = strpos($result_comments, "\n")) { // "=" is not a mistake!
142 // If the first line of comments is not empty, then it is actually a long textual
143 // result value with lines delimited by "~" characters.
144 $result_comments = str_replace("~", "\n", substr($result_comments, 0, $i)) .
145 substr($result_comments, $i);
148 $result_comments = trim($result_comments);
150 $result_noteid = '';
151 if (!empty($result_comments)) {
152 $result_noteid = 1 + storeNote($result_comments);
155 if ($priors_omitted) {
156 if ($result_noteid) {
157 $result_noteid .= ', ';
160 $result_noteid .= 1 + storeNote(xl('This is the latest of multiple result values.'));
161 $ctx['priors_omitted'] = true;
164 // If a performing organization is provided, make a note for it also.
165 $result_facility = trim(str_replace("\r", "\n", $result_facility));
166 if ($result_facility) {
167 if ($result_noteid) {
168 $result_noteid .= ', ';
171 $result_noteid .= 1 + storeNote(xl('Performing organization') . ":\n" . $result_facility);
174 if ($ctx['lastpcid'] != $order_seq) {
175 ++$ctx['encount'];
178 $bgcolor = "#" . (($ctx['encount'] & 1) ? "ddddff" : "ffdddd");
180 echo " <tr class='detail' style='background: $bgcolor;'>\n";
182 if ($ctx['lastpcid'] != $order_seq) {
183 $ctx['lastprid'] = -1; // force report fields on first line of each procedure
184 $tmp = text("$procedure_code: $procedure_name: $diagnosis");
185 // Get the LOINC code if one exists in the compendium for this order type.
186 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
187 $trow = sqlQuery(
188 "SELECT standard_code FROM procedure_type WHERE " .
189 "lab_id = ? AND procedure_code = ? AND procedure_type = 'ord' " .
190 "ORDER BY procedure_type_id LIMIT 1",
191 array($lab_id, $procedure_code)
193 if (!empty($trow['standard_code'])) {
194 $tmp = "<a href='javascript:educlick(\"LOINC\"," . attr_js($trow['standard_code']) .
195 ")'>$tmp</a>";
199 echo " <td>$tmp</td>\n";
200 } else {
201 echo " <td>&nbsp;</td>";
204 // If this starts a new report or a new order, generate the report fields.
205 if ($report_id != $ctx['lastprid']) {
206 echo " <td>";
207 echo myCellText(oeFormatShortDate(substr($date_report, 0, 10)) . substr($date_report, 10) . $date_report_suf);
208 echo "</td>\n";
210 echo " <td>";
211 echo myCellText(oeFormatShortDate(substr($date_collected, 0, 10)) . substr($date_collected, 10) . $date_collected_suf);
212 echo "</td>\n";
214 echo " <td>";
215 echo myCellText($specimen_num);
216 echo "</td>\n";
218 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
219 echo myCellText(getListItem('proc_rep_status', $report_status));
220 if ($row['review_status'] == 'reviewed') {
221 echo " &#x2713;"; // unicode check mark character
224 echo "</td>\n";
226 echo " <td class='text-center'>";
227 echo myCellText($report_noteid);
228 echo "</td>\n";
229 } else {
230 echo " <td colspan='5'>&nbsp;</td>\n";
233 if ($result_code !== '' || $result_document_id) {
234 $tmp = myCellText($result_code);
235 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE']) && !empty($result_code)) {
236 $tmp = "<a href='javascript:educlick(\"LOINC\"," . attr_js($result_code) .
237 ")'>$tmp</a>";
240 echo " <td>$tmp</td>\n";
241 echo " <td>";
242 echo myCellText($result_text);
243 echo "</td>\n";
244 echo " <td>";
245 $tmp = myCellText(getListItem('proc_res_abnormal', $result_abnormal));
246 if ($result_abnormal && strtolower($result_abnormal) != 'no') {
247 echo "<p class='font-weight-bold text-danger'>$tmp</p>";
248 } else {
249 echo $tmp;
252 echo "</td>\n";
254 if ($result_document_id) {
255 $d = new Document($result_document_id);
256 echo " <td colspan='3'>";
257 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
258 echo "<a href='" . $GLOBALS['webroot'] . "/controller.php?document";
259 echo "&retrieve&patient_id=" . attr_url($patient_id) . "&document_id=" . attr_url($result_document_id) . "' ";
260 echo "onclick='top.restoreSession()'>";
263 echo $d->get_url_file();
264 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
265 echo "</a>";
268 echo "</td>\n";
269 $narrative_notes = sqlQuery("select group_concat(note SEPARATOR '\n') as notes from notes where foreign_id = ?", array($result_document_id));
270 if (!empty($narrative_notes)) {
271 $nnotes = explode("\n", $narrative_notes['notes']);
272 $narrative_note_list = '';
273 foreach ($nnotes as $nnote) {
274 if ($narrative_note_list == '') {
275 $narrative_note_list = 'Narrative Notes:';
278 $narrative_note_list .= $nnote;
281 if ($narrative_note_list != '') {
282 if ($result_noteid) {
283 $result_noteid .= ', ';
286 $result_noteid .= 1 + storeNote($narrative_note_list);
289 } else {
290 echo " <td>";
291 echo myCellText($result_result);
292 echo "</td>\n";
293 echo " <td>";
294 echo myCellText($result_range);
295 echo "</td>\n";
296 echo " <td>";
297 // Units comes from the lab so might not match anything in the proc_unit list,
298 // but in that case the call will return the same value.
299 echo myCellText(getListItemTitle('proc_unit', $result_units));
300 echo "</td>\n";
303 echo " <td align='center'>";
304 echo myCellText($result_noteid);
305 echo "</td>\n";
306 } else {
307 echo " <td colspan='7'>&nbsp;</td>\n";
310 echo " </tr>\n";
312 $ctx['lastpcid'] = $order_seq;
313 $ctx['lastprid'] = $report_id;
314 ++$ctx['lino'];
317 function generate_order_report($orderid, $input_form = false, $genstyles = true, $finals_only = false)
319 global $aNotes;
321 // Check authorization.
322 $thisauth = AclMain::aclCheckCore('patients', 'med');
323 if (!$thisauth) {
324 return xl('Not authorized');
327 $orow = sqlQuery(
328 "SELECT " .
329 "po.procedure_order_id, po.date_ordered, po.control_id, " .
330 "po.order_status, po.specimen_type, po.patient_id, po.order_diagnosis, " .
331 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.cmsportal_login, pd.language, " .
332 "fe.date, " .
333 "pp.name AS labname, pp.recv_fac_id AS rcvfacid, " .
334 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
335 "FROM procedure_order AS po " .
336 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
337 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
338 "LEFT JOIN users AS u ON u.id = po.provider_id " .
339 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
340 "WHERE po.procedure_order_id = ?",
341 array($orderid)
343 $dres = sqlStatementNoLog(
344 "Select diagnoses as codes FROM procedure_order_code WHERE procedure_order_id = ? ",
345 array($orow['procedure_order_id'])
347 $codes = array();
348 $bld = '';
349 while ($diag = sqlFetchArray($dres)) {
350 $bld .= $diag['codes'] . ';';
352 $bld .= $orow['order_diagnosis'];
353 $diags = explode(';', $bld);
354 $diags = array_unique($diags);
355 foreach ($diags as $d) {
356 if (!$d) {
357 continue;
359 $r['code'] = $d;
360 $r['short_desc'] = lookup_code_descriptions($d, "code_text_short");
361 $codes[] = $r;
364 $patient_id = $orow['patient_id'];
365 $language = $orow['language'];
369 <?php if ($genstyles) { ?>
370 <style>
372 <?php if (empty($_SESSION['language_direction']) || $_SESSION['language_direction'] == 'ltr') { ?>
373 .labres tr.head {
374 font-size: 0.8125rem;
375 background-color: var(--gray200);
376 text-align: center;
379 .labres tr.detail {
380 font-size: 0.8125rem;
383 .labres a, .labres a:visited, .labres a:hover {
384 color: #0000cc;
387 .labres table {
388 border-style: solid;
389 border-width: 1px 0px 0px 1px;
390 border-color: var(--black);
393 .labres td, .labres th {
394 border-style: solid;
395 border-width: 0px 1px 1px 0px;
396 border-color: var(--black);
399 <?php } else { ?>
400 .labres tr.head {
401 font-size: 0.8125rem;
402 text-align: center;
405 .labres tr.detail {
406 font-size: 0.8125rem;
409 .labres table {
410 border-style: none;
411 border-width: 1px 0px 0px 1px;
412 border-color: var(--black);
415 .labres td, .labres th {
416 border-style: none;
417 border-width: 0px 1px 1px 0px;
418 border-color: var(--black);
419 padding: 4px;
422 <?php } ?>
424 @media print {
425 .labres tr.head,
426 .labres tr.detail {
427 font-size: 10pt;
430 </style>
431 <?php } ?>
433 <?php if ($input_form) { ?>
434 <script src="<?php echo $GLOBALS['webroot']; ?>/library/textformat.js"></script>
435 <?php } // end if input form
438 <?php if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) { ?>
439 <script>
440 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
441 if (typeof top.webroot_url === "undefined") {
442 if (typeof opener.top.webroot_url !== "undefined") {
443 top.webroot_url = opener.top.webroot_url;
447 // This works even if we are in a separate window.
448 function showpnotes(orderid) {
449 let url = top.webroot_url + '/interface/patient_file/summary/pnotes_full.php?orderid=' + <?php echo js_url($orderid); ?>;
450 dlgopen(url, 'notes', 950, 750, false, '');
451 return false;
454 // Process click on LOINC code for patient education popup.
455 function educlick(codetype, codevalue) {
456 dlgopen(top.webroot_url + '/interface/patient_file/education.php' +
457 '?type=' + encodeURIComponent(codetype) +
458 '&code=' + encodeURIComponent(codevalue) +
459 '&language=' + <?php echo js_url($language); ?>,
460 '_blank', 1024, 750, true); // Force a new window instead of iframe to address cross site scripting potential
462 </script>
464 <?php } // end if not patient report ?>
465 <?php if ($input_form) { ?>
466 <form method='post' action='single_order_results.php?orderid=<?php echo attr_url($orderid); ?>'>
467 <?php } // end if input form
470 <div class='labres table-responsive'>
471 <table class="table">
472 <tr>
473 <td class="font-weight-bold text-nowrap" width='5%'><?php echo xlt('Patient ID'); ?></td>
474 <td width='45%'><?php echo myCellText($orow['pubpid']); ?></td>
475 <td class="font-weight-bold text-nowrap" width='5%'><?php echo xlt('Order ID'); ?></td>
476 <td width='45%'>
477 <?php
478 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
479 echo " <a href='" . $GLOBALS['webroot'];
480 echo "/interface/orders/order_manifest.php?orderid=";
481 echo attr_url($orow['procedure_order_id']);
482 echo "' target='_blank' onclick='top.restoreSession()'>";
485 echo myCellText($orow['procedure_order_id']);
486 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
487 echo "</a>\n";
490 if ($orow['control_id']) {
491 echo myCellText(' ' . xl('Lab') . ': ' . $orow['control_id']);
494 </td>
495 </tr>
496 <tr>
497 <td class="font-weight-bold text-nowrap"><?php echo xlt('Patient Name'); ?></td>
498 <td><?php echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?></td>
499 <td class="font-weight-bold text-nowrap"><?php echo xlt('Ordered By'); ?></td>
500 <td><?php echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?></td>
501 </tr>
502 <tr>
503 <td class="font-weight-bold text-nowrap"><?php echo xlt('Order Date'); ?></td>
504 <td><?php echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?></td>
505 <td class="font-weight-bold text-nowrap"><?php echo xlt('Print Date'); ?></td>
506 <td><?php echo text(oeFormatShortDate(date('Y-m-d'))); ?></td>
507 </tr>
508 <tr>
509 <td class="font-weight-bold text-nowrap"><?php echo xlt('Order Status'); ?></td>
510 <td><?php echo $orow['order_status'] ? myCellText($orow['order_status']) : xlt('Pending'); ?></td>
511 <td class="font-weight-bold text-nowrap"><?php echo xlt('Encounter Date'); ?></td>
512 <td><?php echo myCellText(oeFormatShortDate(substr($orow['date'], 0, 10))); ?></td>
513 </tr>
514 <tr>
515 <td class="font-weight-bold text-nowrap"><?php echo xlt('Lab'); ?></td>
516 <td><?php echo myCellText($orow['labname']); ?></td>
517 <td class="font-weight-bold text-nowrap"><?php echo xlt('Receiving Fac.'); ?></td>
518 <td><?php echo myCellText($orow['rcvfacid']); ?></td>
519 <!-- replaced specimen with receiving facility -->
520 </tr>
521 </table>
522 <br/>
523 <table class="table">
524 <tr class='head'>
525 <td class="align-middle" style="font-size: 1rem;" width='20%'><?php echo xlt('Diagnosis'); ?></td>
526 <td class="align-middle" style="font-size: 1rem;"><?php echo xlt('Diagnosis Description'); ?></td>
527 </tr>
528 <?php
529 foreach ($codes as $code) {
530 echo "<tr><td>" . myCellText($code['code']) . "</td>";
531 echo "<td>" . myCellText($code['short_desc']) . "</td></tr>";
534 </table>
535 <br/>
536 <table class="table">
537 <tr class='head'>
538 <td class="font-weight-bold align-middle" rowspan='2'><?php echo xlt('Ordered Procedure'); ?></td>
539 <td class="font-weight-bold" colspan='5'><?php echo xlt('Report'); ?></td>
540 <td class="font-weight-bold" colspan='7'><?php echo xlt('Results'); ?></td>
541 </tr>
542 <tr class='head'>
543 <td><?php echo xlt('Reported'); ?></td>
544 <td><?php echo xlt('Collected'); ?></td>
545 <td><?php echo xlt('Specimen'); ?></td>
546 <td><?php echo xlt('Status'); ?></td>
547 <td><?php echo xlt('Note'); ?></td>
548 <td><?php echo xlt('Code'); ?></td>
549 <td><?php echo xlt('Name'); ?></td>
550 <td><?php echo xlt('Abn'); ?></td>
551 <td><?php echo xlt('Value'); ?></td>
552 <td><?php echo xlt('Range'); ?></td>
553 <td><?php echo xlt('Units'); ?></td>
554 <td><?php echo xlt('Note'); ?></td>
555 </tr>
557 <?php
558 $query = "SELECT " .
559 "po.lab_id, po.date_ordered, pc.procedure_order_seq, pc.procedure_code, " .
560 "pc.procedure_name, pc.diagnoses, " .
561 "pr.date_report, pr.date_report_tz, pr.date_collected, pr.date_collected_tz, " .
562 "pr.procedure_report_id, pr.specimen_num, pr.report_status, pr.review_status, pr.report_notes " .
563 "FROM procedure_order AS po " .
564 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
565 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
566 "pr.procedure_order_seq = pc.procedure_order_seq " .
567 "WHERE po.procedure_order_id = ? " .
568 "ORDER BY pc.procedure_order_seq, pr.date_report, pr.procedure_report_id";
570 $res = sqlStatement($query, array($orderid));
571 $aNotes = array();
572 $finals = array();
573 $empty_results = array('result_code' => '');
575 // Context for this call that may be used in other functions.
576 $ctx = array(
577 'lastpcid' => -1,
578 'lastprid' => -1,
579 'encount' => 0,
580 'lino' => 0,
581 'sign_list' => '',
582 'seen_report_ids' => array(),
585 while ($row = sqlFetchArray($res)) {
586 $report_id = empty($row['procedure_report_id']) ? 0 : ($row['procedure_report_id'] + 0);
588 $query = "SELECT " .
589 "ps.result_code, ps.result_text, ps.abnormal, ps.result, ps.range, " .
590 "ps.result_status, ps.facility, ps.units, ps.comments, ps.document_id, ps.date " .
591 "FROM procedure_result AS ps " .
592 "WHERE ps.procedure_report_id = ? " .
593 "ORDER BY ps.procedure_result_id";
595 $rres = sqlStatement($query, array($report_id));
597 if ($finals_only) {
598 // We are consolidating reports.
599 if (sqlNumRows($rres)) {
600 $rrowsets = array();
601 // First pass creates a $rrowsets[$key] for each unique result code in *this* report, with
602 // the value being an array of the corresponding result rows. This caters to multiple
603 // occurrences of the same result code in the same report.
604 while ($rrow = sqlFetchArray($rres)) {
605 $result_code = empty($rrow['result_code']) ? '' : $rrow['result_code'];
606 $key = sprintf('%05d/', $row['procedure_order_seq']) . $result_code;
607 if (!isset($rrowsets[$key])) {
608 $rrowsets[$key] = array();
611 $rrowsets[$key][] = $rrow;
614 // Second pass builds onto the array of final results for *all* reports, where each final
615 // result for a given result code is its *array* of result rows from *one* of the reports.
616 foreach ($rrowsets as $key => $rrowset) {
617 // When two reports have the same date, use the result date to decide which is "latest".
618 if (
619 isset($finals[$key]) &&
620 $row['date_report'] == $finals[$key][0]['date_report'] &&
621 !empty($rrow['date']) && !empty($finals[$key][1]['date']) &&
622 $rrow['date'] < $finals[$key][1]['date']
624 $finals[$key][2] = true; // see comment below
625 continue;
628 // $finals[$key][2] indicates if there are multiple results for this result code.
629 $finals[$key] = array($row, $rrowset, isset($finals[$key]));
631 } else {
632 // We have no results for this report.
633 $key = sprintf('%05d/', $row['procedure_order_seq']);
634 $finals[$key] = array($row, array($empty_results), false);
636 } else {
637 // We are showing all results for all reports.
638 if (sqlNumRows($rres)) {
639 while ($rrow = sqlFetchArray($rres)) {
640 generate_result_row($ctx, $row, $rrow, false);
642 } else {
643 generate_result_row($ctx, $row, $empty_results, false);
648 if ($finals_only) {
649 // The sort here was removed because $finals is already ordered by procedure_result_id
650 // within procedure_order_seq which is probably desirable. Sorting by result code defeats
651 // the sequencing of results chosen by the sender.
652 // ksort($finals);
653 foreach ($finals as $final) {
654 foreach ($final[1] as $rrow) {
655 generate_result_row($ctx, $final[0], $rrow, $final[2]);
661 </table>
662 <br/>
663 <table class="table border-0">
664 <tr>
665 <td class="border-0">
666 <?php
667 if (!empty($aNotes)) {
668 echo "<div class='table-responsive'>";
669 echo "<table class='table'>\n";
670 echo " <tr style='background-color: var(--gray200);'>\n";
671 echo " <th class='text-center' colspan='2'>" . xlt('Notes') . "</th>\n";
672 echo " </tr>\n";
673 foreach ($aNotes as $key => $value) {
674 echo " <tr>\n";
675 echo " <td class='align-top' style='padding:5px 5px;'>" . ($key + 1) . "</td>\n";
676 // <pre> tag because white space and a fixed font are often used to line things up.
677 echo " <td><pre class='border-0 bg-white' style='white-space:pre-wrap;'>" . text($value) . "</pre></td>\n";
678 echo " </tr>\n";
681 echo "</table></div>\n";
684 </td>
685 <td class="border-0 text-right align-top">
686 <?php if ($input_form && !empty($ctx['priors_omitted']) /* empty($_POST['form_showall']) */) { ?>
687 <input type='submit' class='btn btn-primary' name='form_showall' value='<?php echo xla('Show All Results'); ?>'
688 title='<?php echo xla('Include all values reported for each result code'); ?>'/>
689 <?php } elseif ($input_form && !empty($_POST['form_showall'])) { ?>
690 <input type='submit' class='btn btn-primary' name='form_latest' value='<?php echo xla('Latest Results Only'); ?>'
691 title='<?php echo xla('Show only latest values reported for each result code'); ?>'/>
692 <?php } ?>
693 <?php if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) { ?>
694 &nbsp;
695 <input type='button' class='btn btn-primary' value='<?php echo xla('Related Patient Notes'); ?>'
696 onclick='showpnotes(<?php echo attr_js($orderid); ?>)' />
697 <?php } ?>
698 <?php if ($input_form && $ctx['sign_list']) { ?>
699 &nbsp;
700 <input type='hidden' class='btn btn-primary' name='form_sign_list' value='<?php echo attr($ctx['sign_list']); ?>'/>
701 <input type='submit' class='btn btn-primary' name='form_sign' value='<?php echo xla('Sign Results'); ?>'
702 title='<?php echo xla('Mark these reports as reviewed'); ?>'/>
703 <?php } ?>
704 <?php if ($input_form) { ?>
705 &nbsp;
706 <input type='button' class='btn btn-danger' value='<?php echo xla('Close'); ?>' onclick='window.close()'/>
707 <?php } ?>
708 </td>
709 </tr>
710 </table>
711 </div>
713 <?php if ($input_form) { ?>
714 </form>
715 <?php } // end if input form ?>
717 <?php
718 } // end function generate_order_report