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>
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)
33 "SELECT title FROM list_options " .
34 "WHERE list_id = ? AND option_id = ? AND activity = 1",
35 array($listid, $value)
37 $tmp = xl_list_label($lrow['title']);
45 function myCellText($s)
54 function generate_order_summary($orderid)
57 // If requested, save checkbox selections as to which procedures are not sendable.
58 if ($_POST['bn_save']) {
60 "UPDATE procedure_order_code " .
61 "SET do_not_send = 0 WHERE " .
62 "procedure_order_id = ? AND " .
66 if (!empty($_POST['form_omit'])) {
67 foreach ($_POST['form_omit'] as $key) {
69 "UPDATE procedure_order_code " .
70 "SET do_not_send = 1 WHERE " .
71 "procedure_order_id = ? AND " .
72 "do_not_send = 0 AND " .
73 "procedure_order_seq = ?",
74 array($orderid, intval($key))
82 "po.procedure_order_id, po.patient_id, po.date_ordered, po.order_status, " .
83 "po.date_collected, po.specimen_type, po.specimen_location, po.lab_id, po.clinical_hx, " .
84 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.DOB, pd.sex, " .
85 "pd.street, pd.city, pd.state, pd.postal_code, " .
87 "pp.name AS labname, " .
88 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname, " .
89 "ru.lname AS ref_lname, ru.fname AS ref_fname, ru.mname AS ref_mname, " .
90 "ru.street AS ref_street, ru.city AS ref_city, ru.state AS ref_state, ru.zip AS ref_zip " .
91 "FROM procedure_order AS po " .
92 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
93 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
94 "LEFT JOIN users AS u ON u.id = po.provider_id " .
95 "LEFT JOIN users AS ru ON ru.id = pd.ref_providerID " .
96 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
97 "WHERE po.procedure_order_id = ?",
101 $lab_id = intval($orow['lab_id']);
102 $patient_id = intval($orow['patient_id']);
103 $encdate = substr($orow['date'], 0, 10);
105 // Get insurance info.
113 $irow = getInsuranceDataByDate(
117 "insd.provider, insd.policy_number, insd.group_number"
119 if (!empty($irow['provider'])) {
120 $ins_policy = $irow['policy_number'];
121 $ins_group = $irow['group_number'];
122 $insco = new InsuranceCompany($irow['provider']);
123 if (!empty($insco)) {
124 $ins_name = $insco->get_name();
125 $tmp = $insco->get_address();
126 $ins_addr = $tmp->get_line1();
127 $ins_city = $tmp->get_city();
128 $ins_state = $tmp->get_state();
129 $ins_zip = $tmp->get_zip();
136 .ordsum tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
137 .ordsum tr
.detail
{ font
-size
:10pt
; }
138 .ordsum a
, .ordsum a
:visited
, .ordsum a
:hover
{ color
:#0000cc; }
142 border
-width
: 1px
0px
0px
1px
;
146 .ordsum td
, .ordsum th
{
148 border
-width
: 0px
1px
1px
0px
;
152 /* specifically exclude from printing */
162 <form method
='post' action
='order_manifest.php?orderid=<?php echo $orderid; ?>'>
166 <table width
='100%' cellpadding
='2' cellspacing
='0'>
167 <tr bgcolor
='#cccccc'>
168 <td nowrap
><?php
echo xlt('Patient Name'); ?
></td
>
169 <td
><?php
echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?
></td
>
170 <td nowrap
><?php
echo xlt('Ordered By'); ?
></td
>
171 <td
><?php
echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?
></td
>
173 <tr bgcolor
='#cccccc'>
174 <td width
='5%' nowrap
><?php
echo xlt('MRN (pid)'); ?
></td
>
175 <td width
='45%'><?php
echo myCellText($patient_id); ?
></td
>
176 <td width
='5%' nowrap
><?php
echo xlt('Order ID'); ?
></td
>
177 <td width
='45%'><?php
echo myCellText($orow['procedure_order_id']); ?
></td
>
179 <tr bgcolor
='#cccccc'>
180 <td nowrap
><?php
echo xlt('Encounter Date'); ?
></td
>
181 <td
><?php
echo myCellText(oeFormatShortDate($encdate)); ?
></td
>
182 <td nowrap
><?php
echo xlt('Order Date'); ?
></td
>
183 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?
></td
>
185 <tr bgcolor
='#cccccc'>
186 <td nowrap
><?php
echo xlt('Birth Date'); ?
></td
>
187 <td
><?php
echo myCellText(oeFormatShortDate($orow['DOB'])); ?
></td
>
188 <td nowrap
><?php
echo xlt('Lab'); ?
></td
>
189 <td
><?php
echo myCellText($orow['labname']); ?
></td
>
191 <tr bgcolor
='#cccccc'>
192 <td nowrap
><?php
echo xlt('Sex'); ?
></td
>
193 <td
><?php
echo myCellText(getListItem('sex', $orow['sex'])); ?
></td
>
194 <td nowrap
><?php
echo xlt('Specimen Type'); ?
></td
>
195 <td
><?php
echo myCellText($orow['specimen_type']); ?
></td
>
197 <tr bgcolor
='#cccccc'>
198 <td nowrap
><?php
echo xlt('Address'); ?
></td
>
199 <td
><?php
echo myCellText($orow['street'] . ', ' . $orow['city'] . ', ' . $orow['state'] . ' ' . $orow['postal_code']); ?
></td
>
200 <td nowrap
><?php
echo xlt('Collection Date'); ?
></td
>
201 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_collected'])); ?
></td
>
203 <tr bgcolor
='#cccccc'>
204 <td nowrap
><?php
echo xlt('Ins Name'); ?
></td
>
205 <td
><?php
echo myCellText($ins_name); ?
></td
>
206 <td nowrap
><?php
echo xlt('Clinical History'); ?
></td
>
207 <td
><?php
echo myCellText($orow['clinical_hx']); ?
></td
>
209 <tr bgcolor
='#cccccc'>
210 <td nowrap
><?php
echo xlt('Ins Address'); ?
></td
>
211 <td
><?php
echo myCellText("$ins_addr, $ins_city, $ins_state $ins_zip"); ?
></td
>
212 <td nowrap
><?php
echo xlt('Order Status'); ?
></td
>
213 <td
><?php
echo myCellText(getListItem('ord_status', $orow['order_status'])); ?
></td
>
215 <tr bgcolor
='#cccccc'>
216 <td nowrap
><?php
echo xlt('Ins Policy'); ?
></td
>
217 <td
><?php
echo myCellText($ins_policy); ?
></td
>
218 <td nowrap
><?php
echo xlt('Referrer'); ?
></td
>
219 <td
><?php
echo myCellText($orow['ref_lname'] . ', ' . $orow['ref_fname'] . ' ' . $orow['ref_mname']); ?
></td
>
221 <tr bgcolor
='#cccccc'>
222 <td nowrap
><?php
echo xlt('Ins Group'); ?
></td
>
223 <td
><?php
echo myCellText($ins_group); ?
></td
>
224 <td nowrap
><?php
echo xlt('Referrer Address'); ?
></td
>
225 <td
><?php
echo myCellText($orow['ref_street'] . ', ' . $orow['ref_city'] . ', ' . $orow['ref_state'] . ' ' . $orow['ref_zip']); ?
></td
>
231 <table width
='100%' cellpadding
='2' cellspacing
='0'>
234 <td
><?php
echo xlt('Omit'); ?
></td
>
235 <td
><?php
echo xlt('Code'); ?
></td
>
236 <td
><?php
echo xlt('Description'); ?
></td
>
237 <td
><?php
echo xlt('Diagnoses'); ?
></td
>
238 <td
><?php
echo xlt('Notes'); ?
></td
>
243 "procedure_order_seq, procedure_code, procedure_name, diagnoses, do_not_send " .
244 "FROM procedure_order_code WHERE " .
245 "procedure_order_id = ? ";
246 if (!empty($_POST['bn_show_sendable'])) {
247 $query .= "AND do_not_send = 0 ";
250 $query .= "ORDER BY procedure_order_seq";
251 $res = sqlStatement($query, array($orderid));
255 while ($row = sqlFetchArray($res)) {
256 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
257 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
258 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
259 $diagnoses = empty($row['diagnoses' ]) ?
'' : $row['diagnoses'];
261 // Create a string of HTML representing the procedure answers.
262 // This code cloned from gen_hl7_order.inc.php.
263 // Should maybe refactor it into something like a ProcedureAnswer class.
264 $qres = sqlStatement(
266 "a.question_code, a.answer, q.fldtype, q.question_text " .
267 "FROM procedure_answers AS a " .
268 "LEFT JOIN procedure_questions AS q ON " .
270 "AND q.procedure_code = ? AND " .
271 "q.question_code = a.question_code " .
273 "a.procedure_order_id = ? AND " .
274 "a.procedure_order_seq = ? " .
275 "ORDER BY q.seq, a.answer_seq",
276 array($lab_id, $procedure_code, $orderid, $order_seq)
280 while ($qrow = sqlFetchArray($qres)) {
281 // Formatting of these answer values may be lab-specific and we'll figure
282 // out how to deal with that as more labs are supported.
283 $answer = trim($qrow['answer']);
284 $fldtype = $qrow['fldtype'];
285 if ($fldtype == 'G') {
286 $weeks = intval($answer / 7);
288 $answer = $weeks . 'wks ' . $days . 'days';
295 $notes .= text($qrow['question_text'] . ': ' . $answer);
303 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
304 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
305 echo " <td><input type='checkbox' name='form_omit[$order_seq]' value='1'";
306 if (!empty($row['do_not_send'])) {
311 echo " <td>" . myCellText("$procedure_code") . "</td>\n";
312 echo " <td>" . myCellText("$procedure_name") . "</td>\n";
313 echo " <td>" . myCellText("$diagnoses") . "</td>\n";
314 echo " <td>$notes</td>\n";
323 <p
class='unprintable'>
324 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save omission selections
'); ?>' />
326 <input type
='submit' name
='bn_show_all' value
='<?php echo xla('Show all procedures
'); ?>' />
328 <input type
='submit' name
='bn_show_sendable' value
='<?php echo xla('Show only procedures not omitted
'); ?>' />
335 } // end function generate_order_summary
337 // Check authorization.
338 $thisauth = acl_check('patients', 'med');
340 die(xl('Not authorized'));
343 $orderid = intval($_GET['orderid']);
347 <?php
html_header_show(); ?
>
348 <link rel
="stylesheet" href
='<?php echo $css_header; ?>' type
='text/css'>
349 <title
><?php
echo xlt('Order Summary'); ?
></title
>
353 font
-family
: sans
-serif
;
360 generate_order_summary($orderid);