Fix to clear LBF form data that is not returned by the form but is defined in its...
[openemr.git] / interface / forms / LBF / new.php
blobe4043d92abd41755ca996ebc4113c483ce77f6c4
1 <?php
2 /**
3 * Copyright (C) 2009-2014 Rod Roark <rod@sunsetsystems.com>
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
16 * @package OpenEMR
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @link http://www.open-emr.org
21 //SANITIZE ALL ESCAPES
22 $sanitize_all_escapes=true;
24 //STOP FAKE REGISTER GLOBALS
25 $fake_register_globals=false;
27 require_once("../../globals.php");
28 require_once("$srcdir/api.inc");
29 require_once("$srcdir/forms.inc");
30 require_once("$srcdir/options.inc.php");
31 require_once("$srcdir/patient.inc");
32 require_once("$srcdir/formdata.inc.php");
33 require_once("$srcdir/formatting.inc.php");
34 if ($GLOBALS['gbl_portal_cms_enable']) {
35 require_once("$include_root/cmsportal/portal.inc.php");
38 $CPR = 4; // cells per row
40 $pprow = array();
42 // $is_lbf is defined in trend_form.php and indicates that we are being
43 // invoked from there; in that case the current encounter is irrelevant.
44 if (empty($is_lbf) && !$encounter) {
45 die("Internal error: we do not seem to be in an encounter!");
48 function end_cell() {
49 global $item_count, $cell_count, $historical_ids;
50 if ($item_count > 0) {
51 // echo "&nbsp;</td>";
52 echo "</td>";
54 foreach ($historical_ids as $key => $dummy) {
55 // $historical_ids[$key] .= "&nbsp;</td>";
56 $historical_ids[$key] .= "</td>";
59 $item_count = 0;
63 function end_row() {
64 global $cell_count, $CPR, $historical_ids;
65 end_cell();
66 if ($cell_count > 0) {
67 for (; $cell_count < $CPR; ++$cell_count) {
68 echo "<td></td>";
69 foreach ($historical_ids as $key => $dummy) {
70 $historical_ids[$key] .= "<td></td>";
74 foreach ($historical_ids as $key => $dummy) {
75 echo $historical_ids[$key];
78 echo "</tr>\n";
79 $cell_count = 0;
83 function end_group() {
84 global $last_group;
85 if (strlen($last_group) > 0) {
86 end_row();
87 echo " </table>\n";
88 // No div for an empty group name.
89 if (strlen($last_group) > 1) {
90 echo "</div>\n"; // div after checkbox
91 echo "</div>\n"; // outer div, including checkbox
96 $formname = isset($_GET['formname']) ? $_GET['formname'] : '';
97 $formid = isset($_GET['id'] ) ? intval($_GET['id']) : 0;
98 $portalid = isset($_GET['portalid']) ? intval($_GET['portalid']) : 0;
100 // Get title and number of history columns for this form.
101 $tmp = sqlQuery("SELECT title, option_value FROM list_options WHERE " .
102 "list_id = 'lbfnames' AND option_id = ?", array($formname) );
103 $formtitle = $tmp['title'];
104 $formhistory = 0 + $tmp['option_value'];
106 if (empty($is_lbf)) {
107 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
108 if (file_exists($fname)) include_once($fname);
111 // If Save was clicked, save the info.
113 if ($_POST['bn_save']) {
114 $newid = 0;
115 if (!$formid) {
116 // Creating a new form. Get the new form_id by inserting and deleting a dummy row.
117 // This is necessary to create the form instance even if it has no native data.
118 $newid = sqlInsert("INSERT INTO lbf_data " .
119 "( field_id, field_value ) VALUES ( '', '' )");
120 sqlStatement("DELETE FROM lbf_data WHERE form_id = ? AND " .
121 "field_id = ''", array($newid));
122 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
124 $sets = "";
125 $fres = sqlStatement("SELECT * FROM layout_options " .
126 "WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
127 "edit_options != 'H' AND edit_options NOT LIKE '%0%' " .
128 "ORDER BY group_name, seq", array($formname) );
129 while ($frow = sqlFetchArray($fres)) {
130 $field_id = $frow['field_id'];
131 $data_type = $frow['data_type'];
132 // If the field was not in the web form, skip it.
133 // Except if it's checkboxes, if unchecked they are not returned.
135 // if ($data_type != 21 && !isset($_POST["form_$field_id"])) continue;
137 // The above statement commented out 2015-01-12 because a LBF plugin might conditionally
138 // disable a field that is not applicable, and we need the ability to clear out the old
139 // garbage in there so it does not show up in the "report" view of the data. So we will
140 // trust that it's OK to clear any field that is defined in the layout but not returned
141 // by the form.
143 $value = get_layout_form_value($frow);
144 // If edit option P or Q, save to the appropriate different table and skip the rest.
145 $source = $frow['source'];
146 if ($source == 'D' || $source == 'H') {
147 // Save to patient_data, employer_data or history_data.
148 if ($source == 'H') {
149 $new = array($field_id => $value);
150 updateHistoryData($pid, $new);
152 else if (strpos($field_id, 'em_') === 0) {
153 $field_id = substr($field_id, 3);
154 $new = array($field_id => $value);
155 updateEmployerData($pid, $new);
157 else {
158 $esc_field_id = escape_sql_column_name($field_id, array('patient_data'));
159 sqlStatement("UPDATE patient_data SET `$esc_field_id` = ? WHERE pid = ?",
160 array($value, $pid));
162 continue;
164 else if ($source == 'E') {
165 // Save to shared_attributes. Can't delete entries for empty fields because with the P option
166 // it's important to know when a current empty value overrides a previous value.
167 sqlStatement("REPLACE INTO shared_attributes SET " .
168 "pid = ?, encounter = ?, field_id = ?, last_update = NOW(), " .
169 "user_id = ?, field_value = ?",
170 array($pid, $encounter, $field_id, $_SESSION['authUserID'], $value));
171 continue;
173 else if ($source == 'V') {
174 // Save to form_encounter.
175 $esc_field_id = escape_sql_column_name($field_id, array('form_encounter'));
176 sqlStatement("UPDATE form_encounter SET `$esc_field_id` = ? WHERE " .
177 "pid = ? AND encounter = ?",
178 array($value, $pid, $encounter));
179 continue;
181 // It's a normal form field, save to lbf_data.
182 if ($formid) { // existing form
183 if ($value === '') {
184 $query = "DELETE FROM lbf_data WHERE " .
185 "form_id = ? AND field_id = ?";
186 sqlStatement($query, array($formid, $field_id));
188 else {
189 $query = "REPLACE INTO lbf_data SET field_value = ?, " .
190 "form_id = ?, field_id = ?";
191 sqlStatement($query,array($value, $formid, $field_id));
194 else { // new form
195 if ($value !== '') {
196 sqlStatement("INSERT INTO lbf_data " .
197 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
198 array($newid, $field_id, $value));
203 if ($portalid) {
204 // Delete the request from the portal.
205 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $portalid));
206 if ($result['errmsg']) {
207 die(text($result['errmsg']));
211 // Support custom behavior at save time, such as going to another form.
212 if (function_exists($formname . '_save_exit')) {
213 if (call_user_func($formname . '_save_exit')) exit;
215 formHeader("Redirecting....");
216 formJump();
217 formFooter();
218 exit;
222 <html>
223 <head>
224 <?php html_header_show();?>
225 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
226 <style>
228 td, input, select, textarea {
229 font-family: Arial, Helvetica, sans-serif;
230 font-size: 10pt;
233 div.section {
234 border: solid;
235 border-width: 1px;
236 border-color: #0000ff;
237 margin: 0 0 0 10pt;
238 padding: 5pt;
241 </style>
243 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
245 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
246 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
247 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
248 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
249 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
250 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
251 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
252 <script type="text/javascript" src="../../../library/textformat.js"></script>
253 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
254 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
255 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
256 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
258 <script language="JavaScript">
259 $(document).ready(function() {
260 // fancy box
261 if (window.enable_modals) {
262 enable_modals();
264 if(window.tabbify){
265 tabbify();
267 if (window.checkSkipConditions) {
268 checkSkipConditions();
270 // special size for
271 $(".iframe_medium").fancybox({
272 'overlayOpacity' : 0.0,
273 'showCloseButton' : true,
274 'frameHeight' : 580,
275 'frameWidth' : 900
277 $(function() {
278 // add drag and drop functionality to fancybox
279 $("#fancy_outer").easydrag();
283 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
285 // Supports customizable forms.
286 function divclick(cb, divid) {
287 var divstyle = document.getElementById(divid).style;
288 if (cb.checked) {
289 divstyle.display = 'block';
290 } else {
291 divstyle.display = 'none';
293 return true;
296 // The ID of the input element to receive a found code.
297 var current_sel_name = '';
299 // This is for callback by the find-code popup.
300 // Appends to or erases the current list of related codes.
301 function set_related(codetype, code, selector, codedesc) {
302 var f = document.forms[0];
303 // frc will be the input element containing the codes.
304 // frcd, if set, will be the input element containing their descriptions.
305 var frc = f[current_sel_name];
306 var frcd;
307 var matches = current_sel_name.match(/^(.*)__desc$/);
308 if (matches) {
309 frcd = frc;
310 frc = f[matches[1]];
312 var s = frc.value;
313 var sd = frcd ? frcd.value : s;
314 if (code) {
315 if (codetype != 'PROD') {
316 if (s.indexOf(codetype + ':') == 0 || s.indexOf(';' + codetype + ':') > 0) {
317 return '<?php echo xl('A code of this type is already selected. Erase the field first if you need to replace it.') ?>';
320 if (s.length > 0) {
321 s += ';';
322 sd += ';';
324 s += codetype + ':' + code;
325 sd += codedesc;
326 } else {
327 s = '';
328 sd = '';
330 frc.value = s;
331 if (frcd) frcd.value = sd;
332 return '';
335 // This invokes the find-code popup.
336 function sel_related(elem, codetype) {
337 current_sel_name = elem.name;
338 var url = '<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php';
339 if (codetype) url += '?codetype=' + codetype;
340 dlgopen(url, '_blank', 500, 400);
343 // Validation logic for form submission.
344 function validate(f) {
345 <?php generate_layout_validation($formname); ?>
346 top.restoreSession();
347 return true;
349 <?php if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?>
351 </script>
352 </head>
354 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
356 <?php
357 echo "<form method='post' " .
358 "action='$rootdir/forms/LBF/new.php?formname=$formname&id=$formid&portalid=$portalid' " .
359 "onsubmit='return validate(this)'>\n";
361 $cmsportal_login = '';
362 $portalres = FALSE;
363 if (empty($is_lbf)) {
364 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, p.cmsportal_login, " .
365 "fe.date FROM " .
366 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
367 "p.pid = ? AND f.pid = p.pid AND f.encounter = ? AND " .
368 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
369 "fe.id = f.form_id LIMIT 1", array($pid, $encounter));
370 echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
371 echo text($formtitle) . " " . xlt('for') . ' ';
372 echo text($enrow['fname']) . ' ' . text($enrow['mname']) . ' ' . text($enrow['lname']);
373 echo ' ' . xlt('on') . ' ' . text(oeFormatShortDate(substr($enrow['date'], 0, 10)));
374 echo "</p>\n";
375 $cmsportal_login = $enrow['cmsportal_login'];
377 // If loading data from portal, get the data.
378 if ($GLOBALS['gbl_portal_cms_enable'] && $portalid) {
379 $portalres = cms_portal_call(array('action' => 'getpost', 'postid' => $portalid));
380 if ($portalres['errmsg']) {
381 die(text($portalres['errmsg']));
386 <!-- This is where a chart might display. -->
387 <div id="chart"></div>
389 <?php
390 $shrow = getHistoryData($pid);
392 $fres = sqlStatement("SELECT * FROM layout_options " .
393 "WHERE form_id = ? AND uor > 0 " .
394 "ORDER BY group_name, seq", array($formname) );
395 $last_group = '';
396 $cell_count = 0;
397 $item_count = 0;
398 $display_style = 'block';
400 // This is an array keyed on forms.form_id for other occurrences of this
401 // form type. The maximum number of such other occurrences to display is
402 // in list_options.option_value for this form's list item. Values in this
403 // array are work areas for building the ending HTML for each displayed row.
405 $historical_ids = array();
407 // True if any data items in this form can be graphed.
408 $form_is_graphable = false;
410 $condition_str = '';
412 while ($frow = sqlFetchArray($fres)) {
413 $this_group = $frow['group_name'];
414 $titlecols = $frow['titlecols'];
415 $datacols = $frow['datacols'];
416 $data_type = $frow['data_type'];
417 $field_id = $frow['field_id'];
418 $list_id = $frow['list_id'];
419 $edit_options = $frow['edit_options'];
420 $source = $frow['source'];
422 $graphable = strpos($edit_options, 'G') !== FALSE;
423 if ($graphable) $form_is_graphable = true;
425 // Accumulate skip conditions into a JavaScript string literal.
426 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
427 foreach ($conditions as $condition) {
428 if (empty($condition['id'])) continue;
429 $andor = empty($condition['andor']) ? '' : $condition['andor'];
430 if ($condition_str) $condition_str .= ",\n";
431 $condition_str .= "{" .
432 "target:'" . addslashes($field_id) . "', " .
433 "id:'" . addslashes($condition['id']) . "', " .
434 "itemid:'" . addslashes($condition['itemid']) . "', " .
435 "operator:'" . addslashes($condition['operator']) . "', " .
436 "value:'" . addslashes($condition['value']) . "', " .
437 "andor:'" . addslashes($andor) . "'}";
440 $currvalue = '';
442 if ($frow['edit_options'] == 'H') {
443 // This data comes from static history
444 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
445 } else {
446 $currvalue = lbf_current_value($frow, $formid, $is_lbf ? 0 : $encounter);
447 if ($currvalue === FALSE) continue; // column does not exist, should not happen
448 // Handle "P" edit option to default to the previous value of a form field.
449 if (!$is_lbf && empty($currvalue) && strpos($edit_options, 'P') !== FALSE) {
450 if ($source == 'F' && !$formid) {
451 // Form attribute for new form, get value from most recent form instance.
452 // Form attributes of existing forms are expected to have existing values.
453 $tmp = sqlQuery("SELECT encounter, form_id FROM forms WHERE " .
454 "pid = ? AND formdir = ? AND deleted = 0 " .
455 "ORDER BY date DESC LIMIT 1",
456 array($pid, $formname));
457 if (!empty($tmp['encounter'])) {
458 $currvalue = lbf_current_value($frow, $tmp['form_id'], $tmp['encounter']);
461 else if ($source == 'E') {
462 // Visit attribute, get most recent value as of this visit.
463 // Even if the form already exists for this visit it may have a readonly value that only
464 // exists in a previous visit and was created from a different form.
465 $tmp = sqlQuery("SELECT sa.field_value FROM form_encounter AS e1 " .
466 "JOIN form_encounter AS e2 ON " .
467 "e2.pid = e1.pid AND (e2.date < e1.date OR (e2.date = e1.date AND e2.encounter <= e1.encounter)) " .
468 "JOIN shared_attributes AS sa ON " .
469 "sa.pid = e2.pid AND sa.encounter = e2.encounter AND sa.field_id = ?" .
470 "WHERE e1.pid = ? AND e1.encounter = ? " .
471 "ORDER BY e2.date DESC, e2.encounter DESC LIMIT 1",
472 array($field_id, $pid, $encounter));
473 if (isset($tmp['field_value'])) $currvalue = $tmp['field_value'];
475 } // End "P" option logic.
478 // Handle a data category (group) change.
479 if (strcmp($this_group, $last_group) != 0) {
480 end_group();
481 $group_seq = 'lbf' . substr($this_group, 0, 1);
482 $group_name = substr($this_group, 1);
483 $last_group = $this_group;
485 // If group name is blank, no checkbox or div.
486 if (strlen($this_group) > 1) {
487 echo "<div id='outerdiv_" . attr($group_seq) . "'>\n";
488 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_" . attr($group_seq) . "' value='1' " .
489 "onclick='return divclick(this,\"div_" . attr(addslashes($group_seq)) . "\");'";
490 if ($display_style == 'block') echo " checked";
491 echo " /><b>" . text(xl_layout_label($group_name)) . "</b></span>\n";
492 echo "<div id='div_" . attr($group_seq) . "' class='section' style='display:" . attr($display_style) . ";'>\n";
494 // echo " <table border='0' cellpadding='0' width='100%'>\n";
495 echo " <table border='0' cellspacing='0' cellpadding='0'>\n";
496 $display_style = 'none';
498 // Initialize historical data array and write date headers.
499 $historical_ids = array();
500 if ($formhistory > 0) {
501 echo " <tr>";
502 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>";
503 if (empty($is_lbf)){
504 // Including actual date per IPPF request 2012-08-23.
505 echo oeFormatShortDate(substr($enrow['date'], 0, 10));
506 echo ' (' . htmlspecialchars(xl('Current')) . ')';
508 echo "&nbsp;</td>\n";
509 $hres = sqlStatement("SELECT f.form_id, fe.date " .
510 "FROM forms AS f, form_encounter AS fe WHERE " .
511 "f.pid = ? AND f.formdir = ? AND " .
512 "f.form_id != ? AND f.deleted = 0 AND " .
513 "fe.pid = f.pid AND fe.encounter = f.encounter " .
514 "ORDER BY fe.date DESC, f.encounter DESC, f.date DESC " .
515 "LIMIT ?",
516 array($pid, $formname, $formid, $formhistory));
517 // For some readings like vitals there may be multiple forms per encounter.
518 // We sort these sensibly, however only the encounter date is shown here;
519 // at some point we may wish to show also the data entry date/time.
520 while ($hrow = sqlFetchArray($hres)) {
521 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>&nbsp;" .
522 text(oeFormatShortDate(substr($hrow['date'], 0, 10))) . "</td>\n";
523 $historical_ids[$hrow['form_id']] = '';
525 echo " </tr>";
530 // Handle starting of a new row.
531 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
532 end_row();
533 echo " <tr>";
534 // Clear historical data string.
535 foreach ($historical_ids as $key => $dummy) {
536 $historical_ids[$key] = '';
540 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
542 // First item is on the "left-border"
543 $leftborder = true;
545 // Handle starting of a new label cell.
546 if ($titlecols > 0) {
547 end_cell();
548 echo "<td valign='top' colspan='" . attr($titlecols) . "' nowrap";
549 echo " class='";
550 echo ($frow['uor'] == 2) ? "required" : "bold";
551 if ($graphable) echo " graph";
552 echo "'";
553 if ($cell_count == 2) echo " style='padding-left:10pt'";
554 // This ID is used by skip conditions and also show_graph().
555 echo " id='label_id_" . attr($field_id) . "'";
556 echo ">";
558 foreach ($historical_ids as $key => $dummy) {
559 $historical_ids[$key] .= "<td valign='top' colspan='" . attr($titlecols) . "' class='text' nowrap>";
562 $cell_count += $titlecols;
564 ++$item_count;
566 echo "<b>";
567 if ($frow['title']) echo text(xl_layout_label($frow['title']) . ":"); else echo "&nbsp;";
568 echo "</b>";
570 // Note the labels are not repeated in the history columns.
572 // Handle starting of a new data cell.
573 if ($datacols > 0) {
574 end_cell();
575 echo "<td valign='top' colspan='" . attr($datacols) . "' class='text'";
576 // This ID is used by skip conditions.
577 echo " id='value_id_" . attr($field_id) . "'";
578 if ($cell_count > 0) echo " style='padding-left:5pt'";
579 echo ">";
581 foreach ($historical_ids as $key => $dummy) {
582 $historical_ids[$key] .= "<td valign='top' align='right' colspan='" . attr($datacols) . "' class='text'>";
585 $cell_count += $datacols;
588 ++$item_count;
590 // Skip current-value fields for the display-only case.
591 if (empty($is_lbf)) {
592 if ($frow['edit_options'] == 'H')
593 echo generate_display_field($frow, $currvalue);
594 else
595 generate_form_field($frow, $currvalue);
598 // Append to historical data of other dates for this item.
599 foreach ($historical_ids as $key => $dummy) {
600 $value = lbf_current_value($frow, $key, 0);
601 $historical_ids[$key] .= generate_display_field($frow, $value);
606 end_group();
609 <p style='text-align:center'>
610 <?php if (empty($is_lbf)) { ?>
611 <input type='submit' name='bn_save' value='<?php echo xla('Save') ?>' />
612 <?php
613 if (function_exists($formname . '_additional_buttons')) {
614 // Allow the plug-in to insert more action buttons here.
615 call_user_func($formname . '_additional_buttons');
618 &nbsp;
619 <input type='button' value='<?php echo xla('Cancel') ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
620 &nbsp;
621 <?php if ($form_is_graphable) { ?>
622 <input type='button' value='<?php echo xla('Show Graph') ?>' onclick="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo attr($formname); ?>'" />
623 &nbsp;
624 <?php } ?>
625 <?php } else { ?>
626 <input type='button' value='<?php echo xla('Back') ?>' onclick='window.history.back();' />
627 <?php } ?>
628 </p>
630 </form>
632 <!-- include support for the list-add selectbox feature -->
633 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
635 <script language="JavaScript">
637 // Array of skip conditions for the checkSkipConditions() function.
638 var skipArray = [
639 <?php echo $condition_str; ?>
642 <?php echo $date_init; ?>
643 <?php
644 if (function_exists($formname . '_javascript_onload')) {
645 call_user_func($formname . '_javascript_onload');
648 // TBD: If $alertmsg, display it with a JavaScript alert().
650 // New form and this patient has a portal login and we have not loaded portal data.
651 // Check if there is portal data pending for this patient and form type.
652 if (!$formid && $GLOBALS['gbl_portal_cms_enable'] && $cmsportal_login && !$portalid) {
653 $portalres = cms_portal_call(array('action' => 'checkptform', 'form' => $formname, 'patient' => $cmsportal_login));
654 if ($portalres['errmsg']) {
655 die(text($portalres['errmsg'])); // TBD: Change to alertmsg
657 $portalid = $portalres['postid'];
658 if ($portalid) {
659 echo "if (confirm('" . xls('The portal has data for this patient and form. Load it now?') . "')) {\n";
660 echo " top.restoreSession();\n";
661 echo " document.location.href = 'load_form.php?formname=$formname&portalid=$portalid';\n";
662 echo "}\n";
666 </script>
668 </body>
669 </html>