consolidate attr_url function (#2143)
[openemr.git] / interface / cmsportal / list_requests.php
blobd1fc0b501c271687074474693bebe45829544b83
1 <?php
2 /**
3 * Fetch and list pending requests from the WordPress portal.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2014 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/log.inc");
17 require_once("$srcdir/acl.inc");
18 require_once("$srcdir/options.inc.php");
19 require_once("portal.inc.php");
21 /**
22 * Get a list item title, translating if required.
24 * @param string $listid List identifier.
25 * @param string $value List item identifier.
26 * @return string The item's title.
28 function getListItem($listid, $value)
30 $lrow = sqlQuery(
31 "SELECT title FROM list_options " .
32 "WHERE list_id = ? AND option_id = ? AND activity = 1",
33 array($listid, $value)
35 $tmp = xl_list_label($lrow['title']);
36 if (empty($tmp)) {
37 $tmp = "($report_status)";
40 return $tmp;
43 /**
44 * Adapt text to be suitable as the contents of a table cell.
46 * @param string $s Input text.
47 * @return string Output text.
49 function myCellText($s)
51 if ($s === '') {
52 return '&nbsp;';
55 return text($s);
58 // Get patient name from OpenEMR, or empty if not there.
59 function patientNameFromLogin($login)
61 $ptname = '';
62 if ($login) {
63 $tmp = sqlQuery(
64 "SELECT fname, lname, mname, pid " .
65 "FROM patient_data WHERE cmsportal_login = ? ORDER BY id LIMIT 1",
66 array($login)
68 if (!empty($tmp['pid'])) {
69 $ptname = $tmp['lname'];
70 if ($tmp['fname'] || $tmp['mname']) {
71 $ptname .= ',';
74 if ($tmp['fname']) {
75 $ptname .= ' ' . $tmp['fname'];
78 if ($tmp['mname']) {
79 $ptname .= ' ' . $tmp['mname'];
84 return $ptname;
87 // Check authorization.
88 $thisauth = acl_check('patients', 'med');
89 if (!$thisauth) {
90 die(xlt('Not authorized'));
93 $errmsg = '';
95 // If Delete clicked, delete selected posts/messages from the portal.
96 if (!empty($_POST['bn_delete'])) {
97 if (is_array($_POST['form_req_cb'])) {
98 foreach ($_POST['form_req_cb'] as $postid) {
99 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
100 if ($result['errmsg']) {
101 die(text($result['errmsg']));
106 if (is_array($_POST['form_msg_cb'])) {
107 foreach ($_POST['form_msg_cb'] as $messageid) {
108 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
109 if ($result['errmsg']) {
110 die(text($result['errmsg']));
116 <html>
117 <head>
118 <?php html_header_show();?>
120 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
121 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
123 <title><?php echo xlt('Portal Requests'); ?></title>
125 <style>
127 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
128 tr.detail { font-size:10pt; }
129 a, a:visited, a:hover { color:#0000cc; }
131 </style>
133 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
134 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
135 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
136 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
138 <script language="JavaScript">
140 function myRestoreSession() {
141 // This works whether we are a popup or in the OpenEMR frameset.
142 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
143 return true;
146 function openRequest(postid, type) {
147 myRestoreSession();
148 // To open results in a new window. The options parameter serves to defeat
149 // Firefox's "open windows in a new tab".
150 // window.open('single_order_results.php?orderid=' + orderid, '_blank',
151 // 'toolbar=0,location=0,menubar=0,scrollbars=yes');
153 // To open results in the same frame:
154 if (type.indexOf('Demographics') == 0) {
155 document.location.href = 'patient_select.php?postid=' + postid + '&csrf_token_form=<?php echo attr_url(collectCsrfToken()); ?>';
156 } else
157 if (type.indexOf('Insurance') == 0) {
158 document.location.href = 'insurance_form.php?postid=' + postid;
159 } else
160 if (type.indexOf('History') == 0) {
161 document.location.href = 'history_form.php?postid=' + postid;
162 } else
163 if (type.indexOf('Issue') == 0) {
164 document.location.href = 'issue_form.php?postid=' + postid;
165 } else
166 if (type.indexOf('LBF') == 0) {
167 document.location.href = 'lbf_form.php?postid=' + postid;
168 } else
169 if (type.indexOf('Upload') == 0) {
170 document.location.href = 'upload_form.php?postid=' + postid;
171 } else
173 // TBD: more types to be handled
176 alert('<?php echo xls('Request type not implemented') ?>: ' + type);
179 // To open results in the "other" frame:
180 // var w = window;
181 // var othername = (w.name == 'RTop') ? 'RBot' : 'RTop';
182 // w.parent.left_nav.forceDual();
183 // w.parent.left_nav.loadFrame('ore1', othername, 'orders/single_order_results.php?orderid=' + orderid);
186 function openMessage(messageid) {
187 myRestoreSession();
188 document.location.href = 'upload_form.php?messageid=' + messageid;
191 $(document).ready(function() {
192 $('.datepicker').datetimepicker({
193 <?php $datetimepicker_timepicker = false; ?>
194 <?php $datetimepicker_showseconds = false; ?>
195 <?php $datetimepicker_formatInput = false; ?>
196 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
197 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
201 </script>
203 </head>
205 <body class="body_top">
206 <form method='post' action='list_requests.php' onsubmit='return myRestoreSession()'>
208 <?php
209 $form_from_date = empty($_POST['form_from_date']) ? '' : trim($_POST['form_from_date']);
210 $form_to_date = empty($_POST['form_to_date']) ? '' : trim($_POST['form_to_date']);
211 // if (empty($form_to_date)) $form_to_date = $form_from_date;
213 $form_patient = !empty($_POST['form_patient']);
215 // Post a form to the WP portal that asks for the request list and get the response.
216 // Write a row for each request that is reported.
218 $result = cms_portal_call(array(
219 'action' => 'list',
220 'date_from' => $form_from_date,
221 'date_to' => $form_to_date,
224 if ($result['errmsg']) {
225 echo "<font color='red'>" . text($result['errmsg']) . "</font><br />\n";
228 <center>
230 <table width='100%'>
231 <tr>
232 <td class='text' align='center'>
233 <?php echo xlt('From'); ?>:
234 <input type='text' size='8' class='datepicker' name='form_from_date' id='form_from_date'
235 value='<?php echo attr($form_from_date); ?>'
236 title='<?php echo xla('yyyy-mm-dd'); ?>' />
237 &nbsp;
238 <?php echo xlt('To'); ?>:
239 <input type='text' size='8' class='datepicker' name='form_to_date' id='form_to_date'
240 value='<?php echo attr($form_to_date); ?>'
241 title='<?php echo xla('yyyy-mm-dd'); ?>' />
242 &nbsp;
243 <input type='submit' name='form_refresh' value=<?php echo xla('Submit'); ?>>
244 </td>
245 </tr>
246 </table>
248 <table width='100%' cellpadding='1' cellspacing='2'>
250 <tr class='head'>
251 <th colspan='2'><?php echo xlt('Patient'); ?></td>
252 <th colspan='3'><?php echo xlt('CMS Portal Request'); ?></td>
253 </tr>
255 <tr class='head'>
256 <th><?php echo xlt('Portal ID'); ?></td>
257 <th><?php echo xlt('Name in EMR'); ?></td>
258 <th><?php echo xlt('Date/Time'); ?></td>
259 <th><?php echo xlt('Request Type'); ?></td>
260 <th><?php echo xlt('Delete'); ?></td>
261 </tr>
263 <?php
264 // Generate a table row for each pending portal request or message.
265 // This logic merges requests with messages by date.
266 $v1 = each($result['list']);
267 $v2 = each($result['messages']);
268 while ($v1 || $v2) {
269 echo " <tr class='detail' bgcolor='#ddddff'>\n";
270 if (!$v2 || $v1 && $v1[1]['datetime'] < $v2[1]['datetime']) {
271 $postid = $v1[1]['postid'];
272 $ptname = patientNameFromLogin($v1[1]['user']);
273 echo " <td>" . text($v1[1]['user']) . "</td>\n";
274 echo " <td>" . text($ptname) . "</td>\n";
275 echo " <td style='cursor:pointer;color:blue;'";
276 echo " onclick=\"openRequest(" .
277 "'" . addslashes($postid) . "'," .
278 "'" . addslashes($v1[1]['type']) . "'" .
279 ")\">" . text($v1[1]['datetime']) . "</td>\n";
280 echo " <td>" . text($v1[1]['type' ]) . "</td>\n";
281 echo " <td align='center'><input type='checkbox' name='form_req_cb[" .
282 attr($postid) . "]' value='" . attr($postid) . "' /></td>\n";
283 $v1 = each($result['list']);
284 } else {
285 $messageid = $v2[1]['messageid'];
286 $ptname = patientNameFromLogin($v2[1]['user']);
287 echo " <td>" . text($v2[1]['user']) . "</td>\n";
288 echo " <td>" . text($ptname) . "</td>\n";
289 echo " <td style='cursor:pointer;color:blue;'";
290 echo " onclick=\"openMessage(" .
291 "'" . addslashes($messageid) . "'" .
292 ")\">" . text($v2[1]['datetime']) . "</td>\n";
293 echo " <td>" . text($v2[1]['user'] == $v2[1]['fromuser'] ?
294 xl('Message from patient') : xl('Message to patient')) . "</td>\n";
295 echo " <td align='center'><input type='checkbox' name='form_msg_cb[" .
296 attr($messageid) . "]' value='" . attr($messageid) . "' /></td>\n";
297 $v2 = each($result['messages']);
300 echo " </tr>\n";
304 </table>
307 <input type='button' value='<?php echo xla('Close Window'); ?>' onclick="window.close();" />
308 &nbsp;
309 <input type='submit' name='bn_delete' value='<?php echo xla('Delete Selected Requests'); ?>' />
310 </p>
312 </center>
313 </form>
314 </body>
315 </html>