3 * Issue posting from the WordPress Patient Portal.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Rod Roark <rod@sunsetsystems.com>
22 $sanitize_all_escapes = true;
23 $fake_register_globals = false;
25 require_once("../globals.php");
26 require_once("$srcdir/formdata.inc.php");
27 require_once("$srcdir/options.inc.php");
28 require_once("$srcdir/patient.inc");
29 require_once("$srcdir/lists.inc");
30 require_once("portal.inc.php");
32 // Consider this a step towards converting issue forms to layout-based.
33 // Faking it here makes things easier.
35 $issue_layout = array(
36 array('field_id' => 'type',
39 'data_type' => '17', // Issue Types
43 array('field_id' => 'title',
46 'data_type' => '2', // Text
50 array('field_id' => 'diagnosis',
51 'title' => 'Diagnosis',
53 'data_type' => '2', // Text
57 array('field_id' => 'begdate',
58 'title' => 'Start Date',
60 'data_type' => '4', // Text-date
64 array('field_id' => 'enddate',
65 'title' => 'End Date',
67 'data_type' => '4', // Text-date
71 array('field_id' => 'occurrence',
72 'title' => 'Occurrence',
74 'data_type' => '1', // List
75 'list_id' => 'occurrence',
78 array('field_id' => 'reaction',
79 'title' => 'Reaction',
81 'data_type' => '2', // Text
85 array('field_id' => 'outcome',
88 'data_type' => '1', // List
89 'list_id' => 'outcome',
92 array('field_id' => 'destination',
93 'title' => 'Destination',
95 'data_type' => '2', // Text
99 array('field_id' => 'comments',
100 'title' => 'Comments',
102 'data_type' => '3', // Textarea
104 'fld_length' => '50',
106 'edit_options' => '',
110 $postid = intval($_REQUEST['postid']);
111 $issueid = empty($_REQUEST['issueid']) ?
0 : intval($_REQUEST['issueid']);
112 $form_type = empty($_REQUEST['form_type']) ?
'' : $_REQUEST['form_type'];
114 if ($_POST['bn_save']) {
115 $ptid = intval($_POST['ptid']);
116 $sets = "date = NOW()";
117 foreach ($issue_layout as $frow) {
118 $key = $frow['field_id'];
119 $value = get_layout_form_value($frow);
120 if ($frow['data_type'] == 4) {
121 // Dates require some special handling.
122 $value = fixDate($value, '');
131 $value = "'" . add_escape_custom($value) . "'";
133 $sets .= ", `$key` = $value";
135 if (empty($issueid)) {
136 $sql = "INSERT INTO lists SET " .
137 "pid = '" . add_escape_custom($ptid) . "', activity = 1, " .
138 "user = '" . add_escape_custom($_SESSION['authUser']) . "', " .
139 "groupname = '" . add_escape_custom($_SESSION['authProvider']) . "', $sets";
140 $issueid = sqlInsert($sql);
143 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
146 // Finally, delete the request from the portal.
147 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
148 if ($result['errmsg']) {
149 die(text($result['errmsg']));
151 echo "<html><body><script language='JavaScript'>\n";
152 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
153 echo "document.location.href = 'list_requests.php';\n";
154 echo "</script></body></html>\n";
158 // Get the portal request data.
159 if (!$postid) die(xlt('Request ID is missing!'));
160 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
161 if ($result['errmsg']) {
162 die(text($result['errmsg']));
164 // If user changed issue type, it will have submitted the form to override it.
165 if ($form_type) $result['fields']['type'] = $form_type;
167 // Look up the patient in OpenEMR.
168 $ptid = lookup_openemr_patient($result['post']['user']);
172 <?php
html_header_show(); ?
>
173 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
175 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
178 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
179 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
180 td input
{ background
-color
:transparent
; }
184 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
185 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
186 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
187 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
188 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script
>
190 <script language
="JavaScript">
192 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
194 function myRestoreSession() {
195 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
199 // This capitalizes the first letter of each word in the passed input
200 // element. It also strips out extraneous spaces.
201 // Copied from demographics_full.php.
202 function capitalizeMe(elem
) {
203 var a
= elem
.value
.split(' ');
205 for(var i
= 0; i
< a
.length
; ++i
) {
206 if (a
[i
].length
> 0) {
207 if (s
.length
> 0) s +
= ' ';
208 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
214 function validate() {
215 var f
= document
.forms
[0];
220 $
(document
).ready(function() {
221 $
("#form_type").change(function() {
223 document
.forms
[0].submit();
231 <body
class="body_top">
234 <form method
='post' action
='issue_form.php' onsubmit
='return validate()'>
236 <input type
='hidden' name
='ptid' value
="<?php echo attr($ptid); ?>" />
237 <input type
='hidden' name
='postid' value
="<?php echo attr($postid); ?>" />
240 <select name
='issueid' onchange
='myRestoreSession();this.form.submit();'>
241 <option value
='0'><?php
echo xlt('Add New Issue'); ?
></option
>
243 $ires = sqlStatement("SELECT id, title, begdate " .
244 "FROM lists WHERE pid = ? AND type = ? AND activity > 0 " .
245 "AND enddate IS NULL ORDER BY enddate, title",
246 array($ptid, $result['fields']['type']));
247 while ($irow = sqlFetchArray($ires)) {
248 echo " <option value='" . attr($irow['id']) . "'";
249 if ($irow['id'] == $issueid) echo " selected";
250 echo ">" . text($irow['title']);
251 if (!empty($irow['begdate'])) echo " (" . text($irow['begdate']) . ")";
258 <table width
='100%' cellpadding
='1' cellspacing
='2'>
260 <th align
='left'><?php
echo xlt('Field' ); ?
></th
>
261 <th align
='left'><?php
echo xlt('Current Value'); ?
></th
>
262 <th align
='left'><?php
echo xlt('New Value' ); ?
></th
>
267 if (!empty($issueid)) $irow = getListById($issueid);
269 foreach ($issue_layout as $lorow) {
270 $data_type = $lorow['data_type'];
271 $field_id = $lorow['field_id'];
273 $list_id = $lorow['list_id'];
274 $field_title = $lorow['title'];
277 if (isset($irow[$field_id])) $currvalue = $irow[$field_id];
280 if (isset($result['fields'][$field_id])) $newvalue = trim($result['fields'][$field_id]);
282 echo " <tr class='detail'>\n";
283 echo " <td class='bold'>" . text($field_title) . "</td>\n";
285 echo generate_display_field($lorow, $currvalue);
288 generate_form_field($lorow, $newvalue);
297 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
and Delete Request
'); ?>' />
299 <input type
='button' value
='<?php echo xla('Back
'); ?>'
300 onclick
="myRestoreSession();location='list_requests.php'" />
305 <script language
="JavaScript">
307 // This is a by-product of generate_form_field().
308 <?php
echo $date_init; ?
>