minor changes to prior commit
[openemr.git] / interface / cmsportal / issue_form.php
blobae06eef0025f4ab8f8617344c3a6bd44d8012a91
1 <?php
2 /**
3 * Issue posting from the WordPress Patient Portal.
5 * @package OpenEMR
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',
26 'title' => 'Type',
27 'uor' => '2',
28 'data_type' => '17', // Issue Types
29 'list_id' => '',
30 'edit_options' => '',
32 array('field_id' => 'title',
33 'title' => 'Title',
34 'uor' => '2',
35 'data_type' => '2', // Text
36 'list_id' => '',
37 'edit_options' => '',
39 array('field_id' => 'diagnosis',
40 'title' => 'Diagnosis',
41 'uor' => '1',
42 'data_type' => '2', // Text
43 'list_id' => '',
44 'edit_options' => '',
46 array('field_id' => 'begdate',
47 'title' => 'Start Date',
48 'uor' => '2',
49 'data_type' => '4', // Text-date
50 'list_id' => '',
51 'edit_options' => '',
53 array('field_id' => 'enddate',
54 'title' => 'End Date',
55 'uor' => '1',
56 'data_type' => '4', // Text-date
57 'list_id' => '',
58 'edit_options' => '',
60 array('field_id' => 'occurrence',
61 'title' => 'Occurrence',
62 'uor' => '1',
63 'data_type' => '1', // List
64 'list_id' => 'occurrence',
65 'edit_options' => '',
67 array('field_id' => 'reaction',
68 'title' => 'Reaction',
69 'uor' => '1',
70 'data_type' => '2', // Text
71 'list_id' => '',
72 'edit_options' => '',
74 array('field_id' => 'outcome',
75 'title' => 'Outcome',
76 'uor' => '1',
77 'data_type' => '1', // List
78 'list_id' => 'outcome',
79 'edit_options' => '',
81 array('field_id' => 'destination',
82 'title' => 'Destination',
83 'uor' => '1',
84 'data_type' => '2', // Text
85 'list_id' => '',
86 'edit_options' => '',
88 array('field_id' => 'comments',
89 'title' => 'Comments',
90 'uor' => '1',
91 'data_type' => '3', // Textarea
92 'list_id' => '',
93 'fld_length' => '50',
94 'fld_rows' => '3',
95 'edit_options' => '',
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, '');
112 if (empty($value)) {
113 $value = "NULL";
114 } else {
115 $value = "'$value'";
117 } else {
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);
130 } else {
131 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
132 sqlStatement($sql);
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";
145 exit();
148 // Get the portal request data.
149 if (!$postid) {
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.
159 if ($form_type) {
160 $result['fields']['type'] = $form_type;
163 // Look up the patient in OpenEMR.
164 $ptid = lookup_openemr_patient($result['post']['user']);
166 <html>
167 <head>
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/build/jquery.datetimepicker.min.css">
172 <style>
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; }
178 </style>
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-1-7-2/jquery.min.js"></script>
182 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
184 <script language="JavaScript">
186 function myRestoreSession() {
187 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
188 return true;
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(' ');
196 var s = '';
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);
203 elem.value = s;
206 function validate() {
207 var f = document.forms[0];
208 // TBD
209 return true;
212 $(document).ready(function() {
213 $("#form_type").change(function() {
214 myRestoreSession();
215 document.forms[0].submit();
216 return true;
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 ?>
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>