4 * Script to display a summary of a given procedure order before it has been processed.
7 * @link https://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Tyler Wrenn <tyler@tylerwrenn.com>
11 * @copyright Copyright (c) 2013, 2016 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2020 Tyler Wrenn <tyler@tylerwrenn.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/options.inc.php");
19 require_once("$srcdir/patient.inc.php");
21 use OpenEMR\Common\Acl\AclMain
;
22 use OpenEMR\Common\Twig\TwigContainer
;
23 use OpenEMR\Core\Header
;
25 // Check authorization.
26 $thisauth = AclMain
::aclCheckCore('patients', 'med');
28 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Order Summary")]);
32 function getListItem($listid, $value)
35 "SELECT title FROM list_options " .
36 "WHERE list_id = ? AND option_id = ? AND activity = 1",
37 array($listid, $value)
39 $tmp = xl_list_label($lrow['title']);
47 function myCellText($s)
56 function generate_order_summary($orderid)
59 // If requested, save checkbox selections as to which procedures are not sendable.
60 if ($_POST['bn_save']) {
62 "UPDATE procedure_order_code " .
63 "SET do_not_send = 0 WHERE " .
64 "procedure_order_id = ? AND " .
68 if (!empty($_POST['form_omit'])) {
69 foreach ($_POST['form_omit'] as $key) {
71 "UPDATE procedure_order_code " .
72 "SET do_not_send = 1 WHERE " .
73 "procedure_order_id = ? AND " .
74 "do_not_send = 0 AND " .
75 "procedure_order_seq = ?",
76 array($orderid, intval($key))
84 "po.procedure_order_id, po.patient_id, po.date_ordered, po.order_status, " .
85 "po.date_collected, po.specimen_type, po.specimen_location, po.lab_id, po.clinical_hx, " .
86 "pd.pubpid, pd.lname, pd.fname, pd.mname, pd.DOB, pd.sex, " .
87 "pd.street, pd.city, pd.state, pd.postal_code, " .
89 "pp.name AS labname, " .
90 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname, " .
91 "ru.lname AS ref_lname, ru.fname AS ref_fname, ru.mname AS ref_mname, " .
92 "ru.street AS ref_street, ru.city AS ref_city, ru.state AS ref_state, ru.zip AS ref_zip " .
93 "FROM procedure_order AS po " .
94 "LEFT JOIN patient_data AS pd ON pd.pid = po.patient_id " .
95 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
96 "LEFT JOIN users AS u ON u.id = po.provider_id " .
97 "LEFT JOIN users AS ru ON ru.id = pd.ref_providerID " .
98 "LEFT JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
99 "WHERE po.procedure_order_id = ?",
103 $lab_id = intval($orow['lab_id']);
104 $patient_id = intval($orow['patient_id']);
105 $encdate = substr($orow['date'], 0, 10);
107 // Get insurance info.
115 $irow = getInsuranceDataByDate(
119 "insd.provider, insd.policy_number, insd.group_number"
121 if (!empty($irow['provider'])) {
122 $ins_policy = $irow['policy_number'];
123 $ins_group = $irow['group_number'];
124 $insco = new InsuranceCompany($irow['provider']);
125 if (!empty($insco)) {
126 $ins_name = $insco->get_name();
127 $tmp = $insco->get_address();
128 $ins_addr = $tmp->get_line1();
129 $ins_city = $tmp->get_city();
130 $ins_state = $tmp->get_state();
131 $ins_zip = $tmp->get_zip();
140 background
-color
: #cccccc;
149 color
: var(--primary
);
154 border
-width
: 1px
0 0 1px
;
155 border
-color
: var(--black
);
161 border
-width
: 0 1px
1px
0;
162 border
-color
: var(--black
);
165 /* specifically exclude from printing */
187 <form method
='post' action
='order_manifest.php?orderid=<?php echo attr_url($orderid); ?>'>
189 <div
class='ordsum table-responsive'>
190 <table
class='table table-active'>
192 <td
class="text-nowrap"><?php
echo xlt('Patient Name'); ?
></td
>
193 <td
><?php
echo myCellText($orow['lname'] . ', ' . $orow['fname'] . ' ' . $orow['mname']); ?
></td
>
194 <td
class="text-nowrap"><?php
echo xlt('Ordered By'); ?
></td
>
195 <td
><?php
echo myCellText($orow['ulname'] . ', ' . $orow['ufname'] . ' ' . $orow['umname']); ?
></td
>
198 <td
class="text-nowrap" width
='5%'><?php
echo xlt('MRN (pid)'); ?
></td
>
199 <td width
='45%'><?php
echo myCellText($patient_id); ?
></td
>
200 <td
class="text-nowrap" width
='5%'><?php
echo xlt('Order ID'); ?
></td
>
201 <td width
='45%'><?php
echo myCellText($orow['procedure_order_id']); ?
></td
>
204 <td
class="text-nowrap"><?php
echo xlt('Encounter Date'); ?
></td
>
205 <td
><?php
echo myCellText(oeFormatShortDate($encdate)); ?
></td
>
206 <td
class="text-nowrap"><?php
echo xlt('Order Date'); ?
></td
>
207 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_ordered'])); ?
></td
>
210 <td
class="text-nowrap"><?php
echo xlt('Birth Date'); ?
></td
>
211 <td
><?php
echo myCellText(oeFormatShortDate($orow['DOB'])); ?
></td
>
212 <td
class="text-nowrap"><?php
echo xlt('Lab'); ?
></td
>
213 <td
><?php
echo myCellText($orow['labname']); ?
></td
>
216 <td
class="text-nowrap"><?php
echo xlt('Sex'); ?
></td
>
217 <td
><?php
echo myCellText(getListItem('sex', $orow['sex'])); ?
></td
>
218 <td
class="text-nowrap"><?php
echo xlt('Specimen Type'); ?
></td
>
219 <td
><?php
echo myCellText($orow['specimen_type']); ?
></td
>
222 <td
class="text-nowrap"><?php
echo xlt('Address'); ?
></td
>
223 <td
><?php
echo myCellText($orow['street'] . ', ' . $orow['city'] . ', ' . $orow['state'] . ' ' . $orow['postal_code']); ?
></td
>
224 <td
class="text-nowrap"><?php
echo xlt('Collection Date'); ?
></td
>
225 <td
><?php
echo myCellText(oeFormatShortDate($orow['date_collected'])); ?
></td
>
228 <td
class="text-nowrap"><?php
echo xlt('Ins Name'); ?
></td
>
229 <td
><?php
echo myCellText($ins_name); ?
></td
>
230 <td
class="text-nowrap"><?php
echo xlt('Clinical History'); ?
></td
>
231 <td
><?php
echo myCellText($orow['clinical_hx']); ?
></td
>
234 <td
class="text-nowrap"><?php
echo xlt('Ins Address'); ?
></td
>
235 <td
><?php
echo myCellText("$ins_addr, $ins_city, $ins_state $ins_zip"); ?
></td
>
236 <td
class="text-nowrap"><?php
echo xlt('Order Status'); ?
></td
>
237 <td
><?php
echo myCellText(getListItem('ord_status', $orow['order_status'])); ?
></td
>
240 <td
class="text-nowrap"><?php
echo xlt('Ins Policy'); ?
></td
>
241 <td
><?php
echo myCellText($ins_policy); ?
></td
>
242 <td
class="text-nowrap"><?php
echo xlt('Referrer'); ?
></td
>
243 <td
><?php
echo myCellText($orow['ref_lname'] . ', ' . $orow['ref_fname'] . ' ' . $orow['ref_mname']); ?
></td
>
246 <td
class="text-nowrap"><?php
echo xlt('Ins Group'); ?
></td
>
247 <td
><?php
echo myCellText($ins_group); ?
></td
>
248 <td
class="text-nowrap"><?php
echo xlt('Referrer Address'); ?
></td
>
249 <td
><?php
echo myCellText($orow['ref_street'] . ', ' . $orow['ref_city'] . ', ' . $orow['ref_state'] . ' ' . $orow['ref_zip']); ?
></td
>
255 <table
class='table'>
258 <th
><?php
echo xlt('Omit'); ?
></th
>
259 <th
><?php
echo xlt('Code'); ?
></th
>
260 <th
><?php
echo xlt('Description'); ?
></th
>
261 <th
><?php
echo xlt('Diagnoses'); ?
></th
>
262 <th
><?php
echo xlt('Notes'); ?
></th
>
268 "procedure_order_seq, procedure_code, procedure_name, diagnoses, do_not_send " .
269 "FROM procedure_order_code WHERE " .
270 "procedure_order_id = ? ";
271 if (!empty($_POST['bn_show_sendable'])) {
272 $query .= "AND do_not_send = 0 ";
275 $query .= "ORDER BY procedure_order_seq";
276 $res = sqlStatement($query, array($orderid));
280 while ($row = sqlFetchArray($res)) {
281 $order_seq = empty($row['procedure_order_seq']) ?
0 : ($row['procedure_order_seq'] +
0);
282 $procedure_code = empty($row['procedure_code' ]) ?
'' : $row['procedure_code'];
283 $procedure_name = empty($row['procedure_name' ]) ?
'' : $row['procedure_name'];
284 $diagnoses = empty($row['diagnoses' ]) ?
'' : $row['diagnoses'];
286 // Create a string of HTML representing the procedure answers.
287 // This code cloned from gen_hl7_order.inc.php.
288 // Should maybe refactor it into something like a ProcedureAnswer class.
289 $qres = sqlStatement(
291 "a.question_code, a.answer, q.fldtype, q.question_text " .
292 "FROM procedure_answers AS a " .
293 "LEFT JOIN procedure_questions AS q ON " .
295 "AND q.procedure_code = ? AND " .
296 "q.question_code = a.question_code " .
298 "a.procedure_order_id = ? AND " .
299 "a.procedure_order_seq = ? " .
300 "ORDER BY q.seq, a.answer_seq",
301 array($lab_id, $procedure_code, $orderid, $order_seq)
305 while ($qrow = sqlFetchArray($qres)) {
306 // Formatting of these answer values may be lab-specific and we'll figure
307 // out how to deal with that as more labs are supported.
308 $answer = trim($qrow['answer']);
309 $fldtype = $qrow['fldtype'];
310 if ($fldtype == 'G') {
311 $weeks = intval($answer / 7);
313 $answer = $weeks . 'wks ' . $days . 'days';
320 $notes .= text($qrow['question_text'] . ': ' . $answer);
328 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
329 echo " <tr class='detail'style='background-color: $bgcolor;'>\n";
330 echo " <td><input type='checkbox' name='form_omit[" . attr($order_seq) . "]' value='1'";
331 if (!empty($row['do_not_send'])) {
336 echo " <td>" . myCellText("$procedure_code") . "</td>\n";
337 echo " <td>" . myCellText("$procedure_name") . "</td>\n";
338 echo " <td>" . myCellText("$diagnoses") . "</td>\n";
339 echo " <td>$notes</td>\n";
346 <div
class='btn-group d-print-none'>
347 <input type
='submit' class='btn btn-primary' name
='bn_save' value
='<?php echo xla('Save omission selections
'); ?>' />
348 <input type
='submit' class='btn btn-primary' name
='bn_show_all' value
='<?php echo xla('Show all procedures
'); ?>' />
349 <input type
='submit' class='btn btn-primary' name
='bn_show_sendable' value
='<?php echo xla('Show only procedures not omitted
'); ?>' />
355 } // end function generate_order_summary
357 $orderid = intval($_GET['orderid']);
361 <?php Header
::setupHeader(); ?
>
362 <title
><?php
echo xlt('Order Summary'); ?
></title
>
366 font
-family
: sans
-serif
;
379 generate_order_summary($orderid);