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");
33 * Get a list item title, translating if required.
35 * @param string $listid List identifier.
36 * @param string $value List item identifier.
37 * @return string The item's title.
39 function getListItem($listid, $value) {
40 $lrow = sqlQuery("SELECT title FROM list_options " .
41 "WHERE list_id = ? AND option_id = ?",
42 array($listid, $value));
43 $tmp = xl_list_label($lrow['title']);
44 if (empty($tmp)) $tmp = "($report_status)";
49 * Adapt text to be suitable as the contents of a table cell.
51 * @param string $s Input text.
52 * @return string Output text.
54 function myCellText($s) {
55 if ($s === '') return ' ';
59 // Check authorization.
60 $thisauth = acl_check('patients', 'med');
61 if (!$thisauth) die(xlt('Not authorized'));
65 <?php
html_header_show();?
>
67 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
68 <title
><?php
echo xlt('Procedure Orders and Reports'); ?
></title
>
72 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
73 tr
.detail
{ font
-size
:10pt
; }
74 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
78 <style type
="text/css">@import
url(<?php
echo $GLOBALS['webroot'] ?
>/library
/dynarch_calendar
.css
);</style
>
79 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script
>
80 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
81 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script
>
83 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
84 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
86 <script language
="JavaScript">
88 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
90 function openResults(orderid
) {
92 window
.open('single_order_results.php?orderid=' + orderid
);
99 <body
class="body_top">
100 <form method
='post' action
='list_reports.php' enctype
='multipart/form-data'
101 onsubmit
='return validate(this)'>
105 $errmsg = poll_hl7_results($messages);
106 foreach ($messages as $message) {
107 echo text($message) . "<br />\n";
110 echo "<font color='red'>" . text($errmsg) . "</font><br />\n";
113 // Process uploaded file if there is one.
114 if (!empty($_FILES['userfile']['name'])) { // if upload was attempted
115 if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
116 $hl7 = file_get_contents($_FILES['userfile']['tmp_name']);
117 $msg = receive_hl7_results($hl7);
118 $message = xl('Upload processed successfully');
120 $message = xl('Error processing upload') . ": " . $msg;
122 echo text($message) . "<br />\n";
125 echo "<font color='red'>" . xlt('Upload failed!') . "</font><br />\n";
129 $form_from_date = empty($_POST['form_from_date']) ?
'' : trim($_POST['form_from_date']);
130 $form_to_date = empty($_POST['form_to_date']) ?
'' : trim($_POST['form_to_date']);
131 // if (empty($form_to_date)) $form_to_date = $form_from_date;
133 $form_reviewed = empty($_POST['form_reviewed']) ?
3 : intval($_POST['form_reviewed']);
135 $form_patient = !empty($_POST['form_patient']);
141  
;<?php
echo xlt('From'); ?
>:
142 <input type
='text' size
='8' name
='form_from_date' id
='form_from_date'
143 value
='<?php echo attr($form_from_date); ?>'
144 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
145 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
146 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
147 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
148 title
='<?php echo xla('Click here to choose a date
'); ?>' />
150  
;<?php
echo xlt('To'); ?
>:
151 <input type
='text' size
='8' name
='form_to_date' id
='form_to_date'
152 value
='<?php echo attr($form_to_date); ?>'
153 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
154 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
155 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
156 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
157 title
='<?php echo xla('Click here to choose a date
'); ?>' />
160 <select name
='form_reviewed'>
162 foreach (array('1' => xl('All'), '2' => xl('Reviewed'), '3' => xl('Unreviewed'),
163 '4' => xl('Unreceived')) as $key => $value) {
164 echo "<option value='$key'";
165 if ($key == $form_reviewed) echo " selected";
166 echo ">" . text($value) . "</option>\n";
172 <input type
='checkbox' name
='form_patient' value
='1'
173 <?php
if ($form_patient) echo 'checked '; ?
>/>Current Patient Only
176 <span title
='<?php echo xla('You may optionally upload HL7 results from a file
'); ?>'>
177 <?php
echo xlt('Upload'); ?
>:
178 <input type
='hidden' name
='MAX_FILE_SIZE' value
='4000000' />
179 <input type
='file' name
='userfile' size
='8' />
183 <input type
='submit' name
='form_refresh' value
=<?php
echo xla('Submit'); ?
>>
188 <table width
='100%' cellpadding
='1' cellspacing
='2'>
191 <td colspan
='2'><?php
echo xlt('Patient' ); ?
></td
>
192 <td colspan
='2'><?php
echo xlt('Order' ); ?
></td
>
193 <td colspan
='2'><?php
echo xlt('Procedure'); ?
></td
>
194 <td colspan
='2'><?php
echo xlt('Report' ); ?
></td
>
198 <td
><?php
echo xlt('Name' ); ?
></td
>
199 <td
><?php
echo xlt('ID' ); ?
></td
>
200 <td
><?php
echo xlt('Date' ); ?
></td
>
201 <td
><?php
echo xlt('ID' ); ?
></td
>
202 <td
><?php
echo xlt('Code' ); ?
></td
>
203 <td
><?php
echo xlt('Description'); ?
></td
>
204 <td
><?php
echo xlt('Date' ); ?
></td
>
205 <td
><?php
echo xlt('Status' ); ?
></td
>
206 <!-- <td
><?php
echo xlt('Reviewed' ); ?
></td
> -->
211 "po.procedure_order_id, po.date_ordered, pc.procedure_order_seq, pc.procedure_code, " .
212 "pc.procedure_name, " .
213 "pr.procedure_report_id, pr.date_report, pr.report_status, pr.review_status";
216 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
217 "pr.procedure_order_seq = pc.procedure_order_seq";
220 "po.date_ordered, po.procedure_order_id, " .
221 "pc.procedure_order_seq, pr.procedure_report_id";
224 $sqlBindArray = array();
226 if (!empty($form_from_date)) {
227 $where .= " AND po.date_ordered >= ?";
228 $sqlBindArray[] = $form_from_date;
230 if (!empty($form_to_date)) {
231 $where .= " AND po.date_ordered <= ?";
232 $sqlBindArray[] = $form_to_date;
236 $where .= " AND po.patient_id = ?";
237 $sqlBindArray[] = $pid;
240 if ($form_reviewed == 2) {
241 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status = 'reviewed'";
243 else if ($form_reviewed == 3) {
244 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status != 'reviewed'";
246 else if ($form_reviewed == 4) {
247 $where .= " AND pr.procedure_report_id IS NULL";
250 $query = "SELECT po.patient_id, " .
251 "pd.fname, pd.mname, pd.lname, pd.pubpid, $selects " .
252 "FROM procedure_order AS po " .
253 "LEFT JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
254 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id $joins " .
256 "ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, $orderby";
258 $res = sqlStatement($query, $sqlBindArray);
267 while ($row = sqlFetchArray($res)) {
268 $patient_id = empty($row['patient_id' ]) ?
0 : ($row['patient_id' ] +
0);
269 $order_id = empty($row['procedure_order_id' ]) ?
0 : ($row['procedure_order_id' ] +
0);
270 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
271 $date_ordered = empty($row['date_ordered']) ?
'' : $row['date_ordered'];
272 $procedure_code = empty($row['procedure_code']) ?
'' : $row['procedure_code'];
273 $procedure_name = empty($row['procedure_name']) ?
'' : $row['procedure_name'];
274 $report_id = empty($row['procedure_report_id']) ?
0 : ($row['procedure_report_id'] +
0);
275 $date_report = empty($row['date_report']) ?
'' : $row['date_report'];
276 $report_status = empty($row['report_status']) ?
'' : $row['report_status'];
277 $review_status = empty($row['review_status']) ?
'' : $row['review_status'];
279 $ptname = $row['lname'];
280 if ($row['fname'] ||
$row['mname'])
281 $ptname .= ', ' . $row['fname'] . ' ' . $row['mname'];
283 if ($lastpoid != $order_id ||
$lastpcid != $order_seq) {
286 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
288 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
290 // Generate patient columns.
291 if ($lastptid != $patient_id) {
293 echo " <td>" . text($ptname) . "</td>\n";
294 echo " <td>" . text($row['pubpid']) . "</td>\n";
297 echo " <td colspan='2' style='background-color:transparent'> </td>";
300 // Generate order columns.
301 if ($lastpoid != $order_id) {
303 echo " <td><a href='javascript:openResults($order_id)'>";
304 echo text($date_ordered);
306 echo " <td>" . text($order_id) . "</td>\n";
309 echo " <td colspan='2' style='background-color:transparent'> </td>";
312 // Generate procedure columns.
313 if ($order_seq && $lastpcid != $order_seq) {
314 echo " <td>" . text($procedure_code) . "</td>\n";
315 echo " <td>" . text($procedure_name) . "</td>\n";
318 echo " <td colspan='2' style='background-color:transparent'> </td>";
321 // Generate report columns.
323 echo " <td>" . text($date_report) . "</td>\n";
325 // echo " <td>" . text($report_status) . "</td>\n";
326 // echo " <td>" . text($review_status) . "</td>\n";
328 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
329 echo myCellText(getListItem('proc_rep_status', $report_status));
330 if ($review_status == 'reviewed') {
331 echo " ✓"; // unicode check mark character
337 echo " <td colspan='2' style='background-color:transparent'> </td>";
342 $lastptid = $patient_id;
343 $lastpoid = $order_id;
344 $lastpcid = $order_seq;
351 <script language
='JavaScript'>
353 // Initialize calendar widgets for "from" and "to" dates.
354 Calendar
.setup({inputField
:'form_from_date', ifFormat
:'%Y-%m-%d',
355 button
:'img_from_date'});
356 Calendar
.setup({inputField
:'form_to_date', ifFormat
:'%Y-%m-%d',
357 button
:'img_to_date'});