3 * List procedure orders and reports, and fetch new reports and their results.
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 $sanitize_all_escapes = true;
23 $fake_register_globals = false;
25 require_once("../globals.php");
26 require_once("$srcdir/acl.inc");
27 require_once("$srcdir/formdata.inc.php");
28 require_once("$srcdir/options.inc.php");
29 require_once("$srcdir/formatting.inc.php");
30 require_once("./receive_hl7_results.inc.php");
31 require_once("./gen_hl7_order.inc.php");
34 * Get a list item title, translating if required.
36 * @param string $listid List identifier.
37 * @param string $value List item identifier.
38 * @return string The item's title.
40 function getListItem($listid, $value) {
41 $lrow = sqlQuery("SELECT title FROM list_options " .
42 "WHERE list_id = ? AND option_id = ?",
43 array($listid, $value));
44 $tmp = xl_list_label($lrow['title']);
45 if (empty($tmp)) $tmp = "($report_status)";
50 * Adapt text to be suitable as the contents of a table cell.
52 * @param string $s Input text.
53 * @return string Output text.
55 function myCellText($s) {
56 if ($s === '') return ' ';
60 // Check authorization.
61 $thisauth = acl_check('patients', 'med');
62 if (!$thisauth) die(xlt('Not authorized'));
66 // Send selected unsent orders if requested. This does not support downloading
67 // very well as it will only send the first of those.
68 if ($_POST['form_xmit']) {
69 foreach ($_POST['form_cb'] as $formid) {
70 $row = sqlQuery("SELECT lab_id FROM procedure_order WHERE " .
71 "procedure_order_id = ?", array($formid));
72 $ppid = intval($row['lab_id']);
74 $errmsg = gen_hl7_order($formid, $hl7);
76 $errmsg = send_hl7_order($ppid, $hl7);
79 sqlStatement("UPDATE procedure_order SET date_transmitted = NOW() WHERE " .
80 "procedure_order_id = ?", array($formid));
86 <?php
html_header_show();?
>
88 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
89 <title
><?php
echo xlt('Procedure Orders and Reports'); ?
></title
>
93 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
94 tr
.detail
{ font
-size
:10pt
; }
95 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
99 <style type
="text/css">@import
url(<?php
echo $GLOBALS['webroot'] ?
>/library
/dynarch_calendar
.css
);</style
>
100 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script
>
101 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
102 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script
>
104 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
105 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
107 <script language
="JavaScript">
109 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
111 function openResults(orderid
) {
112 top
.restoreSession();
113 // window.open('single_order_results.php?orderid=' + orderid);
114 document
.location
.href
= 'single_order_results.php?orderid=' + orderid
;
121 <body
class="body_top">
122 <form method
='post' action
='list_reports.php' enctype
='multipart/form-data'
123 onsubmit
='return validate(this)'>
127 echo "<font color='red'>" . text($errmsg) . "</font><br />\n";
130 $errmsg = poll_hl7_results($messages);
131 foreach ($messages as $message) {
132 echo text($message) . "<br />\n";
135 echo "<font color='red'>" . text($errmsg) . "</font><br />\n";
138 // Process uploaded file if there is one.
139 if (!empty($_FILES['userfile']['name'])) { // if upload was attempted
140 if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
141 $hl7 = file_get_contents($_FILES['userfile']['tmp_name']);
142 $msg = receive_hl7_results($hl7);
143 $message = xl('Upload processed successfully');
145 $message = xl('Error processing upload') . ": " . $msg;
147 echo text($message) . "<br />\n";
150 echo "<font color='red'>" . xlt('Upload failed!') . "</font><br />\n";
154 $form_from_date = empty($_POST['form_from_date']) ?
'' : trim($_POST['form_from_date']);
155 $form_to_date = empty($_POST['form_to_date']) ?
'' : trim($_POST['form_to_date']);
156 // if (empty($form_to_date)) $form_to_date = $form_from_date;
158 $form_reviewed = empty($_POST['form_reviewed']) ?
3 : intval($_POST['form_reviewed']);
160 $form_patient = !empty($_POST['form_patient']);
162 $form_provider = empty($_POST['form_provider']) ?
0 : intval($_POST['form_provider']);
167 <td
class='text' align
='center'>
168  
;<?php
echo xlt('From'); ?
>:
169 <input type
='text' size
='8' name
='form_from_date' id
='form_from_date'
170 value
='<?php echo attr($form_from_date); ?>'
171 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
172 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
173 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
174 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
175 title
='<?php echo xla('Click here to choose a date
'); ?>' />
177  
;<?php
echo xlt('To'); ?
>:
178 <input type
='text' size
='8' name
='form_to_date' id
='form_to_date'
179 value
='<?php echo attr($form_to_date); ?>'
180 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
181 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
182 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
183 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
184 title
='<?php echo xla('Click here to choose a date
'); ?>' />
187 <select name
='form_reviewed'>
191 '2' => xl('Reviewed'),
192 '3' => xl('Received, not reviewed'),
193 '4' => xl('Sent, not received'),
194 '5' => xl('Not sent'),
195 ) as $key => $value) {
196 echo "<option value='$key'";
197 if ($key == $form_reviewed) echo " selected";
198 echo ">" . text($value) . "</option>\n";
205 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
206 'empty_title' => '-- All Providers --'), $form_provider);
211 <td
class='text' align
='center'>
212 <input type
='checkbox' name
='form_patient' value
='1'
213 <?php
if ($form_patient) echo 'checked '; ?
>/>Current Patient Only
216 <span title
='<?php echo xla('You may optionally upload HL7 results from a file
'); ?>'>
217 <?php
echo xlt('Upload'); ?
>:
218 <input type
='hidden' name
='MAX_FILE_SIZE' value
='4000000' />
219 <input type
='file' name
='userfile' size
='8' />
223 <input type
='submit' name
='form_refresh' value
=<?php
echo xla('Submit'); ?
>>
228 <table width
='100%' cellpadding
='1' cellspacing
='2'>
231 <td colspan
='2'><?php
echo xlt('Patient' ); ?
></td
>
232 <td colspan
='2'><?php
echo xlt('Order' ); ?
></td
>
233 <td colspan
='2'><?php
echo xlt('Procedure'); ?
></td
>
234 <td colspan
='2'><?php
echo xlt('Report' ); ?
></td
>
238 <td
><?php
echo xlt('Name' ); ?
></td
>
239 <td
><?php
echo xlt('ID' ); ?
></td
>
240 <td
><?php
echo xlt('Date' ); ?
></td
>
241 <td
><?php
echo xlt('ID' ); ?
></td
>
242 <td
><?php
echo xlt('Code' ); ?
></td
>
243 <td
><?php
echo xlt('Description'); ?
></td
>
244 <td
><?php
echo xlt('Date' ); ?
></td
>
245 <td
><?php
echo xlt('Status' ); ?
></td
>
246 <!-- <td
><?php
echo xlt('Reviewed' ); ?
></td
> -->
251 "po.patient_id, po.procedure_order_id, po.date_ordered, po.date_transmitted, " .
252 "pc.procedure_order_seq, pc.procedure_code, pc.procedure_name, " .
253 "pr.procedure_report_id, pr.date_report, pr.report_status, pr.review_status";
256 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
257 "pr.procedure_order_seq = pc.procedure_order_seq";
260 "po.date_ordered, po.procedure_order_id, " .
261 "pc.procedure_order_seq, pr.procedure_report_id";
264 $sqlBindArray = array();
266 if (!empty($form_from_date)) {
267 $where .= " AND po.date_ordered >= ?";
268 $sqlBindArray[] = $form_from_date;
270 if (!empty($form_to_date)) {
271 $where .= " AND po.date_ordered <= ?";
272 $sqlBindArray[] = $form_to_date;
276 $where .= " AND po.patient_id = ?";
277 $sqlBindArray[] = $pid;
280 if ($form_provider) {
281 $where .= " AND po.provider_id = ?";
282 $sqlBindArray[] = $form_provider;
285 if ($form_reviewed == 2) {
286 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status = 'reviewed'";
288 else if ($form_reviewed == 3) {
289 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status != 'reviewed'";
291 else if ($form_reviewed == 4) {
292 $where .= " AND po.date_transmitted IS NOT NULL AND pr.procedure_report_id IS NULL";
294 else if ($form_reviewed == 5) {
295 $where .= " AND po.date_transmitted IS NULL AND pr.procedure_report_id IS NULL";
299 "pd.fname, pd.mname, pd.lname, pd.pubpid, $selects " .
300 "FROM procedure_order AS po " .
301 "LEFT JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
302 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id $joins " .
304 "ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, $orderby";
306 $res = sqlStatement($query, $sqlBindArray);
316 while ($row = sqlFetchArray($res)) {
317 $patient_id = empty($row['patient_id' ]) ?
0 : ($row['patient_id' ] +
0);
318 $order_id = empty($row['procedure_order_id' ]) ?
0 : ($row['procedure_order_id' ] +
0);
319 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
320 $date_ordered = empty($row['date_ordered' ]) ?
'' : $row['date_ordered'];
321 $date_transmitted = empty($row['date_transmitted' ]) ?
'' : $row['date_transmitted'];
322 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
323 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
324 $report_id = empty($row['procedure_report_id']) ?
0 : ($row['procedure_report_id'] +
0);
325 $date_report = empty($row['date_report' ]) ?
'' : $row['date_report'];
326 $report_status = empty($row['report_status' ]) ?
'' : $row['report_status'];
327 $review_status = empty($row['review_status' ]) ?
'' : $row['review_status'];
329 $ptname = $row['lname'];
330 if ($row['fname'] ||
$row['mname'])
331 $ptname .= ', ' . $row['fname'] . ' ' . $row['mname'];
333 if ($lastpoid != $order_id ||
$lastpcid != $order_seq) {
336 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
338 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
340 // Generate patient columns.
341 if ($lastptid != $patient_id) {
343 echo " <td>" . text($ptname) . "</td>\n";
344 echo " <td>" . text($row['pubpid']) . "</td>\n";
347 echo " <td colspan='2' style='background-color:transparent'> </td>";
350 // Generate order columns.
351 if ($lastpoid != $order_id) {
354 // Checkbox to support sending unsent orders, disabled if sent.
355 echo "<input type='checkbox' name='form_cb[$order_id]' value='$order_id' ";
356 if ($date_transmitted) {
363 // Order date comes with a link to open results in the same frame.
364 echo "<a href='javascript:openResults($order_id)' ";
365 echo "title='" . xla('Click for results') . "'>";
366 echo text($date_ordered);
369 // Order ID comes with a link to open the manifest in a new window/tab.
370 echo "<a href='" . $GLOBALS['webroot'];
371 echo "/interface/orders/order_manifest.php?orderid=";
372 echo attr($order_id);
373 echo "' target='_blank' onclick='top.restoreSession()' ";
374 echo "title='" . xla('Click for order summary') . "'>";
375 echo text($order_id);
379 echo " <td colspan='2' style='background-color:transparent'> </td>";
382 // Generate procedure columns.
383 if ($order_seq && $lastpcid != $order_seq) {
384 echo " <td>" . text($procedure_code) . "</td>\n";
385 echo " <td>" . text($procedure_name) . "</td>\n";
388 echo " <td colspan='2' style='background-color:transparent'> </td>";
391 // Generate report columns.
393 echo " <td>" . text($date_report) . "</td>\n";
394 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
395 echo myCellText(getListItem('proc_rep_status', $report_status));
396 if ($review_status == 'reviewed') {
397 echo " ✓"; // unicode check mark character
402 echo " <td colspan='2' style='background-color:transparent'> </td>";
407 $lastptid = $patient_id;
408 $lastpoid = $order_id;
409 $lastpcid = $order_seq;
416 <?php
if ($num_checkboxes) { ?
>
418 <input type
='submit' name
='form_xmit' value
='<?php echo xla('Transmit Selected Orders
'); ?>' />
422 <script language
='JavaScript'>
424 // Initialize calendar widgets for "from" and "to" dates.
425 Calendar
.setup({inputField
:'form_from_date', ifFormat
:'%Y-%m-%d',
426 button
:'img_from_date'});
427 Calendar
.setup({inputField
:'form_to_date', ifFormat
:'%Y-%m-%d',
428 button
:'img_to_date'});