2 // Copyright (C) 2009-2014 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
10 $sanitize_all_escapes=true;
12 //STOP FAKE REGISTER GLOBALS
13 $fake_register_globals=false;
15 require_once("../../globals.php");
16 require_once("$srcdir/api.inc");
17 require_once("$srcdir/forms.inc");
18 require_once("$srcdir/options.inc.php");
19 require_once("$srcdir/patient.inc");
20 require_once("$srcdir/formdata.inc.php");
21 require_once("$srcdir/formatting.inc.php");
22 if ($GLOBALS['gbl_portal_cms_enable']) {
23 require_once("$include_root/cmsportal/portal.inc.php");
26 $CPR = 4; // cells per row
30 // $is_lbf is defined in trend_form.php and indicates that we are being
31 // invoked from there; in that case the current encounter is irrelevant.
32 if (empty($is_lbf) && !$encounter) {
33 die("Internal error: we do not seem to be in an encounter!");
37 global $item_count, $cell_count, $historical_ids;
38 if ($item_count > 0) {
41 foreach ($historical_ids as $key => $dummy) {
42 $historical_ids[$key] .= " </td>";
50 global $cell_count, $CPR, $historical_ids;
52 if ($cell_count > 0) {
53 for (; $cell_count < $CPR; ++
$cell_count) {
55 foreach ($historical_ids as $key => $dummy) {
56 $historical_ids[$key] .= "<td></td>";
60 foreach ($historical_ids as $key => $dummy) {
61 echo $historical_ids[$key];
69 function end_group() {
71 if (strlen($last_group) > 0) {
74 // No div for an empty group name.
75 if (strlen($last_group) > 1) echo "</div>\n";
79 $formname = isset($_GET['formname']) ?
$_GET['formname'] : '';
80 $formid = isset($_GET['id'] ) ?
intval($_GET['id']) : 0;
81 $portalid = isset($_GET['portalid']) ?
intval($_GET['portalid']) : 0;
83 // Get title and number of history columns for this form.
84 $tmp = sqlQuery("SELECT title, option_value FROM list_options WHERE " .
85 "list_id = 'lbfnames' AND option_id = ?", array($formname) );
86 $formtitle = $tmp['title'];
87 $formhistory = 0 +
$tmp['option_value'];
92 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
93 if (file_exists($fname)) include_once($fname);
96 // If Save was clicked, save the info.
98 if ($_POST['bn_save']) {
100 $fres = sqlStatement("SELECT * FROM layout_options " .
101 "WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
102 "edit_options != 'H' " .
103 "ORDER BY group_name, seq", array($formname) );
104 while ($frow = sqlFetchArray($fres)) {
105 $field_id = $frow['field_id'];
106 $value = get_layout_form_value($frow);
107 $sql_bind_array = array();
108 if ($formid) { // existing form
110 $query = "DELETE FROM lbf_data WHERE " .
111 "form_id = ? AND field_id = ?";
112 array_push($sql_bind_array,$formid,$field_id);
115 $query = "REPLACE INTO lbf_data SET field_value = ?, " .
116 "form_id = ?, field_id = ?";
117 array_push($sql_bind_array,$value,$formid,$field_id);
119 sqlStatement($query,$sql_bind_array);
124 sqlStatement("INSERT INTO lbf_data " .
125 "( form_id, field_id, field_value ) " .
126 " VALUES (?,?,?)", array($newid, $field_id, $value) );
129 $newid = sqlInsert("INSERT INTO lbf_data " .
130 "( field_id, field_value ) " .
131 " VALUES (?,?)", array($field_id, $value) );
134 // Note that a completely empty form will not be created at all!
139 if (!$formid && $newid) {
140 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
144 // Delete the request from the portal.
145 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $portalid));
146 if ($result['errmsg']) {
147 die(text($result['errmsg']));
151 // Support custom behavior at save time, such as going to another form.
152 if (function_exists($formname . '_save_exit')) {
153 if (call_user_func($formname . '_save_exit')) exit;
155 formHeader("Redirecting....");
164 <?php
html_header_show();?
>
165 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
168 td
, input
, select
, textarea
{
169 font
-family
: Arial
, Helvetica
, sans
-serif
;
176 border
-color
: #0000ff;
183 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
185 <link rel
="stylesheet" type
="text/css" href
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
186 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script
>
187 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script
>
188 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script
>
189 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
190 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script
>
191 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script
>
192 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
193 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
194 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
195 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
197 <script language
="JavaScript">
198 $
(document
).ready(function(){
200 if(window
.enable_modals
){
207 $
(".iframe_medium").fancybox( {
208 'overlayOpacity' : 0.0,
209 'showCloseButton' : true,
215 // add drag and drop functionality to fancybox
216 $
("#fancy_outer").easydrag();
219 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
221 // Supports customizable forms.
222 function divclick(cb
, divid
) {
223 var divstyle
= document
.getElementById(divid
).style
;
225 divstyle
.display
= 'block';
227 divstyle
.display
= 'none';
232 // This is for callback by the find-code popup.
233 // Appends to or erases the current list of related codes.
234 function set_related(codetype
, code
, selector
, codedesc
) {
235 var frc
= document
.getElementById('form_related_code');
238 if (codetype
!= 'PROD') {
239 if (s
.indexOf(codetype +
':') == 0 || s
.indexOf(';' + codetype +
':') > 0) {
240 return '<?php echo xl('A code of this type is already selected
. Erase the field first
if you need to replace it
.') ?>';
243 if (s
.length
> 0) s +
= ';';
244 s +
= codetype +
':' + code
;
252 // This invokes the find-code popup.
253 function sel_related(elem
, codetype
) {
254 var url
= '<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php';
255 if (codetype
) url +
= '?codetype=' + codetype
;
256 dlgopen(url
, '_blank', 500, 400);
259 // Validation logic for form submission.
260 function validate(f
) {
261 <?php
generate_layout_validation($formname); ?
>
262 top
.restoreSession();
265 <?php
if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?
>
270 <body
<?php
echo $top_bg_line; ?
> topmargin
="0" rightmargin
="0" leftmargin
="2" bottommargin
="0" marginwidth
="2" marginheight
="0">
273 echo "<form method='post' " .
274 "action='$rootdir/forms/LBF/new.php?formname=$formname&id=$formid&portalid=$portalid' " .
275 "onsubmit='return validate(this)'>\n";
277 $cmsportal_login = '';
279 if (empty($is_lbf)) {
280 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, p.cmsportal_login, " .
282 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
283 "p.pid = ? AND f.pid = p.pid AND f.encounter = ? AND " .
284 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
285 "fe.id = f.form_id LIMIT 1", array($pid, $encounter));
286 echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
287 echo text($formtitle) . " " . xlt('for') . ' ';
288 echo text($enrow['fname']) . ' ' . text($enrow['mname']) . ' ' . text($enrow['lname']);
289 echo ' ' . xlt('on') . ' ' . text(oeFormatShortDate(substr($enrow['date'], 0, 10)));
291 $cmsportal_login = $enrow['cmsportal_login'];
293 // If loading data from portal, get the data.
294 if ($GLOBALS['gbl_portal_cms_enable'] && $portalid) {
295 $portalres = cms_portal_call(array('action' => 'getpost', 'postid' => $portalid));
296 if ($portalres['errmsg']) {
297 die(text($portalres['errmsg']));
302 <!-- This is where a chart might display
. -->
303 <div id
="chart"></div
>
306 $shrow = getHistoryData($pid);
308 $fres = sqlStatement("SELECT * FROM layout_options " .
309 "WHERE form_id = ? AND uor > 0 " .
310 "ORDER BY group_name, seq", array($formname) );
314 $display_style = 'block';
316 // This is an array keyed on forms.form_id for other occurrences of this
317 // form type. The maximum number of such other occurrences to display is
318 // in list_options.option_value for this form's list item. Values in this
319 // array are work areas for building the ending HTML for each displayed row.
321 $historical_ids = array();
323 // True if any data items in this form can be graphed.
324 $form_is_graphable = false;
326 while ($frow = sqlFetchArray($fres)) {
327 $this_group = $frow['group_name'];
328 $titlecols = $frow['titlecols'];
329 $datacols = $frow['datacols'];
330 $data_type = $frow['data_type'];
331 $field_id = $frow['field_id'];
332 $list_id = $frow['list_id'];
333 $edit_options = $frow['edit_options'];
335 $graphable = strpos($edit_options, 'G') !== FALSE;
336 if ($graphable) $form_is_graphable = true;
340 if ($frow['edit_options'] == 'H') {
341 // This data comes from static history
342 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
345 $pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
346 "form_id = ? AND field_id = ?", array($formid, $field_id) );
347 if (!empty($pprow)) $currvalue = $pprow['field_value'];
350 // This is a new form.
351 // Get data from the CMS portal if applicable.
352 /*************************************************************
353 if ($portalres && isset($portalres['fields'][$field_id])) {
354 $currvalue = $portalres['fields'][$field_id];
355 $currvalue = cms_field_to_lbf($currvalue, $data_type, $field_id);
357 *************************************************************/
359 $currvalue = cms_field_to_lbf($data_type, $field_id, $portalres['fields']);
361 if ($currvalue === '') {
362 // Still no data. See if there is a custom default from a plugin.
363 $fname = $formname . '_default_' . $field_id;
364 if (function_exists($fname)) {
365 $currvalue = call_user_func($fname);
371 // Handle a data category (group) change.
372 if (strcmp($this_group, $last_group) != 0) {
374 $group_seq = 'lbf' . substr($this_group, 0, 1);
375 $group_name = substr($this_group, 1);
376 $last_group = $this_group;
378 // If group name is blank, no checkbox or div.
379 if (strlen($this_group) > 1) {
380 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_" . attr($group_seq) . "' value='1' " .
381 "onclick='return divclick(this,\"div_" . attr(addslashes($group_seq)) . "\");'";
382 if ($display_style == 'block') echo " checked";
383 echo " /><b>" . text(xl_layout_label($group_name)) . "</b></span>\n";
384 echo "<div id='div_" . attr($group_seq) . "' class='section' style='display:" . attr($display_style) . ";'>\n";
386 // echo " <table border='0' cellpadding='0' width='100%'>\n";
387 echo " <table border='0' cellspacing='0' cellpadding='0'>\n";
388 $display_style = 'none';
390 // Initialize historical data array and write date headers.
391 $historical_ids = array();
392 if ($formhistory > 0) {
394 echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>";
396 // Including actual date per IPPF request 2012-08-23.
397 echo oeFormatShortDate(substr($enrow['date'], 0, 10));
398 echo ' (' . htmlspecialchars(xl('Current')) . ')';
400 echo " </td>\n";
401 $hres = sqlStatement("SELECT f.form_id, fe.date " .
402 "FROM forms AS f, form_encounter AS fe WHERE " .
403 "f.pid = ? AND f.formdir = ? AND " .
404 "f.form_id != ? AND f.deleted = 0 AND " .
405 "fe.pid = f.pid AND fe.encounter = f.encounter " .
406 "ORDER BY fe.date DESC, f.encounter DESC, f.date DESC " .
408 array($pid, $formname, $formid, $formhistory));
409 // For some readings like vitals there may be multiple forms per encounter.
410 // We sort these sensibly, however only the encounter date is shown here;
411 // at some point we may wish to show also the data entry date/time.
412 while ($hrow = sqlFetchArray($hres)) {
414 echo "<td colspan='".attr($CPR)."' align='right' class='bold' style='";
415 echo "border-top:1px solid black;";
416 echo "border-right:1px solid black;";
417 echo "border-bottom:1px solid black;";
418 if (empty($historical_ids)) { echo "border-left:1px solid black;"; }
420 oeFormatShortDate(substr($hrow['date'], 0, 10)) . " </td>\n";
421 $historical_ids[$hrow['form_id']] = '';
428 // Handle starting of a new row.
429 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
432 // Clear historical data string.
433 foreach ($historical_ids as $key => $dummy) {
434 $historical_ids[$key] = '';
438 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
440 // First item is on the "left-border"
443 // Handle starting of a new label cell.
444 if ($titlecols > 0) {
446 echo "<td valign='top' colspan='" . attr($titlecols) . "' nowrap";
448 echo ($frow['uor'] == 2) ?
"required" : "bold";
449 if ($graphable) echo " graph";
451 if ($cell_count == 2) echo " style='padding-left:10pt'";
452 if ($graphable) echo " id='" . attr($field_id) . "'";
455 foreach ($historical_ids as $key => $dummy) {
456 $historical_ids[$key] .= "<td valign='top' colspan='" . attr($titlecols) . "' class='text' style='";
457 $historical_ids[$key] .= "border-bottom:1px solid black;";
458 if ($leftborder) $historical_ids[$key] .= "border-left:1px solid black;";
459 if (!$datacols ) $historical_ids[$key] .= "border-right:1px solid black;";
460 $historical_ids[$key] .= "' nowrap>";
465 $cell_count +
= $titlecols;
470 if ($frow['title']) echo text(xl_layout_label($frow['title']) . ":"); else echo " ";
473 // Note the labels are not repeated in the history columns.
475 // Handle starting of a new data cell.
478 echo "<td valign='top' colspan='" . attr($datacols) . "' class='text'";
479 if ($cell_count > 0) echo " style='padding-left:5pt'";
482 foreach ($historical_ids as $key => $dummy) {
483 $historical_ids[$key] .= "<td valign='top' align='right' colspan='" . attr($datacols) . "' class='text' style='";
484 $historical_ids[$key] .= "border-bottom:1px solid black;";
485 $historical_ids[$key] .= "border-right:1px solid black;";
486 if ($leftborder) $historical_ids[$key] .= "border-left:1px solid black;";
487 $historical_ids[$key] .= "'>";
491 $cell_count +
= $datacols;
496 // Skip current-value fields for the display-only case.
497 if (empty($is_lbf)) {
498 if ($frow['edit_options'] == 'H')
499 echo generate_display_field($frow, $currvalue);
501 generate_form_field($frow, $currvalue);
504 // Append to historical data of other dates for this item.
505 foreach ($historical_ids as $key => $dummy) {
506 $hvrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
507 "form_id = ? AND field_id = ?", array($key, $field_id) );
508 $value = empty($hvrow) ?
'' : $hvrow['field_value'];
509 $historical_ids[$key] .= generate_display_field($frow, $value);
517 <p style
='text-align:center'>
518 <?php
if (empty($is_lbf)) { ?
>
519 <input type
='submit' name
='bn_save' value
='<?php echo xla('Save
') ?>' />
521 if (function_exists($formname . '_additional_buttons')) {
522 // Allow the plug-in to insert more action buttons here.
523 call_user_func($formname . '_additional_buttons');
527 <input type
='button' value
='<?php echo xla('Cancel
') ?>' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
529 <?php
if ($form_is_graphable) { ?
>
530 <input type
='button' value
='<?php echo xla('Show Graph
') ?>' onclick
="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo attr($formname); ?>'" />
534 <input type
='button' value
='<?php echo xla('Back
') ?>' onclick
='window.history.back();' />
540 <!-- include support
for the
list-add selectbox feature
-->
541 <?php
include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?
>
543 <script language
="JavaScript">
544 <?php
echo $date_init; ?
>
546 if (function_exists($formname . '_javascript_onload')) {
547 call_user_func($formname . '_javascript_onload');
550 // TBD: If $alertmsg, display it with a JavaScript alert().
552 // New form and this patient has a portal login and we have not loaded portal data.
553 // Check if there is portal data pending for this patient and form type.
554 if (!$formid && $GLOBALS['gbl_portal_cms_enable'] && $cmsportal_login && !$portalid) {
555 $portalres = cms_portal_call(array('action' => 'checkptform', 'form' => $formname, 'patient' => $cmsportal_login));
556 if ($portalres['errmsg']) {
557 die(text($portalres['errmsg'])); // TBD: Change to alertmsg
559 $portalid = $portalres['postid'];
561 echo "if (confirm('" . xls('The portal has data for this patient and form. Load it now?') . "')) {\n";
562 echo " top.restoreSession();\n";
563 echo " document.location.href = 'load_form.php?formname=$formname&portalid=$portalid';\n";