3 * Patient matching and selection for 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>;.
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/patient.inc");
27 require_once("$srcdir/formdata.inc.php");
28 require_once("$srcdir/options.inc.php");
29 require_once("portal.inc.php");
31 $postid = intval($_REQUEST['postid']);
32 $ptid = intval($_REQUEST['ptid' ]);
34 if ($_POST['bn_save']) {
36 $newdata['patient_data' ] = array();
37 $newdata['employer_data'] = array();
38 $ptid = intval($_POST['ptid']);
39 // Note we are careful to maintain cmsportal_login even if the layout has it
40 // configured as unused.
41 $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
42 "form_id = 'DEM' AND field_id != '' AND (uor > 0 OR field_id = 'cmsportal_login') " .
43 "ORDER BY group_name, seq");
44 while ($frow = sqlFetchArray($fres)) {
45 $data_type = $frow['data_type'];
46 $field_id = $frow['field_id'];
47 $table = 'patient_data';
48 if (isset($_POST["form_$field_id"])) {
49 $newdata[$table][$field_id] = get_layout_form_value($frow);
53 $tmp = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
54 $ptid = empty($tmp['pid']) ?
1 : intval($tmp['pid']);
55 if (empty($newdata['patient_data']['pubpid'])) {
56 // pubpid for new patient defaults to pid.
57 $newdata['patient_data']['pubpid'] = "$ptid";
59 updatePatientData ($ptid, $newdata['patient_data' ], true);
60 updateEmployerData($ptid, $newdata['employer_data'], true);
61 newHistoryData($ptid);
64 $newdata['patient_data']['id'] = $_POST['db_id'];
65 updatePatientData($ptid, $newdata['patient_data']);
67 // Finally, delete the request from the portal.
68 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
69 if ($result['errmsg']) {
70 die(text($result['errmsg']));
72 echo "<html><body><script language='JavaScript'>\n";
73 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
74 echo "document.location.href = 'list_requests.php';\n";
75 echo "</script></body></html>\n";
81 $ptrow = getPatientData($ptid, "*");
82 $db_id = $ptrow['id'];
86 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
87 if ($result['errmsg']) {
88 die(text($result['errmsg']));
94 <?php
html_header_show(); ?
>
95 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
97 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
100 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
101 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
102 td input
{ background
-color
:transparent
; }
106 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
107 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
108 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
109 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
110 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
112 <script language
="JavaScript">
114 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
116 function myRestoreSession() {
117 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
121 // This capitalizes the first letter of each word in the passed input
122 // element. It also strips out extraneous spaces.
123 // Copied from demographics_full.php.
124 function capitalizeMe(elem
) {
125 var a
= elem
.value
.split(' ');
127 for(var i
= 0; i
< a
.length
; ++i
) {
128 if (a
[i
].length
> 0) {
129 if (s
.length
> 0) s +
= ' ';
130 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
136 // Generates and returns a random 6-character password.
138 function randompass() {
141 while (newpass
.length
< 6) {
142 var r
= Math
.floor(Math
.random() * 33); // for 2-9 and a-y
144 newchar
= String.fromCharCode('a'.charCodeAt(0) + r
- 8);
145 if (newchar
== 'l') newchar
= 'z';
147 newchar
= String.fromCharCode('2'.charCodeAt(0) + r
);
151 var e
= document
.forms
[0].form_cmsportal_login_pass
;
152 if (e
) e
.value
= newpass
;
155 // If needed, this creates the new patient in the CMS. It executes as an AJAX script
156 // in case it doesn't work and a correction is needed before submitting the form.
158 function validate() {
159 var f
= document
.forms
[0];
162 if (f
.form_cmsportal_login_pass
) {
163 var login
= encodeURIComponent(f
.form_cmsportal_login
.value
);
164 var pass
= encodeURIComponent(f
.form_cmsportal_login_pass
.value
);
165 var email
= encodeURIComponent(f
.form_email
.value
);
168 alert('<?php echo xls('Portal password is missing
'); ?>');
172 alert('<?php echo xls('Email address is missing
'); ?>');
175 // Need a *synchronous* ajax request here. Successful updating of the portal
176 // is required before we can submit the form.
180 url
: 'patient_form_ajax.php?login=' + login +
'&pass=' + pass +
'&email=' + email
,
182 success
: function(data
) {
191 if (errmsg
) return false;
198 <body
class="body_top">
201 <form method
='post' action
='patient_form.php' onsubmit
='return validate()'>
203 <input type
='hidden' name
='db_id' value
="<?php echo attr($db_id); ?>" />
204 <input type
='hidden' name
='ptid' value
="<?php echo attr($ptid); ?>" />
205 <input type
='hidden' name
='postid' value
="<?php echo attr($postid); ?>" />
207 <table width
='100%' cellpadding
='1' cellspacing
='2'>
209 <th align
='left'><?php
echo xlt('Field' ); ?
></th
>
210 <th align
='left'><?php
echo xlt('Current Value'); ?
></th
>
211 <th align
='left'><?php
echo xlt('New Value' ); ?
></th
>
215 $lores = sqlStatement("SELECT * FROM layout_options " .
216 "WHERE form_id = ? AND uor > 0 ORDER BY group_name, seq",
219 // Will be used to indicate if this user does not yet have a portal login.
220 $portal_registration_needed = false;
222 while ($lorow = sqlFetchArray($lores)) {
223 $data_type = $lorow['data_type'];
224 $field_id = $lorow['field_id'];
225 // We deal with this one at the end.
226 if ($field_id == 'cmsportal_login') continue;
227 // Flamingo translates field names to lower case so we have to match with those.
229 foreach ($result['fields'] as $key => $dummy) {
230 if (strcasecmp($key, $field_id) == 0) $reskey = $key;
232 // Generate form fields for items that are either from the WordPress form
233 // or are mandatory for a new patient.
234 if (isset($result['fields'][$reskey]) ||
($lorow['uor'] > 1 && $ptid == 0)) {
235 $list_id = $lorow['list_id'];
236 $field_title = $lorow['title'];
237 if ($field_title === '') $field_title = '(' . $field_id . ')';
240 if (isset($ptrow[$field_id])) $currvalue = $ptrow[$field_id];
242 /*****************************************************************
244 if (isset($result['fields'][$reskey])) $newvalue = $result['fields'][$reskey];
245 //// Zero-length input means nothing will change.
246 // if ($newvalue === '') $newvalue = $currvalue;
247 // $newvalue = trim($newvalue);
248 $newvalue = cms_field_to_lbf($newvalue, $data_type, $field_id);
249 *****************************************************************/
250 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
252 echo " <tr class='detail'>\n";
253 echo " <td class='bold'>" . text($field_title) . "</td>\n";
254 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
256 generate_form_field($lorow, $newvalue);
262 $field_id = 'cmsportal_login';
263 if (empty($ptrow[$field_id])) {
264 if ($result['post']['user'] !== '') {
265 // Registered in portal but still need to record that in openemr.
267 echo "<input type='hidden' name='form_$field_id' value='" . attr($result['post']['user']) . "' />\n";
270 // Portal registration is needed.
271 $newvalue = isset($result['fields']['email']) ?
trim($result['fields']['email']) : '';
272 echo " <tr class='detail'>\n";
273 echo " <td class='bold' style='color:red;'>" . xlt('New Portal Login') . "</td>\n";
274 echo " <td> </td>\n";
276 echo "<input type='text' name='form_$field_id' size='10' maxlength='60' value='" . attr($newvalue) . "' />";
277 echo " " . xlt('Password') . ": ";
278 echo "<input type='text' name='form_" . attr($field_id) . "_pass' size='10' maxlength='60' />";
279 echo "<input type='button' value='" . xla('Generate') . "' onclick='randompass()' />";
286 // Portal login name is already in openemr.
292 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
and Delete Request
'); ?>' />
294 <input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="window.history.back()" />
295 <!-- Was
: onclick
="myRestoreSession();location='list_requests.php'" -->
300 <script language
="JavaScript">
302 // hard code validation for old validation, in the new validation possible to add match rules
303 <?php
if($GLOBALS['new_validate'] == 0) { ?
>
305 // Fix inconsistently formatted phone numbers from the database.
306 var f
= document
.forms
[0];
307 if (f
.form_phone_contact
) phonekeyup(f
.form_phone_contact
,mypcc
);
308 if (f
.form_phone_home
) phonekeyup(f
.form_phone_home
,mypcc
);
309 if (f
.form_phone_biz
) phonekeyup(f
.form_phone_biz
,mypcc
);
310 if (f
.form_phone_cell
) phonekeyup(f
.form_phone_cell
,mypcc
);
316 // This is a by-product of generate_form_field().
317 <?php
echo $date_init; ?
>
321 <!-- include support
for the
list-add selectbox feature
-->
322 <?php
include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?
>