Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / cmsportal / patient_form.php
blob22e2fba22bfb307fa07a54fab8d3cb8caf850335
1 <?php
2 /**
3 * Patient matching and selection for 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/patient.inc");
17 require_once("$srcdir/options.inc.php");
18 require_once("portal.inc.php");
20 $postid = intval($_REQUEST['postid']);
21 $ptid = intval($_REQUEST['ptid' ]);
23 if ($_POST['bn_save']) {
24 $newdata = array();
25 $newdata['patient_data' ] = array();
26 $newdata['employer_data'] = array();
27 $ptid = intval($_POST['ptid']);
28 // Note we are careful to maintain cmsportal_login even if the layout has it
29 // configured as unused.
30 $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
31 "form_id = 'DEM' AND field_id != '' AND (uor > 0 OR field_id = 'cmsportal_login') " .
32 "ORDER BY group_id, seq");
33 while ($frow = sqlFetchArray($fres)) {
34 $data_type = $frow['data_type'];
35 $field_id = $frow['field_id'];
36 $table = 'patient_data';
37 if (isset($_POST["form_$field_id"])) {
38 $newdata[$table][$field_id] = get_layout_form_value($frow);
42 if (empty($ptid)) {
43 $tmp = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
44 $ptid = empty($tmp['pid']) ? 1 : intval($tmp['pid']);
45 if (empty($newdata['patient_data']['pubpid'])) {
46 // pubpid for new patient defaults to pid.
47 $newdata['patient_data']['pubpid'] = "$ptid";
50 updatePatientData($ptid, $newdata['patient_data' ], true);
51 updateEmployerData($ptid, $newdata['employer_data'], true);
52 newHistoryData($ptid);
53 } else {
54 $newdata['patient_data']['id'] = $_POST['db_id'];
55 updatePatientData($ptid, $newdata['patient_data']);
58 // Finally, delete the request from the portal.
59 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
60 if ($result['errmsg']) {
61 die(text($result['errmsg']));
64 echo "<html><body><script language='JavaScript'>\n";
65 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
66 echo "document.location.href = 'list_requests.php';\n";
67 echo "</script></body></html>\n";
68 exit();
71 $db_id = 0;
72 if ($ptid) {
73 $ptrow = getPatientData($ptid, "*");
74 $db_id = $ptrow['id'];
77 if ($postid) {
78 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
79 if ($result['errmsg']) {
80 die(text($result['errmsg']));
84 <html>
85 <head>
86 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
87 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
89 <style>
91 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
92 tr.detail { font-size:10pt; background-color:#ddddff; }
93 td input { background-color:transparent; }
95 </style>
97 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
98 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-7-2/jquery.min.js"></script>
99 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
101 <script language="JavaScript">
103 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
105 function myRestoreSession() {
106 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
107 return true;
110 // This capitalizes the first letter of each word in the passed input
111 // element. It also strips out extraneous spaces.
112 // Copied from demographics_full.php.
113 function capitalizeMe(elem) {
114 var a = elem.value.split(' ');
115 var s = '';
116 for(var i = 0; i < a.length; ++i) {
117 if (a[i].length > 0) {
118 if (s.length > 0) s += ' ';
119 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
122 elem.value = s;
125 // Generates and returns a random 6-character password.
127 function randompass() {
128 var newpass = '';
129 var newchar = '';
130 while (newpass.length < 6) {
131 var r = Math.floor(Math.random() * 33); // for 2-9 and a-y
132 if (r > 7) {
133 newchar = String.fromCharCode('a'.charCodeAt(0) + r - 8);
134 if (newchar == 'l') newchar = 'z';
135 } else {
136 newchar = String.fromCharCode('2'.charCodeAt(0) + r);
138 newpass += newchar;
140 var e = document.forms[0].form_cmsportal_login_pass;
141 if (e) e.value = newpass;
144 // If needed, this creates the new patient in the CMS. It executes as an AJAX script
145 // in case it doesn't work and a correction is needed before submitting the form.
147 function validate() {
148 var f = document.forms[0];
149 var errmsg = '';
150 myRestoreSession();
151 if (f.form_cmsportal_login_pass) {
152 var login = encodeURIComponent(f.form_cmsportal_login.value);
153 var pass = encodeURIComponent(f.form_cmsportal_login_pass.value);
154 var email = encodeURIComponent(f.form_email.value);
155 if (login) {
156 if (!pass) {
157 alert('<?php echo xls('Portal password is missing'); ?>');
158 return false;
160 if (!email) {
161 alert('<?php echo xls('Email address is missing'); ?>');
162 return false;
164 // Need a *synchronous* ajax request here. Successful updating of the portal
165 // is required before we can submit the form.
166 $.ajax({
167 type: "GET",
168 dataType: "text",
169 url: 'patient_form_ajax.php?login=' + login + '&pass=' + pass + '&email=' + email,
170 async: false,
171 success: function(data) {
172 if (data) {
173 alert(data);
174 errmsg = data;
180 if (errmsg) return false;
181 return true;
184 $(function() {
185 $('.datepicker').datetimepicker({
186 <?php $datetimepicker_timepicker = false; ?>
187 <?php $datetimepicker_showseconds = false; ?>
188 <?php $datetimepicker_formatInput = true; ?>
189 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
190 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
192 $('.datetimepicker').datetimepicker({
193 <?php $datetimepicker_timepicker = true; ?>
194 <?php $datetimepicker_showseconds = false; ?>
195 <?php $datetimepicker_formatInput = true; ?>
196 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
197 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
201 </script>
202 </head>
204 <body class="body_top">
205 <center>
207 <form method='post' action='patient_form.php' onsubmit='return validate()'>
209 <input type='hidden' name='db_id' value="<?php echo attr($db_id); ?>" />
210 <input type='hidden' name='ptid' value="<?php echo attr($ptid); ?>" />
211 <input type='hidden' name='postid' value="<?php echo attr($postid); ?>" />
213 <table width='100%' cellpadding='1' cellspacing='2'>
214 <tr class='head'>
215 <th align='left'><?php echo xlt('Field'); ?></th>
216 <th align='left'><?php echo xlt('Current Value'); ?></th>
217 <th align='left'><?php echo xlt('New Value'); ?></th>
218 </tr>
220 <?php
221 $lores = sqlStatement(
222 "SELECT * FROM layout_options " .
223 "WHERE form_id = ? AND uor > 0 ORDER BY group_id, seq",
224 array('DEM')
227 // Will be used to indicate if this user does not yet have a portal login.
228 $portal_registration_needed = false;
230 while ($lorow = sqlFetchArray($lores)) {
231 $data_type = $lorow['data_type'];
232 $field_id = $lorow['field_id'];
233 // We deal with this one at the end.
234 if ($field_id == 'cmsportal_login') {
235 continue;
238 // Flamingo translates field names to lower case so we have to match with those.
239 $reskey = $field_id;
240 foreach ($result['fields'] as $key => $dummy) {
241 if (strcasecmp($key, $field_id) == 0) {
242 $reskey = $key;
246 // Generate form fields for items that are either from the WordPress form
247 // or are mandatory for a new patient.
248 if (isset($result['fields'][$reskey]) || ($lorow['uor'] > 1 && $ptid == 0)) {
249 $list_id = $lorow['list_id'];
250 $field_title = $lorow['title'];
251 if ($field_title === '') {
252 $field_title = '(' . $field_id . ')';
255 $currvalue = '';
256 if (isset($ptrow[$field_id])) {
257 $currvalue = $ptrow[$field_id];
260 /*****************************************************************
261 $newvalue = '';
262 if (isset($result['fields'][$reskey])) $newvalue = $result['fields'][$reskey];
263 //// Zero-length input means nothing will change.
264 // if ($newvalue === '') $newvalue = $currvalue;
265 // $newvalue = trim($newvalue);
266 $newvalue = cms_field_to_lbf($newvalue, $data_type, $field_id);
267 *****************************************************************/
268 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
270 echo " <tr class='detail'>\n";
271 echo " <td class='bold'>" . text($field_title) . "</td>\n";
272 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
273 echo " <td>";
274 generate_form_field($lorow, $newvalue);
275 echo "</td>\n";
276 echo " </tr>\n";
280 $field_id = 'cmsportal_login';
281 if (empty($ptrow[$field_id])) {
282 if ($result['post']['user'] !== '') {
283 // Registered in portal but still need to record that in openemr.
284 echo "</table>\n";
285 echo "<input type='hidden' name='form_$field_id' value='" . attr($result['post']['user']) . "' />\n";
286 } else {
287 // Portal registration is needed.
288 $newvalue = isset($result['fields']['email']) ? trim($result['fields']['email']) : '';
289 echo " <tr class='detail'>\n";
290 echo " <td class='bold' style='color:red;'>" . xlt('New Portal Login') . "</td>\n";
291 echo " <td>&nbsp;</td>\n";
292 echo " <td>";
293 echo "<input type='text' name='form_$field_id' size='10' maxlength='60' value='" . attr($newvalue) . "' />";
294 echo "&nbsp;&nbsp;" . xlt('Password') . ": ";
295 echo "<input type='text' name='form_" . attr($field_id) . "_pass' size='10' maxlength='60' />";
296 echo "<input type='button' value='" . xla('Generate') . "' onclick='randompass()' />";
297 echo "</td>\n";
298 echo " </tr>\n";
299 echo "</table>\n";
301 } else {
302 // Portal login name is already in openemr.
303 echo "</table>\n";
308 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
309 &nbsp;
310 <input type='button' value='<?php echo xla('Back'); ?>' onclick="window.history.back()" />
311 <!-- Was: onclick="myRestoreSession();location='list_requests.php'" -->
312 </p>
314 </form>
316 <script language="JavaScript">
318 // hard code validation for old validation, in the new validation possible to add match rules
319 <?php if ($GLOBALS['new_validate'] == 0) { ?>
321 // Fix inconsistently formatted phone numbers from the database.
322 var f = document.forms[0];
323 if (f.form_phone_contact) phonekeyup(f.form_phone_contact,mypcc);
324 if (f.form_phone_home ) phonekeyup(f.form_phone_home ,mypcc);
325 if (f.form_phone_biz ) phonekeyup(f.form_phone_biz ,mypcc);
326 if (f.form_phone_cell ) phonekeyup(f.form_phone_cell ,mypcc);
328 <?php }?>
330 randompass();
332 // This is a by-product of generate_form_field().
333 <?php echo $date_init; ?>
335 </script>
337 <!-- include support for the list-add selectbox feature -->
338 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
340 </center>
341 </body>
342 </html>