Space to separate "&&" so that all "&$var" can be made into "$var" later
[openemr.git] / library / forms.inc
blob3b8b13b8e53cd60e7cd117307d2c0d63a7177db3
1 <?php
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";
23         }
24         $sql = "select * from form_" . $result['formdir'] . " where id='" . $result['form_id']  . "'";
25         //echo $sql . "<br />";
26         $result =  sqlQuery($sql);
27         //print_r($result);
28         return $result;
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);
41         if(!empty($name)){
42                 $sql .= "and form_name=? ";
43                 array_push($arraySqlBind,$name);
44         }
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++)
51         {
52                 $all[$iter] = $row;
53         }
54         return $all;
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'];
63         $arraySqlBind = array();
64         $sql = "insert into forms (date, encounter, form_name, form_id, pid, " .
65                 "user, groupname, authorized, formdir) values (";
66         if($date == "NOW()") {
67                 $sql .= "$date";
68         }
69         else {
70                 $sql .= "?";
71                 array_push($arraySqlBind,$date);
72         }
73         $sql .= ", ?, ?, ?, ?, ?, ?, ?, ?)";
74         array_push($arraySqlBind,$encounter,$form_name,$form_id,$pid,$user,$group,$authorized,$formdir);
75         return sqlInsert($sql,$arraySqlBind);
78 function authorizeForm($id, $authorized = "1")
80         sqlQuery("update forms set authorized = '$authorized' where id = '$id'");
83 function getEncounters($pid,$dateStart='',$dateEnd='',$encounterRuleType='')
86         $arraySqlBind = array();
87         
88         if ($encounterRuleType) {
89                 // Only collect certain type of encounters (list_options item from the rule_enc_types list that is mapped via enc_category_map table)
90                 $from = "form_encounter LEFT JOIN enc_category_map ON (form_encounter.pc_catid = enc_category_map.main_cat_id)";
91                 $where = "enc_category_map.rule_enc_id = ? and ";
92                 array_push($arraySqlBind,$encounterRuleType);
93         }
94         else {
95                 // Collect all encounters
96                 $from = "form_encounter";
97         }
99         if ($dateStart && $dateEnd) {
100                 $where .= "form_encounter.pid = ? and form_encounter.date >= ? and form_encounter.date <= ?";
101                 array_push($arraySqlBind,$pid,$dateStart,$dateEnd);
102         }
103         else if ($dateStart && !$dateEnd) {
104                 $where .= "form_encounter.pid = ? and form_encounter.date >= ?";
105                 array_push($arraySqlBind,$pid,$dateStart);
106         }
107         else if (!$dateStart && $dateEnd) {
108                 $where .= "form_encounter.pid = ? and form_encounter.date <= ?";
109                 array_push($arraySqlBind,$pid,$dateEnd);
110         }
111         else {
112                 $where .= "form_encounter.pid = ?";
113                 array_push($arraySqlBind,$pid);
114         }
116         $res = sqlStatement("SELECT distinct encounter FROM $from WHERE $where ORDER by date desc;", $arraySqlBind);
118         for($iter=0; $row=sqlFetchArray($res); $iter++)
119         {
120                 $all[$iter] = $row;
121         }
122         return $all;
125 function getEncounterDateByEncounter($encounter)
127         // $sql = "select date from forms where encounter='$encounter' order by date";
128         $sql = "select date from form_encounter where encounter='$encounter' order by date";
129         return sqlQuery($sql);
132 function getProviderIdOfEncounter($encounter)
134         $sql = "select provider_id from form_encounter where encounter='$encounter' order by date";
135         $res = sqlQuery($sql);
136         return $res['provider_id'];
139 function getFormNameByFormdirAndFormid ($formdir,$form_id)
141         return sqlQuery("select form_name from forms where formdir='$formdir' and form_id='$form_id'");
144 function getFormNameByFormdir ($formdir)
146         return sqlQuery("select form_name from forms where formdir='$formdir'");