forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
282 lines (251 loc) · 7.61 KB
/
view.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
<?php
//////////////////////////////////////////////////////////////////////
// ------------------ DO NOT MODIFY VIEW.PHP !!! ---------------------
// View.php is an exact duplicate of new.php. If you wish to make
// any changes, then change new.php and either (recommended) make
// view.php a symbolic link to new.php, or copy new.php to view.php.
//
// And if you check in a change to either module, be sure to check
// in the other (identical) module also.
//
// This nonsense will go away if we ever move to subversion.
//////////////////////////////////////////////////////////////////////
// Copyright (C) 2006 Rod Roark <[email protected]>
//
// 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.
include_once("../../globals.php");
include_once("$srcdir/api.inc");
include_once("$srcdir/forms.inc");
$scale_file_name = '/tmp/tanita_scale.txt';
$scale_file_age = -1;
$row = array();
if (! $encounter) { // comes from globals.php
die("Internal error: we do not seem to be in an encounter!");
}
// encode a string from a form field for database writing.
function form2db($fldval) {
$fldval = trim($fldval);
$fldval = formDataCore($fldval);
return $fldval;
}
function rbvalue($rbname) {
$tmp = $_POST[$rbname];
if (! $tmp) return "NULL";
return "'$tmp'";
}
function rbinput($name, $value, $desc, $colname) {
global $row;
$ret = "<input type='radio' name='$name' value='$value'";
if ($row[$colname] == $value) $ret .= " checked";
$ret .= " />$desc";
return $ret;
}
$formid = $_GET['id'];
// If Save was clicked, save the info.
//
if ($_POST['bn_save']) {
// If updating an existing form...
//
if ($formid) {
$query = "UPDATE form_body_composition SET " .
"body_type = " . rbvalue('form_body_type') . ", " .
"height = '" . form2db($_POST['form_height']) . "', " .
"weight = '" . form2db($_POST['form_weight']) . "', " .
"bmi = '" . form2db($_POST['form_bmi']) . "', " .
"bmr = '" . form2db($_POST['form_bmr']) . "', " .
"impedance = '" . form2db($_POST['form_impedance']) . "', " .
"fat_pct = '" . form2db($_POST['form_fat_pct']) . "', " .
"fat_mass = '" . form2db($_POST['form_fat_mass']) . "', " .
"ffm = '" . form2db($_POST['form_ffm']) . "', " .
"tbw = '" . form2db($_POST['form_tbw']) . "', " .
"other = '" . form2db($_POST['form_other']) . "' " .
"WHERE id = '$formid'";
sqlStatement($query);
}
// If adding a new form...
//
else {
$query = "INSERT INTO form_body_composition ( " .
"body_type, height, weight, bmi, bmr, impedance, fat_pct, " .
"fat_mass, ffm, tbw, other " .
") VALUES ( " .
rbvalue('form_body_type') . ", " .
"'" . form2db($_POST['form_height']) . "', " .
"'" . form2db($_POST['form_weight']) . "', " .
"'" . form2db($_POST['form_bmi']) . "', " .
"'" . form2db($_POST['form_bmr']) . "', " .
"'" . form2db($_POST['form_impedance']) . "', " .
"'" . form2db($_POST['form_fat_pct']) . "', " .
"'" . form2db($_POST['form_fat_mass']) . "', " .
"'" . form2db($_POST['form_ffm']) . "', " .
"'" . form2db($_POST['form_tbw']) . "', " .
"'" . form2db($_POST['form_other']) . "' " .
")";
$newid = sqlInsert($query);
addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
}
formHeader("Redirecting....");
formJump();
formFooter();
exit;
}
if ($formid) {
$row = sqlQuery ("SELECT * FROM form_body_composition WHERE " .
"id = '$formid' AND activity = '1'") ;
}
else {
// Get the most recent scale reading.
$items = explode(',', trim(file_get_contents($scale_file_name)));
if ($items && count($items) > 11) {
$scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
$row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
$row['height'] = $items[2];
$row['weight'] = $items[3];
$row['bmi'] = $items[10];
$row['bmr'] = $items[11];
$row['impedance'] = $items[4];
$row['fat_pct'] = $items[5];
$row['fat_mass'] = $items[6];
$row['ffm'] = $items[7];
$row['tbw'] = $items[8];
}
}
?>
<html>
<head>
<?php html_header_show();?>
<link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
<script language="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/body_composition/new.php?id=<?php echo $formid ?>"
onsubmit="return top.restoreSession()">
<center>
<p>
<table border='0' width='95%'>
<tr bgcolor='#dddddd'>
<td colspan='3' align='center'><b>Body Composition</b></td>
</tr>
<tr>
<td width='5%' nowrap>Body Type</td>
<td colspan='2' nowrap>
<?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>
<?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>
</td>
</tr>
<tr>
<td nowrap>Height in inches</td>
<td nowrap>
<input type='text' name='form_height' size='6'
value='<?php echo addslashes($row['height']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>Weight in pounds</td>
<td nowrap>
<input type='text' name='form_weight' size='6'
value='<?php echo addslashes($row['weight']) ?>' />
</td>
<td align='center' nowrap>
<?php
if ($scale_file_age >= 0) {
echo "<font color='blue'>This reading was taken $scale_file_age minutes ago.</font>\n";
} else {
echo " \n";
}
?>
</td>
</tr>
<tr>
<td nowrap>BMI</td>
<td nowrap>
<input type='text' name='form_bmi' size='6'
value='<?php echo addslashes($row['bmi']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>BMR in kj</td>
<td nowrap>
<input type='text' name='form_bmr' size='6'
value='<?php echo addslashes($row['bmr']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>Impedance in ohms</td>
<td nowrap>
<input type='text' name='form_impedance' size='6'
value='<?php echo addslashes($row['impedance']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>Fat %</td>
<td nowrap>
<input type='text' name='form_fat_pct' size='6'
value='<?php echo addslashes($row['fat_pct']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>Fat Mass in pounds</td>
<td nowrap>
<input type='text' name='form_fat_mass' size='6'
value='<?php echo addslashes($row['fat_mass']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>FFM in pounds</td>
<td nowrap>
<input type='text' name='form_ffm' size='6'
value='<?php echo addslashes($row['ffm']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>TBW in pounds</td>
<td nowrap>
<input type='text' name='form_tbw' size='6'
value='<?php echo addslashes($row['tbw']) ?>' />
</td>
<td nowrap>
</td>
</tr>
<tr>
<td nowrap>Notes</td>
<td colspan='2' nowrap>
<textarea name='form_other' rows='8' style='width:100%'><?php echo $row['other'] ?></textarea>
</td>
</tr>
</table>
<p>
<input type='submit' name='bn_save' value='Save' />
<input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url'] ?>'" />
</p>
</center>
</form>
</body>
</html>