3 require_once("{$GLOBALS['srcdir']}/sql.inc");
5 $GLOBALS['form_exit_url'] = $GLOBALS['concurrent_layout'] ?
6 "$rootdir/patient_file/encounter/encounter_top.php" :
7 "$rootdir/patient_file/encounter/patient_encounter.php";
9 function getFormById ($id, $cols = "*")
11 $sql = "select $cols from forms where id='$id' order by date DESC limit 0,1";
12 //echo $sql . "<br />";
13 return sqlQuery($sql);
16 function getFormInfoById ($id, $cols = "*")
18 $sql = "select $cols from forms where id='$id' order by date DESC limit 0,1";
19 //echo $sql . "<br />";
20 $result = sqlQuery($sql);
21 if ($result['formdir'] == "newpatient") {
22 $result['formdir'] = "encounter";
24 $sql = "select * from form_" . $result['formdir'] . " where id='" . $result['form_id'] . "'";
25 //echo $sql . "<br />";
26 $result = sqlQuery($sql);
31 function getFormsByPid ($pid, $cols = "*")
33 return sqlQuery("select $cols from forms where pid ='$pid'");
36 function getFormByEncounter($pid,$encounter, $cols="form_id, form_name", $name="")
38 $arraySqlBind = array();
39 $sql = "select $cols from forms where encounter = ? and pid=? ";
40 array_push($arraySqlBind,$encounter,$pid);
42 $sql .= "and form_name=? ";
43 array_push($arraySqlBind,$name);
45 // This puts vitals first in the list, and newpatient last:
46 $sql .= "ORDER BY FIND_IN_SET(formdir,'vitals') DESC, date DESC";
48 $res = sqlStatement($sql,$arraySqlBind);
50 for($iter=0; $row=sqlFetchArray($res); $iter++)
57 function addForm($encounter, $form_name, $form_id, $formdir, $pid,
58 $authorized = "0", $date="NOW()", $user="", $group="")
60 if (!$user) $user = $_SESSION['authUser'];
61 if (!$group) $group = $_SESSION['authProvider'];
62 $sql = "insert into forms (date, encounter, form_name, form_id, pid, " .
63 "user, groupname, authorized, formdir) values (";
68 $sql .= ", '$encounter', '$form_name', '$form_id', '$pid', '$user', " .
69 "'$group', '$authorized', '$formdir')";
70 return sqlInsert( $sql );
73 function authorizeForm($id, $authorized = "1")
75 sqlQuery("update forms set authorized = '$authorized' where id = '$id'");
78 function getEncounters($pid,$dateStart='',$dateEnd='',$encounterRuleType='')
81 $arraySqlBind = array();
83 if ($encounterRuleType) {
84 // Only collect certain type of encounters (list_options item from the rule_enc_types list that is mapped via enc_category_map table)
85 $from = "form_encounter LEFT JOIN enc_category_map ON (form_encounter.pc_catid = enc_category_map.main_cat_id)";
86 $where = "enc_category_map.rule_enc_id = ? and ";
87 array_push($arraySqlBind,$encounterRuleType);
90 // Collect all encounters
91 $from = "form_encounter";
94 if ($dateStart && $dateEnd) {
95 $where .= "form_encounter.pid = ? and form_encounter.date >= ? and form_encounter.date <= ?";
96 array_push($arraySqlBind,$pid,$dateStart,$dateEnd);
98 else if ($dateStart && !$dateEnd) {
99 $where .= "form_encounter.pid = ? and form_encounter.date >= ?";
100 array_push($arraySqlBind,$pid,$dateStart);
102 else if (!$dateStart && $dateEnd) {
103 $where .= "form_encounter.pid = ? and form_encounter.date <= ?";
104 array_push($arraySqlBind,$pid,$dateEnd);
107 $where .= "form_encounter.pid = ?";
108 array_push($arraySqlBind,$pid);
111 $res = sqlStatement("SELECT distinct encounter FROM $from WHERE $where ORDER by date desc;", $arraySqlBind);
113 for($iter=0; $row=sqlFetchArray($res); $iter++)
120 function getEncounterDateByEncounter($encounter)
122 // $sql = "select date from forms where encounter='$encounter' order by date";
123 $sql = "select date from form_encounter where encounter='$encounter' order by date";
124 return sqlQuery($sql);
127 function getFormNameByFormdirAndFormid ($formdir,$form_id)
129 return sqlQuery("select form_name from forms where formdir='$formdir' and form_id='$form_id'");
132 function getFormNameByFormdir ($formdir)
134 return sqlQuery("select form_name from forms where formdir='$formdir'");