3 * Patient matching and selection for the WordPress Patient Portal.
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']) {
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);
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);
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";
73 $ptrow = getPatientData($ptid, "*");
74 $db_id = $ptrow['id'];
78 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
79 if ($result['errmsg']) {
80 die(text($result['errmsg']));
86 <?php
html_header_show(); ?
>
87 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
88 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
92 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
93 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
94 td input
{ background
-color
:transparent
; }
98 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
99 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-7-2/jquery.min.js"></script
>
100 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script
>
102 <script language
="JavaScript">
104 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
106 function myRestoreSession() {
107 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
111 // This capitalizes the first letter of each word in the passed input
112 // element. It also strips out extraneous spaces.
113 // Copied from demographics_full.php.
114 function capitalizeMe(elem
) {
115 var a
= elem
.value
.split(' ');
117 for(var i
= 0; i
< a
.length
; ++i
) {
118 if (a
[i
].length
> 0) {
119 if (s
.length
> 0) s +
= ' ';
120 s +
= a
[i
].charAt(0).toUpperCase() + a
[i
].substring(1);
126 // Generates and returns a random 6-character password.
128 function randompass() {
131 while (newpass
.length
< 6) {
132 var r
= Math
.floor(Math
.random() * 33); // for 2-9 and a-y
134 newchar
= String.fromCharCode('a'.charCodeAt(0) + r
- 8);
135 if (newchar
== 'l') newchar
= 'z';
137 newchar
= String.fromCharCode('2'.charCodeAt(0) + r
);
141 var e
= document
.forms
[0].form_cmsportal_login_pass
;
142 if (e
) e
.value
= newpass
;
145 // If needed, this creates the new patient in the CMS. It executes as an AJAX script
146 // in case it doesn't work and a correction is needed before submitting the form.
148 function validate() {
149 var f
= document
.forms
[0];
152 if (f
.form_cmsportal_login_pass
) {
153 var login
= encodeURIComponent(f
.form_cmsportal_login
.value
);
154 var pass
= encodeURIComponent(f
.form_cmsportal_login_pass
.value
);
155 var email
= encodeURIComponent(f
.form_email
.value
);
158 alert('<?php echo xls('Portal password is missing
'); ?>');
162 alert('<?php echo xls('Email address is missing
'); ?>');
165 // Need a *synchronous* ajax request here. Successful updating of the portal
166 // is required before we can submit the form.
170 url
: 'patient_form_ajax.php?login=' + login +
'&pass=' + pass +
'&email=' + email
,
172 success
: function(data
) {
181 if (errmsg
) return false;
185 $
(document
).ready(function() {
186 $
('.datepicker').datetimepicker({
187 <?php
$datetimepicker_timepicker = false; ?
>
188 <?php
$datetimepicker_showseconds = false; ?
>
189 <?php
$datetimepicker_formatInput = true; ?
>
190 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
191 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
193 $
('.datetimepicker').datetimepicker({
194 <?php
$datetimepicker_timepicker = true; ?
>
195 <?php
$datetimepicker_showseconds = false; ?
>
196 <?php
$datetimepicker_formatInput = true; ?
>
197 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
198 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
205 <body
class="body_top">
208 <form method
='post' action
='patient_form.php' onsubmit
='return validate()'>
210 <input type
='hidden' name
='db_id' value
="<?php echo attr($db_id); ?>" />
211 <input type
='hidden' name
='ptid' value
="<?php echo attr($ptid); ?>" />
212 <input type
='hidden' name
='postid' value
="<?php echo attr($postid); ?>" />
214 <table width
='100%' cellpadding
='1' cellspacing
='2'>
216 <th align
='left'><?php
echo xlt('Field'); ?
></th
>
217 <th align
='left'><?php
echo xlt('Current Value'); ?
></th
>
218 <th align
='left'><?php
echo xlt('New Value'); ?
></th
>
222 $lores = sqlStatement(
223 "SELECT * FROM layout_options " .
224 "WHERE form_id = ? AND uor > 0 ORDER BY group_id, seq",
228 // Will be used to indicate if this user does not yet have a portal login.
229 $portal_registration_needed = false;
231 while ($lorow = sqlFetchArray($lores)) {
232 $data_type = $lorow['data_type'];
233 $field_id = $lorow['field_id'];
234 // We deal with this one at the end.
235 if ($field_id == 'cmsportal_login') {
239 // Flamingo translates field names to lower case so we have to match with those.
241 foreach ($result['fields'] as $key => $dummy) {
242 if (strcasecmp($key, $field_id) == 0) {
247 // Generate form fields for items that are either from the WordPress form
248 // or are mandatory for a new patient.
249 if (isset($result['fields'][$reskey]) ||
($lorow['uor'] > 1 && $ptid == 0)) {
250 $list_id = $lorow['list_id'];
251 $field_title = $lorow['title'];
252 if ($field_title === '') {
253 $field_title = '(' . $field_id . ')';
257 if (isset($ptrow[$field_id])) {
258 $currvalue = $ptrow[$field_id];
261 /*****************************************************************
263 if (isset($result['fields'][$reskey])) $newvalue = $result['fields'][$reskey];
264 //// Zero-length input means nothing will change.
265 // if ($newvalue === '') $newvalue = $currvalue;
266 // $newvalue = trim($newvalue);
267 $newvalue = cms_field_to_lbf($newvalue, $data_type, $field_id);
268 *****************************************************************/
269 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
271 echo " <tr class='detail'>\n";
272 echo " <td class='bold'>" . text($field_title) . "</td>\n";
273 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
275 generate_form_field($lorow, $newvalue);
281 $field_id = 'cmsportal_login';
282 if (empty($ptrow[$field_id])) {
283 if ($result['post']['user'] !== '') {
284 // Registered in portal but still need to record that in openemr.
286 echo "<input type='hidden' name='form_$field_id' value='" . attr($result['post']['user']) . "' />\n";
288 // Portal registration is needed.
289 $newvalue = isset($result['fields']['email']) ?
trim($result['fields']['email']) : '';
290 echo " <tr class='detail'>\n";
291 echo " <td class='bold' style='color:red;'>" . xlt('New Portal Login') . "</td>\n";
292 echo " <td> </td>\n";
294 echo "<input type='text' name='form_$field_id' size='10' maxlength='60' value='" . attr($newvalue) . "' />";
295 echo " " . xlt('Password') . ": ";
296 echo "<input type='text' name='form_" . attr($field_id) . "_pass' size='10' maxlength='60' />";
297 echo "<input type='button' value='" . xla('Generate') . "' onclick='randompass()' />";
303 // Portal login name is already in openemr.
309 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
and Delete Request
'); ?>' />
311 <input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="window.history.back()" />
312 <!-- Was
: onclick
="myRestoreSession();location='list_requests.php'" -->
317 <script language
="JavaScript">
319 // hard code validation for old validation, in the new validation possible to add match rules
320 <?php
if ($GLOBALS['new_validate'] == 0) { ?
>
322 // Fix inconsistently formatted phone numbers from the database.
323 var f
= document
.forms
[0];
324 if (f
.form_phone_contact
) phonekeyup(f
.form_phone_contact
,mypcc
);
325 if (f
.form_phone_home
) phonekeyup(f
.form_phone_home
,mypcc
);
326 if (f
.form_phone_biz
) phonekeyup(f
.form_phone_biz
,mypcc
);
327 if (f
.form_phone_cell
) phonekeyup(f
.form_phone_cell
,mypcc
);
333 // This is a by-product of generate_form_field().
334 <?php
echo $date_init; ?
>
338 <!-- include support
for the
list-add selectbox feature
-->
339 <?php
include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?
>