-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
new.php
466 lines (399 loc) · 15.1 KB
/
new.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<?php
// Copyright (C) 2009-2011 Rod Roark <rod@sunsetsystems.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//SANITIZE ALL ESCAPES
$sanitize_all_escapes=true;
//STOP FAKE REGISTER GLOBALS
$fake_register_globals=false;
require_once("../../globals.php");
require_once("$srcdir/api.inc");
require_once("$srcdir/forms.inc");
require_once("$srcdir/options.inc.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/formdata.inc.php");
require_once("$srcdir/formatting.inc.php");
$CPR = 4; // cells per row
$pprow = array();
// $is_lbf is defined in trend_form.php and indicates that we are being
// invoked from there; in that case the current encounter is irrelevant.
if (empty($is_lbf) && !$encounter) {
die("Internal error: we do not seem to be in an encounter!");
}
function end_cell() {
global $item_count, $cell_count, $historical_ids;
if ($item_count > 0) {
echo "</td>";
foreach ($historical_ids as $key => $dummy) {
$historical_ids[$key] .= "</td>";
}
$item_count = 0;
}
}
function end_row() {
global $cell_count, $CPR, $historical_ids;
end_cell();
if ($cell_count > 0) {
for (; $cell_count < $CPR; ++$cell_count) {
echo "<td></td>";
foreach ($historical_ids as $key => $dummy) {
$historical_ids[$key] .= "<td></td>";
}
}
foreach ($historical_ids as $key => $dummy) {
echo $historical_ids[$key];
}
echo "</tr>\n";
$cell_count = 0;
}
}
function end_group() {
global $last_group;
if (strlen($last_group) > 0) {
end_row();
echo " </table>\n";
// No div for an empty group name.
if (strlen($last_group) > 1) echo "</div>\n";
}
}
$formname = isset($_GET['formname']) ? $_GET['formname'] : '';
$formid = 0 + (isset($_GET['id']) ? $_GET['id'] : '');
// Get title and number of history columns for this form.
$tmp = sqlQuery("SELECT title, option_value FROM list_options WHERE " .
"list_id = 'lbfnames' AND option_id = ?", array($formname) );
$formtitle = $tmp['title'];
$formhistory = 0 + $tmp['option_value'];
$newid = 0;
// If Save was clicked, save the info.
//
if ($_POST['bn_save']) {
$sets = "";
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
"edit_options != 'H' " .
"ORDER BY group_name, seq", array($formname) );
while ($frow = sqlFetchArray($fres)) {
$field_id = $frow['field_id'];
$value = get_layout_form_value($frow);
$sql_bind_array = array();
if ($formid) { // existing form
if ($value === '') {
$query = "DELETE FROM lbf_data WHERE " .
"form_id = ? AND field_id = ?";
array_push($sql_bind_array,$formid,$field_id);
}
else {
$query = "REPLACE INTO lbf_data SET field_value = ?, " .
"form_id = ?, field_id = ?";
array_push($sql_bind_array,$value,$formid,$field_id);
}
sqlStatement($query,$sql_bind_array);
}
else { // new form
if ($value !== '') {
if ($newid) {
sqlStatement("INSERT INTO lbf_data " .
"( form_id, field_id, field_value ) " .
" VALUES (?,?,?)", array($newid, $field_id, $value) );
}
else {
$newid = sqlInsert("INSERT INTO lbf_data " .
"( field_id, field_value ) " .
" VALUES (?,?)", array($field_id, $value) );
}
}
// Note that a completely empty form will not be created at all!
}
}
if (!$formid && $newid) {
addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
}
formHeader("Redirecting....");
formJump();
formFooter();
exit;
}
if (empty($is_lbf)) {
$fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
if (file_exists($fname)) include_once($fname);
}
?>
<html>
<head>
<?php html_header_show();?>
<link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
<style>
td, input, select, textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
div.section {
border: solid;
border-width: 1px;
border-color: #0000ff;
margin: 0 0 0 10pt;
padding: 5pt;
}
</style>
<style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
<link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript" src="../../../library/textformat.js"></script>
<script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
<?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
<script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
<script language="JavaScript">
$(document).ready(function(){
// fancy box
if(window.enable_modals){
enable_modals();
}
if(window.tabbify){
tabbify();
}
// special size for
$(".iframe_medium").fancybox( {
'overlayOpacity' : 0.0,
'showCloseButton' : true,
'frameHeight' : 580,
'frameWidth' : 900
});
$(function(){
// add drag and drop functionality to fancybox
$("#fancy_outer").easydrag();
});
});
var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
// Supports customizable forms.
function divclick(cb, divid) {
var divstyle = document.getElementById(divid).style;
if (cb.checked) {
divstyle.display = 'block';
} else {
divstyle.display = 'none';
}
return true;
}
// This is for callback by the find-code popup.
// Appends to or erases the current list of related codes.
function set_related(codetype, code, selector, codedesc) {
var frc = document.getElementById('form_related_code');
var s = frc.value;
if (code) {
if (s.length > 0) s += ';';
s += codetype + ':' + code;
} else {
s = '';
}
frc.value = s;
}
// This invokes the find-code popup.
function sel_related() {
dlgopen('<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
}
<?php if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?>
</script>
</head>
<body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
<form method="post" action="<?php echo $rootdir ?>/forms/LBF/new.php?formname=<?php echo attr($formname) ?>&id=<?php echo attr($formid) ?>"
onsubmit="return top.restoreSession()">
<?php
if (empty($is_lbf)) {
$enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
"form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
"p.pid = ? AND f.pid = ? AND f.encounter = ? AND " .
"f.formdir = 'newpatient' AND f.deleted = 0 AND " .
"fe.id = f.form_id LIMIT 1", array($pid, $pid, $encounter) );
echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
echo text($formtitle) . " " . xlt('for') . ' ';
echo text($enrow['fname']) . ' ' . text($enrow['mname']) . ' ' . text($enrow['lname']);
echo ' ' . xlt('on') . ' ' . text(substr($enrow['date'], 0, 10));
echo "</p>\n";
}
?>
<!-- This is where a chart might display. -->
<div id="chart"></div>
<?php
$shrow = getHistoryData($pid);
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = ? AND uor > 0 " .
"ORDER BY group_name, seq", array($formname) );
$last_group = '';
$cell_count = 0;
$item_count = 0;
$display_style = 'block';
// This is an array keyed on forms.form_id for other occurrences of this
// form type. The maximum number of such other occurrences to display is
// in list_options.option_value for this form's list item. Values in this
// array are work areas for building the ending HTML for each displayed row.
//
$historical_ids = array();
// True if any data items in this form can be graphed.
$form_is_graphable = false;
while ($frow = sqlFetchArray($fres)) {
$this_group = $frow['group_name'];
$titlecols = $frow['titlecols'];
$datacols = $frow['datacols'];
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$list_id = $frow['list_id'];
$edit_options = $frow['edit_options'];
$graphable = strpos($edit_options, 'G') !== FALSE;
if ($graphable) $form_is_graphable = true;
$currvalue = '';
if ($frow['edit_options'] == 'H') {
// This data comes from static history
if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
} else {
if ($formid) {
$pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
"form_id = ? AND field_id = ?", array($formid, $field_id) );
if (!empty($pprow)) $currvalue = $pprow['field_value'];
}
else {
// New form, see if there is a custom default from a plugin.
$fname = $formname . '_default_' . $field_id;
if (function_exists($fname)) {
$currvalue = call_user_func($fname);
}
}
}
// Handle a data category (group) change.
if (strcmp($this_group, $last_group) != 0) {
end_group();
$group_seq = 'lbf' . substr($this_group, 0, 1);
$group_name = substr($this_group, 1);
$last_group = $this_group;
// If group name is blank, no checkbox or div.
if (strlen($this_group) > 1) {
echo "<br /><span class='bold'><input type='checkbox' name='form_cb_" . attr($group_seq) . "' value='1' " .
"onclick='return divclick(this,\"div_" . attr(addslashes($group_seq)) . "\");'";
if ($display_style == 'block') echo " checked";
echo " /><b>" . text(xl_layout_label($group_name)) . "</b></span>\n";
echo "<div id='div_" . attr($group_seq) . "' class='section' style='display:" . attr($display_style) . ";'>\n";
}
// echo " <table border='0' cellpadding='0' width='100%'>\n";
echo " <table border='0' cellpadding='0' width='100%'>\n";
$display_style = 'none';
// Initialize historical data array and write date headers.
$historical_ids = array();
if ($formhistory > 0) {
echo " <tr>";
echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'>";
if (empty($is_lbf)) echo xlt('Current');
echo "</td>\n";
$hres = sqlStatement("SELECT f.form_id, fe.date " .
"FROM forms AS f, form_encounter AS fe WHERE " .
"f.pid = ? AND f.formdir = ? AND " .
"f.form_id != ? AND f.deleted = 0 AND " .
"fe.pid = f.pid AND fe.encounter = f.encounter " .
"ORDER BY fe.date DESC, f.encounter DESC, f.date DESC " .
"LIMIT ?",
array($pid, $formname, $formid, $formhistory));
// For some readings like vitals there may be multiple forms per encounter.
// We sort these sensibly, however only the encounter date is shown here;
// at some point we may wish to show also the data entry date/time.
while ($hrow = sqlFetchArray($hres)) {
$historical_ids[$hrow['form_id']] = '';
echo "<td colspan='" . attr($CPR) . "' align='right' class='bold'> " .
text(oeFormatShortDate(substr($hrow['date'], 0, 10))) . "</td>\n";
}
echo " </tr>";
}
}
// Handle starting of a new row.
if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
end_row();
echo " <tr>";
// Clear historical data string.
foreach ($historical_ids as $key => $dummy) {
$historical_ids[$key] = '';
}
}
if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
// Handle starting of a new label cell.
if ($titlecols > 0) {
end_cell();
echo "<td valign='top' colspan='" . attr($titlecols) . "' width='1%' nowrap";
echo " class='";
echo ($frow['uor'] == 2) ? "required" : "bold";
if ($graphable) echo " graph";
echo "'";
if ($cell_count == 2) echo " style='padding-left:10pt'";
if ($graphable) echo " id='" . attr($field_id) . "'";
echo ">";
foreach ($historical_ids as $key => $dummy) {
$historical_ids[$key] .= "<td valign='top' colspan='" . attr($titlecols) . "' class='text' nowrap>";
}
$cell_count += $titlecols;
}
++$item_count;
echo "<b>";
if ($frow['title']) echo text(xl_layout_label($frow['title']) . ":"); else echo " ";
echo "</b>";
// Note the labels are not repeated in the history columns.
// Handle starting of a new data cell.
if ($datacols > 0) {
end_cell();
echo "<td valign='top' colspan='" . attr($datacols) . "' class='text'";
if ($cell_count > 0) echo " style='padding-left:5pt'";
echo ">";
foreach ($historical_ids as $key => $dummy) {
$historical_ids[$key] .= "<td valign='top' align='right' colspan='" . attr($datacols) . "' class='text'>";
}
$cell_count += $datacols;
}
++$item_count;
// Skip current-value fields for the display-only case.
if (empty($is_lbf)) {
if ($frow['edit_options'] == 'H')
echo generate_display_field($frow, $currvalue);
else
generate_form_field($frow, $currvalue);
}
// Append to historical data of other dates for this item.
foreach ($historical_ids as $key => $dummy) {
$hvrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
"form_id = ? AND field_id = ?", array($key, $field_id) );
$value = empty($hvrow) ? '' : $hvrow['field_value'];
$historical_ids[$key] .= generate_display_field($frow, $value);
}
}
end_group();
?>
<p style='text-align:center'>
<?php if (empty($is_lbf)) { ?>
<input type='submit' name='bn_save' value='<?php echo xla('Save') ?>' />
<input type='button' value='<?php echo xla('Cancel') ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
<?php if ($form_is_graphable) { ?>
<input type='button' value='<?php echo xla('Show Graph') ?>' onclick="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo attr($formname); ?>'" />
<?php } ?>
<?php } else { ?>
<input type='button' value='<?php echo xla('Back') ?>' onclick='window.back();' />
<?php } ?>
</p>
</form>
<!-- include support for the list-add selectbox feature -->
<?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
<script language="JavaScript">
<?php echo $date_init; ?>
<?php
if (function_exists($formname . '_javascript_onload')) {
call_user_func($formname . '_javascript_onload');
}
// TBD: If $alertmsg, display it with a JavaScript alert().
?>
</script>
</body>
</html>