PHP7 bug fix 4
[openemr.git] / interface / cmsportal / list_requests.php
blob66b4dcd0a119ef96001f6ff8ca5892307658488e
1 <?php
2 /**
3 * Fetch and list pending requests from the WordPress portal.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option) any
10 * later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
17 * @package OpenEMR
18 * @author Rod Roark <rod@sunsetsystems.com>
21 $sanitize_all_escapes = true;
22 $fake_register_globals = false;
24 require_once("../globals.php");
25 require_once("$srcdir/log.inc");
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("portal.inc.php");
32 /**
33 * Get a list item title, translating if required.
35 * @param string $listid List identifier.
36 * @param string $value List item identifier.
37 * @return string The item's title.
39 function getListItem($listid, $value) {
40 $lrow = sqlQuery("SELECT title FROM list_options " .
41 "WHERE list_id = ? AND option_id = ?",
42 array($listid, $value));
43 $tmp = xl_list_label($lrow['title']);
44 if (empty($tmp)) $tmp = "($report_status)";
45 return $tmp;
48 /**
49 * Adapt text to be suitable as the contents of a table cell.
51 * @param string $s Input text.
52 * @return string Output text.
54 function myCellText($s) {
55 if ($s === '') return '&nbsp;';
56 return text($s);
59 // Get patient name from OpenEMR, or empty if not there.
60 function patientNameFromLogin($login) {
61 $ptname = '';
62 if ($login) {
63 $tmp = sqlQuery("SELECT fname, lname, mname, pid " .
64 "FROM patient_data WHERE cmsportal_login = ? ORDER BY id LIMIT 1",
65 array($login));
66 if (!empty($tmp['pid'])) {
67 $ptname = $tmp['lname'];
68 if ($tmp['fname'] || $tmp['mname']) $ptname .= ',';
69 if ($tmp['fname']) $ptname .= ' ' . $tmp['fname'];
70 if ($tmp['mname']) $ptname .= ' ' . $tmp['mname'];
73 return $ptname;
76 // Check authorization.
77 $thisauth = acl_check('patients', 'med');
78 if (!$thisauth) die(xlt('Not authorized'));
80 $errmsg = '';
82 // If Delete clicked, delete selected posts/messages from the portal.
83 if (!empty($_POST['bn_delete'])) {
84 if (is_array($_POST['form_req_cb'])) {
85 foreach ($_POST['form_req_cb'] as $postid) {
86 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
87 if ($result['errmsg']) {
88 die(text($result['errmsg']));
92 if (is_array($_POST['form_msg_cb'])) {
93 foreach ($_POST['form_msg_cb'] as $messageid) {
94 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
95 if ($result['errmsg']) {
96 die(text($result['errmsg']));
102 <html>
103 <head>
104 <?php html_header_show();?>
106 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
107 <title><?php echo xlt('Portal Requests'); ?></title>
109 <style>
111 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
112 tr.detail { font-size:10pt; }
113 a, a:visited, a:hover { color:#0000cc; }
115 </style>
117 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
118 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
119 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
120 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
122 <script type="text/javascript" src="../../library/dialog.js"></script>
123 <script type="text/javascript" src="../../library/textformat.js"></script>
125 <script language="JavaScript">
127 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
129 function myRestoreSession() {
130 // This works whether we are a popup or in the OpenEMR frameset.
131 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
132 return true;
135 function openRequest(postid, type) {
136 myRestoreSession();
137 // To open results in a new window. The options parameter serves to defeat
138 // Firefox's "open windows in a new tab".
139 // window.open('single_order_results.php?orderid=' + orderid, '_blank',
140 // 'toolbar=0,location=0,menubar=0,scrollbars=yes');
142 // To open results in the same frame:
143 if (type.indexOf('Demographics') == 0) {
144 document.location.href = 'patient_select.php?postid=' + postid;
145 } else
146 if (type.indexOf('Insurance') == 0) {
147 document.location.href = 'insurance_form.php?postid=' + postid;
148 } else
149 if (type.indexOf('History') == 0) {
150 document.location.href = 'history_form.php?postid=' + postid;
151 } else
152 if (type.indexOf('Issue') == 0) {
153 document.location.href = 'issue_form.php?postid=' + postid;
154 } else
155 if (type.indexOf('LBF') == 0) {
156 document.location.href = 'lbf_form.php?postid=' + postid;
157 } else
158 if (type.indexOf('Upload') == 0) {
159 document.location.href = 'upload_form.php?postid=' + postid;
160 } else
162 // TBD: more types to be handled
165 alert('<?php echo xla('Request type not implemented') ?>: ' + type);
168 // To open results in the "other" frame:
169 // var w = window;
170 // var othername = (w.name == 'RTop') ? 'RBot' : 'RTop';
171 // w.parent.left_nav.forceDual();
172 // w.parent.left_nav.setRadio(othername, 'ore');
173 // w.parent.left_nav.loadFrame('ore1', othername, 'orders/single_order_results.php?orderid=' + orderid);
176 function openMessage(messageid) {
177 myRestoreSession();
178 document.location.href = 'upload_form.php?messageid=' + messageid;
181 </script>
183 </head>
185 <body class="body_top">
186 <form method='post' action='list_requests.php' onsubmit='return myRestoreSession()'>
188 <?php
189 $form_from_date = empty($_POST['form_from_date']) ? '' : trim($_POST['form_from_date']);
190 $form_to_date = empty($_POST['form_to_date']) ? '' : trim($_POST['form_to_date']);
191 // if (empty($form_to_date)) $form_to_date = $form_from_date;
193 $form_patient = !empty($_POST['form_patient']);
195 // Post a form to the WP portal that asks for the request list and get the response.
196 // Write a row for each request that is reported.
198 $result = cms_portal_call(array(
199 'action' => 'list',
200 'date_from' => $form_from_date,
201 'date_to' => $form_to_date,
204 if ($result['errmsg']) {
205 echo "<font color='red'>" . text($result['errmsg']) . "</font><br />\n";
208 <center>
210 <table width='100%'>
211 <tr>
212 <td class='text' align='center'>
213 <?php echo xlt('From'); ?>:
214 <input type='text' size='8' name='form_from_date' id='form_from_date'
215 value='<?php echo attr($form_from_date); ?>'
216 title='<?php echo xla('yyyy-mm-dd'); ?>'
217 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
218 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
219 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
220 title='<?php echo xla('Click here to choose a date'); ?>' />
221 &nbsp;
222 <?php echo xlt('To'); ?>:
223 <input type='text' size='8' name='form_to_date' id='form_to_date'
224 value='<?php echo attr($form_to_date); ?>'
225 title='<?php echo xla('yyyy-mm-dd'); ?>'
226 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
227 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
228 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
229 title='<?php echo xla('Click here to choose a date'); ?>' />
230 &nbsp;
231 <input type='submit' name='form_refresh' value=<?php echo xla('Submit'); ?>>
232 </td>
233 </tr>
234 </table>
236 <table width='100%' cellpadding='1' cellspacing='2'>
238 <tr class='head'>
239 <th colspan='2'><?php echo xlt('Patient'); ?></td>
240 <th colspan='3'><?php echo xlt('CMS Portal Request'); ?></td>
241 </tr>
243 <tr class='head'>
244 <th><?php echo xlt('Portal ID' ); ?></td>
245 <th><?php echo xlt('Name in EMR' ); ?></td>
246 <th><?php echo xlt('Date/Time' ); ?></td>
247 <th><?php echo xlt('Request Type'); ?></td>
248 <th><?php echo xlt('Delete' ); ?></td>
249 </tr>
251 <?php
252 // Generate a table row for each pending portal request or message.
253 // This logic merges requests with messages by date.
254 $v1 = each($result['list']);
255 $v2 = each($result['messages']);
256 while ($v1 || $v2) {
257 echo " <tr class='detail' bgcolor='#ddddff'>\n";
258 if (!$v2 || $v1 && $v1[1]['datetime'] < $v2[1]['datetime']) {
259 $postid = $v1[1]['postid'];
260 $ptname = patientNameFromLogin($v1[1]['user']);
261 echo " <td>" . text($v1[1]['user']) . "</td>\n";
262 echo " <td>" . text($ptname ) . "</td>\n";
263 echo " <td style='cursor:pointer;color:blue;'";
264 echo " onclick=\"openRequest(" .
265 "'" . addslashes($postid) . "'," .
266 "'" . addslashes($v1[1]['type']) . "'" .
267 ")\">" . text($v1[1]['datetime']) . "</td>\n";
268 echo " <td>" . text($v1[1]['type' ]) . "</td>\n";
269 echo " <td align='center'><input type='checkbox' name='form_req_cb[" .
270 attr($postid) . "]' value='" . attr($postid) . "' /></td>\n";
271 $v1 = each($result['list']);
273 else {
274 $messageid = $v2[1]['messageid'];
275 $ptname = patientNameFromLogin($v2[1]['user']);
276 echo " <td>" . text($v2[1]['user']) . "</td>\n";
277 echo " <td>" . text($ptname ) . "</td>\n";
278 echo " <td style='cursor:pointer;color:blue;'";
279 echo " onclick=\"openMessage(" .
280 "'" . addslashes($messageid) . "'" .
281 ")\">" . text($v2[1]['datetime']) . "</td>\n";
282 echo " <td>" . text($v2[1]['user'] == $v2[1]['fromuser'] ?
283 xl('Message from patient') : xl('Message to patient')) . "</td>\n";
284 echo " <td align='center'><input type='checkbox' name='form_msg_cb[" .
285 attr($messageid) . "]' value='" . attr($messageid) . "' /></td>\n";
286 $v2 = each($result['messages']);
288 echo " </tr>\n";
292 </table>
295 <input type='button' value='<?php echo xla('Close Window'); ?>' onclick="window.close();" />
296 &nbsp;
297 <input type='submit' name='bn_delete' value='<?php echo xla('Delete Selected Requests'); ?>' />
298 </p>
300 </center>
302 <script language='JavaScript'>
304 // Initialize calendar widgets for "from" and "to" dates.
305 Calendar.setup({inputField:'form_from_date', ifFormat:'%Y-%m-%d',
306 button:'img_from_date'});
307 Calendar.setup({inputField:'form_to_date', ifFormat:'%Y-%m-%d',
308 button:'img_to_date'});
310 </script>
312 </form>
313 </body>
314 </html>