3 * Script to display a summary of a given procedure order before it has been processed.
5 * Copyright (C) 2013, 2016 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/options.inc.php");
28 require_once("$srcdir/patient.inc");
30 function getListItem($listid, $value) {
31 $lrow = sqlQuery("SELECT title FROM list_options " .
32 "WHERE list_id = ? AND option_id = ? AND activity = 1",
33 array($listid, $value));
34 $tmp = xl_list_label($lrow['title']);
35 if (empty($tmp)) $tmp = "($value)";
39 function myCellText($s) {
40 if ($s === '') return ' ';
44 function generate_order_summary($orderid) {
46 // If requested, save checkbox selections as to which procedures are not sendable.
47 if ($_POST['bn_save']) {
48 sqlStatement("UPDATE procedure_order_code " .
49 "SET do_not_send = 0 WHERE " .
50 "procedure_order_id = ? AND " .
53 if (!empty($_POST['form_omit'])) {
54 foreach ($_POST['form_omit'] as $key) {
55 sqlStatement("UPDATE procedure_order_code " .
56 "SET do_not_send = 1 WHERE " .
57 "procedure_order_id = ? AND " .
58 "do_not_send = 0 AND " .
59 "procedure_order_seq = ?",
60 array($orderid, intval($key)));
65 $orow = sqlQuery("SELECT " .
66 "po.procedure_order_id, po.patient_id, po.date_ordered, po.order_status, " .
67 "po.date_collected, po.specimen_type, po.specimen_location, po.lab_id, po.clinical_hx, " .
68 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.DOB, pd.sex, " .
69 "pd.street, pd.city, pd.state, pd.postal_code, " .
71 "pp.name AS labname, " .
72 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname, " .
73 "ru.lname AS ref_lname, ru.fname AS ref_fname, ru.mname AS ref_mname, " .
74 "ru.street AS ref_street, ru.city AS ref_city, ru.state AS ref_state, ru.zip AS ref_zip " .
75 "FROM procedure_order AS po " .
76 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
77 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
78 "LEFT JOIN users AS u ON u.id = po.provider_id " .
79 "LEFT JOIN users AS ru ON ru.id = pd.ref_providerID " .
80 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
81 "WHERE po.procedure_order_id = ?",
84 $lab_id = intval($orow['lab_id']);
85 $patient_id = intval($orow['patient_id']);
86 $encdate = substr($orow['date'], 0, 10);
88 // Get insurance info.
96 $irow = getInsuranceDataByDate($patient_id, $encdate, 'primary',
97 "insd.provider, insd.policy_number, insd.group_number");
98 if (!empty($irow['provider'])) {
99 $ins_policy = $irow['policy_number'];
100 $ins_group = $irow['group_number'];
101 $insco = new InsuranceCompany($irow['provider']);
102 if (!empty($insco)) {
103 $ins_name = $insco->get_name();
104 $tmp = $insco->get_address();
105 $ins_addr = $tmp->get_line1();
106 $ins_city = $tmp->get_city();
107 $ins_state = $tmp->get_state();
108 $ins_zip = $tmp->get_zip();
115 .ordsum tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
116 .ordsum tr
.detail
{ font
-size
:10pt
; }
117 .ordsum a
, .ordsum a
:visited
, .ordsum a
:hover
{ color
:#0000cc; }
121 border
-width
: 1px
0px
0px
1px
;
125 .ordsum td
, .ordsum th
{
127 border
-width
: 0px
1px
1px
0px
;
131 /* specifically exclude from printing */
141 <form method
='post' action
='order_manifest.php?orderid=<?php echo $orderid; ?>'>
145 <table width
='100%' cellpadding
='2' cellspacing
='0'>
146 <tr bgcolor
='#cccccc'>
147 <td nowrap
><?php
echo xlt('Patient Name'); ?
></td
>
148 <td
><?php
echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?
></td
>
149 <td nowrap
><?php
echo xlt('Ordered By'); ?
></td
>
150 <td
><?php
echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?
></td
>
152 <tr bgcolor
='#cccccc'>
153 <td width
='5%' nowrap
><?php
echo xlt('MRN (pid)'); ?
></td
>
154 <td width
='45%'><?php
echo myCellText($patient_id); ?
></td
>
155 <td width
='5%' nowrap
><?php
echo xlt('Order ID'); ?
></td
>
156 <td width
='45%'><?php
echo myCellText($orow['procedure_order_id']); ?
></td
>
158 <tr bgcolor
='#cccccc'>
159 <td nowrap
><?php
echo xlt('Encounter Date'); ?
></td
>
160 <td
><?php
echo myCellText(oeFormatShortDate($encdate)); ?
></td
>
161 <td nowrap
><?php
echo xlt('Order Date'); ?
></td
>
162 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?
></td
>
164 <tr bgcolor
='#cccccc'>
165 <td nowrap
><?php
echo xlt('Birth Date'); ?
></td
>
166 <td
><?php
echo myCellText(oeFormatShortDate($orow['DOB'])); ?
></td
>
167 <td nowrap
><?php
echo xlt('Lab'); ?
></td
>
168 <td
><?php
echo myCellText($orow['labname']); ?
></td
>
170 <tr bgcolor
='#cccccc'>
171 <td nowrap
><?php
echo xlt('Sex'); ?
></td
>
172 <td
><?php
echo myCellText(getListItem('sex', $orow['sex'])); ?
></td
>
173 <td nowrap
><?php
echo xlt('Specimen Type'); ?
></td
>
174 <td
><?php
echo myCellText($orow['specimen_type']); ?
></td
>
176 <tr bgcolor
='#cccccc'>
177 <td nowrap
><?php
echo xlt('Address'); ?
></td
>
178 <td
><?php
echo myCellText($orow['street'] . ', ' . $orow['city'] . ', ' . $orow['state'] . ' ' . $orow['postal_code']); ?
></td
>
179 <td nowrap
><?php
echo xlt('Collection Date'); ?
></td
>
180 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_collected'])); ?
></td
>
182 <tr bgcolor
='#cccccc'>
183 <td nowrap
><?php
echo xlt('Ins Name'); ?
></td
>
184 <td
><?php
echo myCellText($ins_name); ?
></td
>
185 <td nowrap
><?php
echo xlt('Clinical History'); ?
></td
>
186 <td
><?php
echo myCellText($orow['clinical_hx']); ?
></td
>
188 <tr bgcolor
='#cccccc'>
189 <td nowrap
><?php
echo xlt('Ins Address'); ?
></td
>
190 <td
><?php
echo myCellText("$ins_addr, $ins_city, $ins_state $ins_zip"); ?
></td
>
191 <td nowrap
><?php
echo xlt('Order Status'); ?
></td
>
192 <td
><?php
echo myCellText(getListItem('ord_status', $orow['order_status'])); ?
></td
>
194 <tr bgcolor
='#cccccc'>
195 <td nowrap
><?php
echo xlt('Ins Policy'); ?
></td
>
196 <td
><?php
echo myCellText($ins_policy); ?
></td
>
197 <td nowrap
><?php
echo xlt('Referrer'); ?
></td
>
198 <td
><?php
echo myCellText($orow['ref_lname'] . ', ' . $orow['ref_fname'] . ' ' . $orow['ref_mname']); ?
></td
>
200 <tr bgcolor
='#cccccc'>
201 <td nowrap
><?php
echo xlt('Ins Group'); ?
></td
>
202 <td
><?php
echo myCellText($ins_group); ?
></td
>
203 <td nowrap
><?php
echo xlt('Referrer Address'); ?
></td
>
204 <td
><?php
echo myCellText($orow['ref_street'] . ', ' . $orow['ref_city'] . ', ' . $orow['ref_state'] . ' ' . $orow['ref_zip']); ?
></td
>
210 <table width
='100%' cellpadding
='2' cellspacing
='0'>
213 <td
><?php
echo xlt('Omit'); ?
></td
>
214 <td
><?php
echo xlt('Code'); ?
></td
>
215 <td
><?php
echo xlt('Description'); ?
></td
>
216 <td
><?php
echo xlt('Diagnoses'); ?
></td
>
217 <td
><?php
echo xlt('Notes'); ?
></td
>
222 "procedure_order_seq, procedure_code, procedure_name, diagnoses, do_not_send " .
223 "FROM procedure_order_code WHERE " .
224 "procedure_order_id = ? ";
225 if (!empty($_POST['bn_show_sendable'])) {
226 $query .= "AND do_not_send = 0 ";
228 $query .= "ORDER BY procedure_order_seq";
229 $res = sqlStatement($query, array($orderid));
233 while ($row = sqlFetchArray($res)) {
234 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
235 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
236 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
237 $diagnoses = empty($row['diagnoses' ]) ?
'' : $row['diagnoses'];
239 // Create a string of HTML representing the procedure answers.
240 // This code cloned from gen_hl7_order.inc.php.
241 // Should maybe refactor it into something like a ProcedureAnswer class.
242 $qres = sqlStatement("SELECT " .
243 "a.question_code, a.answer, q.fldtype, q.question_text " .
244 "FROM procedure_answers AS a " .
245 "LEFT JOIN procedure_questions AS q ON " .
247 "AND q.procedure_code = ? AND " .
248 "q.question_code = a.question_code " .
250 "a.procedure_order_id = ? AND " .
251 "a.procedure_order_seq = ? " .
252 "ORDER BY q.seq, a.answer_seq",
253 array($lab_id, $procedure_code, $orderid, $order_seq));
256 while ($qrow = sqlFetchArray($qres)) {
257 // Formatting of these answer values may be lab-specific and we'll figure
258 // out how to deal with that as more labs are supported.
259 $answer = trim($qrow['answer']);
260 $fldtype = $qrow['fldtype'];
261 if ($fldtype == 'G') {
262 $weeks = intval($answer / 7);
264 $answer = $weeks . 'wks ' . $days . 'days';
266 if ($notes) $notes .= '<br />';
267 $notes .= text($qrow['question_text'] . ': ' . $answer);
269 if ($notes === '') $notes = ' ';
272 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
273 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
274 echo " <td><input type='checkbox' name='form_omit[$order_seq]' value='1'";
275 if (!empty($row['do_not_send'])) echo " checked";
277 echo " <td>" . myCellText("$procedure_code") . "</td>\n";
278 echo " <td>" . myCellText("$procedure_name") . "</td>\n";
279 echo " <td>" . myCellText("$diagnoses") . "</td>\n";
280 echo " <td>$notes</td>\n";
289 <p
class='unprintable'>
290 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save omission selections
'); ?>' />
292 <input type
='submit' name
='bn_show_all' value
='<?php echo xla('Show all procedures
'); ?>' />
294 <input type
='submit' name
='bn_show_sendable' value
='<?php echo xla('Show only procedures not omitted
'); ?>' />
301 } // end function generate_order_summary
303 // Check authorization.
304 $thisauth = acl_check('patients', 'med');
305 if (!$thisauth) die(xl('Not authorized'));
307 $orderid = intval($_GET['orderid']);
311 <?php
html_header_show(); ?
>
312 <link rel
="stylesheet" href
='<?php echo $css_header; ?>' type
='text/css'>
313 <title
><?php
echo xlt('Order Summary'); ?
></title
>
317 font
-family
: sans
-serif
;
324 generate_order_summary($orderid);