Highway to PSR2
[openemr.git] / interface / forms / LBF / new.php
blob403ad534fea3d83da77306365107d23a70c87cc4
1 <?php
2 /**
3 * Copyright (C) 2009-2017 Rod Roark <rod@sunsetsystems.com>
4 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
6 * LICENSE: This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
17 * @package OpenEMR
18 * @author Rod Roark <rod@sunsetsystems.com>
19 * @author Brady Miller <brady.g.miller@gmail.com>
20 * @link http://www.open-emr.org
25 require_once("../../globals.php");
26 require_once("$srcdir/api.inc");
27 require_once("$srcdir/forms.inc");
28 require_once("$srcdir/options.inc.php");
29 require_once("$srcdir/patient.inc");
30 if ($GLOBALS['gbl_portal_cms_enable']) {
31 require_once("$include_root/cmsportal/portal.inc.php");
34 $CPR = 4; // cells per row
36 $pprow = array();
38 // $is_lbf is defined in trend_form.php and indicates that we are being
39 // invoked from there; in that case the current encounter is irrelevant.
40 if (empty($is_lbf) && !$encounter) {
41 die("Internal error: we do not seem to be in an encounter!");
44 function end_cell()
46 global $item_count, $cell_count, $historical_ids;
47 if ($item_count > 0) {
48 // echo "&nbsp;</td>";
49 echo "</td>";
51 foreach ($historical_ids as $key => $dummy) {
52 // $historical_ids[$key] .= "&nbsp;</td>";
53 $historical_ids[$key] .= "</td>";
56 $item_count = 0;
60 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()
83 global $last_group;
84 if (strlen($last_group) > 0) {
85 end_row();
86 echo " </table>\n";
87 // No div for an empty group name.
88 if (strlen($last_group) > 1) {
89 echo "</div>\n"; // div after checkbox
90 echo "</div>\n"; // outer div, including checkbox
95 $formname = isset($_GET['formname']) ? $_GET['formname'] : '';
96 $formid = isset($_GET['id']) ? intval($_GET['id']) : 0;
97 $portalid = isset($_GET['portalid']) ? intval($_GET['portalid']) : 0;
99 // Get some info about this form.
100 $tmp = sqlQuery("SELECT title, option_value, notes FROM list_options WHERE " .
101 "list_id = 'lbfnames' AND option_id = ? AND activity = 1", array($formname));
102 $formtitle = $tmp['title'];
103 $formhistory = 0 + $tmp['option_value'];
105 // Extract parameters from this form's list item entry.
106 $jobj = json_decode($tmp['notes'], true);
107 if (!empty($jobj['columns'])) {
108 $CPR = intval($jobj['columns']);
111 if (!empty($jobj['issue' ])) {
112 $LBF_ISSUE_TYPE = $jobj['issue'];
115 if (!empty($jobj['aco' ])) {
116 $LBF_ACO = explode('|', $jobj['aco']);
119 // Check access control.
120 if (!acl_check('admin', 'super') && !empty($LBF_ACO)) {
121 $auth_aco_write = acl_check($LBF_ACO[0], $LBF_ACO[1], '', 'write');
122 $auth_aco_addonly = acl_check($LBF_ACO[0], $LBF_ACO[1], '', 'addonly');
123 if (!$auth_aco_write && !($auth_aco_addonly && !$formid)) {
124 die(xlt('Access denied'));
128 if (empty($is_lbf)) {
129 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
130 if (file_exists($fname)) {
131 include_once($fname);
135 // If Save was clicked, save the info.
137 if ($_POST['bn_save']) {
138 $newid = 0;
139 if (!$formid) {
140 // Creating a new form. Get the new form_id by inserting and deleting a dummy row.
141 // This is necessary to create the form instance even if it has no native data.
142 $newid = sqlInsert("INSERT INTO lbf_data " .
143 "( field_id, field_value ) VALUES ( '', '' )");
144 sqlStatement("DELETE FROM lbf_data WHERE form_id = ? AND " .
145 "field_id = ''", array($newid));
146 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
149 $sets = "";
150 $fres = sqlStatement("SELECT * FROM layout_options " .
151 "WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
152 "edit_options != 'H' AND edit_options NOT LIKE '%0%' " .
153 "ORDER BY group_name, seq", array($formname));
154 while ($frow = sqlFetchArray($fres)) {
155 $field_id = $frow['field_id'];
156 $data_type = $frow['data_type'];
157 // If the field was not in the web form, skip it.
158 // Except if it's checkboxes, if unchecked they are not returned.
160 // if ($data_type != 21 && !isset($_POST["form_$field_id"])) continue;
162 // The above statement commented out 2015-01-12 because a LBF plugin might conditionally
163 // disable a field that is not applicable, and we need the ability to clear out the old
164 // garbage in there so it does not show up in the "report" view of the data. So we will
165 // trust that it's OK to clear any field that is defined in the layout but not returned
166 // by the form.
168 $value = get_layout_form_value($frow);
169 // If edit option P or Q, save to the appropriate different table and skip the rest.
170 $source = $frow['source'];
171 if ($source == 'D' || $source == 'H') {
172 // Save to patient_data, employer_data or history_data.
173 if ($source == 'H') {
174 $new = array($field_id => $value);
175 updateHistoryData($pid, $new);
176 } else if (strpos($field_id, 'em_') === 0) {
177 $field_id = substr($field_id, 3);
178 $new = array($field_id => $value);
179 updateEmployerData($pid, $new);
180 } else {
181 $esc_field_id = escape_sql_column_name($field_id, array('patient_data'));
182 sqlStatement(
183 "UPDATE patient_data SET `$esc_field_id` = ? WHERE pid = ?",
184 array($value, $pid)
188 continue;
189 } else if ($source == 'E') {
190 // Save to shared_attributes. Can't delete entries for empty fields because with the P option
191 // it's important to know when a current empty value overrides a previous value.
192 sqlStatement(
193 "REPLACE INTO shared_attributes SET " .
194 "pid = ?, encounter = ?, field_id = ?, last_update = NOW(), " .
195 "user_id = ?, field_value = ?",
196 array($pid, $encounter, $field_id, $_SESSION['authUserID'], $value)
198 continue;
199 } else if ($source == 'V') {
200 // Save to form_encounter.
201 $esc_field_id = escape_sql_column_name($field_id, array('form_encounter'));
202 sqlStatement(
203 "UPDATE form_encounter SET `$esc_field_id` = ? WHERE " .
204 "pid = ? AND encounter = ?",
205 array($value, $pid, $encounter)
207 continue;
210 // It's a normal form field, save to lbf_data.
211 if ($formid) { // existing form
212 if ($value === '') {
213 $query = "DELETE FROM lbf_data WHERE " .
214 "form_id = ? AND field_id = ?";
215 sqlStatement($query, array($formid, $field_id));
216 } else {
217 $query = "REPLACE INTO lbf_data SET field_value = ?, " .
218 "form_id = ?, field_id = ?";
219 sqlStatement($query, array($value, $formid, $field_id));
221 } else { // new form
222 if ($value !== '') {
223 sqlStatement(
224 "INSERT INTO lbf_data " .
225 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
226 array($newid, $field_id, $value)
232 if ($portalid) {
233 // Delete the request from the portal.
234 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $portalid));
235 if ($result['errmsg']) {
236 die(text($result['errmsg']));
240 // Support custom behavior at save time, such as going to another form.
241 if (function_exists($formname . '_save_exit')) {
242 if (call_user_func($formname . '_save_exit')) {
243 exit;
247 formHeader("Redirecting....");
248 formJump();
249 formFooter();
250 exit;
254 <html>
255 <head>
256 <?php html_header_show();?>
257 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
258 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
259 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
261 <style>
263 td, input, select, textarea {
264 font-family: Arial, Helvetica, sans-serif;
265 font-size: 10pt;
268 div.section {
269 border: solid;
270 border-width: 1px;
271 border-color: #0000ff;
272 margin: 0 0 0 10pt;
273 padding: 5pt;
276 </style>
278 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
279 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
280 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
281 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
282 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
283 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
284 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
285 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
287 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
289 <!-- LiterallyCanvas support -->
290 <?php echo lbf_canvas_head(); ?>
292 <script language="JavaScript">
294 // Support for beforeunload handler.
295 var somethingChanged = false;
297 $(document).ready(function() {
299 // fancy box
300 if (window.enable_modals) {
301 enable_modals();
303 if(window.tabbify){
304 tabbify();
306 if (window.checkSkipConditions) {
307 checkSkipConditions();
309 // special size for
310 $(".iframe_medium").fancybox({
311 'overlayOpacity' : 0.0,
312 'showCloseButton' : true,
313 'frameHeight' : 580,
314 'frameWidth' : 900
316 $(function() {
317 // add drag and drop functionality to fancybox
318 $("#fancy_outer").easydrag();
321 // Support for beforeunload handler.
322 $('.lbfdata input, .lbfdata select, .lbfdata textarea').change(function() {
323 somethingChanged = true;
325 window.addEventListener("beforeunload", function (e) {
326 if (somethingChanged && !top.timed_out) {
327 var msg = "<?php echo xls('You have unsaved changes.'); ?>";
328 e.returnValue = msg; // Gecko, Trident, Chrome 34+
329 return msg; // Gecko, WebKit, Chrome <34
333 $('.datepicker').datetimepicker({
334 <?php $datetimepicker_timepicker = false; ?>
335 <?php $datetimepicker_showseconds = false; ?>
336 <?php $datetimepicker_formatInput = false; ?>
337 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
338 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
340 $('.datetimepicker').datetimepicker({
341 <?php $datetimepicker_timepicker = true; ?>
342 <?php $datetimepicker_showseconds = false; ?>
343 <?php $datetimepicker_formatInput = false; ?>
344 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
345 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
349 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
351 // Supports customizable forms.
352 function divclick(cb, divid) {
353 var divstyle = document.getElementById(divid).style;
354 if (cb.checked) {
355 divstyle.display = 'block';
356 } else {
357 divstyle.display = 'none';
359 return true;
362 // The ID of the input element to receive a found code.
363 var current_sel_name = '';
365 // This is for callback by the find-code popup.
366 // Appends to or erases the current list of related codes.
367 function set_related(codetype, code, selector, codedesc) {
368 var f = document.forms[0];
369 // frc will be the input element containing the codes.
370 // frcd, if set, will be the input element containing their descriptions.
371 var frc = f[current_sel_name];
372 var frcd;
373 var matches = current_sel_name.match(/^(.*)__desc$/);
374 if (matches) {
375 frcd = frc;
376 frc = f[matches[1]];
378 var s = frc.value;
379 var sd = frcd ? frcd.value : s;
380 if (code) {
381 if (s.length > 0) {
382 s += ';';
383 sd += ';';
385 s += codetype + ':' + code;
386 sd += codedesc;
387 } else {
388 s = '';
389 sd = '';
391 frc.value = s;
392 if (frcd) frcd.value = sd;
393 return '';
396 // This invokes the find-code popup.
397 function sel_related(elem, codetype) {
398 current_sel_name = elem.name;
399 var url = '<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php';
400 if (codetype) url += '?codetype=' + codetype;
401 dlgopen(url, '_blank', 500, 400);
404 // Compute the length of a string without leading and trailing spaces.
405 function trimlen(s) {
406 var i = 0;
407 var j = s.length - 1;
408 for (; i <= j && s.charAt(i) == ' '; ++i);
409 for (; i <= j && s.charAt(j) == ' '; --j);
410 if (i > j) return 0;
411 return j + 1 - i;
414 // Validation logic for form submission.
415 function validate(f) {
416 <?php generate_layout_validation($formname); ?>
417 somethingChanged = false; // turn off "are you sure you want to leave"
418 top.restoreSession();
419 return true;
422 <?php
423 if (function_exists($formname . '_javascript')) {
424 call_user_func($formname . '_javascript');
425 } ?>
427 </script>
428 </head>
430 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
432 <?php
433 echo "<form method='post' " .
434 "action='$rootdir/forms/LBF/new.php?formname=$formname&id=$formid&portalid=$portalid' " .
435 "onsubmit='return validate(this)'>\n";
437 $cmsportal_login = '';
438 $portalres = false;
439 if (empty($is_lbf)) {
440 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, p.cmsportal_login, " .
441 "fe.date FROM " .
442 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
443 "p.pid = ? AND f.pid = p.pid AND f.encounter = ? AND " .
444 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
445 "fe.id = f.form_id LIMIT 1", array($pid, $encounter));
446 echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
447 echo text($formtitle) . " " . xlt('for') . ' ';
448 echo text($enrow['fname']) . ' ' . text($enrow['mname']) . ' ' . text($enrow['lname']);
449 echo ' ' . xlt('on') . ' ' . text(oeFormatShortDate(substr($enrow['date'], 0, 10)));
450 echo "</p>\n";
451 $cmsportal_login = $enrow['cmsportal_login'];
454 // If loading data from portal, get the data.
455 if ($GLOBALS['gbl_portal_cms_enable'] && $portalid) {
456 $portalres = cms_portal_call(array('action' => 'getpost', 'postid' => $portalid));
457 if ($portalres['errmsg']) {
458 die(text($portalres['errmsg']));
463 <!-- This is where a chart might display. -->
464 <div id="chart"></div>
466 <?php
467 $shrow = getHistoryData($pid);
469 $fres = sqlStatement("SELECT * FROM layout_options " .
470 "WHERE form_id = ? AND uor > 0 " .
471 "ORDER BY group_name, seq", array($formname));
472 $last_group = '';
473 $cell_count = 0;
474 $item_count = 0;
475 $display_style = 'block';
477 // This is an array keyed on forms.form_id for other occurrences of this
478 // form type. The maximum number of such other occurrences to display is
479 // in list_options.option_value for this form's list item. Values in this
480 // array are work areas for building the ending HTML for each displayed row.
482 $historical_ids = array();
484 // True if any data items in this form can be graphed.
485 $form_is_graphable = false;
487 $condition_str = '';
489 while ($frow = sqlFetchArray($fres)) {
490 $this_group = $frow['group_name'];
491 $titlecols = $frow['titlecols'];
492 $datacols = $frow['datacols'];
493 $data_type = $frow['data_type'];
494 $field_id = $frow['field_id'];
495 $list_id = $frow['list_id'];
496 $edit_options = $frow['edit_options'];
497 $source = $frow['source'];
499 $graphable = strpos($edit_options, 'G') !== false;
500 if ($graphable) {
501 $form_is_graphable = true;
504 // Accumulate skip conditions into a JavaScript string literal.
505 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
506 foreach ($conditions as $condition) {
507 if (empty($condition['id'])) {
508 continue;
511 $andor = empty($condition['andor']) ? '' : $condition['andor'];
512 if ($condition_str) {
513 $condition_str .= ",\n";
516 $condition_str .= "{" .
517 "target:'" . addslashes($field_id) . "', " .
518 "id:'" . addslashes($condition['id']) . "', " .
519 "itemid:'" . addslashes($condition['itemid']) . "', " .
520 "operator:'" . addslashes($condition['operator']) . "', " .
521 "value:'" . addslashes($condition['value']) . "', " .
522 "andor:'" . addslashes($andor) . "'}";
525 $currvalue = '';
527 if ($frow['edit_options'] == 'H') {
528 // This data comes from static history
529 if (isset($shrow[$field_id])) {
530 $currvalue = $shrow[$field_id];
532 } else {
533 if (!$formid && $portalres) {
534 // Copying CMS Portal form data into this field if appropriate.
535 $currvalue = cms_field_to_lbf($data_type, $field_id, $portalres['fields']);
538 if ($currvalue === '') {
539 $currvalue = lbf_current_value($frow, $formid, $is_lbf ? 0 : $encounter);
542 if ($currvalue === false) {
543 continue; // column does not exist, should not happen
546 // Handle "P" edit option to default to the previous value of a form field.
547 if (!$is_lbf && empty($currvalue) && strpos($edit_options, 'P') !== false) {
548 if ($source == 'F' && !$formid) {
549 // Form attribute for new form, get value from most recent form instance.
550 // Form attributes of existing forms are expected to have existing values.
551 $tmp = sqlQuery(
552 "SELECT encounter, form_id FROM forms WHERE " .
553 "pid = ? AND formdir = ? AND deleted = 0 " .
554 "ORDER BY date DESC LIMIT 1",
555 array($pid, $formname)
557 if (!empty($tmp['encounter'])) {
558 $currvalue = lbf_current_value($frow, $tmp['form_id'], $tmp['encounter']);
560 } else if ($source == 'E') {
561 // Visit attribute, get most recent value as of this visit.
562 // Even if the form already exists for this visit it may have a readonly value that only
563 // exists in a previous visit and was created from a different form.
564 $tmp = sqlQuery(
565 "SELECT sa.field_value FROM form_encounter AS e1 " .
566 "JOIN form_encounter AS e2 ON " .
567 "e2.pid = e1.pid AND (e2.date < e1.date OR (e2.date = e1.date AND e2.encounter <= e1.encounter)) " .
568 "JOIN shared_attributes AS sa ON " .
569 "sa.pid = e2.pid AND sa.encounter = e2.encounter AND sa.field_id = ?" .
570 "WHERE e1.pid = ? AND e1.encounter = ? " .
571 "ORDER BY e2.date DESC, e2.encounter DESC LIMIT 1",
572 array($field_id, $pid, $encounter)
574 if (isset($tmp['field_value'])) {
575 $currvalue = $tmp['field_value'];
578 } // End "P" option logic.
581 // Handle a data category (group) change.
582 if (strcmp($this_group, $last_group) != 0) {
583 end_group();
584 $group_seq = 'lbf' . substr($this_group, 0, 1);
585 $group_name = substr($this_group, 1);
586 $last_group = $this_group;
588 // If group name is blank, no checkbox or div.
589 if (strlen($this_group) > 1) {
590 echo "<div id='outerdiv_" . attr($group_seq) . "'>\n";
591 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_" . attr($group_seq) . "' value='1' " .
592 "onclick='return divclick(this,\"div_" . attr(addslashes($group_seq)) . "\");'";
593 if ($display_style == 'block') {
594 echo " checked";
597 echo " /><b>" . text(xl_layout_label($group_name)) . "</b></span>\n";
598 echo "<div id='div_" . attr($group_seq) . "' class='section' style='display:" . attr($display_style) . ";'>\n";
601 // echo " <table border='0' cellpadding='0' width='100%'>\n";
602 echo " <table border='0' cellspacing='0' cellpadding='0' width='100%' class='lbfdata'>\n";
603 $display_style = 'none';
605 // Initialize historical data array and write date headers.
606 $historical_ids = array();
607 if ($formhistory > 0) {
608 echo " <tr>";
609 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>";
610 if (empty($is_lbf)) {
611 // Including actual date per IPPF request 2012-08-23.
612 echo oeFormatShortDate(substr($enrow['date'], 0, 10));
613 echo ' (' . htmlspecialchars(xl('Current')) . ')';
616 echo "&nbsp;</td>\n";
617 $hres = sqlStatement(
618 "SELECT f.form_id, fe.date " .
619 "FROM forms AS f, form_encounter AS fe WHERE " .
620 "f.pid = ? AND f.formdir = ? AND " .
621 "f.form_id != ? AND f.deleted = 0 AND " .
622 "fe.pid = f.pid AND fe.encounter = f.encounter " .
623 "ORDER BY fe.date DESC, f.encounter DESC, f.date DESC " .
624 "LIMIT ?",
625 array($pid, $formname, $formid, $formhistory)
627 // For some readings like vitals there may be multiple forms per encounter.
628 // We sort these sensibly, however only the encounter date is shown here;
629 // at some point we may wish to show also the data entry date/time.
630 while ($hrow = sqlFetchArray($hres)) {
631 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>&nbsp;" .
632 text(oeFormatShortDate(substr($hrow['date'], 0, 10))) . "</td>\n";
633 $historical_ids[$hrow['form_id']] = '';
636 echo " </tr>";
640 // Handle starting of a new row.
641 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
642 end_row();
643 echo " <tr>";
644 // Clear historical data string.
645 foreach ($historical_ids as $key => $dummy) {
646 $historical_ids[$key] = '';
650 if ($item_count == 0 && $titlecols == 0) {
651 $titlecols = 1;
654 // First item is on the "left-border"
655 $leftborder = true;
657 // Handle starting of a new label cell.
658 if ($titlecols > 0) {
659 end_cell();
660 echo "<td valign='top' colspan='" . attr($titlecols) . "' nowrap";
661 echo " class='";
662 echo ($frow['uor'] == 2) ? "required" : "bold";
663 if ($graphable) {
664 echo " graph";
667 echo "'";
668 if ($cell_count == 2) {
669 echo " style='padding-left:10pt'";
672 // This ID is used by skip conditions and also show_graph().
673 echo " id='label_id_" . attr($field_id) . "'";
674 echo ">";
676 foreach ($historical_ids as $key => $dummy) {
677 $historical_ids[$key] .= "<td valign='top' colspan='" . attr($titlecols) . "' class='text' nowrap>";
680 $cell_count += $titlecols;
683 ++$item_count;
685 echo "<b>";
686 if ($frow['title']) {
687 echo text(xl_layout_label($frow['title']) . ":");
688 } else {
689 echo "&nbsp;";
692 echo "</b>";
694 // Note the labels are not repeated in the history columns.
696 // Handle starting of a new data cell.
697 if ($datacols > 0) {
698 end_cell();
699 echo "<td valign='top' colspan='" . attr($datacols) . "' class='text'";
700 // This ID is used by skip conditions.
701 echo " id='value_id_" . attr($field_id) . "'";
702 if ($cell_count > 0) {
703 echo " style='padding-left:5pt'";
706 echo ">";
708 foreach ($historical_ids as $key => $dummy) {
709 $historical_ids[$key] .= "<td valign='top' align='right' colspan='" . attr($datacols) . "' class='text'>";
712 $cell_count += $datacols;
715 ++$item_count;
717 // Skip current-value fields for the display-only case.
718 if (empty($is_lbf)) {
719 if ($frow['edit_options'] == 'H') {
720 echo generate_display_field($frow, $currvalue);
721 } else {
722 generate_form_field($frow, $currvalue);
726 // Append to historical data of other dates for this item.
727 foreach ($historical_ids as $key => $dummy) {
728 $value = lbf_current_value($frow, $key, 0);
729 $historical_ids[$key] .= generate_display_field($frow, $value);
733 end_group();
736 <p style='text-align:center'>
737 <?php if (empty($is_lbf)) { ?>
738 <input type='submit' name='bn_save' value='<?php echo xla('Save') ?>' />
739 <?php
740 if (function_exists($formname . '_additional_buttons')) {
741 // Allow the plug-in to insert more action buttons here.
742 call_user_func($formname . '_additional_buttons');
745 &nbsp;
746 <input type='button' value='<?php echo xla('Cancel') ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
747 &nbsp;
748 <?php if ($form_is_graphable) { ?>
749 <input type='button' value='<?php echo xla('Show Graph') ?>' onclick="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo attr($formname); ?>'" />
750 &nbsp;
751 <?php } ?>
752 <?php } else { ?>
753 <input type='button' value='<?php echo xla('Back') ?>' onclick='window.history.back();' />
754 <?php } ?>
755 </p>
757 </form>
759 <!-- include support for the list-add selectbox feature -->
760 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
762 <script language="JavaScript">
764 // Array of skip conditions for the checkSkipConditions() function.
765 var skipArray = [
766 <?php echo $condition_str; ?>
769 <?php echo $date_init; ?>
770 <?php
771 if (function_exists($formname . '_javascript_onload')) {
772 call_user_func($formname . '_javascript_onload');
775 // TBD: If $alertmsg, display it with a JavaScript alert().
777 // New form and this patient has a portal login and we have not loaded portal data.
778 // Check if there is portal data pending for this patient and form type.
779 if (!$formid && $GLOBALS['gbl_portal_cms_enable'] && $cmsportal_login && !$portalid) {
780 $portalres = cms_portal_call(array('action' => 'checkptform', 'form' => $formname, 'patient' => $cmsportal_login));
781 if ($portalres['errmsg']) {
782 die(text($portalres['errmsg'])); // TBD: Change to alertmsg
785 $portalid = $portalres['postid'];
786 if ($portalid) {
787 echo "if (confirm('" . xls('The portal has data for this patient and form. Load it now?') . "')) {\n";
788 echo " top.restoreSession();\n";
789 echo " document.location.href = 'load_form.php?formname=$formname&portalid=$portalid';\n";
790 echo "}\n";
794 </script>
796 </body>
797 </html>