3 * Issue posting from the WordPress Patient Portal.
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/options.inc.php");
17 require_once("$srcdir/patient.inc");
18 require_once("$srcdir/lists.inc");
19 require_once("portal.inc.php");
21 // Consider this a step towards converting issue forms to layout-based.
22 // Faking it here makes things easier.
24 $issue_layout = array(
25 array('field_id' => 'type',
28 'data_type' => '17', // Issue Types
32 array('field_id' => 'title',
35 'data_type' => '2', // Text
39 array('field_id' => 'diagnosis',
40 'title' => 'Diagnosis',
42 'data_type' => '2', // Text
46 array('field_id' => 'begdate',
47 'title' => 'Start Date',
49 'data_type' => '4', // Text-date
53 array('field_id' => 'enddate',
54 'title' => 'End Date',
56 'data_type' => '4', // Text-date
60 array('field_id' => 'occurrence',
61 'title' => 'Occurrence',
63 'data_type' => '1', // List
64 'list_id' => 'occurrence',
67 array('field_id' => 'reaction',
68 'title' => 'Reaction',
70 'data_type' => '2', // Text
74 array('field_id' => 'outcome',
77 'data_type' => '1', // List
78 'list_id' => 'outcome',
81 array('field_id' => 'destination',
82 'title' => 'Destination',
84 'data_type' => '2', // Text
88 array('field_id' => 'comments',
89 'title' => 'Comments',
91 'data_type' => '3', // Textarea
99 $postid = intval($_REQUEST['postid']);
100 $issueid = empty($_REQUEST['issueid']) ?
0 : intval($_REQUEST['issueid']);
101 $form_type = empty($_REQUEST['form_type']) ?
'' : $_REQUEST['form_type'];
103 if ($_POST['bn_save']) {
104 $ptid = intval($_POST['ptid']);
105 $sets = "date = NOW()";
106 foreach ($issue_layout as $frow) {
107 $key = $frow['field_id'];
108 $value = get_layout_form_value($frow);
109 if ($frow['data_type'] == 4) {
110 // Dates require some special handling.
111 $value = fixDate($value, '');
118 $value = "'" . add_escape_custom($value) . "'";
121 $sets .= ", `$key` = $value";
124 if (empty($issueid)) {
125 $sql = "INSERT INTO lists SET " .
126 "pid = '" . add_escape_custom($ptid) . "', activity = 1, " .
127 "user = '" . add_escape_custom($_SESSION['authUser']) . "', " .
128 "groupname = '" . add_escape_custom($_SESSION['authProvider']) . "', $sets";
129 $issueid = sqlInsert($sql);
131 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
135 // Finally, delete the request from the portal.
136 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
137 if ($result['errmsg']) {
138 die(text($result['errmsg']));
141 echo "<html><body><script language='JavaScript'>\n";
142 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
143 echo "document.location.href = 'list_requests.php';\n";
144 echo "</script></body></html>\n";
148 // Get the portal request data.
150 die(xlt('Request ID is missing!'));
153 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
154 if ($result['errmsg']) {
155 die(text($result['errmsg']));
158 // If user changed issue type, it will have submitted the form to override it.
160 $result['fields']['type'] = $form_type;
163 // Look up the patient in OpenEMR.
164 $ptid = lookup_openemr_patient($result['post']['user']);
168 <?php
html_header_show(); ?
>
169 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
170 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
174 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
175 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
176 td input
{ background
-color
:transparent
; }
180 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
181 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
182 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
184 <script language
="JavaScript">
186 function myRestoreSession() {
187 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
191 // This capitalizes the first letter of each word in the passed input
192 // element. It also strips out extraneous spaces.
193 // Copied from demographics_full.php.
194 function capitalizeMe(elem
) {
195 var a
= elem
.value
.split(' ');
197 for(var i
= 0; i
< a
.length
; ++i
) {
198 if (a
[i
].length
> 0) {
199 if (s
.length
> 0) s +
= ' ';
200 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
206 function validate() {
207 var f
= document
.forms
[0];
212 $
(document
).ready(function() {
213 $
("#form_type").change(function() {
215 document
.forms
[0].submit();
218 $
('.datepicker').datetimepicker({
219 <?php
$datetimepicker_timepicker = false; ?
>
220 <?php
$datetimepicker_showseconds = false; ?
>
221 <?php
$datetimepicker_formatInput = true; ?
>
222 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
223 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
225 $
('.datetimepicker').datetimepicker({
226 <?php
$datetimepicker_timepicker = true; ?
>
227 <?php
$datetimepicker_showseconds = false; ?
>
228 <?php
$datetimepicker_formatInput = true; ?
>
229 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
230 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
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; ?
>