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>
25 require_once("../globals.php");
26 require_once("$srcdir/options.inc.php");
27 require_once("$srcdir/patient.inc");
28 require_once("$srcdir/lists.inc");
29 require_once("portal.inc.php");
31 // Consider this a step towards converting issue forms to layout-based.
32 // Faking it here makes things easier.
34 $issue_layout = array(
35 array('field_id' => 'type',
38 'data_type' => '17', // Issue Types
42 array('field_id' => 'title',
45 'data_type' => '2', // Text
49 array('field_id' => 'diagnosis',
50 'title' => 'Diagnosis',
52 'data_type' => '2', // Text
56 array('field_id' => 'begdate',
57 'title' => 'Start Date',
59 'data_type' => '4', // Text-date
63 array('field_id' => 'enddate',
64 'title' => 'End Date',
66 'data_type' => '4', // Text-date
70 array('field_id' => 'occurrence',
71 'title' => 'Occurrence',
73 'data_type' => '1', // List
74 'list_id' => 'occurrence',
77 array('field_id' => 'reaction',
78 'title' => 'Reaction',
80 'data_type' => '2', // Text
84 array('field_id' => 'outcome',
87 'data_type' => '1', // List
88 'list_id' => 'outcome',
91 array('field_id' => 'destination',
92 'title' => 'Destination',
94 'data_type' => '2', // Text
98 array('field_id' => 'comments',
99 'title' => 'Comments',
101 'data_type' => '3', // Textarea
103 'fld_length' => '50',
105 'edit_options' => '',
109 $postid = intval($_REQUEST['postid']);
110 $issueid = empty($_REQUEST['issueid']) ?
0 : intval($_REQUEST['issueid']);
111 $form_type = empty($_REQUEST['form_type']) ?
'' : $_REQUEST['form_type'];
113 if ($_POST['bn_save']) {
114 $ptid = intval($_POST['ptid']);
115 $sets = "date = NOW()";
116 foreach ($issue_layout as $frow) {
117 $key = $frow['field_id'];
118 $value = get_layout_form_value($frow);
119 if ($frow['data_type'] == 4) {
120 // Dates require some special handling.
121 $value = fixDate($value, '');
128 $value = "'" . add_escape_custom($value) . "'";
131 $sets .= ", `$key` = $value";
134 if (empty($issueid)) {
135 $sql = "INSERT INTO lists SET " .
136 "pid = '" . add_escape_custom($ptid) . "', activity = 1, " .
137 "user = '" . add_escape_custom($_SESSION['authUser']) . "', " .
138 "groupname = '" . add_escape_custom($_SESSION['authProvider']) . "', $sets";
139 $issueid = sqlInsert($sql);
141 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
145 // Finally, delete the request from the portal.
146 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
147 if ($result['errmsg']) {
148 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.
160 die(xlt('Request ID is missing!'));
163 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
164 if ($result['errmsg']) {
165 die(text($result['errmsg']));
168 // If user changed issue type, it will have submitted the form to override it.
170 $result['fields']['type'] = $form_type;
173 // Look up the patient in OpenEMR.
174 $ptid = lookup_openemr_patient($result['post']['user']);
178 <?php
html_header_show(); ?
>
179 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
181 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
184 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
185 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
186 td input
{ background
-color
:transparent
; }
190 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
191 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
192 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
193 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
194 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
196 <script language
="JavaScript">
198 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
200 function myRestoreSession() {
201 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
205 // This capitalizes the first letter of each word in the passed input
206 // element. It also strips out extraneous spaces.
207 // Copied from demographics_full.php.
208 function capitalizeMe(elem
) {
209 var a
= elem
.value
.split(' ');
211 for(var i
= 0; i
< a
.length
; ++i
) {
212 if (a
[i
].length
> 0) {
213 if (s
.length
> 0) s +
= ' ';
214 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
220 function validate() {
221 var f
= document
.forms
[0];
226 $
(document
).ready(function() {
227 $
("#form_type").change(function() {
229 document
.forms
[0].submit();
237 <body
class="body_top">
240 <form method
='post' action
='issue_form.php' onsubmit
='return validate()'>
242 <input type
='hidden' name
='ptid' value
="<?php echo attr($ptid); ?>" />
243 <input type
='hidden' name
='postid' value
="<?php echo attr($postid); ?>" />
246 <select name
='issueid' onchange
='myRestoreSession();this.form.submit();'>
247 <option value
='0'><?php
echo xlt('Add New Issue'); ?
></option
>
249 $ires = sqlStatement(
250 "SELECT id, title, begdate " .
251 "FROM lists WHERE pid = ? AND type = ? AND activity > 0 " .
252 "AND enddate IS NULL ORDER BY enddate, title",
253 array($ptid, $result['fields']['type'])
255 while ($irow = sqlFetchArray($ires)) {
256 echo " <option value='" . attr($irow['id']) . "'";
257 if ($irow['id'] == $issueid) {
261 echo ">" . text($irow['title']);
262 if (!empty($irow['begdate'])) {
263 echo " (" . text($irow['begdate']) . ")";
272 <table width
='100%' cellpadding
='1' cellspacing
='2'>
274 <th align
='left'><?php
echo xlt('Field'); ?
></th
>
275 <th align
='left'><?php
echo xlt('Current Value'); ?
></th
>
276 <th align
='left'><?php
echo xlt('New Value'); ?
></th
>
281 if (!empty($issueid)) {
282 $irow = getListById($issueid);
285 foreach ($issue_layout as $lorow) {
286 $data_type = $lorow['data_type'];
287 $field_id = $lorow['field_id'];
289 $list_id = $lorow['list_id'];
290 $field_title = $lorow['title'];
293 if (isset($irow[$field_id])) {
294 $currvalue = $irow[$field_id];
298 if (isset($result['fields'][$field_id])) {
299 $newvalue = trim($result['fields'][$field_id]);
302 echo " <tr class='detail'>\n";
303 echo " <td class='bold'>" . text($field_title) . "</td>\n";
305 echo generate_display_field($lorow, $currvalue);
308 generate_form_field($lorow, $newvalue);
317 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
and Delete Request
'); ?>' />
319 <input type
='button' value
='<?php echo xla('Back
'); ?>'
320 onclick
="myRestoreSession();location='list_requests.php'" />
325 <script language
="JavaScript">
327 // This is a by-product of generate_form_field().
328 <?php
echo $date_init; ?
>