Added option to omit circumferences in the Vitals form.
[openemr.git] / interface / forms / vitals / C_FormVitals.class.php
blob8f41d3ace4eb3a7a128ccb91cebe2778e21d01ca
1 <?php
3 require_once ($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once ($GLOBALS['fileroot'] . "/library/forms.inc");
5 require_once ($GLOBALS['fileroot'] . "/library/patient.inc");
6 require_once("FormVitals.class.php");
8 class C_FormVitals extends Controller {
10 var $template_dir;
12 function C_FormVitals($template_mod = "general") {
13 parent::Controller();
14 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
15 $this->template_mod = $template_mod;
16 $this->template_dir = dirname(__FILE__) . "/templates/vitals/";
17 $this->assign("FORM_ACTION", $GLOBALS['web_root']);
18 $this->assign("DONT_SAVE_LINK",$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl");
19 $this->assign("STYLE", $GLOBALS['style']);
21 // Options for units of measurement and things to omit.
22 $this->assign("units_of_measurement",$GLOBALS['units_of_measurement']);
23 $this->assign("gbl_vitals_options",$GLOBALS['gbl_vitals_options']);
26 function default_action_old() {
27 //$vitals = array();
28 //array_push($vitals, new FormVitals());
29 $vitals = new FormVitals();
30 $this->assign("vitals",$vitals);
31 $this->assign("results", $results);
32 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
35 function default_action($form_id) {
37 if (is_numeric($form_id)) {
38 $vitals = new FormVitals($form_id);
40 else {
41 $vitals = new FormVitals();
44 $dbconn = $GLOBALS['adodb']['db'];
45 //Combined query for retrieval of vital information which is not deleted
46 $sql = "SELECT fv.*, fe.date AS encdate " .
47 "FROM form_vitals AS fv, forms AS f, form_encounter AS fe WHERE " .
48 "fv.id != $form_id and fv.pid = " . $GLOBALS['pid'] . " AND " .
49 "f.formdir = 'vitals' AND f.deleted = 0 AND f.form_id = fv.id AND " .
50 "fe.pid = f.pid AND fe.encounter = f.encounter " .
51 "ORDER BY encdate DESC, fv.date DESC";
52 $result = $dbconn->Execute($sql);
54 // get the patient's current age
55 $patient_data = getPatientData($GLOBALS['pid']);
56 $patient_dob=$patient_data['DOB'];
57 $patient_age = getPatientAge($patient_dob);
58 $this->assign("patient_age", $patient_age);
59 $this->assign("patient_dob",$patient_dob);
61 $i = 1;
62 while($result && !$result->EOF)
64 $results[$i]['id'] = $result->fields['id'];
65 $results[$i]['encdate'] = substr($result->fields['encdate'], 0, 10);
66 $results[$i]['date'] = $result->fields['date'];
67 $results[$i]['activity'] = $result->fields['activity'];
68 $results[$i]['bps'] = $result->fields['bps'];
69 $results[$i]['bpd'] = $result->fields['bpd'];
70 $results[$i]['weight'] = $result->fields['weight'];
71 $results[$i]['height'] = $result->fields['height'];
72 $results[$i]['temperature'] = $result->fields['temperature'];
73 $results[$i]['temp_method'] = $result->fields['temp_method'];
74 $results[$i]['pulse'] = $result->fields['pulse'];
75 $results[$i]['respiration'] = $result->fields['respiration'];
76 $results[$i]['BMI'] = $result->fields['BMI'];
77 $results[$i]['BMI_status'] = $result->fields['BMI_status'];
78 $results[$i]['note'] = $result->fields['note'];
79 $results[$i]['waist_circ'] = $result->fields['waist_circ'];
80 $results[$i]['head_circ'] = $result->fields['head_circ'];
81 $results[$i++]['oxygen_saturation'] = $result->fields['oxygen_saturation'];
82 $result->MoveNext();
85 $this->assign("vitals",$vitals);
86 $this->assign("results", $results);
88 $this->assign("VIEW",true);
89 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
93 function default_action_process() {
94 if ($_POST['process'] != "true")
95 return;
97 $weight = $_POST["weight"];
98 $height = $_POST["height"];
99 if ($weight > 0 && $height > 0) {
100 $_POST["BMI"] = ($weight/$height/$height)*703;
102 if ( $_POST["BMI"] > 42 ) $_POST["BMI_status"] = 'Obesity III';
103 elseif ( $_POST["BMI"] > 34 ) $_POST["BMI_status"] = 'Obesity II';
104 elseif ( $_POST["BMI"] > 30 ) $_POST["BMI_status"] = 'Obesity I';
105 elseif ( $_POST["BMI"] > 27 ) $_POST["BMI_status"] = 'Overweight';
106 elseif ( $_POST["BMI"] > 25 ) $_POST["BMI_status"] = 'Normal BL';
107 elseif ( $_POST["BMI"] > 18.5 ) $_POST["BMI_status"] = 'Normal';
108 elseif ( $_POST["BMI"] > 10 ) $_POST["BMI_status"] = 'Underweight';
109 $temperature = $_POST["temperature"];
110 if ($temperature == '0' || $temperature == '') {
111 $_POST["temp_method"] = "";
114 $this->vitals = new FormVitals($_POST['id']);
116 parent::populate_object($this->vitals);
118 $this->vitals->persist();
119 if ($GLOBALS['encounter'] < 1) {
120 $GLOBALS['encounter'] = date("Ymd");
122 if(empty($_POST['id']))
124 addForm($GLOBALS['encounter'], "Vitals", $this->vitals->id, "vitals", $GLOBALS['pid'], $_SESSION['userauthorized']);
125 $_POST['process'] = "";
127 return;