Fix: delete entry in immunization (#7346)
[openemr.git] / contrib / forms / body_composition / view.php
blob59cb642ea3cf3a2d6ba139d262e554cb50202c53
1 <?php
3 /**
4 * body_composition view.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Daniel Ehrlich <daniel.ehrlich1@gmail.com>
11 * @copyright Copyright (c) 2006 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2018 Daniel Ehrlich <daniel.ehrlich1@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../../globals.php");
18 require_once("$srcdir/api.inc.php");
19 require_once("$srcdir/forms.inc.php");
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Core\Header;
24 $scale_file_name = '/tmp/tanita_scale.txt';
25 $scale_file_age = -1;
26 $row = array();
28 if (! $encounter) { // comes from globals.php
29 die("Internal error: we do not seem to be in an encounter!");
32 function rbvalue($rbname)
34 $tmp = $_POST[$rbname];
35 if (! $tmp) {
36 return "NULL";
39 return "$tmp";
42 function rbinput($name, $value, $desc, $colname)
44 global $row;
45 $ret = "<input type='radio' name='" . attr($name) . "' value='" . attr($value) . "'";
46 if ($row[$colname] == $value) {
47 $ret .= " checked";
50 $ret .= " />" . text($desc);
51 return $ret;
54 $formid = $_GET['id'];
56 // If Save was clicked, save the info.
58 if ($_POST['bn_save']) {
59 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
60 CsrfUtils::csrfNotVerified();
63 // If updating an existing form...
65 if ($formid) {
66 $query = "UPDATE form_body_composition SET
67 body_type = ?, height = ?, weight = ?, bmi = ?, bmr = ?, impedance = ?,
68 fat_pct = ?, fat_mass = ?, ffm = ?, tbw = ?, other = ? WHERE id = ?";
70 sqlStatement($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
71 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
72 trim($_POST['form_tbw']), trim($_POST['form_other']), $formid ));
74 sqlStatement($query);
75 } else { // If adding a new form...
76 $query = "INSERT INTO form_body_composition
77 ( body_type, height, weight, bmi, bmr, impedance,
78 fat_pct, fat_mass, ffm, tbw, other )
79 VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
81 $newid = sqlInsert($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
82 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
83 trim($_POST['form_tbw']), trim($_POST['form_other'])));
85 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
88 formHeader("Redirecting....");
89 formJump();
90 formFooter();
91 exit;
94 if ($formid) {
95 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
96 "id = ? AND activity = '1'", array($formid));
97 } else {
98 // Get the most recent scale reading.
99 $items = explode(',', trim(file_get_contents($scale_file_name)));
100 if ($items && count($items) > 11) {
101 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
102 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
103 $row['height'] = $items[2];
104 $row['weight'] = $items[3];
105 $row['bmi'] = $items[10];
106 $row['bmr'] = $items[11];
107 $row['impedance'] = $items[4];
108 $row['fat_pct'] = $items[5];
109 $row['fat_mass'] = $items[6];
110 $row['ffm'] = $items[7];
111 $row['tbw'] = $items[8];
115 <html>
116 <head>
117 <?php Header::setupHeader(); ?>
118 </head>
120 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
121 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo attr_url($formid) ?>"
122 onsubmit="return top.restoreSession()">
123 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
125 <center>
128 <table border='0' width='95%'>
130 <tr bgcolor='#dddddd'>
131 <td colspan='3' align='center'><b>Body Composition</b></td>
132 </tr>
134 <tr>
135 <td width='5%' nowrap>Body Type</td>
136 <td colspan='2' nowrap>
138 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type'); ?>&nbsp;
139 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type'); ?>&nbsp;
140 </td>
141 </tr>
143 <tr>
144 <td nowrap>Height in inches</td>
145 <td nowrap>
146 <input type='text' name='form_height' size='6'
147 value='<?php echo attr($row['height']) ?>' /> &nbsp;
148 </td>
149 <td nowrap>
150 &nbsp;
151 </td>
152 </tr>
154 <tr>
155 <td nowrap>Weight in pounds</td>
156 <td nowrap>
157 <input type='text' name='form_weight' size='6'
158 value='<?php echo attr($row['weight']) ?>' /> &nbsp;
159 </td>
160 <td align='center' nowrap>
161 <?php
162 if ($scale_file_age >= 0) {
163 echo "<font color='blue'>This reading was taken " . text($scale_file_age) . " minutes ago.</font>\n";
164 } else {
165 echo "&nbsp;\n";
168 </td>
169 </tr>
171 <tr>
172 <td nowrap>BMI</td>
173 <td nowrap>
174 <input type='text' name='form_bmi' size='6'
175 value='<?php echo attr($row['bmi']) ?>' /> &nbsp;
176 </td>
177 <td nowrap>
178 &nbsp;
179 </td>
180 </tr>
182 <tr>
183 <td nowrap>BMR in kj</td>
184 <td nowrap>
185 <input type='text' name='form_bmr' size='6'
186 value='<?php echo attr($row['bmr']) ?>' /> &nbsp;
187 </td>
188 <td nowrap>
189 &nbsp;
190 </td>
191 </tr>
193 <tr>
194 <td nowrap>Impedance in ohms</td>
195 <td nowrap>
196 <input type='text' name='form_impedance' size='6'
197 value='<?php echo attr($row['impedance']) ?>' /> &nbsp;
198 </td>
199 <td nowrap>
200 &nbsp;
201 </td>
202 </tr>
204 <tr>
205 <td nowrap>Fat %</td>
206 <td nowrap>
207 <input type='text' name='form_fat_pct' size='6'
208 value='<?php echo attr($row['fat_pct']) ?>' /> &nbsp;
209 </td>
210 <td nowrap>
211 &nbsp;
212 </td>
213 </tr>
215 <tr>
216 <td nowrap>Fat Mass in pounds</td>
217 <td nowrap>
218 <input type='text' name='form_fat_mass' size='6'
219 value='<?php echo attr($row['fat_mass']) ?>' /> &nbsp;
220 </td>
221 <td nowrap>
222 &nbsp;
223 </td>
224 </tr>
226 <tr>
227 <td nowrap>FFM in pounds</td>
228 <td nowrap>
229 <input type='text' name='form_ffm' size='6'
230 value='<?php echo attr($row['ffm']) ?>' /> &nbsp;
231 </td>
232 <td nowrap>
233 &nbsp;
234 </td>
235 </tr>
237 <tr>
238 <td nowrap>TBW in pounds</td>
239 <td nowrap>
240 <input type='text' name='form_tbw' size='6'
241 value='<?php echo attr($row['tbw']) ?>' /> &nbsp;
242 </td>
243 <td nowrap>
244 &nbsp;
245 </td>
246 </tr>
248 <tr>
249 <td nowrap>Notes</td>
250 <td colspan='2' nowrap>
251 <textarea name='form_other' rows='8' style='width:100%'><?php echo text($row['other']) ?></textarea>
252 </td>
253 </tr>
255 </table>
258 <input type='submit' name='bn_save' value='Save' />
259 &nbsp;
260 <input type='button' value='Cancel' onclick="parent.closeTab(window.name, false)" />
261 </p>
263 </center>
265 </form>
266 </body>
267 </html>