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'
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 $form_from_date = empty($_POST['form_from_date']) ?
'' : trim($_POST['form_from_date']);
114 $form_to_date = empty($_POST['form_to_date']) ?
'' : trim($_POST['form_to_date']);
115 // if (empty($form_to_date)) $form_to_date = $form_from_date;
117 $form_reviewed = empty($_POST['form_reviewed']) ?
3 : intval($_POST['form_reviewed']);
119 $form_patient = !empty($_POST['form_patient']);
125  
;<?php
echo xlt('From'); ?
>:
126 <input type
='text' size
='10' name
='form_from_date' id
='form_from_date'
127 value
='<?php echo attr($form_from_date); ?>'
128 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
129 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
130 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
131 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
132 title
='<?php echo xla('Click here to choose a date
'); ?>' />
134  
;<?php
echo xlt('To'); ?
>:
135 <input type
='text' size
='10' name
='form_to_date' id
='form_to_date'
136 value
='<?php echo attr($form_to_date); ?>'
137 title
='<?php echo xla('yyyy
-mm
-dd
'); ?>'
138 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
139 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
140 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
141 title
='<?php echo xla('Click here to choose a date
'); ?>' />
144 <select name
='form_reviewed'>
146 foreach (array('1' => xl('All'), '2' => xl('Reviewed'), '3' => xl('Unreviewed'),
147 '4' => xl('Unreceived')) as $key => $value) {
148 echo "<option value='$key'";
149 if ($key == $form_reviewed) echo " selected";
150 echo ">" . text($value) . "</option>\n";
156 <input type
='checkbox' name
='form_patient' value
='1'
157 <?php
if ($form_patient) echo 'checked '; ?
>/>Current Patient Only
160 <input type
='submit' name
='form_refresh' value
=<?php
echo xla('Refresh'); ?
>>
165 <table width
='100%' cellpadding
='1' cellspacing
='2'>
168 <td colspan
='2'><?php
echo xlt('Patient' ); ?
></td
>
169 <td colspan
='2'><?php
echo xlt('Order' ); ?
></td
>
170 <td colspan
='2'><?php
echo xlt('Procedure'); ?
></td
>
171 <td colspan
='2'><?php
echo xlt('Report' ); ?
></td
>
175 <td
><?php
echo xlt('Name' ); ?
></td
>
176 <td
><?php
echo xlt('ID' ); ?
></td
>
177 <td
><?php
echo xlt('Date' ); ?
></td
>
178 <td
><?php
echo xlt('ID' ); ?
></td
>
179 <td
><?php
echo xlt('Code' ); ?
></td
>
180 <td
><?php
echo xlt('Description'); ?
></td
>
181 <td
><?php
echo xlt('Date' ); ?
></td
>
182 <td
><?php
echo xlt('Status' ); ?
></td
>
183 <!-- <td
><?php
echo xlt('Reviewed' ); ?
></td
> -->
188 "po.procedure_order_id, po.date_ordered, pc.procedure_order_seq, pc.procedure_code, " .
189 "pc.procedure_name, " .
190 "pr.procedure_report_id, pr.date_report, pr.report_status, pr.review_status";
193 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
194 "pr.procedure_order_seq = pc.procedure_order_seq";
197 "po.date_ordered, po.procedure_order_id, " .
198 "pc.procedure_order_seq, pr.procedure_report_id";
201 $sqlBindArray = array();
203 if (!empty($form_from_date)) {
204 $where .= " AND po.date_ordered >= ?";
205 $sqlBindArray[] = $form_from_date;
207 if (!empty($form_to_date)) {
208 $where .= " AND po.date_ordered <= ?";
209 $sqlBindArray[] = $form_to_date;
213 $where .= " AND po.patient_id = ?";
214 $sqlBindArray[] = $pid;
217 if ($form_reviewed == 2) {
218 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status = 'reviewed'";
220 else if ($form_reviewed == 3) {
221 $where .= " AND pr.procedure_report_id IS NOT NULL AND pr.review_status != 'reviewed'";
223 else if ($form_reviewed == 4) {
224 $where .= " AND pr.procedure_report_id IS NULL";
227 $query = "SELECT po.patient_id, " .
228 "pd.fname, pd.mname, pd.lname, pd.pubpid, $selects " .
229 "FROM procedure_order AS po " .
230 "LEFT JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
231 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id $joins " .
233 "ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, $orderby";
235 $res = sqlStatement($query, $sqlBindArray);
244 while ($row = sqlFetchArray($res)) {
245 $patient_id = empty($row['patient_id' ]) ?
0 : ($row['patient_id' ] +
0);
246 $order_id = empty($row['procedure_order_id' ]) ?
0 : ($row['procedure_order_id' ] +
0);
247 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
248 $date_ordered = empty($row['date_ordered']) ?
'' : $row['date_ordered'];
249 $procedure_code = empty($row['procedure_code']) ?
'' : $row['procedure_code'];
250 $procedure_name = empty($row['procedure_name']) ?
'' : $row['procedure_name'];
251 $report_id = empty($row['procedure_report_id']) ?
0 : ($row['procedure_report_id'] +
0);
252 $date_report = empty($row['date_report']) ?
'' : $row['date_report'];
253 $report_status = empty($row['report_status']) ?
'' : $row['report_status'];
254 $review_status = empty($row['review_status']) ?
'' : $row['review_status'];
256 $ptname = $row['lname'];
257 if ($row['fname'] ||
$row['mname'])
258 $ptname .= ', ' . $row['fname'] . ' ' . $row['mname'];
260 if ($lastpoid != $order_id ||
$lastpcid != $order_seq) {
263 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
265 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
267 // Generate patient columns.
268 if ($lastptid != $patient_id) {
270 echo " <td>" . text($ptname) . "</td>\n";
271 echo " <td>" . text($row['pubpid']) . "</td>\n";
274 echo " <td colspan='2' style='background-color:transparent'> </td>";
277 // Generate order columns.
278 if ($lastpoid != $order_id) {
280 echo " <td><a href='javascript:openResults($order_id)'>";
281 echo text($date_ordered);
283 echo " <td>" . text($order_id) . "</td>\n";
286 echo " <td colspan='2' style='background-color:transparent'> </td>";
289 // Generate procedure columns.
290 if ($order_seq && $lastpcid != $order_seq) {
291 echo " <td>" . text($procedure_code) . "</td>\n";
292 echo " <td>" . text($procedure_name) . "</td>\n";
295 echo " <td colspan='2' style='background-color:transparent'> </td>";
298 // Generate report columns.
300 echo " <td>" . text($date_report) . "</td>\n";
302 // echo " <td>" . text($report_status) . "</td>\n";
303 // echo " <td>" . text($review_status) . "</td>\n";
305 echo " <td title='" . xla('Check mark indicates reviewed') . "'>";
306 echo myCellText(getListItem('proc_rep_status', $report_status));
307 if ($review_status == 'reviewed') {
308 echo " ✓"; // unicode check mark character
314 echo " <td colspan='2' style='background-color:transparent'> </td>";
319 $lastptid = $patient_id;
320 $lastpoid = $order_id;
321 $lastpcid = $order_seq;
328 <script language
='JavaScript'>
330 // Initialize calendar widgets for "from" and "to" dates.
331 Calendar
.setup({inputField
:'form_from_date', ifFormat
:'%Y-%m-%d',
332 button
:'img_from_date'});
333 Calendar
.setup({inputField
:'form_to_date', ifFormat
:'%Y-%m-%d',
334 button
:'img_to_date'});