3 * Script to display results for a given procedure order.
5 * Copyright (C) 2013 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
19 * @author Rod Roark <rod@sunsetsystems.com>
22 require_once("../globals.php");
23 require_once("$srcdir/acl.inc");
24 require_once("$srcdir/formdata.inc.php");
25 require_once("$srcdir/options.inc.php");
26 require_once("$srcdir/formatting.inc.php");
27 require_once("../orders/lab_exchange_tools.php");
29 // Check authorization.
30 $thisauth = acl_check('patients', 'med');
31 if (!$thisauth) die(xl('Not authorized'));
33 $orderid = intval($_GET['orderid']);
35 function getListItem($listid, $value) {
36 $lrow = sqlQuery("SELECT title FROM list_options " .
37 "WHERE list_id = ? AND option_id = ?",
38 array($listid, $value));
39 $tmp = xl_list_label($lrow['title']);
40 if (empty($tmp)) $tmp = "($report_status)";
44 function myCellText($s) {
45 if ($s === '') return ' ';
49 // Check if the given string already exists in the $aNotes array.
50 // If not, stores it as a new entry.
51 // Either way, returns the corresponding key which is a small integer.
52 function storeNote($s) {
54 $key = array_search($s, $aNotes);
55 if ($key !== FALSE) return $key;
56 $key = count($aNotes);
61 if (!empty($_POST['form_sign_list'])) {
62 if (!acl_check('patients', 'sign')) {
63 die(xl('Not authorized to sign results'));
65 // When signing results we are careful to sign only those reports that were
66 // in the sending form. While this will usually be all the reports linked to
67 // the order it's possible for a new report to come in while viewing these,
68 // and it would be very bad to sign results that nobody has seen!
69 $arrSign = explode(',', $_POST['form_sign_list']);
70 foreach ($arrSign as $id) {
71 sqlStatement("UPDATE procedure_report SET " .
72 "review_status = 'reviewed' WHERE " .
73 "procedure_report_id = ?", array($id));
77 $orow = sqlQuery("SELECT " .
78 "po.procedure_order_id, po.date_ordered, po.diagnoses, " .
79 "po.order_status, po.specimen_type, " .
80 "pd.pubpid, pd.lname, pd.fname, pd.mname, " .
81 "pp.name AS labname, " .
82 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
83 "FROM procedure_order AS po " .
84 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
85 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
86 "LEFT JOIN users AS u ON u.id = po.provider_id " .
87 "WHERE po.procedure_order_id = ?",
93 <?php
html_header_show(); ?
>
95 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
96 <title
><?php
xl('Order Results','e'); ?
></title
>
102 font
-family
: sans
-serif
;
106 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
107 tr
.detail
{ font
-size
:10pt
; }
108 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
112 border
-width
: 1px
0px
0px
1px
;
118 border
-width
: 0px
1px
1px
0px
;
124 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
125 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
127 <script language
="JavaScript">
129 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
136 <form method
='post' action
='single_order_results.php?orderid=<?php echo $orderid; ?>'>
138 <table width
='100%' cellpadding
='2' cellspacing
='0'>
139 <tr bgcolor
='#cccccc'>
140 <td width
='5%' nowrap
><?php
echo xlt('Patient ID'); ?
></td
>
141 <td width
='45%'><?php
echo myCellText($orow['pubpid']); ?
></td
>
142 <td width
='5%' nowrap
><?php
echo xlt('Order ID'); ?
></td
>
143 <td width
='45%'><?php
echo myCellText($orow['procedure_order_id']); ?
></td
>
145 <tr bgcolor
='#cccccc'>
146 <td nowrap
><?php
echo xlt('Patient Name'); ?
></td
>
147 <td
><?php
echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?
></td
>
148 <td nowrap
><?php
echo xlt('Ordered By'); ?
></td
>
149 <td
><?php
echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?
></td
>
151 <tr bgcolor
='#cccccc'>
152 <td nowrap
><?php
echo xlt('Order Date'); ?
></td
>
153 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?
></td
>
154 <td nowrap
><?php
echo xlt('Print Date'); ?
></td
>
155 <td
><?php
echo oeFormatShortDate(date('Y-m-d')); ?
></td
>
157 <tr bgcolor
='#cccccc'>
158 <td nowrap
><?php
echo xlt('Order Status'); ?
></td
>
159 <td
><?php
echo myCellText($orow['order_status']); ?
></td
>
160 <td nowrap
><?php
echo xlt('Diagnoses'); ?
></td
>
161 <td
><?php
echo myCellText($orow['diagnoses']); ?
></td
>
163 <tr bgcolor
='#cccccc'>
164 <td nowrap
><?php
echo xlt('Lab'); ?
></td
>
165 <td
><?php
echo myCellText($orow['labname']); ?
></td
>
166 <td nowrap
><?php
echo xlt('Specimen Type'); ?
></td
>
167 <td
><?php
echo myCellText($orow['specimen_type']); ?
></td
>
173 <table width
='100%' cellpadding
='2' cellspacing
='0'>
176 <td rowspan
='2' valign
='middle'><?php
echo xlt('Ordered Procedure'); ?
></td
>
177 <td colspan
='4'><?php
echo xlt('Report'); ?
></td
>
178 <td colspan
='7'><?php
echo xlt('Results'); ?
></td
>
182 <td
><?php
echo xlt('Reported'); ?
></td
>
183 <td
><?php
echo xlt('Specimen'); ?
></td
>
184 <td
><?php
echo xlt('Status'); ?
></td
>
185 <td
><?php
echo xlt('Note'); ?
></td
>
186 <td
><?php
echo xlt('Code'); ?
></td
>
187 <td
><?php
echo xlt('Name'); ?
></td
>
188 <td
><?php
echo xlt('Abn'); ?
></td
>
189 <td
><?php
echo xlt('Value'); ?
></td
>
190 <td
><?php
echo xlt('Range'); ?
></td
>
191 <td
><?php
echo xlt('Units'); ?
></td
>
192 <td
><?php
echo xlt('Note'); ?
></td
>
197 "po.date_ordered, pc.procedure_order_seq, pc.procedure_code, " .
198 "pc.procedure_name, " .
199 "pr.procedure_report_id, pr.date_report, pr.date_collected, pr.specimen_num, " .
200 "pr.report_status, pr.review_status, pr.report_notes " .
201 "FROM procedure_order AS po " .
202 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
203 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
204 "pr.procedure_order_seq = pc.procedure_order_seq " .
205 "WHERE po.procedure_order_id = ? " .
206 "ORDER BY pc.procedure_order_seq, pr.procedure_report_id";
208 $res = sqlStatement($query, array($orderid));
219 while ($row = sqlFetchArray($res)) {
220 $order_type_id = empty($row['order_type_id' ]) ?
0 : ($row['order_type_id' ] +
0);
221 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
222 $report_id = empty($row['procedure_report_id']) ?
0 : ($row['procedure_report_id'] +
0);
223 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
224 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
225 $date_report = empty($row['date_report' ]) ?
'' : $row['date_report'];
226 $date_collected = empty($row['date_collected' ]) ?
'' : substr($row['date_collected'], 0, 16);
227 $specimen_num = empty($row['specimen_num' ]) ?
'' : $row['specimen_num'];
228 $report_status = empty($row['report_status' ]) ?
'' : $row['report_status'];
229 $review_status = empty($row['review_status' ]) ?
'received' : $row['review_status'];
231 if ($review_status != 'reviewed') {
232 if ($sign_list) $sign_list .= ',';
233 $sign_list .= $report_id;
236 $report_noteid =' ';
237 if (!empty($row['report_notes'])) {
238 $report_noteid = 1 +
storeNote($row['report_notes']);
242 "ps.result_code, ps.result_text, ps.abnormal, ps.result, " .
243 "ps.range, ps.result_status, ps.facility, ps.units, ps.comments " .
244 "FROM procedure_result AS ps " .
245 "WHERE ps.procedure_report_id = ? " .
246 "ORDER BY ps.result_code, ps.procedure_result_id";
248 $rres = sqlStatement($query, array($report_id));
250 while ($rrow = sqlFetchArray($rres)) {
254 $rrows[0] = array('result_code' => '');
257 foreach ($rrows as $rrow) {
258 $result_code = empty($rrow['result_code' ]) ?
'' : $rrow['result_code'];
259 $result_text = empty($rrow['result_text' ]) ?
'' : $rrow['result_text'];
260 $result_abnormal = empty($rrow['abnormal' ]) ?
'' : $rrow['abnormal'];
261 $result_result = empty($rrow['result' ]) ?
'' : $rrow['result'];
262 $result_units = empty($rrow['units' ]) ?
'' : $rrow['units'];
263 $result_facility = empty($rrow['facility' ]) ?
'' : $rrow['facility'];
264 $result_comments = empty($rrow['comments' ]) ?
'' : $rrow['comments'];
265 $result_range = empty($rrow['range' ]) ?
'' : $rrow['range'];
266 $result_status = empty($rrow['result_status' ]) ?
'' : $rrow['result_status'];
268 $result_comments = trim($result_comments);
269 $result_noteid = ' ';
270 if (!empty($result_comments)) {
271 $result_noteid = 1 +
storeNote($result_comments);
274 if ($lastpoid != $order_id ||
$lastpcid != $order_seq) {
277 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
279 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
281 if ($lastpcid != $order_seq) {
282 $lastprid = -1; // force report fields on first line of each procedure
283 echo " <td>" . htmlentities("$procedure_code: $procedure_name") . "</td>\n";
286 echo " <td style='background-color:transparent'> </td>";
289 // If this starts a new report or a new order, generate the report fields.
290 if ($report_id != $lastprid) {
292 echo myCellText(oeFormatShortDate($date_report));
296 echo myCellText($specimen_num);
299 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
300 echo myCellText(getListItem('proc_rep_status', $report_status));
301 if ($row['review_status'] == 'reviewed') {
302 echo " ✓"; // unicode check mark character
306 echo " <td align='center'>";
311 echo " <td colspan='4' style='background-color:transparent'> </td>\n";
314 if ($result_code !== '') {
316 echo myCellText($result_code);
319 echo myCellText($result_text);
322 echo myCellText(getListItem('proc_res_abnormal', $result_abnormal));
325 echo myCellText($result_result);
328 echo myCellText($result_range);
331 echo myCellText($result_units);
333 echo " <td align='center'>";
338 echo " <td colspan='7' style='background-color:transparent'> </td>\n";
343 $lastpoid = $order_id;
344 $lastpcid = $order_seq;
345 $lastprid = $report_id;
354 <table width
='100%' style
='border-width:0px;'>
356 <td style
='border-width:0px;'>
358 if (!empty($aNotes)) {
359 echo "<table cellpadding='3' cellspacing='0'>\n";
360 echo " <tr bgcolor='#cccccc'>\n";
361 echo " <th align='center' colspan='2'>" . xlt('Notes') . "</th>\n";
363 foreach ($aNotes as $key => $value) {
365 echo " <td valign='top'>" . ($key +
1) . "</td>\n";
366 echo " <td>" . nl2br(text($value)) . "</td>\n";
373 <td style
='border-width:0px;' align
='right' valign
='top'>
374 <?php
if ($sign_list) { ?
>
375 <input type
='hidden' name
='form_sign_list' value
='<?php echo attr($sign_list); ?>' />
376 <input type
='submit' name
='form_sign' value
='<?php echo xla('Sign Results
'); ?>'
377 title
='<?php echo xla('Mark these reports
as reviewed
'); ?>' />