2 // Copyright (C) 2009 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.
9 require_once("../../globals.php");
10 require_once("$srcdir/api.inc");
11 require_once("$srcdir/forms.inc");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/formdata.inc.php");
16 $CPR = 4; // cells per row
20 if (! $encounter) { // comes from globals.php
21 die("Internal error: we do not seem to be in an encounter!");
25 global $item_count, $cell_count;
26 if ($item_count > 0) {
33 global $cell_count, $CPR;
35 if ($cell_count > 0) {
36 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
42 function end_group() {
44 if (strlen($last_group) > 0) {
51 $formname = formData('formname', 'G');
52 $formid = 0 +
formData('id', 'G');
54 $tmp = sqlQuery("SELECT title FROM list_options WHERE " .
55 "list_id = 'lbfnames' AND option_id = '$formname'");
56 $formtitle = $tmp['title'];
60 // If Save was clicked, save the info.
62 if ($_POST['bn_save']) {
64 $fres = sqlStatement("SELECT * FROM layout_options " .
65 "WHERE form_id = '$formname' AND uor > 0 AND field_id != '' AND " .
66 "edit_options != 'H' " .
67 "ORDER BY group_name, seq");
68 while ($frow = sqlFetchArray($fres)) {
69 $field_id = $frow['field_id'];
70 $value = get_layout_form_value($frow);
71 if ($formid) { // existing form
73 $query = "DELETE FROM lbf_data WHERE " .
74 "form_id = '$formid' AND field_id = '$field_id'";
77 $query = "REPLACE INTO lbf_data SET field_value = '$value', " .
78 "form_id = '$formid', field_id = '$field_id'";
85 sqlStatement("INSERT INTO lbf_data " .
86 "( form_id, field_id, field_value ) " .
87 " VALUES ( '$newid', '$field_id', '$value' )");
90 $newid = sqlInsert("INSERT INTO lbf_data " .
91 "( field_id, field_value ) " .
92 " VALUES ( '$field_id', '$value' )");
95 // Note that a completely empty form will not be created at all!
99 if (!$formid && $newid) {
100 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
103 formHeader("Redirecting....");
109 $fname = "../../../custom/LBF/$formname.plugin.php";
110 if (file_exists($fname)) include_once($fname);
112 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
113 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
114 "p.pid = '$pid' AND f.pid = '$pid' AND f.encounter = '$encounter' AND " .
115 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
116 "fe.id = f.form_id LIMIT 1");
120 <?php
html_header_show();?
>
121 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
124 td
, input
, select
, textarea
{
125 font
-family
: Arial
, Helvetica
, sans
-serif
;
132 border
-color
: #0000ff;
139 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
141 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
142 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
143 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
144 <script type
="text/javascript" src
="../../../library/dynarch_calendar_en.js"></script
>
145 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
146 <script type
="text/javascript" src
="../../../library/js/jquery.js"></script
>
148 <script language
="JavaScript">
150 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
152 // Supports customizable forms.
153 function divclick(cb
, divid
) {
154 var divstyle
= document
.getElementById(divid
).style
;
156 divstyle
.display
= 'block';
158 divstyle
.display
= 'none';
163 // This is for callback by the find-code popup.
164 // Appends to or erases the current list of related codes.
165 function set_related(codetype
, code
, selector
, codedesc
) {
166 var frc
= document
.getElementById('form_related_code');
169 if (s
.length
> 0) s +
= ';';
170 s +
= codetype +
':' + code
;
177 // This invokes the find-code popup.
178 function sel_related() {
179 dlgopen('<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
182 <?php
if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?
>
187 <body
<?php
echo $top_bg_line; ?
> topmargin
="0" rightmargin
="0" leftmargin
="2" bottommargin
="0" marginwidth
="2" marginheight
="0">
188 <form method
="post" action
="<?php echo $rootdir ?>/forms/LBF/new.php?formname=<?php echo $formname ?>&id=<?php echo $formid ?>"
189 onsubmit
="return top.restoreSession()">
191 <p
class='title' style
='margin-top:8px;margin-bottom:8px;text-align:center'>
193 echo "$formtitle " . xl('for') . ' ';
194 echo $enrow['fname'] . ' ' . $enrow['mname'] . ' ' . $enrow['lname'];
195 echo ' ' . xl('on') . ' ' . substr($enrow['date'], 0, 10);
200 $shrow = getHistoryData($pid);
202 $fres = sqlStatement("SELECT * FROM layout_options " .
203 "WHERE form_id = '$formname' AND uor > 0 " .
204 "ORDER BY group_name, seq");
208 $display_style = 'block';
210 while ($frow = sqlFetchArray($fres)) {
211 $this_group = $frow['group_name'];
212 $titlecols = $frow['titlecols'];
213 $datacols = $frow['datacols'];
214 $data_type = $frow['data_type'];
215 $field_id = $frow['field_id'];
216 $list_id = $frow['list_id'];
220 if ($frow['edit_options'] == 'H') {
221 // This data comes from static history
222 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
225 $pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
226 "form_id = '$formid' AND field_id = '$field_id'");
227 if (!empty($pprow)) $currvalue = $pprow['field_value'];
230 // New form, see if there is a custom default from a plugin.
231 $fname = $formname . '_default_' . $field_id;
232 if (function_exists($fname)) {
233 $currvalue = call_user_func($fname);
238 // Handle a data category (group) change.
239 if (strcmp($this_group, $last_group) != 0) {
241 $group_seq = 'lbf' . substr($this_group, 0, 1);
242 $group_name = substr($this_group, 1);
243 $last_group = $this_group;
244 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
245 "onclick='return divclick(this,\"div_$group_seq\");'";
246 if ($display_style == 'block') echo " checked";
247 echo " /><b>" . xl_layout_label($group_name) . "</b></span>\n";
248 echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
249 echo " <table border='0' cellpadding='0' width='100%'>\n";
250 $display_style = 'none';
253 // Handle starting of a new row.
254 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
259 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
261 // Handle starting of a new label cell.
262 if ($titlecols > 0) {
264 echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
265 echo ($frow['uor'] == 2) ?
" class='required'" : " class='bold'";
266 if ($cell_count == 2) echo " style='padding-left:10pt'";
268 $cell_count +
= $titlecols;
273 if ($frow['title']) echo (xl_layout_label($frow['title']) . ":"); else echo " ";
276 // Handle starting of a new data cell.
279 echo "<td valign='top' colspan='$datacols' class='text'";
280 if ($cell_count > 0) echo " style='padding-left:5pt'";
282 $cell_count +
= $datacols;
287 if ($frow['edit_options'] == 'H')
288 echo generate_display_field($frow, $currvalue);
290 generate_form_field($frow, $currvalue);
296 <p style
='text-align:center'>
297 <input type
='submit' name
='bn_save' value
='Save' />
299 <input type
='button' value
='Cancel' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
305 <!-- include support
for the
list-add selectbox feature
-->
306 <?php
include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?
>
308 <script language
="JavaScript">
309 <?php
echo $date_init; ?
>
311 if (function_exists($formname . '_javascript_onload')) {
312 call_user_func($formname . '_javascript_onload');
314 // TBD: If $alertmsg, display it with a JavaScript alert().