migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / cmsportal / issue_form.php
blobfedc4e1ecb6c872e891eb78be509005d49238168
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>
22 $sanitize_all_escapes = true;
23 $fake_register_globals = false;
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";
125 else {
126 $value = "'$value'";
129 else {
130 $value = "'" . add_escape_custom($value) . "'";
132 $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 else {
142 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
143 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']));
150 echo "<html><body><script language='JavaScript'>\n";
151 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
152 echo "document.location.href = 'list_requests.php';\n";
153 echo "</script></body></html>\n";
154 exit();
157 // Get the portal request data.
158 if (!$postid) die(xlt('Request ID is missing!'));
159 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
160 if ($result['errmsg']) {
161 die(text($result['errmsg']));
163 // If user changed issue type, it will have submitted the form to override it.
164 if ($form_type) $result['fields']['type'] = $form_type;
166 // Look up the patient in OpenEMR.
167 $ptid = lookup_openemr_patient($result['post']['user']);
169 <html>
170 <head>
171 <?php html_header_show(); ?>
172 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
174 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
175 <style>
177 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
178 tr.detail { font-size:10pt; background-color:#ddddff; }
179 td input { background-color:transparent; }
181 </style>
183 <script type="text/javascript" src="../../library/textformat.js"></script>
184 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
185 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
186 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
187 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
189 <script language="JavaScript">
191 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
193 function myRestoreSession() {
194 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
195 return true;
198 // This capitalizes the first letter of each word in the passed input
199 // element. It also strips out extraneous spaces.
200 // Copied from demographics_full.php.
201 function capitalizeMe(elem) {
202 var a = elem.value.split(' ');
203 var s = '';
204 for(var i = 0; i < a.length; ++i) {
205 if (a[i].length > 0) {
206 if (s.length > 0) s += ' ';
207 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
210 elem.value = s;
213 function validate() {
214 var f = document.forms[0];
215 // TBD
216 return true;
219 $(document).ready(function() {
220 $("#form_type").change(function() {
221 myRestoreSession();
222 document.forms[0].submit();
223 return true;
227 </script>
228 </head>
230 <body class="body_top">
231 <center>
233 <form method='post' action='issue_form.php' onsubmit='return validate()'>
235 <input type='hidden' name='ptid' value="<?php echo attr($ptid); ?>" />
236 <input type='hidden' name='postid' value="<?php echo attr($postid); ?>" />
239 <select name='issueid' onchange='myRestoreSession();this.form.submit();'>
240 <option value='0'><?php echo xlt('Add New Issue'); ?></option>
241 <?php
242 $ires = sqlStatement("SELECT id, title, begdate " .
243 "FROM lists WHERE pid = ? AND type = ? AND activity > 0 " .
244 "AND enddate IS NULL ORDER BY enddate, title",
245 array($ptid, $result['fields']['type']));
246 while ($irow = sqlFetchArray($ires)) {
247 echo " <option value='" . attr($irow['id']) . "'";
248 if ($irow['id'] == $issueid) echo " selected";
249 echo ">" . text($irow['title']);
250 if (!empty($irow['begdate'])) echo " (" . text($irow['begdate']) . ")";
251 echo "</option>\n";
254 </select>
255 </p>
257 <table width='100%' cellpadding='1' cellspacing='2'>
258 <tr class='head'>
259 <th align='left'><?php echo xlt('Field' ); ?></th>
260 <th align='left'><?php echo xlt('Current Value'); ?></th>
261 <th align='left'><?php echo xlt('New Value' ); ?></th>
262 </tr>
264 <?php
265 $irow = array();
266 if (!empty($issueid)) $irow = getListById($issueid);
268 foreach ($issue_layout as $lorow) {
269 $data_type = $lorow['data_type'];
270 $field_id = $lorow['field_id'];
272 $list_id = $lorow['list_id'];
273 $field_title = $lorow['title'];
275 $currvalue = '';
276 if (isset($irow[$field_id])) $currvalue = $irow[$field_id];
278 $newvalue = '';
279 if (isset($result['fields'][$field_id])) $newvalue = trim($result['fields'][$field_id]);
281 echo " <tr class='detail'>\n";
282 echo " <td class='bold'>" . text($field_title) . "</td>\n";
283 echo " <td>";
284 echo generate_display_field($lorow, $currvalue);
285 echo "</td>\n";
286 echo " <td>";
287 generate_form_field($lorow, $newvalue);
288 echo "</td>\n";
289 echo " </tr>\n";
293 </table>
296 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
297 &nbsp;
298 <input type='button' value='<?php echo xla('Back'); ?>'
299 onclick="myRestoreSession();location='list_requests.php'" />
300 </p>
302 </form>
304 <script language="JavaScript">
306 // This is a by-product of generate_form_field().
307 <?php echo $date_init; ?>
309 </script>
311 </center>
312 </body>
313 </html>