Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / interface / forms / vitals / C_FormVitals.class.php
blobf524a1a9800c1ef9723c0b9ffe8d208730712f7f
1 <?php
3 require_once ($GLOBALS['fileroot'] . "/library/forms.inc");
4 require_once ($GLOBALS['fileroot'] . "/library/patient.inc");
5 require_once("FormVitals.class.php");
7 class C_FormVitals extends Controller {
9 var $template_dir;
10 var $form_id;
12 function __construct($template_mod = "general") {
13 parent::__construct();
14 $returnurl = 'encounter_top.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 setFormId($form_id){
36 $this->form_id = $form_id;
39 function default_action() {
41 $form_id = $this->form_id;
43 if (is_numeric($form_id)) {
44 $vitals = new FormVitals($form_id);
46 else {
47 $vitals = new FormVitals();
50 $dbconn = $GLOBALS['adodb']['db'];
51 //Combined query for retrieval of vital information which is not deleted
52 $sql = "SELECT fv.*, fe.date AS encdate " .
53 "FROM form_vitals AS fv, forms AS f, form_encounter AS fe WHERE " .
54 "fv.id != $form_id and fv.pid = " . $GLOBALS['pid'] . " AND " .
55 "f.formdir = 'vitals' AND f.deleted = 0 AND f.form_id = fv.id AND " .
56 "fe.pid = f.pid AND fe.encounter = f.encounter " .
57 "ORDER BY encdate DESC, fv.date DESC";
58 $result = $dbconn->Execute($sql);
60 // get the patient's current age
61 $patient_data = getPatientData($GLOBALS['pid']);
62 $patient_dob=$patient_data['DOB'];
63 $patient_age = getPatientAge($patient_dob);
64 $this->assign("patient_age", $patient_age);
65 $this->assign("patient_dob",$patient_dob);
67 $i = 1;
68 while($result && !$result->EOF)
70 $results[$i]['id'] = $result->fields['id'];
71 $results[$i]['encdate'] = substr($result->fields['encdate'], 0, 10);
72 $results[$i]['date'] = $result->fields['date'];
73 $results[$i]['activity'] = $result->fields['activity'];
74 $results[$i]['bps'] = $result->fields['bps'];
75 $results[$i]['bpd'] = $result->fields['bpd'];
76 $results[$i]['weight'] = $result->fields['weight'];
77 $results[$i]['height'] = $result->fields['height'];
78 $results[$i]['temperature'] = $result->fields['temperature'];
79 $results[$i]['temp_method'] = $result->fields['temp_method'];
80 $results[$i]['pulse'] = $result->fields['pulse'];
81 $results[$i]['respiration'] = $result->fields['respiration'];
82 $results[$i]['BMI'] = $result->fields['BMI'];
83 $results[$i]['BMI_status'] = $result->fields['BMI_status'];
84 $results[$i]['note'] = $result->fields['note'];
85 $results[$i]['waist_circ'] = $result->fields['waist_circ'];
86 $results[$i]['head_circ'] = $result->fields['head_circ'];
87 $results[$i++]['oxygen_saturation'] = $result->fields['oxygen_saturation'];
88 $result->MoveNext();
91 $this->assign("vitals",$vitals);
92 $this->assign("results", $results);
94 $this->assign("VIEW",true);
95 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
99 function default_action_process() {
100 if ($_POST['process'] != "true")
101 return;
103 $weight = $_POST["weight"];
104 $height = $_POST["height"];
105 if ($weight > 0 && $height > 0) {
106 $_POST["BMI"] = ($weight/$height/$height)*703;
108 if ( $_POST["BMI"] > 42 ) $_POST["BMI_status"] = 'Obesity III';
109 elseif ( $_POST["BMI"] > 34 ) $_POST["BMI_status"] = 'Obesity II';
110 elseif ( $_POST["BMI"] > 30 ) $_POST["BMI_status"] = 'Obesity I';
111 elseif ( $_POST["BMI"] > 27 ) $_POST["BMI_status"] = 'Overweight';
112 elseif ( $_POST["BMI"] > 25 ) $_POST["BMI_status"] = 'Normal BL';
113 elseif ( $_POST["BMI"] > 18.5 ) $_POST["BMI_status"] = 'Normal';
114 elseif ( $_POST["BMI"] > 10 ) $_POST["BMI_status"] = 'Underweight';
115 $temperature = $_POST["temperature"];
116 if ($temperature == '0' || $temperature == '') {
117 $_POST["temp_method"] = "";
120 $this->vitals = new FormVitals($_POST['id']);
122 parent::populate_object($this->vitals);
124 $this->vitals->persist();
125 if ($GLOBALS['encounter'] < 1) {
126 $GLOBALS['encounter'] = date("Ymd");
128 if(empty($_POST['id']))
130 addForm($GLOBALS['encounter'], "Vitals", $this->vitals->id, "vitals", $GLOBALS['pid'], $_SESSION['userauthorized']);
131 $_POST['process'] = "";
133 return;