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>
25 require_once("../globals.php");
26 require_once("$srcdir/patient.inc");
27 require_once("$srcdir/options.inc.php");
28 require_once("portal.inc.php");
30 $postid = intval($_REQUEST['postid']);
31 $ptid = intval($_REQUEST['ptid' ]);
33 if ($_POST['bn_save']) {
35 $newdata['patient_data' ] = array();
36 $newdata['employer_data'] = array();
37 $ptid = intval($_POST['ptid']);
38 // Note we are careful to maintain cmsportal_login even if the layout has it
39 // configured as unused.
40 $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
41 "form_id = 'DEM' AND field_id != '' AND (uor > 0 OR field_id = 'cmsportal_login') " .
42 "ORDER BY group_name, seq");
43 while ($frow = sqlFetchArray($fres)) {
44 $data_type = $frow['data_type'];
45 $field_id = $frow['field_id'];
46 $table = 'patient_data';
47 if (isset($_POST["form_$field_id"])) {
48 $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";
60 updatePatientData($ptid, $newdata['patient_data' ], true);
61 updateEmployerData($ptid, $newdata['employer_data'], true);
62 newHistoryData($ptid);
64 $newdata['patient_data']['id'] = $_POST['db_id'];
65 updatePatientData($ptid, $newdata['patient_data']);
68 // Finally, delete the request from the portal.
69 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
70 if ($result['errmsg']) {
71 die(text($result['errmsg']));
74 echo "<html><body><script language='JavaScript'>\n";
75 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
76 echo "document.location.href = 'list_requests.php';\n";
77 echo "</script></body></html>\n";
83 $ptrow = getPatientData($ptid, "*");
84 $db_id = $ptrow['id'];
88 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
89 if ($result['errmsg']) {
90 die(text($result['errmsg']));
96 <?php
html_header_show(); ?
>
97 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
99 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
102 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
103 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
104 td input
{ background
-color
:transparent
; }
108 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
109 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
110 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
111 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
112 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
114 <script language
="JavaScript">
116 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
118 function myRestoreSession() {
119 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
123 // This capitalizes the first letter of each word in the passed input
124 // element. It also strips out extraneous spaces.
125 // Copied from demographics_full.php.
126 function capitalizeMe(elem
) {
127 var a
= elem
.value
.split(' ');
129 for(var i
= 0; i
< a
.length
; ++i
) {
130 if (a
[i
].length
> 0) {
131 if (s
.length
> 0) s +
= ' ';
132 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
138 // Generates and returns a random 6-character password.
140 function randompass() {
143 while (newpass
.length
< 6) {
144 var r
= Math
.floor(Math
.random() * 33); // for 2-9 and a-y
146 newchar
= String.fromCharCode('a'.charCodeAt(0) + r
- 8);
147 if (newchar
== 'l') newchar
= 'z';
149 newchar
= String.fromCharCode('2'.charCodeAt(0) + r
);
153 var e
= document
.forms
[0].form_cmsportal_login_pass
;
154 if (e
) e
.value
= newpass
;
157 // If needed, this creates the new patient in the CMS. It executes as an AJAX script
158 // in case it doesn't work and a correction is needed before submitting the form.
160 function validate() {
161 var f
= document
.forms
[0];
164 if (f
.form_cmsportal_login_pass
) {
165 var login
= encodeURIComponent(f
.form_cmsportal_login
.value
);
166 var pass
= encodeURIComponent(f
.form_cmsportal_login_pass
.value
);
167 var email
= encodeURIComponent(f
.form_email
.value
);
170 alert('<?php echo xls('Portal password is missing
'); ?>');
174 alert('<?php echo xls('Email address is missing
'); ?>');
177 // Need a *synchronous* ajax request here. Successful updating of the portal
178 // is required before we can submit the form.
182 url
: 'patient_form_ajax.php?login=' + login +
'&pass=' + pass +
'&email=' + email
,
184 success
: function(data
) {
193 if (errmsg
) return false;
200 <body
class="body_top">
203 <form method
='post' action
='patient_form.php' onsubmit
='return validate()'>
205 <input type
='hidden' name
='db_id' value
="<?php echo attr($db_id); ?>" />
206 <input type
='hidden' name
='ptid' value
="<?php echo attr($ptid); ?>" />
207 <input type
='hidden' name
='postid' value
="<?php echo attr($postid); ?>" />
209 <table width
='100%' cellpadding
='1' cellspacing
='2'>
211 <th align
='left'><?php
echo xlt('Field'); ?
></th
>
212 <th align
='left'><?php
echo xlt('Current Value'); ?
></th
>
213 <th align
='left'><?php
echo xlt('New Value'); ?
></th
>
217 $lores = sqlStatement(
218 "SELECT * FROM layout_options " .
219 "WHERE form_id = ? AND uor > 0 ORDER BY group_name, seq",
223 // Will be used to indicate if this user does not yet have a portal login.
224 $portal_registration_needed = false;
226 while ($lorow = sqlFetchArray($lores)) {
227 $data_type = $lorow['data_type'];
228 $field_id = $lorow['field_id'];
229 // We deal with this one at the end.
230 if ($field_id == 'cmsportal_login') {
234 // Flamingo translates field names to lower case so we have to match with those.
236 foreach ($result['fields'] as $key => $dummy) {
237 if (strcasecmp($key, $field_id) == 0) {
242 // Generate form fields for items that are either from the WordPress form
243 // or are mandatory for a new patient.
244 if (isset($result['fields'][$reskey]) ||
($lorow['uor'] > 1 && $ptid == 0)) {
245 $list_id = $lorow['list_id'];
246 $field_title = $lorow['title'];
247 if ($field_title === '') {
248 $field_title = '(' . $field_id . ')';
252 if (isset($ptrow[$field_id])) {
253 $currvalue = $ptrow[$field_id];
256 /*****************************************************************
258 if (isset($result['fields'][$reskey])) $newvalue = $result['fields'][$reskey];
259 //// Zero-length input means nothing will change.
260 // if ($newvalue === '') $newvalue = $currvalue;
261 // $newvalue = trim($newvalue);
262 $newvalue = cms_field_to_lbf($newvalue, $data_type, $field_id);
263 *****************************************************************/
264 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
266 echo " <tr class='detail'>\n";
267 echo " <td class='bold'>" . text($field_title) . "</td>\n";
268 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
270 generate_form_field($lorow, $newvalue);
276 $field_id = 'cmsportal_login';
277 if (empty($ptrow[$field_id])) {
278 if ($result['post']['user'] !== '') {
279 // Registered in portal but still need to record that in openemr.
281 echo "<input type='hidden' name='form_$field_id' value='" . attr($result['post']['user']) . "' />\n";
283 // Portal registration is needed.
284 $newvalue = isset($result['fields']['email']) ?
trim($result['fields']['email']) : '';
285 echo " <tr class='detail'>\n";
286 echo " <td class='bold' style='color:red;'>" . xlt('New Portal Login') . "</td>\n";
287 echo " <td> </td>\n";
289 echo "<input type='text' name='form_$field_id' size='10' maxlength='60' value='" . attr($newvalue) . "' />";
290 echo " " . xlt('Password') . ": ";
291 echo "<input type='text' name='form_" . attr($field_id) . "_pass' size='10' maxlength='60' />";
292 echo "<input type='button' value='" . xla('Generate') . "' onclick='randompass()' />";
298 // Portal login name is already in openemr.
304 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
and Delete Request
'); ?>' />
306 <input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="window.history.back()" />
307 <!-- Was
: onclick
="myRestoreSession();location='list_requests.php'" -->
312 <script language
="JavaScript">
314 // hard code validation for old validation, in the new validation possible to add match rules
315 <?php
if ($GLOBALS['new_validate'] == 0) { ?
>
317 // Fix inconsistently formatted phone numbers from the database.
318 var f
= document
.forms
[0];
319 if (f
.form_phone_contact
) phonekeyup(f
.form_phone_contact
,mypcc
);
320 if (f
.form_phone_home
) phonekeyup(f
.form_phone_home
,mypcc
);
321 if (f
.form_phone_biz
) phonekeyup(f
.form_phone_biz
,mypcc
);
322 if (f
.form_phone_cell
) phonekeyup(f
.form_phone_cell
,mypcc
);
328 // This is a by-product of generate_form_field().
329 <?php
echo $date_init; ?
>
333 <!-- include support
for the
list-add selectbox feature
-->
334 <?php
include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?
>