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