fix: Smarty cal php82 warnings (#6316)
[openemr.git] / interface / orders / order_manifest.php
blob1f809636257fde80780a4c85ecd8646baa3d3afc
1 <?php
3 /**
4 * Script to display a summary of a given procedure order before it has been processed.
6 * @package OpenEMR
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');
27 if (!$thisauth) {
28 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Order Summary")]);
29 exit;
32 function getListItem($listid, $value)
34 $lrow = sqlQuery(
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']);
40 if (empty($tmp)) {
41 $tmp = "($value)";
44 return $tmp;
47 function myCellText($s)
49 if ($s === '') {
50 return '&nbsp;';
53 return text($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']) {
61 sqlStatement(
62 "UPDATE procedure_order_code " .
63 "SET do_not_send = 0 WHERE " .
64 "procedure_order_id = ? AND " .
65 "do_not_send != 0",
66 array($orderid)
68 if (!empty($_POST['form_omit'])) {
69 foreach ($_POST['form_omit'] as $key) {
70 sqlStatement(
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))
82 $orow = sqlQuery(
83 "SELECT " .
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, " .
88 "fe.date, " .
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 = ?",
100 array($orderid)
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.
108 $ins_policy = '';
109 $ins_group = '';
110 $ins_name = '';
111 $ins_addr = '';
112 $ins_city = '';
113 $ins_state = '';
114 $ins_zip = '';
115 $irow = getInsuranceDataByDate(
116 $patient_id,
117 $encdate,
118 'primary',
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();
136 <style>
138 .ordsum tr.head {
139 font-size: 13px;
140 background-color: #cccccc;
141 text-align: center;
143 .ordsum tr.detail {
144 font-size: 13px;
146 .ordsum a,
147 .ordsum a:visited,
148 .ordsum a:hover {
149 color: var(--primary);
152 .ordsum table {
153 border-style: solid;
154 border-width: 1px 0 0 1px;
155 border-color: var(--black);
158 .ordsum td,
159 .ordsum th {
160 border-style: solid;
161 border-width: 0 1px 1px 0;
162 border-color: var(--black);
165 /* specifically exclude from printing */
166 @media print {
167 .ordsum tr.head {
168 font-size: 10pt;
171 .ordsum tr.detail {
172 font-size: 10pt;
175 .ordsum table {
176 border-color: black;
179 .ordsum td,
180 .ordsum th {
181 border-color: black;
185 </style>
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'>
191 <tr>
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>
196 </tr>
197 <tr>
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>
202 </tr>
203 <tr>
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>
208 </tr>
209 <tr>
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>
214 </tr>
215 <tr>
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>
220 </tr>
221 <tr>
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>
226 </tr>
227 <tr>
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>
232 </tr>
233 <tr>
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>
238 </tr>
239 <tr>
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>
244 </tr>
245 <tr>
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>
250 </tr>
251 </table>
253 <br />
255 <table class='table'>
256 <thead>
257 <tr class='head'>
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>
263 </tr>
264 </thead>
266 <?php
267 $query = "SELECT " .
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));
278 $encount = 0;
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(
290 "SELECT " .
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 " .
294 "q.lab_id = ? " .
295 "AND q.procedure_code = ? AND " .
296 "q.question_code = a.question_code " .
297 "WHERE " .
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)
304 $notes = '';
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);
312 $days = $answer % 7;
313 $answer = $weeks . 'wks ' . $days . 'days';
316 if ($notes) {
317 $notes .= '<br />';
320 $notes .= text($qrow['question_text'] . ': ' . $answer);
323 if ($notes === '') {
324 $notes = '&nbsp;';
327 ++$encount;
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'])) {
332 echo " checked";
335 echo " /></td>\n";
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";
340 echo " </tr>\n";
343 </table>
344 </div>
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'); ?>' />
350 </div>
352 </form>
354 <?php
355 } // end function generate_order_summary
357 $orderid = intval($_GET['orderid']);
359 <html>
360 <head>
361 <?php Header::setupHeader(); ?>
362 <title><?php echo xlt('Order Summary'); ?></title>
363 <style>
364 body {
365 margin: 0.75rem;
366 font-family: sans-serif;
367 font-size: 1rem;
369 @media print {
370 body {
371 margin: 9pt;
372 font-size: 12pt;
375 </style>
376 </head>
377 <body>
378 <?php
379 generate_order_summary($orderid);
381 </body>
382 </html>