Allows display of appointments in descending order, take 2.
[openemr.git] / interface / cmsportal / issue_form.php
blob8b75eebaa0fc0a330be81fd8052f530aebee3615
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/formdata.inc.php");
27 require_once("$srcdir/options.inc.php");
28 require_once("$srcdir/patient.inc");
29 require_once("$srcdir/lists.inc");
30 require_once("portal.inc.php");
32 // Consider this a step towards converting issue forms to layout-based.
33 // Faking it here makes things easier.
35 $issue_layout = array(
36 array('field_id' => 'type',
37 'title' => 'Type',
38 'uor' => '2',
39 'data_type' => '17', // Issue Types
40 'list_id' => '',
41 'edit_options' => '',
43 array('field_id' => 'title',
44 'title' => 'Title',
45 'uor' => '2',
46 'data_type' => '2', // Text
47 'list_id' => '',
48 'edit_options' => '',
50 array('field_id' => 'diagnosis',
51 'title' => 'Diagnosis',
52 'uor' => '1',
53 'data_type' => '2', // Text
54 'list_id' => '',
55 'edit_options' => '',
57 array('field_id' => 'begdate',
58 'title' => 'Start Date',
59 'uor' => '2',
60 'data_type' => '4', // Text-date
61 'list_id' => '',
62 'edit_options' => '',
64 array('field_id' => 'enddate',
65 'title' => 'End Date',
66 'uor' => '1',
67 'data_type' => '4', // Text-date
68 'list_id' => '',
69 'edit_options' => '',
71 array('field_id' => 'occurrence',
72 'title' => 'Occurrence',
73 'uor' => '1',
74 'data_type' => '1', // List
75 'list_id' => 'occurrence',
76 'edit_options' => '',
78 array('field_id' => 'reaction',
79 'title' => 'Reaction',
80 'uor' => '1',
81 'data_type' => '2', // Text
82 'list_id' => '',
83 'edit_options' => '',
85 array('field_id' => 'outcome',
86 'title' => 'Outcome',
87 'uor' => '1',
88 'data_type' => '1', // List
89 'list_id' => 'outcome',
90 'edit_options' => '',
92 array('field_id' => 'destination',
93 'title' => 'Destination',
94 'uor' => '1',
95 'data_type' => '2', // Text
96 'list_id' => '',
97 'edit_options' => '',
99 array('field_id' => 'comments',
100 'title' => 'Comments',
101 'uor' => '1',
102 'data_type' => '3', // Textarea
103 'list_id' => '',
104 'fld_length' => '50',
105 'fld_rows' => '3',
106 'edit_options' => '',
110 $postid = intval($_REQUEST['postid']);
111 $issueid = empty($_REQUEST['issueid']) ? 0 : intval($_REQUEST['issueid']);
112 $form_type = empty($_REQUEST['form_type']) ? '' : $_REQUEST['form_type'];
114 if ($_POST['bn_save']) {
115 $ptid = intval($_POST['ptid']);
116 $sets = "date = NOW()";
117 foreach ($issue_layout as $frow) {
118 $key = $frow['field_id'];
119 $value = get_layout_form_value($frow);
120 if ($frow['data_type'] == 4) {
121 // Dates require some special handling.
122 $value = fixDate($value, '');
123 if (empty($value)) {
124 $value = "NULL";
126 else {
127 $value = "'$value'";
130 else {
131 $value = "'" . add_escape_custom($value) . "'";
133 $sets .= ", `$key` = $value";
135 if (empty($issueid)) {
136 $sql = "INSERT INTO lists SET " .
137 "pid = '" . add_escape_custom($ptid) . "', activity = 1, " .
138 "user = '" . add_escape_custom($_SESSION['authUser']) . "', " .
139 "groupname = '" . add_escape_custom($_SESSION['authProvider']) . "', $sets";
140 $issueid = sqlInsert($sql);
142 else {
143 $sql = "UPDATE lists SET $sets WHERE id = '" . add_escape_custom($issueid) . "'";
144 sqlStatement($sql);
146 // Finally, delete the request from the portal.
147 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
148 if ($result['errmsg']) {
149 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) die(xlt('Request ID is missing!'));
160 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
161 if ($result['errmsg']) {
162 die(text($result['errmsg']));
164 // If user changed issue type, it will have submitted the form to override it.
165 if ($form_type) $result['fields']['type'] = $form_type;
167 // Look up the patient in OpenEMR.
168 $ptid = lookup_openemr_patient($result['post']['user']);
170 <html>
171 <head>
172 <?php html_header_show(); ?>
173 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
175 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
176 <style>
178 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
179 tr.detail { font-size:10pt; background-color:#ddddff; }
180 td input { background-color:transparent; }
182 </style>
184 <script type="text/javascript" src="../../library/textformat.js"></script>
185 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
186 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
187 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
188 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script>
190 <script language="JavaScript">
192 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
194 function myRestoreSession() {
195 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
196 return true;
199 // This capitalizes the first letter of each word in the passed input
200 // element. It also strips out extraneous spaces.
201 // Copied from demographics_full.php.
202 function capitalizeMe(elem) {
203 var a = elem.value.split(' ');
204 var s = '';
205 for(var i = 0; i < a.length; ++i) {
206 if (a[i].length > 0) {
207 if (s.length > 0) s += ' ';
208 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
211 elem.value = s;
214 function validate() {
215 var f = document.forms[0];
216 // TBD
217 return true;
220 $(document).ready(function() {
221 $("#form_type").change(function() {
222 myRestoreSession();
223 document.forms[0].submit();
224 return true;
228 </script>
229 </head>
231 <body class="body_top">
232 <center>
234 <form method='post' action='issue_form.php' onsubmit='return validate()'>
236 <input type='hidden' name='ptid' value="<?php echo attr($ptid); ?>" />
237 <input type='hidden' name='postid' value="<?php echo attr($postid); ?>" />
240 <select name='issueid' onchange='myRestoreSession();this.form.submit();'>
241 <option value='0'><?php echo xlt('Add New Issue'); ?></option>
242 <?php
243 $ires = sqlStatement("SELECT id, title, begdate " .
244 "FROM lists WHERE pid = ? AND type = ? AND activity > 0 " .
245 "AND enddate IS NULL ORDER BY enddate, title",
246 array($ptid, $result['fields']['type']));
247 while ($irow = sqlFetchArray($ires)) {
248 echo " <option value='" . attr($irow['id']) . "'";
249 if ($irow['id'] == $issueid) echo " selected";
250 echo ">" . text($irow['title']);
251 if (!empty($irow['begdate'])) echo " (" . text($irow['begdate']) . ")";
252 echo "</option>\n";
255 </select>
256 </p>
258 <table width='100%' cellpadding='1' cellspacing='2'>
259 <tr class='head'>
260 <th align='left'><?php echo xlt('Field' ); ?></th>
261 <th align='left'><?php echo xlt('Current Value'); ?></th>
262 <th align='left'><?php echo xlt('New Value' ); ?></th>
263 </tr>
265 <?php
266 $irow = array();
267 if (!empty($issueid)) $irow = getListById($issueid);
269 foreach ($issue_layout as $lorow) {
270 $data_type = $lorow['data_type'];
271 $field_id = $lorow['field_id'];
273 $list_id = $lorow['list_id'];
274 $field_title = $lorow['title'];
276 $currvalue = '';
277 if (isset($irow[$field_id])) $currvalue = $irow[$field_id];
279 $newvalue = '';
280 if (isset($result['fields'][$field_id])) $newvalue = trim($result['fields'][$field_id]);
282 echo " <tr class='detail'>\n";
283 echo " <td class='bold'>" . text($field_title) . "</td>\n";
284 echo " <td>";
285 echo generate_display_field($lorow, $currvalue);
286 echo "</td>\n";
287 echo " <td>";
288 generate_form_field($lorow, $newvalue);
289 echo "</td>\n";
290 echo " </tr>\n";
294 </table>
297 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
298 &nbsp;
299 <input type='button' value='<?php echo xla('Back'); ?>'
300 onclick="myRestoreSession();location='list_requests.php'" />
301 </p>
303 </form>
305 <script language="JavaScript">
307 // This is a by-product of generate_form_field().
308 <?php echo $date_init; ?>
310 </script>
312 </center>
313 </body>
314 </html>