fix: set default x12 partner for item in billing manager (#7513)
[openemr.git] / contrib / forms / body_composition / new.php
blob6ec39a0f6174808b41c9d77421a1500574a4401b
1 <?php
3 /**
4 * body_composition new.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";
49 $ret .= " />" . text($desc);
50 return $ret;
53 $formid = $_GET['id'];
55 // If Save was clicked, save the info.
57 if ($_POST['bn_save']) {
58 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
59 CsrfUtils::csrfNotVerified();
62 // If updating an existing form...
64 if ($formid) {
65 $query = "UPDATE form_body_composition SET
66 body_type = ?, height = ?, weight = ?, bmi = ?, bmr = ?, impedance = ?,
67 fat_pct = ?, fat_mass = ?, ffm = ?, tbw = ?, other = ? WHERE id = ?";
69 sqlStatement($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
70 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
71 trim($_POST['form_tbw']), trim($_POST['form_other']), $formid ));
72 } else { // If adding a new form...
73 $query = 'INSERT INTO form_body_composition (
74 body_type, height, weight, bmi, bmr, impedance, fat_pct, fat_mass, ffm, tbw, other
75 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
77 $newid = sqlInsert($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
78 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']),
79 trim($_POST['form_ffm']), trim($_POST['form_tbw']), trim($_POST['form_other'])));
81 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
84 formHeader("Redirecting....");
85 formJump();
86 formFooter();
87 exit;
90 if ($formid) {
91 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
92 "id = ? AND activity = '1'", array($formid));
93 } else {
94 // Get the most recent scale reading.
95 $items = explode(',', trim(file_get_contents($scale_file_name)));
96 if ($items && count($items) > 11) {
97 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
98 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
99 $row['height'] = $items[2];
100 $row['weight'] = $items[3];
101 $row['bmi'] = $items[10];
102 $row['bmr'] = $items[11];
103 $row['impedance'] = $items[4];
104 $row['fat_pct'] = $items[5];
105 $row['fat_mass'] = $items[6];
106 $row['ffm'] = $items[7];
107 $row['tbw'] = $items[8];
111 <html>
112 <head>
113 <?php Header::setupHeader(); ?>
114 </head>
116 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
117 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo attr_url($formid) ?>"
118 onsubmit="return top.restoreSession()">
119 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
121 <center>
124 <table border='0' width='95%'>
126 <tr bgcolor='#dddddd'>
127 <td colspan='3' align='center'><b>Body Composition</b></td>
128 </tr>
130 <tr>
131 <td width='5%' nowrap>Body Type</td>
132 <td colspan='2' nowrap>
133 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>&nbsp;
134 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>&nbsp;
135 </td>
136 </tr>
138 <tr>
139 <td nowrap>Height in inches</td>
140 <td nowrap>
141 <input type='text' name='form_height' size='6'
142 value='<?php echo attr($row['height']) ?>' /> &nbsp;
143 </td>
144 <td nowrap>
145 &nbsp;
146 </td>
147 </tr>
149 <tr>
150 <td nowrap>Weight in pounds</td>
151 <td nowrap>
152 <input type='text' name='form_weight' size='6'
153 value='<?php echo attr($row['weight']) ?>' /> &nbsp;
154 </td>
155 <td align='center' nowrap>
156 <?php
157 if ($scale_file_age >= 0) {
158 echo "<font color='blue'>This reading was taken " . text($scale_file_age) . " minutes ago.</font>\n";
159 } else {
160 echo "&nbsp;\n";
163 </td>
164 </tr>
166 <tr>
167 <td nowrap>BMI</td>
168 <td nowrap>
169 <input type='text' name='form_bmi' size='6'
170 value='<?php echo attr($row['bmi']) ?>' /> &nbsp;
171 </td>
172 <td nowrap>
173 &nbsp;
174 </td>
175 </tr>
177 <tr>
178 <td nowrap>BMR in kj</td>
179 <td nowrap>
180 <input type='text' name='form_bmr' size='6'
181 value='<?php echo attr($row['bmr']) ?>' /> &nbsp;
182 </td>
183 <td nowrap>
184 &nbsp;
185 </td>
186 </tr>
188 <tr>
189 <td nowrap>Impedance in ohms</td>
190 <td nowrap>
191 <input type='text' name='form_impedance' size='6'
192 value='<?php echo attr($row['impedance']) ?>' /> &nbsp;
193 </td>
194 <td nowrap>
195 &nbsp;
196 </td>
197 </tr>
199 <tr>
200 <td nowrap>Fat %</td>
201 <td nowrap>
202 <input type='text' name='form_fat_pct' size='6'
203 value='<?php echo attr($row['fat_pct']) ?>' /> &nbsp;
204 </td>
205 <td nowrap>
206 &nbsp;
207 </td>
208 </tr>
210 <tr>
211 <td nowrap>Fat Mass in pounds</td>
212 <td nowrap>
213 <input type='text' name='form_fat_mass' size='6'
214 value='<?php echo attr($row['fat_mass']) ?>' /> &nbsp;
215 </td>
216 <td nowrap>
217 &nbsp;
218 </td>
219 </tr>
221 <tr>
222 <td nowrap>FFM in pounds</td>
223 <td nowrap>
224 <input type='text' name='form_ffm' size='6'
225 value='<?php echo attr($row['ffm']) ?>' /> &nbsp;
226 </td>
227 <td nowrap>
228 &nbsp;
229 </td>
230 </tr>
232 <tr>
233 <td nowrap>TBW in pounds</td>
234 <td nowrap>
235 <input type='text' name='form_tbw' size='6'
236 value='<?php echo attr($row['tbw']) ?>' /> &nbsp;
237 </td>
238 <td nowrap>
239 &nbsp;
240 </td>
241 </tr>
243 <tr>
244 <td nowrap>Notes</td>
245 <td colspan='2' nowrap>
246 <textarea name='form_other' rows='8' style='width:100%'><?php echo text($row['other']) ?></textarea>
247 </td>
248 </tr>
250 </table>
253 <input type='submit' name='bn_save' value='Save' />
254 &nbsp;
255 <input type='button' value='Cancel' onclick="parent.closeTab(window.name, false)" />
256 </p>
258 </center>
260 </form>
261 </body>
262 </html>