Highway to PSR2
[openemr.git] / interface / cmsportal / issue_form.php
blob91fed5619e04e537eea27be5d11824cf025c2e37
1 <?php
2 /**
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>;.
18 * @package OpenEMR
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',
36 'title' => 'Type',
37 'uor' => '2',
38 'data_type' => '17', // Issue Types
39 'list_id' => '',
40 'edit_options' => '',
42 array('field_id' => 'title',
43 'title' => 'Title',
44 'uor' => '2',
45 'data_type' => '2', // Text
46 'list_id' => '',
47 'edit_options' => '',
49 array('field_id' => 'diagnosis',
50 'title' => 'Diagnosis',
51 'uor' => '1',
52 'data_type' => '2', // Text
53 'list_id' => '',
54 'edit_options' => '',
56 array('field_id' => 'begdate',
57 'title' => 'Start Date',
58 'uor' => '2',
59 'data_type' => '4', // Text-date
60 'list_id' => '',
61 'edit_options' => '',
63 array('field_id' => 'enddate',
64 'title' => 'End Date',
65 'uor' => '1',
66 'data_type' => '4', // Text-date
67 'list_id' => '',
68 'edit_options' => '',
70 array('field_id' => 'occurrence',
71 'title' => 'Occurrence',
72 'uor' => '1',
73 'data_type' => '1', // List
74 'list_id' => 'occurrence',
75 'edit_options' => '',
77 array('field_id' => 'reaction',
78 'title' => 'Reaction',
79 'uor' => '1',
80 'data_type' => '2', // Text
81 'list_id' => '',
82 'edit_options' => '',
84 array('field_id' => 'outcome',
85 'title' => 'Outcome',
86 'uor' => '1',
87 'data_type' => '1', // List
88 'list_id' => 'outcome',
89 'edit_options' => '',
91 array('field_id' => 'destination',
92 'title' => 'Destination',
93 'uor' => '1',
94 'data_type' => '2', // Text
95 'list_id' => '',
96 'edit_options' => '',
98 array('field_id' => 'comments',
99 'title' => 'Comments',
100 'uor' => '1',
101 'data_type' => '3', // Textarea
102 'list_id' => '',
103 'fld_length' => '50',
104 'fld_rows' => '3',
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, '');
122 if (empty($value)) {
123 $value = "NULL";
124 } else {
125 $value = "'$value'";
127 } else {
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);
140 } else {
141 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
142 sqlStatement($sql);
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";
155 exit();
158 // Get the portal request data.
159 if (!$postid) {
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.
169 if ($form_type) {
170 $result['fields']['type'] = $form_type;
173 // Look up the patient in OpenEMR.
174 $ptid = lookup_openemr_patient($result['post']['user']);
176 <html>
177 <head>
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>
182 <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; }
188 </style>
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();
202 return true;
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(' ');
210 var s = '';
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);
217 elem.value = s;
220 function validate() {
221 var f = document.forms[0];
222 // TBD
223 return true;
226 $(document).ready(function() {
227 $("#form_type").change(function() {
228 myRestoreSession();
229 document.forms[0].submit();
230 return true;
234 </script>
235 </head>
237 <body class="body_top">
238 <center>
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>
248 <?php
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) {
258 echo " selected";
261 echo ">" . text($irow['title']);
262 if (!empty($irow['begdate'])) {
263 echo " (" . text($irow['begdate']) . ")";
266 echo "</option>\n";
269 </select>
270 </p>
272 <table width='100%' cellpadding='1' cellspacing='2'>
273 <tr class='head'>
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>
277 </tr>
279 <?php
280 $irow = array();
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'];
292 $currvalue = '';
293 if (isset($irow[$field_id])) {
294 $currvalue = $irow[$field_id];
297 $newvalue = '';
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";
304 echo " <td>";
305 echo generate_display_field($lorow, $currvalue);
306 echo "</td>\n";
307 echo " <td>";
308 generate_form_field($lorow, $newvalue);
309 echo "</td>\n";
310 echo " </tr>\n";
314 </table>
317 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
318 &nbsp;
319 <input type='button' value='<?php echo xla('Back'); ?>'
320 onclick="myRestoreSession();location='list_requests.php'" />
321 </p>
323 </form>
325 <script language="JavaScript">
327 // This is a by-product of generate_form_field().
328 <?php echo $date_init; ?>
330 </script>
332 </center>
333 </body>
334 </html>