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
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>.
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");
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)";
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 ' ';
58 // Get patient name from OpenEMR, or empty if not there.
59 function patientNameFromLogin($login) {
62 $tmp = sqlQuery("SELECT fname, lname, mname, pid " .
63 "FROM patient_data WHERE cmsportal_login = ? ORDER BY id LIMIT 1",
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'];
75 // Check authorization.
76 $thisauth = acl_check('patients', 'med');
77 if (!$thisauth) die(xlt('Not authorized'));
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']));
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
>
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; }
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();
134 function openRequest(postid
, type
) {
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
;
145 if (type
.indexOf('Insurance') == 0) {
146 document
.location
.href
= 'insurance_form.php?postid=' + postid
;
148 if (type
.indexOf('History') == 0) {
149 document
.location
.href
= 'history_form.php?postid=' + postid
;
151 if (type
.indexOf('Issue') == 0) {
152 document
.location
.href
= 'issue_form.php?postid=' + postid
;
154 if (type
.indexOf('LBF') == 0) {
155 document
.location
.href
= 'lbf_form.php?postid=' + postid
;
157 if (type
.indexOf('Upload') == 0) {
158 document
.location
.href
= 'upload_form.php?postid=' + postid
;
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:
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
) {
176 document
.location
.href
= 'upload_form.php?messageid=' + messageid
;
183 <body
class="body_top">
184 <form method
='post' action
='list_requests.php' onsubmit
='return myRestoreSession()'>
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(
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";
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
'); ?>' />
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
'); ?>' />
229 <input type
='submit' name
='form_refresh' value
=<?php
echo xla('Submit'); ?
>>
234 <table width
='100%' cellpadding
='1' cellspacing
='2'>
237 <th colspan
='2'><?php
echo xlt('Patient'); ?
></td
>
238 <th colspan
='3'><?php
echo xlt('CMS Portal Request'); ?
></td
>
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
>
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']);
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']);
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']);
293 <input type
='button' value
='<?php echo xla('Close Window
'); ?>' onclick
="window.close();" />
295 <input type
='submit' name
='bn_delete' value
='<?php echo xla('Delete Selected Requests
'); ?>' />
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'});