3 * Script to display a summary of a given procedure order before it has been processed.
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("$srcdir/patient.inc");
31 require_once("$srcdir/classes/InsuranceCompany.class.php");
33 function getListItem($listid, $value) {
34 $lrow = sqlQuery("SELECT title FROM list_options " .
35 "WHERE list_id = ? AND option_id = ?",
36 array($listid, $value));
37 $tmp = xl_list_label($lrow['title']);
38 if (empty($tmp)) $tmp = "($value)";
42 function myCellText($s) {
43 if ($s === '') return ' ';
47 function generate_order_summary($orderid) {
49 // If requested, save checkbox selections as to which procedures are not sendable.
50 if ($_POST['bn_save']) {
51 sqlStatement("UPDATE procedure_order_code " .
52 "SET do_not_send = 0 WHERE " .
53 "procedure_order_id = ? AND " .
56 if (!empty($_POST['form_omit'])) {
57 foreach ($_POST['form_omit'] as $key) {
58 sqlStatement("UPDATE procedure_order_code " .
59 "SET do_not_send = 1 WHERE " .
60 "procedure_order_id = ? AND " .
61 "do_not_send = 0 AND " .
62 "procedure_order_seq = ?",
63 array($orderid, intval($key)));
68 $orow = sqlQuery("SELECT " .
69 "po.procedure_order_id, po.patient_id, po.date_ordered, po.order_status, " .
70 "po.date_collected, po.specimen_type, po.specimen_location, po.lab_id, po.clinical_hx, " .
71 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.DOB, pd.sex, " .
72 "pd.street, pd.city, pd.state, pd.postal_code, " .
74 "pp.name AS labname, " .
75 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname, " .
76 "ru.lname AS ref_lname, ru.fname AS ref_fname, ru.mname AS ref_mname, " .
77 "ru.street AS ref_street, ru.city AS ref_city, ru.state AS ref_state, ru.zip AS ref_zip " .
78 "FROM procedure_order AS po " .
79 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
80 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
81 "LEFT JOIN users AS u ON u.id = po.provider_id " .
82 "LEFT JOIN users AS ru ON ru.id = pd.ref_providerID " .
83 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
84 "WHERE po.procedure_order_id = ?",
87 $lab_id = intval($orow['lab_id']);
88 $patient_id = intval($orow['patient_id']);
89 $encdate = substr($orow['date'], 0, 10);
91 // Get insurance info.
99 $irow = getInsuranceDataByDate($patient_id, $encdate, 'primary',
100 "insd.provider, insd.policy_number, insd.group_number");
101 if (!empty($irow['provider'])) {
102 $ins_policy = $irow['policy_number'];
103 $ins_group = $irow['group_number'];
104 $insco = new InsuranceCompany($irow['provider']);
105 if (!empty($insco)) {
106 $ins_name = $insco->get_name();
107 $tmp = $insco->get_address();
108 $ins_addr = $tmp->get_line1();
109 $ins_city = $tmp->get_city();
110 $ins_state = $tmp->get_state();
111 $ins_zip = $tmp->get_zip();
118 .ordsum tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
119 .ordsum tr
.detail
{ font
-size
:10pt
; }
120 .ordsum a
, .ordsum a
:visited
, .ordsum a
:hover
{ color
:#0000cc; }
124 border
-width
: 1px
0px
0px
1px
;
128 .ordsum td
, .ordsum th
{
130 border
-width
: 0px
1px
1px
0px
;
134 /* specifically exclude from printing */
144 <form method
='post' action
='order_manifest.php?orderid=<?php echo $orderid; ?>'>
148 <table width
='100%' cellpadding
='2' cellspacing
='0'>
149 <tr bgcolor
='#cccccc'>
150 <td nowrap
><?php
echo xlt('Patient Name'); ?
></td
>
151 <td
><?php
echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?
></td
>
152 <td nowrap
><?php
echo xlt('Ordered By'); ?
></td
>
153 <td
><?php
echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?
></td
>
155 <tr bgcolor
='#cccccc'>
156 <td width
='5%' nowrap
><?php
echo xlt('MRN (pid)'); ?
></td
>
157 <td width
='45%'><?php
echo myCellText($patient_id); ?
></td
>
158 <td width
='5%' nowrap
><?php
echo xlt('Order ID'); ?
></td
>
159 <td width
='45%'><?php
echo myCellText($orow['procedure_order_id']); ?
></td
>
161 <tr bgcolor
='#cccccc'>
162 <td nowrap
><?php
echo xlt('Encounter Date'); ?
></td
>
163 <td
><?php
echo myCellText(oeFormatShortDate($encdate)); ?
></td
>
164 <td nowrap
><?php
echo xlt('Order Date'); ?
></td
>
165 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?
></td
>
167 <tr bgcolor
='#cccccc'>
168 <td nowrap
><?php
echo xlt('Birth Date'); ?
></td
>
169 <td
><?php
echo myCellText(oeFormatShortDate($orow['DOB'])); ?
></td
>
170 <td nowrap
><?php
echo xlt('Lab'); ?
></td
>
171 <td
><?php
echo myCellText($orow['labname']); ?
></td
>
173 <tr bgcolor
='#cccccc'>
174 <td nowrap
><?php
echo xlt('Sex'); ?
></td
>
175 <td
><?php
echo myCellText(getListItem('sex', $orow['sex'])); ?
></td
>
176 <td nowrap
><?php
echo xlt('Specimen Type'); ?
></td
>
177 <td
><?php
echo myCellText($orow['specimen_type']); ?
></td
>
179 <tr bgcolor
='#cccccc'>
180 <td nowrap
><?php
echo xlt('Address'); ?
></td
>
181 <td
><?php
echo myCellText($orow['street'] . ', ' . $orow['city'] . ', ' . $orow['state'] . ' ' . $orow['postal_code']); ?
></td
>
182 <td nowrap
><?php
echo xlt('Collection Date'); ?
></td
>
183 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_collected'])); ?
></td
>
185 <tr bgcolor
='#cccccc'>
186 <td nowrap
><?php
echo xlt('Ins Name'); ?
></td
>
187 <td
><?php
echo myCellText($ins_name); ?
></td
>
188 <td nowrap
><?php
echo xlt('Clinical History'); ?
></td
>
189 <td
><?php
echo myCellText($orow['clinical_hx']); ?
></td
>
191 <tr bgcolor
='#cccccc'>
192 <td nowrap
><?php
echo xlt('Ins Address'); ?
></td
>
193 <td
><?php
echo myCellText("$ins_addr, $ins_city, $ins_state $ins_zip"); ?
></td
>
194 <td nowrap
><?php
echo xlt('Order Status'); ?
></td
>
195 <td
><?php
echo myCellText(getListItem('ord_status', $orow['order_status'])); ?
></td
>
197 <tr bgcolor
='#cccccc'>
198 <td nowrap
><?php
echo xlt('Ins Policy'); ?
></td
>
199 <td
><?php
echo myCellText($ins_policy); ?
></td
>
200 <td nowrap
><?php
echo xlt('Referrer'); ?
></td
>
201 <td
><?php
echo myCellText($orow['ref_lname'] . ', ' . $orow['ref_fname'] . ' ' . $orow['ref_mname']); ?
></td
>
203 <tr bgcolor
='#cccccc'>
204 <td nowrap
><?php
echo xlt('Ins Group'); ?
></td
>
205 <td
><?php
echo myCellText($ins_group); ?
></td
>
206 <td nowrap
><?php
echo xlt('Referrer Address'); ?
></td
>
207 <td
><?php
echo myCellText($orow['ref_street'] . ', ' . $orow['ref_city'] . ', ' . $orow['ref_state'] . ' ' . $orow['ref_zip']); ?
></td
>
213 <table width
='100%' cellpadding
='2' cellspacing
='0'>
216 <td
><?php
echo xlt('Omit'); ?
></td
>
217 <td
><?php
echo xlt('Code'); ?
></td
>
218 <td
><?php
echo xlt('Description'); ?
></td
>
219 <td
><?php
echo xlt('Diagnoses'); ?
></td
>
220 <td
><?php
echo xlt('Notes'); ?
></td
>
225 "procedure_order_seq, procedure_code, procedure_name, diagnoses, do_not_send " .
226 "FROM procedure_order_code WHERE " .
227 "procedure_order_id = ? ";
228 if (!empty($_POST['bn_show_sendable'])) {
229 $query .= "AND do_not_send = 0 ";
231 $query .= "ORDER BY procedure_order_seq";
232 $res = sqlStatement($query, array($orderid));
236 while ($row = sqlFetchArray($res)) {
237 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
238 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
239 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
240 $diagnoses = empty($row['diagnoses' ]) ?
'' : $row['diagnoses'];
242 // Create a string of HTML representing the procedure answers.
243 // This code cloned from gen_hl7_order.inc.php.
244 // Should maybe refactor it into something like a ProcedureAnswer class.
245 $qres = sqlStatement("SELECT " .
246 "a.question_code, a.answer, q.fldtype, q.question_text " .
247 "FROM procedure_answers AS a " .
248 "LEFT JOIN procedure_questions AS q ON " .
250 "AND q.procedure_code = ? AND " .
251 "q.question_code = a.question_code " .
253 "a.procedure_order_id = ? AND " .
254 "a.procedure_order_seq = ? " .
255 "ORDER BY q.seq, a.answer_seq",
256 array($lab_id, $procedure_code, $orderid, $order_seq));
259 while ($qrow = sqlFetchArray($qres)) {
260 // Formatting of these answer values may be lab-specific and we'll figure
261 // out how to deal with that as more labs are supported.
262 $answer = trim($qrow['answer']);
263 $fldtype = $qrow['fldtype'];
264 if ($fldtype == 'G') {
265 $weeks = intval($answer / 7);
267 $answer = $weeks . 'wks ' . $days . 'days';
269 if ($notes) $notes .= '<br />';
270 $notes .= text($qrow['question_text'] . ': ' . $answer);
272 if ($notes === '') $notes = ' ';
275 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
276 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
277 echo " <td><input type='checkbox' name='form_omit[$order_seq]' value='1'";
278 if (!empty($row['do_not_send'])) echo " checked";
280 echo " <td>" . myCellText("$procedure_code") . "</td>\n";
281 echo " <td>" . myCellText("$procedure_name") . "</td>\n";
282 echo " <td>" . myCellText("$diagnoses") . "</td>\n";
283 echo " <td>$notes</td>\n";
292 <p
class='unprintable'>
293 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save omission selections
'); ?>' />
295 <input type
='submit' name
='bn_show_all' value
='<?php echo xla('Show all procedures
'); ?>' />
297 <input type
='submit' name
='bn_show_sendable' value
='<?php echo xla('Show only procedures not omitted
'); ?>' />
304 } // end function generate_order_summary
306 // Check authorization.
307 $thisauth = acl_check('patients', 'med');
308 if (!$thisauth) die(xl('Not authorized'));
310 $orderid = intval($_GET['orderid']);
314 <?php
html_header_show(); ?
>
315 <link rel
="stylesheet" href
='<?php echo $css_header; ?>' type
='text/css'>
316 <title
><?php
echo xlt('Order Summary'); ?
></title
>
320 font
-family
: sans
-serif
;
327 generate_order_summary($orderid);