fix: ccda zip import and php warnings and deprecations (#7416)
[openemr.git] / interface / orders / single_order_results.inc.php
blobbb26c01b038895febd00f9d3178cf6cab00aaa00
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);
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 if ($i = strpos($result_comments, "\n")) { // "=" is not a mistake!
145 $result_comments = str_replace("~", "\n", substr($result_comments, 0, $i)) .
146 substr($result_comments, $i);
149 $result_comments = trim($result_comments);
151 $result_noteid = '';
152 if (!empty($result_comments)) {
153 $result_noteid = 1 + storeNote($result_comments);
156 if ($priors_omitted) {
157 if ($result_noteid) {
158 $result_noteid .= ', ';
161 $result_noteid .= 1 + storeNote(xl('This is the latest of multiple result values.'));
162 $ctx['priors_omitted'] = true;
165 // If a performing organization is provided, make a note for it also.
166 $result_facility = trim(str_replace("\r", "\n", $result_facility));
167 if ($result_facility) {
168 if ($result_noteid) {
169 $result_noteid .= ', ';
172 $result_noteid .= 1 + storeNote(xl('Performing organization') . ":\n" . $result_facility);
175 if ($ctx['lastpcid'] != $order_seq) {
176 ++$ctx['encount'];
179 echo " <tr class='detail'>\n";
181 if ($ctx['lastpcid'] != $order_seq) {
182 $ctx['lastprid'] = -1; // force report fields on first line of each procedure
183 $tmp = text("$procedure_code: $procedure_name: $diagnosis");
184 // Get the LOINC code if one exists in the compendium for this order type.
185 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
186 $trow = sqlQuery(
187 "SELECT standard_code FROM procedure_type WHERE " .
188 "lab_id = ? AND procedure_code = ? AND procedure_type = 'ord' " .
189 "ORDER BY procedure_type_id LIMIT 1",
190 array($lab_id, $procedure_code)
192 if (!empty($trow['standard_code'])) {
193 $tmp = "<a href='javascript:educlick(\"LOINC\"," . attr_js($trow['standard_code']) .
194 ")'>$tmp</a>";
198 echo " <td>$tmp</td>\n";
199 } else {
200 echo " <td>&nbsp;</td>";
203 // If this starts a new report or a new order, generate the report fields.
204 if ($report_id != $ctx['lastprid']) {
205 echo " <td>";
206 echo myCellText(oeFormatShortDate(substr($date_report, 0, 10)) . substr($date_report, 10) . $date_report_suf);
207 echo "</td>\n";
209 echo " <td>";
210 echo myCellText(oeFormatShortDate(substr($date_collected, 0, 10)) . substr($date_collected, 10) . $date_collected_suf);
211 echo "</td>\n";
213 echo " <td>";
214 echo !empty($specimen_num) ? myCellText($specimen_num) : myCellText($date_collected); //quest wanted the specimen date to show here
215 echo "</td>\n";
217 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
218 echo myCellText(getListItem('proc_rep_status', $report_status));
219 if ($row['review_status'] == 'reviewed') {
220 echo " &#x2713;"; // unicode check mark character
223 echo "</td>\n";
225 echo " <td class='text-center'>";
226 echo myCellText($report_noteid);
227 echo "</td>\n";
228 } else {
229 echo " <td colspan='5'>&nbsp;</td>\n";
232 if ($result_code !== '' || $result_document_id) {
233 $tmp = myCellText($result_code);
234 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE']) && !empty($result_code)) {
235 $tmp = "<a href='javascript:educlick(\"LOINC\"," . attr_js($result_code) .
236 ")'>$tmp</a>";
239 echo " <td>$tmp</td>\n";
240 echo " <td>";
241 echo myCellText($result_text);
242 echo "</td>\n";
243 echo " <td>";
244 $tmp = myCellText(getListItem('proc_res_abnormal', $result_abnormal));
245 if ($result_abnormal && strtolower($result_abnormal) != 'no') {
246 echo "<p class='font-weight-bold text-danger'>$tmp</p>";
247 } else {
248 echo $tmp;
251 echo "</td>\n";
253 if ($result_document_id) {
254 $d = new Document($result_document_id);
255 echo " <td colspan='3'>";
256 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
257 echo "<a href='" . $GLOBALS['webroot'] . "/controller.php?document";
258 echo "&retrieve&patient_id=" . attr_url($patient_id) . "&document_id=" . attr_url($result_document_id) . "' ";
259 echo "onclick='top.restoreSession()'>";
262 echo $d->get_url_file();
263 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
264 echo "</a>";
267 echo "</td>\n";
268 $narrative_notes = sqlQuery("select group_concat(note SEPARATOR '\n') as notes from notes where foreign_id = ?", array($result_document_id));
269 if (!empty($narrative_notes)) {
270 $nnotes = explode("\n", $narrative_notes['notes'] ?? '');
271 $narrative_note_list = '';
272 foreach ($nnotes as $nnote) {
273 if ($narrative_note_list == '') {
274 $narrative_note_list = 'Narrative Notes:';
277 $narrative_note_list .= $nnote;
280 if ($narrative_note_list != '') {
281 if ($result_noteid) {
282 $result_noteid .= ', ';
285 $result_noteid .= 1 + storeNote($narrative_note_list);
288 } else {
289 echo " <td>";
290 echo myCellText($result_result);
291 echo "</td>\n";
292 echo " <td>";
293 echo myCellText($result_range);
294 echo "</td>\n";
295 echo " <td>";
296 // Units comes from the lab so might not match anything in the proc_unit list,
297 // but in that case the call will return the same value.
298 echo myCellText(getListItemTitle('proc_unit', $result_units));
299 echo "</td>\n";
302 echo " <td align='center'>";
303 echo myCellText($result_noteid);
304 echo "</td>\n";
305 } else {
306 echo " <td colspan='7'>&nbsp;</td>\n";
309 echo " </tr>\n";
311 $ctx['lastpcid'] = $order_seq;
312 $ctx['lastprid'] = $report_id;
313 ++$ctx['lino'];
316 function generate_order_report($orderid, $input_form = false, $genstyles = true, $finals_only = false)
318 global $aNotes;
320 // Check authorization.
321 $thisauth = AclMain::aclCheckCore('patients', 'med');
322 if (!$thisauth) {
323 return xl('Not authorized');
326 $orow = sqlQuery(
327 "SELECT " .
328 "po.procedure_order_id, po.date_ordered, po.control_id, " .
329 "po.order_status, po.specimen_type, po.patient_id, po.order_diagnosis, " .
330 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.cmsportal_login, pd.language, " .
331 "fe.date, " .
332 "pp.name AS labname, pp.recv_fac_id AS rcvfacid, " .
333 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
334 "FROM procedure_order AS po " .
335 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
336 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
337 "LEFT JOIN users AS u ON u.id = po.provider_id " .
338 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
339 "WHERE po.procedure_order_id = ?",
340 array($orderid)
342 $dres = sqlStatementNoLog(
343 "Select diagnoses as codes FROM procedure_order_code WHERE procedure_order_id = ? ",
344 array($orow['procedure_order_id'])
346 $codes = array();
347 $bld = '';
348 while ($diag = sqlFetchArray($dres)) {
349 $bld .= $diag['codes'] . ';';
351 $bld .= $orow['order_diagnosis'];
352 $diags = explode(';', $bld);
353 $diags = array_unique($diags);
354 foreach ($diags as $d) {
355 if (!$d) {
356 continue;
358 $r['code'] = $d;
359 $r['short_desc'] = lookup_code_descriptions($d, "code_text_short");
360 $codes[] = $r;
363 $patient_id = $orow['patient_id'];
364 $language = $orow['language'];
368 <?php if ($genstyles) { ?>
369 <style>
371 <?php if (empty($_SESSION['language_direction']) || $_SESSION['language_direction'] == 'ltr') { ?>
372 .labres tr.head {
373 font-size: 0.8125rem;
374 background-color: var(--gray200);
375 text-align: center;
378 .labres tr.detail {
379 font-size: 0.8125rem;
382 .labres a, .labres a:visited, .labres a:hover {
383 color: #0000cc;
386 .labres table {
387 border-style: solid;
388 border-width: 1px 0px 0px 1px;
389 border-color: var(--black);
392 .labres td, .labres th {
393 border-style: solid;
394 border-width: 0px 1px 1px 0px;
395 border-color: var(--black);
398 <?php } else { ?>
399 .labres tr.head {
400 font-size: 0.8125rem;
401 text-align: center;
404 .labres tr.detail {
405 font-size: 0.8125rem;
408 .labres table {
409 border-style: none;
410 border-width: 1px 0px 0px 1px;
411 border-color: var(--black);
414 .labres td, .labres th {
415 border-style: none;
416 border-width: 0px 1px 1px 0px;
417 border-color: var(--black);
418 padding: 4px;
421 <?php } ?>
423 @media print {
424 .labres tr.head,
425 .labres tr.detail {
426 font-size: 10pt;
429 </style>
430 <?php } ?>
432 <?php if ($input_form) { ?>
433 <script src="<?php echo $GLOBALS['webroot']; ?>/library/textformat.js"></script>
434 <?php } // end if input form
437 <?php if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) { ?>
438 <script>
439 var mypcc = <?php echo js_escape($GLOBALS['phone_country_code']); ?>;
440 if (typeof top.webroot_url === "undefined") {
441 if (typeof opener.top.webroot_url !== "undefined") {
442 top.webroot_url = opener.top.webroot_url;
446 // This works even if we are in a separate window.
447 function showpnotes(orderid) {
448 let url = top.webroot_url + '/interface/patient_file/summary/pnotes_full.php?orderid=' + <?php echo js_url($orderid); ?>;
449 dlgopen(url, 'notes', 950, 750, false, '');
450 return false;
453 // Process click on LOINC code for patient education popup.
454 function educlick(codetype, codevalue) {
455 dlgopen(top.webroot_url + '/interface/patient_file/education.php' +
456 '?type=' + encodeURIComponent(codetype) +
457 '&code=' + encodeURIComponent(codevalue) +
458 '&language=' + <?php echo js_url($language); ?>,
459 '_blank', 1024, 750, true); // Force a new window instead of iframe to address cross site scripting potential
461 </script>
463 <?php } // end if not patient report ?>
464 <?php if ($input_form) { ?>
465 <form method='post' action='single_order_results.php?orderid=<?php echo attr_url($orderid); ?>'>
466 <?php } // end if input form
469 <div class='labres table-responsive'>
470 <table class="table table-sm">
471 <tr>
472 <td class="font-weight-bold text-nowrap" width='5%'><?php echo xlt('Patient ID'); ?></td>
473 <td width='45%'><?php echo myCellText($orow['pubpid']); ?></td>
474 <td class="font-weight-bold text-nowrap" width='5%'><?php echo xlt('Order ID'); ?></td>
475 <td width='45%'>
476 <?php
477 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
478 echo " <a href='" . $GLOBALS['webroot'];
479 echo "/interface/orders/order_manifest.php?orderid=";
480 echo attr_url($orow['procedure_order_id']);
481 echo "' target='_blank' onclick='top.restoreSession()'>";
484 echo myCellText($orow['procedure_order_id']);
485 if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) {
486 echo "</a>\n";
489 if ($orow['control_id']) {
490 echo myCellText(' ' . xl('Lab') . ': ' . $orow['control_id']);
493 </td>
494 </tr>
495 <tr>
496 <td class="font-weight-bold text-nowrap"><?php echo xlt('Patient Name'); ?></td>
497 <td><?php echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?></td>
498 <td class="font-weight-bold text-nowrap"><?php echo xlt('Ordered By'); ?></td>
499 <td><?php echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?></td>
500 </tr>
501 <tr>
502 <td class="font-weight-bold text-nowrap"><?php echo xlt('Order Date'); ?></td>
503 <td><?php echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?></td>
504 <td class="font-weight-bold text-nowrap"><?php echo xlt('Print Date'); ?></td>
505 <td><?php echo text(oeFormatShortDate(date('Y-m-d'))); ?></td>
506 </tr>
507 <tr>
508 <td class="font-weight-bold text-nowrap"><?php echo xlt('Order Status'); ?></td>
509 <td><?php echo $orow['order_status'] ? myCellText($orow['order_status']) : xlt('Pending'); ?></td>
510 <td class="font-weight-bold text-nowrap"><?php echo xlt('Encounter Date'); ?></td>
511 <td><?php echo myCellText(oeFormatShortDate(substr($orow['date'], 0, 10))); ?></td>
512 </tr>
513 <tr>
514 <td class="font-weight-bold text-nowrap"><?php echo xlt('Lab'); ?></td>
515 <td><?php echo myCellText($orow['labname']); ?></td>
516 <td class="font-weight-bold text-nowrap"><?php echo xlt('Receiving Fac.'); ?></td>
517 <td><?php echo myCellText($orow['rcvfacid']); ?></td>
518 <!-- replaced specimen with receiving facility -->
519 </tr>
520 </table>
521 <br/>
522 <table class="table table-sm">
523 <tr class='head'>
524 <td class="align-middle" style="font-size: 1rem;" width='20%'><?php echo xlt('Diagnosis'); ?></td>
525 <td class="align-middle" style="font-size: 1rem;"><?php echo xlt('Diagnosis Description'); ?></td>
526 </tr>
527 <?php
528 foreach ($codes as $code) {
529 echo "<tr><td>" . myCellText($code['code']) . "</td>";
530 echo "<td>" . myCellText($code['short_desc']) . "</td></tr>";
533 </table>
534 <br/>
535 <table class="table table-sm table-striped">
536 <tr class='head'>
537 <td class="font-weight-bold align-middle" rowspan='2'><?php echo xlt('Ordered Procedure'); ?></td>
538 <td class="font-weight-bold" colspan='5'><?php echo xlt('Report'); ?></td>
539 <td class="font-weight-bold" colspan='7'><?php echo xlt('Results'); ?></td>
540 </tr>
541 <tr class='head'>
542 <td><?php echo xlt('Reported'); ?></td>
543 <td><?php echo xlt('Collected'); ?></td>
544 <td><?php echo xlt('Specimen'); ?></td>
545 <td><?php echo xlt('Status'); ?></td>
546 <td><?php echo xlt('Note'); ?></td>
547 <td><?php echo xlt('Code'); ?></td>
548 <td><?php echo xlt('Name'); ?></td>
549 <td><?php echo xlt('Abn'); ?></td>
550 <td><?php echo xlt('Value'); ?></td>
551 <td><?php echo xlt('Range'); ?></td>
552 <td><?php echo xlt('Units'); ?></td>
553 <td><?php echo xlt('Note'); ?></td>
554 </tr>
556 <?php
557 $query = "SELECT " .
558 "po.lab_id, po.date_ordered, pc.procedure_order_seq, pc.procedure_code, " .
559 "pc.procedure_name, pc.diagnoses, " .
560 "pr.date_report, pr.date_report_tz, pr.date_collected, pr.date_collected_tz, " .
561 "pr.procedure_report_id, pr.specimen_num, pr.report_status, pr.review_status, pr.report_notes " .
562 "FROM procedure_order AS po " .
563 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
564 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
565 "pr.procedure_order_seq = pc.procedure_order_seq " .
566 "WHERE po.procedure_order_id = ? " .
567 "ORDER BY pc.procedure_order_seq, pr.date_report, pr.procedure_report_id";
569 $res = sqlStatement($query, array($orderid));
570 $aNotes = array();
571 $finals = array();
572 $empty_results = array('result_code' => '');
574 // Context for this call that may be used in other functions.
575 $ctx = array(
576 'lastpcid' => -1,
577 'lastprid' => -1,
578 'encount' => 0,
579 'lino' => 0,
580 'sign_list' => '',
581 'seen_report_ids' => array(),
584 while ($row = sqlFetchArray($res)) {
585 $report_id = empty($row['procedure_report_id']) ? 0 : ($row['procedure_report_id'] + 0);
587 $query = "SELECT " .
588 "ps.result_code, ps.result_text, ps.abnormal, ps.result, ps.range, " .
589 "ps.result_status, ps.facility, ps.units, ps.comments, ps.document_id, ps.date " .
590 "FROM procedure_result AS ps " .
591 "WHERE ps.procedure_report_id = ? " .
592 "ORDER BY ps.procedure_result_id";
594 $rres = sqlStatement($query, array($report_id));
596 if ($finals_only) {
597 // We are consolidating reports.
598 if (sqlNumRows($rres)) {
599 $rrowsets = array();
600 // First pass creates a $rrowsets[$key] for each unique result code in *this* report, with
601 // the value being an array of the corresponding result rows. This caters to multiple
602 // occurrences of the same result code in the same report.
603 while ($rrow = sqlFetchArray($rres)) {
604 $result_code = empty($rrow['result_code']) ? '' : $rrow['result_code'];
605 $key = sprintf('%05d/', $row['procedure_order_seq']) . $result_code;
606 if (!isset($rrowsets[$key])) {
607 $rrowsets[$key] = array();
610 $rrowsets[$key][] = $rrow;
613 // Second pass builds onto the array of final results for *all* reports, where each final
614 // result for a given result code is its *array* of result rows from *one* of the reports.
615 foreach ($rrowsets as $key => $rrowset) {
616 // When two reports have the same date, use the result date to decide which is "latest".
617 if (
618 isset($finals[$key]) &&
619 $row['date_report'] == $finals[$key][0]['date_report'] &&
620 !empty($rrow['date']) && !empty($finals[$key][1]['date']) &&
621 $rrow['date'] < $finals[$key][1]['date']
623 $finals[$key][2] = true; // see comment below
624 continue;
627 // $finals[$key][2] indicates if there are multiple results for this result code.
628 $finals[$key] = array($row, $rrowset, isset($finals[$key]));
630 } else {
631 // We have no results for this report.
632 $key = sprintf('%05d/', $row['procedure_order_seq']);
633 $finals[$key] = array($row, array($empty_results), false);
635 } else {
636 // We are showing all results for all reports.
637 if (sqlNumRows($rres)) {
638 while ($rrow = sqlFetchArray($rres)) {
639 generate_result_row($ctx, $row, $rrow, false);
641 } else {
642 generate_result_row($ctx, $row, $empty_results, false);
647 if ($finals_only) {
648 // The sort here was removed because $finals is already ordered by procedure_result_id
649 // within procedure_order_seq which is probably desirable. Sorting by result code defeats
650 // the sequencing of results chosen by the sender.
651 // ksort($finals);
652 foreach ($finals as $final) {
653 foreach ($final[1] as $rrow) {
654 generate_result_row($ctx, $final[0], $rrow, $final[2]);
660 </table>
661 <br/>
662 <table class="table table-sm border-0">
663 <tr>
664 <td class="border-0">
665 <?php
666 if (!empty($aNotes)) {
667 echo "<div class='table-responsive'>";
668 echo "<table class='table'>\n";
669 echo " <tr style='background-color: var(--gray200);'>\n";
670 echo " <th class='text-center' colspan='2'>" . xlt('Notes') . "</th>\n";
671 echo " </tr>\n";
672 foreach ($aNotes as $key => $value) {
673 echo " <tr>\n";
674 echo " <td class='align-top' style='padding:5px 5px;'>" . ($key + 1) . "</td>\n";
675 // <pre> tag because white space and a fixed font are often used to line things up.
676 echo " <td><pre class='border-0 bg-white' style='white-space:pre-wrap;'>" . text($value) . "</pre></td>\n";
677 echo " </tr>\n";
680 echo "</table></div>\n";
683 </td>
684 <td class="border-0 text-right align-top">
685 <?php if ($input_form && !empty($ctx['priors_omitted']) /* empty($_POST['form_showall']) */) { ?>
686 <input type='submit' class='btn btn-primary' name='form_showall' value='<?php echo xla('Show All Results'); ?>'
687 title='<?php echo xla('Include all values reported for each result code'); ?>'/>
688 <?php } elseif ($input_form && !empty($_POST['form_showall'])) { ?>
689 <input type='submit' class='btn btn-primary' name='form_latest' value='<?php echo xla('Latest Results Only'); ?>'
690 title='<?php echo xla('Show only latest values reported for each result code'); ?>'/>
691 <?php } ?>
692 <?php if (empty($GLOBALS['PATIENT_REPORT_ACTIVE'])) { ?>
693 &nbsp;
694 <input type='button' class='btn btn-primary' value='<?php echo xla('Related Patient Notes'); ?>'
695 onclick='showpnotes(<?php echo attr_js($orderid); ?>)' />
696 <?php } ?>
697 <?php if ($input_form && $ctx['sign_list']) { ?>
698 &nbsp;
699 <input type='hidden' class='btn btn-primary' name='form_sign_list' value='<?php echo attr($ctx['sign_list']); ?>'/>
700 <input type='submit' class='btn btn-primary' name='form_sign' value='<?php echo xla('Sign Results'); ?>'
701 title='<?php echo xla('Mark these reports as reviewed'); ?>'/>
702 <?php } ?>
703 <?php if ($input_form) { ?>
704 &nbsp;
705 <input type='button' class='btn btn-danger' value='<?php echo xla('Close'); ?>' onclick='window.close()'/>
706 <?php } ?>
707 </td>
708 </tr>
709 </table>
710 </div>
712 <?php if ($input_form) { ?>
713 </form>
714 <?php } // end if input form ?>
716 <?php
717 // end function generate_order_report