migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / cmsportal / list_requests.php
blobe5bc79789ec7e7c2e3f4486bc76eca069069839b
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/options.inc.php");
28 require_once("$srcdir/formatting.inc.php");
29 require_once("portal.inc.php");
31 /**
32 * Get a list item title, translating if required.
34 * @param string $listid List identifier.
35 * @param string $value List item identifier.
36 * @return string The item's title.
38 function getListItem($listid, $value) {
39 $lrow = sqlQuery("SELECT title FROM list_options " .
40 "WHERE list_id = ? AND option_id = ? AND activity = 1",
41 array($listid, $value));
42 $tmp = xl_list_label($lrow['title']);
43 if (empty($tmp)) $tmp = "($report_status)";
44 return $tmp;
47 /**
48 * Adapt text to be suitable as the contents of a table cell.
50 * @param string $s Input text.
51 * @return string Output text.
53 function myCellText($s) {
54 if ($s === '') return '&nbsp;';
55 return text($s);
58 // Get patient name from OpenEMR, or empty if not there.
59 function patientNameFromLogin($login) {
60 $ptname = '';
61 if ($login) {
62 $tmp = sqlQuery("SELECT fname, lname, mname, pid " .
63 "FROM patient_data WHERE cmsportal_login = ? ORDER BY id LIMIT 1",
64 array($login));
65 if (!empty($tmp['pid'])) {
66 $ptname = $tmp['lname'];
67 if ($tmp['fname'] || $tmp['mname']) $ptname .= ',';
68 if ($tmp['fname']) $ptname .= ' ' . $tmp['fname'];
69 if ($tmp['mname']) $ptname .= ' ' . $tmp['mname'];
72 return $ptname;
75 // Check authorization.
76 $thisauth = acl_check('patients', 'med');
77 if (!$thisauth) die(xlt('Not authorized'));
79 $errmsg = '';
81 // If Delete clicked, delete selected posts/messages from the portal.
82 if (!empty($_POST['bn_delete'])) {
83 if (is_array($_POST['form_req_cb'])) {
84 foreach ($_POST['form_req_cb'] as $postid) {
85 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
86 if ($result['errmsg']) {
87 die(text($result['errmsg']));
91 if (is_array($_POST['form_msg_cb'])) {
92 foreach ($_POST['form_msg_cb'] as $messageid) {
93 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
94 if ($result['errmsg']) {
95 die(text($result['errmsg']));
101 <html>
102 <head>
103 <?php html_header_show();?>
105 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
106 <title><?php echo xlt('Portal Requests'); ?></title>
108 <style>
110 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
111 tr.detail { font-size:10pt; }
112 a, a:visited, a:hover { color:#0000cc; }
114 </style>
116 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
117 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
118 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
119 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
121 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
122 <script type="text/javascript" src="../../library/textformat.js"></script>
124 <script language="JavaScript">
126 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
128 function myRestoreSession() {
129 // This works whether we are a popup or in the OpenEMR frameset.
130 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
131 return true;
134 function openRequest(postid, type) {
135 myRestoreSession();
136 // To open results in a new window. The options parameter serves to defeat
137 // Firefox's "open windows in a new tab".
138 // window.open('single_order_results.php?orderid=' + orderid, '_blank',
139 // 'toolbar=0,location=0,menubar=0,scrollbars=yes');
141 // To open results in the same frame:
142 if (type.indexOf('Demographics') == 0) {
143 document.location.href = 'patient_select.php?postid=' + postid;
144 } else
145 if (type.indexOf('Insurance') == 0) {
146 document.location.href = 'insurance_form.php?postid=' + postid;
147 } else
148 if (type.indexOf('History') == 0) {
149 document.location.href = 'history_form.php?postid=' + postid;
150 } else
151 if (type.indexOf('Issue') == 0) {
152 document.location.href = 'issue_form.php?postid=' + postid;
153 } else
154 if (type.indexOf('LBF') == 0) {
155 document.location.href = 'lbf_form.php?postid=' + postid;
156 } else
157 if (type.indexOf('Upload') == 0) {
158 document.location.href = 'upload_form.php?postid=' + postid;
159 } else
161 // TBD: more types to be handled
164 alert('<?php echo xla('Request type not implemented') ?>: ' + type);
167 // To open results in the "other" frame:
168 // var w = window;
169 // var othername = (w.name == 'RTop') ? 'RBot' : 'RTop';
170 // w.parent.left_nav.forceDual();
171 // w.parent.left_nav.loadFrame('ore1', othername, 'orders/single_order_results.php?orderid=' + orderid);
174 function openMessage(messageid) {
175 myRestoreSession();
176 document.location.href = 'upload_form.php?messageid=' + messageid;
179 </script>
181 </head>
183 <body class="body_top">
184 <form method='post' action='list_requests.php' onsubmit='return myRestoreSession()'>
186 <?php
187 $form_from_date = empty($_POST['form_from_date']) ? '' : trim($_POST['form_from_date']);
188 $form_to_date = empty($_POST['form_to_date']) ? '' : trim($_POST['form_to_date']);
189 // if (empty($form_to_date)) $form_to_date = $form_from_date;
191 $form_patient = !empty($_POST['form_patient']);
193 // Post a form to the WP portal that asks for the request list and get the response.
194 // Write a row for each request that is reported.
196 $result = cms_portal_call(array(
197 'action' => 'list',
198 'date_from' => $form_from_date,
199 'date_to' => $form_to_date,
202 if ($result['errmsg']) {
203 echo "<font color='red'>" . text($result['errmsg']) . "</font><br />\n";
206 <center>
208 <table width='100%'>
209 <tr>
210 <td class='text' align='center'>
211 <?php echo xlt('From'); ?>:
212 <input type='text' size='8' name='form_from_date' id='form_from_date'
213 value='<?php echo attr($form_from_date); ?>'
214 title='<?php echo xla('yyyy-mm-dd'); ?>'
215 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
216 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
217 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
218 title='<?php echo xla('Click here to choose a date'); ?>' />
219 &nbsp;
220 <?php echo xlt('To'); ?>:
221 <input type='text' size='8' name='form_to_date' id='form_to_date'
222 value='<?php echo attr($form_to_date); ?>'
223 title='<?php echo xla('yyyy-mm-dd'); ?>'
224 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
225 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
226 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
227 title='<?php echo xla('Click here to choose a date'); ?>' />
228 &nbsp;
229 <input type='submit' name='form_refresh' value=<?php echo xla('Submit'); ?>>
230 </td>
231 </tr>
232 </table>
234 <table width='100%' cellpadding='1' cellspacing='2'>
236 <tr class='head'>
237 <th colspan='2'><?php echo xlt('Patient'); ?></td>
238 <th colspan='3'><?php echo xlt('CMS Portal Request'); ?></td>
239 </tr>
241 <tr class='head'>
242 <th><?php echo xlt('Portal ID' ); ?></td>
243 <th><?php echo xlt('Name in EMR' ); ?></td>
244 <th><?php echo xlt('Date/Time' ); ?></td>
245 <th><?php echo xlt('Request Type'); ?></td>
246 <th><?php echo xlt('Delete' ); ?></td>
247 </tr>
249 <?php
250 // Generate a table row for each pending portal request or message.
251 // This logic merges requests with messages by date.
252 $v1 = each($result['list']);
253 $v2 = each($result['messages']);
254 while ($v1 || $v2) {
255 echo " <tr class='detail' bgcolor='#ddddff'>\n";
256 if (!$v2 || $v1 && $v1[1]['datetime'] < $v2[1]['datetime']) {
257 $postid = $v1[1]['postid'];
258 $ptname = patientNameFromLogin($v1[1]['user']);
259 echo " <td>" . text($v1[1]['user']) . "</td>\n";
260 echo " <td>" . text($ptname ) . "</td>\n";
261 echo " <td style='cursor:pointer;color:blue;'";
262 echo " onclick=\"openRequest(" .
263 "'" . addslashes($postid) . "'," .
264 "'" . addslashes($v1[1]['type']) . "'" .
265 ")\">" . text($v1[1]['datetime']) . "</td>\n";
266 echo " <td>" . text($v1[1]['type' ]) . "</td>\n";
267 echo " <td align='center'><input type='checkbox' name='form_req_cb[" .
268 attr($postid) . "]' value='" . attr($postid) . "' /></td>\n";
269 $v1 = each($result['list']);
271 else {
272 $messageid = $v2[1]['messageid'];
273 $ptname = patientNameFromLogin($v2[1]['user']);
274 echo " <td>" . text($v2[1]['user']) . "</td>\n";
275 echo " <td>" . text($ptname ) . "</td>\n";
276 echo " <td style='cursor:pointer;color:blue;'";
277 echo " onclick=\"openMessage(" .
278 "'" . addslashes($messageid) . "'" .
279 ")\">" . text($v2[1]['datetime']) . "</td>\n";
280 echo " <td>" . text($v2[1]['user'] == $v2[1]['fromuser'] ?
281 xl('Message from patient') : xl('Message to patient')) . "</td>\n";
282 echo " <td align='center'><input type='checkbox' name='form_msg_cb[" .
283 attr($messageid) . "]' value='" . attr($messageid) . "' /></td>\n";
284 $v2 = each($result['messages']);
286 echo " </tr>\n";
290 </table>
293 <input type='button' value='<?php echo xla('Close Window'); ?>' onclick="window.close();" />
294 &nbsp;
295 <input type='submit' name='bn_delete' value='<?php echo xla('Delete Selected Requests'); ?>' />
296 </p>
298 </center>
300 <script language='JavaScript'>
302 // Initialize calendar widgets for "from" and "to" dates.
303 Calendar.setup({inputField:'form_from_date', ifFormat:'%Y-%m-%d',
304 button:'img_from_date'});
305 Calendar.setup({inputField:'form_to_date', ifFormat:'%Y-%m-%d',
306 button:'img_to_date'});
308 </script>
310 </form>
311 </body>
312 </html>