Centralized formatting.inc.php include
[openemr.git] / interface / forms / LBF / new.php
blob2cb7927d062484226bd6e56eaa3d41b07501ed19
1 <?php
2 /**
3 * Copyright (C) 2009-2017 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 if ($GLOBALS['gbl_portal_cms_enable']) {
33 require_once("$include_root/cmsportal/portal.inc.php");
36 $CPR = 4; // cells per row
38 $pprow = array();
40 // $is_lbf is defined in trend_form.php and indicates that we are being
41 // invoked from there; in that case the current encounter is irrelevant.
42 if (empty($is_lbf) && !$encounter) {
43 die("Internal error: we do not seem to be in an encounter!");
46 function end_cell() {
47 global $item_count, $cell_count, $historical_ids;
48 if ($item_count > 0) {
49 // echo "&nbsp;</td>";
50 echo "</td>";
52 foreach ($historical_ids as $key => $dummy) {
53 // $historical_ids[$key] .= "&nbsp;</td>";
54 $historical_ids[$key] .= "</td>";
57 $item_count = 0;
61 function end_row() {
62 global $cell_count, $CPR, $historical_ids;
63 end_cell();
64 if ($cell_count > 0) {
65 for (; $cell_count < $CPR; ++$cell_count) {
66 echo "<td></td>";
67 foreach ($historical_ids as $key => $dummy) {
68 $historical_ids[$key] .= "<td></td>";
72 foreach ($historical_ids as $key => $dummy) {
73 echo $historical_ids[$key];
76 echo "</tr>\n";
77 $cell_count = 0;
81 function end_group() {
82 global $last_group;
83 if (strlen($last_group) > 0) {
84 end_row();
85 echo " </table>\n";
86 // No div for an empty group name.
87 if (strlen($last_group) > 1) {
88 echo "</div>\n"; // div after checkbox
89 echo "</div>\n"; // outer div, including checkbox
94 $formname = isset($_GET['formname']) ? $_GET['formname'] : '';
95 $formid = isset($_GET['id'] ) ? intval($_GET['id']) : 0;
96 $portalid = isset($_GET['portalid']) ? intval($_GET['portalid']) : 0;
98 // Get some info about this form.
99 $tmp = sqlQuery("SELECT title, option_value, notes FROM list_options WHERE " .
100 "list_id = 'lbfnames' AND option_id = ? AND activity = 1", array($formname));
101 $formtitle = $tmp['title'];
102 $formhistory = 0 + $tmp['option_value'];
104 // Extract parameters from this form's list item entry.
105 $jobj = json_decode($tmp['notes'], true);
106 if (!empty($jobj['columns'])) $CPR = intval($jobj['columns']);
107 if (!empty($jobj['issue' ])) $LBF_ISSUE_TYPE = $jobj['issue'];
108 if (!empty($jobj['aco' ])) $LBF_ACO = explode('|', $jobj['aco']);
110 // Check access control.
111 if (!acl_check('admin', 'super') && !empty($LBF_ACO)) {
112 $auth_aco_write = acl_check($LBF_ACO[0], $LBF_ACO[1], '', 'write' );
113 $auth_aco_addonly = acl_check($LBF_ACO[0], $LBF_ACO[1], '', 'addonly');
114 if (!$auth_aco_write && !($auth_aco_addonly && !$formid)) {
115 die(xlt('Access denied'));
119 if (empty($is_lbf)) {
120 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
121 if (file_exists($fname)) include_once($fname);
124 // If Save was clicked, save the info.
126 if ($_POST['bn_save']) {
127 $newid = 0;
128 if (!$formid) {
129 // Creating a new form. Get the new form_id by inserting and deleting a dummy row.
130 // This is necessary to create the form instance even if it has no native data.
131 $newid = sqlInsert("INSERT INTO lbf_data " .
132 "( field_id, field_value ) VALUES ( '', '' )");
133 sqlStatement("DELETE FROM lbf_data WHERE form_id = ? AND " .
134 "field_id = ''", array($newid));
135 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
137 $sets = "";
138 $fres = sqlStatement("SELECT * FROM layout_options " .
139 "WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
140 "edit_options != 'H' AND edit_options NOT LIKE '%0%' " .
141 "ORDER BY group_name, seq", array($formname) );
142 while ($frow = sqlFetchArray($fres)) {
143 $field_id = $frow['field_id'];
144 $data_type = $frow['data_type'];
145 // If the field was not in the web form, skip it.
146 // Except if it's checkboxes, if unchecked they are not returned.
148 // if ($data_type != 21 && !isset($_POST["form_$field_id"])) continue;
150 // The above statement commented out 2015-01-12 because a LBF plugin might conditionally
151 // disable a field that is not applicable, and we need the ability to clear out the old
152 // garbage in there so it does not show up in the "report" view of the data. So we will
153 // trust that it's OK to clear any field that is defined in the layout but not returned
154 // by the form.
156 $value = get_layout_form_value($frow);
157 // If edit option P or Q, save to the appropriate different table and skip the rest.
158 $source = $frow['source'];
159 if ($source == 'D' || $source == 'H') {
160 // Save to patient_data, employer_data or history_data.
161 if ($source == 'H') {
162 $new = array($field_id => $value);
163 updateHistoryData($pid, $new);
165 else if (strpos($field_id, 'em_') === 0) {
166 $field_id = substr($field_id, 3);
167 $new = array($field_id => $value);
168 updateEmployerData($pid, $new);
170 else {
171 $esc_field_id = escape_sql_column_name($field_id, array('patient_data'));
172 sqlStatement("UPDATE patient_data SET `$esc_field_id` = ? WHERE pid = ?",
173 array($value, $pid));
175 continue;
177 else if ($source == 'E') {
178 // Save to shared_attributes. Can't delete entries for empty fields because with the P option
179 // it's important to know when a current empty value overrides a previous value.
180 sqlStatement("REPLACE INTO shared_attributes SET " .
181 "pid = ?, encounter = ?, field_id = ?, last_update = NOW(), " .
182 "user_id = ?, field_value = ?",
183 array($pid, $encounter, $field_id, $_SESSION['authUserID'], $value));
184 continue;
186 else if ($source == 'V') {
187 // Save to form_encounter.
188 $esc_field_id = escape_sql_column_name($field_id, array('form_encounter'));
189 sqlStatement("UPDATE form_encounter SET `$esc_field_id` = ? WHERE " .
190 "pid = ? AND encounter = ?",
191 array($value, $pid, $encounter));
192 continue;
194 // It's a normal form field, save to lbf_data.
195 if ($formid) { // existing form
196 if ($value === '') {
197 $query = "DELETE FROM lbf_data WHERE " .
198 "form_id = ? AND field_id = ?";
199 sqlStatement($query, array($formid, $field_id));
201 else {
202 $query = "REPLACE INTO lbf_data SET field_value = ?, " .
203 "form_id = ?, field_id = ?";
204 sqlStatement($query,array($value, $formid, $field_id));
207 else { // new form
208 if ($value !== '') {
209 sqlStatement("INSERT INTO lbf_data " .
210 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
211 array($newid, $field_id, $value));
216 if ($portalid) {
217 // Delete the request from the portal.
218 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $portalid));
219 if ($result['errmsg']) {
220 die(text($result['errmsg']));
224 // Support custom behavior at save time, such as going to another form.
225 if (function_exists($formname . '_save_exit')) {
226 if (call_user_func($formname . '_save_exit')) exit;
228 formHeader("Redirecting....");
229 formJump();
230 formFooter();
231 exit;
235 <html>
236 <head>
237 <?php html_header_show();?>
238 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
239 <style>
241 td, input, select, textarea {
242 font-family: Arial, Helvetica, sans-serif;
243 font-size: 10pt;
246 div.section {
247 border: solid;
248 border-width: 1px;
249 border-color: #0000ff;
250 margin: 0 0 0 10pt;
251 padding: 5pt;
254 </style>
256 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
258 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
259 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
260 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
261 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
262 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
263 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
264 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
265 <script type="text/javascript" src="../../../library/textformat.js"></script>
266 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
267 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
268 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
269 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
271 <!-- LiterallyCanvas support -->
272 <?php echo lbf_canvas_head(); ?>
274 <script language="JavaScript">
276 // Support for beforeunload handler.
277 var somethingChanged = false;
279 $(document).ready(function() {
281 // fancy box
282 if (window.enable_modals) {
283 enable_modals();
285 if(window.tabbify){
286 tabbify();
288 if (window.checkSkipConditions) {
289 checkSkipConditions();
291 // special size for
292 $(".iframe_medium").fancybox({
293 'overlayOpacity' : 0.0,
294 'showCloseButton' : true,
295 'frameHeight' : 580,
296 'frameWidth' : 900
298 $(function() {
299 // add drag and drop functionality to fancybox
300 $("#fancy_outer").easydrag();
303 // Support for beforeunload handler.
304 $('.lbfdata input, .lbfdata select, .lbfdata textarea').change(function() {
305 somethingChanged = true;
307 window.addEventListener("beforeunload", function (e) {
308 if (somethingChanged && !top.timed_out) {
309 var msg = "<?php echo xls('You have unsaved changes.'); ?>";
310 e.returnValue = msg; // Gecko, Trident, Chrome 34+
311 return msg; // Gecko, WebKit, Chrome <34
317 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
319 // Supports customizable forms.
320 function divclick(cb, divid) {
321 var divstyle = document.getElementById(divid).style;
322 if (cb.checked) {
323 divstyle.display = 'block';
324 } else {
325 divstyle.display = 'none';
327 return true;
330 // The ID of the input element to receive a found code.
331 var current_sel_name = '';
333 // This is for callback by the find-code popup.
334 // Appends to or erases the current list of related codes.
335 function set_related(codetype, code, selector, codedesc) {
336 var f = document.forms[0];
337 // frc will be the input element containing the codes.
338 // frcd, if set, will be the input element containing their descriptions.
339 var frc = f[current_sel_name];
340 var frcd;
341 var matches = current_sel_name.match(/^(.*)__desc$/);
342 if (matches) {
343 frcd = frc;
344 frc = f[matches[1]];
346 var s = frc.value;
347 var sd = frcd ? frcd.value : s;
348 if (code) {
349 if (codetype != 'PROD') {
350 if (s.indexOf(codetype + ':') == 0 || s.indexOf(';' + codetype + ':') > 0) {
351 return '<?php echo xl('A code of this type is already selected. Erase the field first if you need to replace it.') ?>';
354 if (s.length > 0) {
355 s += ';';
356 sd += ';';
358 s += codetype + ':' + code;
359 sd += codedesc;
360 } else {
361 s = '';
362 sd = '';
364 frc.value = s;
365 if (frcd) frcd.value = sd;
366 return '';
369 // This invokes the find-code popup.
370 function sel_related(elem, codetype) {
371 current_sel_name = elem.name;
372 var url = '<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php';
373 if (codetype) url += '?codetype=' + codetype;
374 dlgopen(url, '_blank', 500, 400);
377 // Compute the length of a string without leading and trailing spaces.
378 function trimlen(s) {
379 var i = 0;
380 var j = s.length - 1;
381 for (; i <= j && s.charAt(i) == ' '; ++i);
382 for (; i <= j && s.charAt(j) == ' '; --j);
383 if (i > j) return 0;
384 return j + 1 - i;
387 // Validation logic for form submission.
388 function validate(f) {
389 <?php generate_layout_validation($formname); ?>
390 somethingChanged = false; // turn off "are you sure you want to leave"
391 top.restoreSession();
392 return true;
395 <?php if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?>
397 </script>
398 </head>
400 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
402 <?php
403 echo "<form method='post' " .
404 "action='$rootdir/forms/LBF/new.php?formname=$formname&id=$formid&portalid=$portalid' " .
405 "onsubmit='return validate(this)'>\n";
407 $cmsportal_login = '';
408 $portalres = FALSE;
409 if (empty($is_lbf)) {
410 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, p.cmsportal_login, " .
411 "fe.date FROM " .
412 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
413 "p.pid = ? AND f.pid = p.pid AND f.encounter = ? AND " .
414 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
415 "fe.id = f.form_id LIMIT 1", array($pid, $encounter));
416 echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
417 echo text($formtitle) . " " . xlt('for') . ' ';
418 echo text($enrow['fname']) . ' ' . text($enrow['mname']) . ' ' . text($enrow['lname']);
419 echo ' ' . xlt('on') . ' ' . text(oeFormatShortDate(substr($enrow['date'], 0, 10)));
420 echo "</p>\n";
421 $cmsportal_login = $enrow['cmsportal_login'];
423 // If loading data from portal, get the data.
424 if ($GLOBALS['gbl_portal_cms_enable'] && $portalid) {
425 $portalres = cms_portal_call(array('action' => 'getpost', 'postid' => $portalid));
426 if ($portalres['errmsg']) {
427 die(text($portalres['errmsg']));
432 <!-- This is where a chart might display. -->
433 <div id="chart"></div>
435 <?php
436 $shrow = getHistoryData($pid);
438 $fres = sqlStatement("SELECT * FROM layout_options " .
439 "WHERE form_id = ? AND uor > 0 " .
440 "ORDER BY group_name, seq", array($formname) );
441 $last_group = '';
442 $cell_count = 0;
443 $item_count = 0;
444 $display_style = 'block';
446 // This is an array keyed on forms.form_id for other occurrences of this
447 // form type. The maximum number of such other occurrences to display is
448 // in list_options.option_value for this form's list item. Values in this
449 // array are work areas for building the ending HTML for each displayed row.
451 $historical_ids = array();
453 // True if any data items in this form can be graphed.
454 $form_is_graphable = false;
456 $condition_str = '';
458 while ($frow = sqlFetchArray($fres)) {
459 $this_group = $frow['group_name'];
460 $titlecols = $frow['titlecols'];
461 $datacols = $frow['datacols'];
462 $data_type = $frow['data_type'];
463 $field_id = $frow['field_id'];
464 $list_id = $frow['list_id'];
465 $edit_options = $frow['edit_options'];
466 $source = $frow['source'];
468 $graphable = strpos($edit_options, 'G') !== FALSE;
469 if ($graphable) $form_is_graphable = true;
471 // Accumulate skip conditions into a JavaScript string literal.
472 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
473 foreach ($conditions as $condition) {
474 if (empty($condition['id'])) continue;
475 $andor = empty($condition['andor']) ? '' : $condition['andor'];
476 if ($condition_str) $condition_str .= ",\n";
477 $condition_str .= "{" .
478 "target:'" . addslashes($field_id) . "', " .
479 "id:'" . addslashes($condition['id']) . "', " .
480 "itemid:'" . addslashes($condition['itemid']) . "', " .
481 "operator:'" . addslashes($condition['operator']) . "', " .
482 "value:'" . addslashes($condition['value']) . "', " .
483 "andor:'" . addslashes($andor) . "'}";
486 $currvalue = '';
488 if ($frow['edit_options'] == 'H') {
489 // This data comes from static history
490 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
491 } else {
492 if (!$formid && $portalres) {
493 // Copying CMS Portal form data into this field if appropriate.
494 $currvalue = cms_field_to_lbf($data_type, $field_id, $portalres['fields']);
496 if ($currvalue === '') {
497 $currvalue = lbf_current_value($frow, $formid, $is_lbf ? 0 : $encounter);
499 if ($currvalue === FALSE) continue; // column does not exist, should not happen
500 // Handle "P" edit option to default to the previous value of a form field.
501 if (!$is_lbf && empty($currvalue) && strpos($edit_options, 'P') !== FALSE) {
502 if ($source == 'F' && !$formid) {
503 // Form attribute for new form, get value from most recent form instance.
504 // Form attributes of existing forms are expected to have existing values.
505 $tmp = sqlQuery("SELECT encounter, form_id FROM forms WHERE " .
506 "pid = ? AND formdir = ? AND deleted = 0 " .
507 "ORDER BY date DESC LIMIT 1",
508 array($pid, $formname));
509 if (!empty($tmp['encounter'])) {
510 $currvalue = lbf_current_value($frow, $tmp['form_id'], $tmp['encounter']);
513 else if ($source == 'E') {
514 // Visit attribute, get most recent value as of this visit.
515 // Even if the form already exists for this visit it may have a readonly value that only
516 // exists in a previous visit and was created from a different form.
517 $tmp = sqlQuery("SELECT sa.field_value FROM form_encounter AS e1 " .
518 "JOIN form_encounter AS e2 ON " .
519 "e2.pid = e1.pid AND (e2.date < e1.date OR (e2.date = e1.date AND e2.encounter <= e1.encounter)) " .
520 "JOIN shared_attributes AS sa ON " .
521 "sa.pid = e2.pid AND sa.encounter = e2.encounter AND sa.field_id = ?" .
522 "WHERE e1.pid = ? AND e1.encounter = ? " .
523 "ORDER BY e2.date DESC, e2.encounter DESC LIMIT 1",
524 array($field_id, $pid, $encounter));
525 if (isset($tmp['field_value'])) $currvalue = $tmp['field_value'];
527 } // End "P" option logic.
530 // Handle a data category (group) change.
531 if (strcmp($this_group, $last_group) != 0) {
532 end_group();
533 $group_seq = 'lbf' . substr($this_group, 0, 1);
534 $group_name = substr($this_group, 1);
535 $last_group = $this_group;
537 // If group name is blank, no checkbox or div.
538 if (strlen($this_group) > 1) {
539 echo "<div id='outerdiv_" . attr($group_seq) . "'>\n";
540 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_" . attr($group_seq) . "' value='1' " .
541 "onclick='return divclick(this,\"div_" . attr(addslashes($group_seq)) . "\");'";
542 if ($display_style == 'block') echo " checked";
543 echo " /><b>" . text(xl_layout_label($group_name)) . "</b></span>\n";
544 echo "<div id='div_" . attr($group_seq) . "' class='section' style='display:" . attr($display_style) . ";'>\n";
546 // echo " <table border='0' cellpadding='0' width='100%'>\n";
547 echo " <table border='0' cellspacing='0' cellpadding='0' width='100%' class='lbfdata'>\n";
548 $display_style = 'none';
550 // Initialize historical data array and write date headers.
551 $historical_ids = array();
552 if ($formhistory > 0) {
553 echo " <tr>";
554 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>";
555 if (empty($is_lbf)){
556 // Including actual date per IPPF request 2012-08-23.
557 echo oeFormatShortDate(substr($enrow['date'], 0, 10));
558 echo ' (' . htmlspecialchars(xl('Current')) . ')';
560 echo "&nbsp;</td>\n";
561 $hres = sqlStatement("SELECT f.form_id, fe.date " .
562 "FROM forms AS f, form_encounter AS fe WHERE " .
563 "f.pid = ? AND f.formdir = ? AND " .
564 "f.form_id != ? AND f.deleted = 0 AND " .
565 "fe.pid = f.pid AND fe.encounter = f.encounter " .
566 "ORDER BY fe.date DESC, f.encounter DESC, f.date DESC " .
567 "LIMIT ?",
568 array($pid, $formname, $formid, $formhistory));
569 // For some readings like vitals there may be multiple forms per encounter.
570 // We sort these sensibly, however only the encounter date is shown here;
571 // at some point we may wish to show also the data entry date/time.
572 while ($hrow = sqlFetchArray($hres)) {
573 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>&nbsp;" .
574 text(oeFormatShortDate(substr($hrow['date'], 0, 10))) . "</td>\n";
575 $historical_ids[$hrow['form_id']] = '';
577 echo " </tr>";
582 // Handle starting of a new row.
583 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
584 end_row();
585 echo " <tr>";
586 // Clear historical data string.
587 foreach ($historical_ids as $key => $dummy) {
588 $historical_ids[$key] = '';
592 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
594 // First item is on the "left-border"
595 $leftborder = true;
597 // Handle starting of a new label cell.
598 if ($titlecols > 0) {
599 end_cell();
600 echo "<td valign='top' colspan='" . attr($titlecols) . "' nowrap";
601 echo " class='";
602 echo ($frow['uor'] == 2) ? "required" : "bold";
603 if ($graphable) echo " graph";
604 echo "'";
605 if ($cell_count == 2) echo " style='padding-left:10pt'";
606 // This ID is used by skip conditions and also show_graph().
607 echo " id='label_id_" . attr($field_id) . "'";
608 echo ">";
610 foreach ($historical_ids as $key => $dummy) {
611 $historical_ids[$key] .= "<td valign='top' colspan='" . attr($titlecols) . "' class='text' nowrap>";
614 $cell_count += $titlecols;
616 ++$item_count;
618 echo "<b>";
619 if ($frow['title']) echo text(xl_layout_label($frow['title']) . ":"); else echo "&nbsp;";
620 echo "</b>";
622 // Note the labels are not repeated in the history columns.
624 // Handle starting of a new data cell.
625 if ($datacols > 0) {
626 end_cell();
627 echo "<td valign='top' colspan='" . attr($datacols) . "' class='text'";
628 // This ID is used by skip conditions.
629 echo " id='value_id_" . attr($field_id) . "'";
630 if ($cell_count > 0) echo " style='padding-left:5pt'";
631 echo ">";
633 foreach ($historical_ids as $key => $dummy) {
634 $historical_ids[$key] .= "<td valign='top' align='right' colspan='" . attr($datacols) . "' class='text'>";
637 $cell_count += $datacols;
640 ++$item_count;
642 // Skip current-value fields for the display-only case.
643 if (empty($is_lbf)) {
644 if ($frow['edit_options'] == 'H')
645 echo generate_display_field($frow, $currvalue);
646 else
647 generate_form_field($frow, $currvalue);
650 // Append to historical data of other dates for this item.
651 foreach ($historical_ids as $key => $dummy) {
652 $value = lbf_current_value($frow, $key, 0);
653 $historical_ids[$key] .= generate_display_field($frow, $value);
658 end_group();
661 <p style='text-align:center'>
662 <?php if (empty($is_lbf)) { ?>
663 <input type='submit' name='bn_save' value='<?php echo xla('Save') ?>' />
664 <?php
665 if (function_exists($formname . '_additional_buttons')) {
666 // Allow the plug-in to insert more action buttons here.
667 call_user_func($formname . '_additional_buttons');
670 &nbsp;
671 <input type='button' value='<?php echo xla('Cancel') ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
672 &nbsp;
673 <?php if ($form_is_graphable) { ?>
674 <input type='button' value='<?php echo xla('Show Graph') ?>' onclick="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo attr($formname); ?>'" />
675 &nbsp;
676 <?php } ?>
677 <?php } else { ?>
678 <input type='button' value='<?php echo xla('Back') ?>' onclick='window.history.back();' />
679 <?php } ?>
680 </p>
682 </form>
684 <!-- include support for the list-add selectbox feature -->
685 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
687 <script language="JavaScript">
689 // Array of skip conditions for the checkSkipConditions() function.
690 var skipArray = [
691 <?php echo $condition_str; ?>
694 <?php echo $date_init; ?>
695 <?php
696 if (function_exists($formname . '_javascript_onload')) {
697 call_user_func($formname . '_javascript_onload');
700 // TBD: If $alertmsg, display it with a JavaScript alert().
702 // New form and this patient has a portal login and we have not loaded portal data.
703 // Check if there is portal data pending for this patient and form type.
704 if (!$formid && $GLOBALS['gbl_portal_cms_enable'] && $cmsportal_login && !$portalid) {
705 $portalres = cms_portal_call(array('action' => 'checkptform', 'form' => $formname, 'patient' => $cmsportal_login));
706 if ($portalres['errmsg']) {
707 die(text($portalres['errmsg'])); // TBD: Change to alertmsg
709 $portalid = $portalres['postid'];
710 if ($portalid) {
711 echo "if (confirm('" . xls('The portal has data for this patient and form. Load it now?') . "')) {\n";
712 echo " top.restoreSession();\n";
713 echo " document.location.href = 'load_form.php?formname=$formname&portalid=$portalid';\n";
714 echo "}\n";
718 </script>
720 </body>
721 </html>