]> Softwares of Agnibho - simpleipd.git/blob - lib/db.php
Added requisition
[simpleipd.git] / lib / db.php
1 <?php
2 class DB extends SQLite3 {
3 function __construct(){
4 $this->open("data/data.db");
5 }
6 function checkUser($username, $password){
7 $stmt=$this->prepare("SELECT hash FROM users WHERE user=:user");
8 $stmt->bindValue(":user", $username);
9 $result=$stmt->execute();
10 $hash=$result->fetchArray();
11 if($hash){
12 return(password_verify($password, $hash["hash"]));
13 }
14 else{
15 return(false);
16 }
17 }
18 function admit($post){
19 $quer=$this->prepare("SELECT count(rowid) FROM patients WHERE pid=:pid");
20 $quer->bindValue(":pid", $post["pid"]);
21 $exist=$quer->execute();
22 if($exist->fetchArray()[0]==0){
23 $stmt=$this->prepare("INSERT INTO patients (pid,name,age,sex,status,summary,ward,bed,diagnosis,data) VALUES (:pid,:name,:age,:sex,'admitted',:summary,:ward,:bed,:diagnosis,:data);");
24 }
25 else{
26 $stmt=$this->prepare("UPDATE patients SET name=:name,age=:age,sex=:sex,ward=:ward,bed=:bed,diagnosis=:diagnosis,summary=:summary,data=:data WHERE pid=:pid;");
27 }
28 $stmt->bindValue(":pid", $post["pid"]);
29 $stmt->bindValue(":name", $post["name"]);
30 $stmt->bindValue(":age", $post["age"]);
31 $stmt->bindValue(":sex", $post["sex"]);
32 $stmt->bindValue(":status", "admitted");
33 $stmt->bindValue(":ward", $post["ward"]);
34 $stmt->bindValue(":bed", $post["bed"]);
35 $stmt->bindValue(":diagnosis", $post["diagnosis"]);
36 $stmt->bindValue(":summary", $post["summary"]);
37 $stmt->bindValue(":data", json_encode($post));
38 $stmt->execute();
39 }
40 function updateHistory($post, $pid){
41 $stmt=$this->prepare("UPDATE patients SET history=:history WHERE pid=:pid;");
42 $stmt->bindValue(":history", json_encode($post));
43 $stmt->bindValue(":pid", $pid);
44 $stmt->execute();
45 }
46 function addPhysician($post, $pid){
47 $stmt=$this->prepare("INSERT INTO physician (pid, time, data) VALUES (:pid, :time, :data);");
48 $stmt->bindValue(":pid", $pid);
49 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
50 $stmt->bindValue(":data", json_encode($post));
51 $stmt->execute();
52 }
53 function editPhysician($post, $pid, $id){
54 $stmt=$this->prepare("UPDATE physician SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;");
55 $stmt->bindValue(":pid", $pid);
56 $stmt->bindValue(":id", $id);
57 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
58 $stmt->bindValue(":data", json_encode($post));
59 $stmt->execute();
60 }
61 function addNursing($post, $pid){
62 $stmt=$this->prepare("INSERT INTO nursing (pid, time, data) VALUES (:pid, :time, :data);");
63 $stmt->bindValue(":pid", $pid);
64 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
65 $stmt->bindValue(":data", json_encode($post));
66 $stmt->execute();
67 }
68 function editNursing($post, $pid, $id){
69 $stmt=$this->prepare("UPDATE nursing SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;");
70 $stmt->bindValue(":pid", $pid);
71 $stmt->bindValue(":id", $id);
72 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
73 $stmt->bindValue(":data", json_encode($post));
74 $stmt->execute();
75 }
76 function addReport($post, $pid, $form){
77 $stmt=$this->prepare("INSERT INTO reports (pid, time, form, data) VALUES (:pid, :time, :form, :data);");
78 $stmt->bindValue(":pid", $pid);
79 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
80 $stmt->bindValue(":form", $post["form"]);
81 $stmt->bindValue(":data", json_encode($post));
82 $stmt->execute();
83 }
84 function editReport($post, $pid, $id, $form){
85 $stmt=$this->prepare("UPDATE reports SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;");
86 $stmt->bindValue(":pid", $pid);
87 $stmt->bindValue(":id", $id);
88 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
89 $stmt->bindValue(":data", json_encode($post));
90 $stmt->execute();
91 }
92 function addDrug($pid, $drug, $dose, $route, $frequency, $date, $time, $duration, $addl){
93 $stmt=$this->prepare("INSERT INTO treatment (pid, drug, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :drug, :dose, :route, :frequency, :start, :duration, :omit, :addl);");
94 $stmt->bindValue(":pid", $pid);
95 $stmt->bindValue(":drug", $drug);
96 $stmt->bindValue(":dose", $dose);
97 $stmt->bindValue(":route", $route);
98 $stmt->bindValue(":frequency", $frequency);
99 $stmt->bindValue(":start", strtotime($date." ".$time));
100 $stmt->bindValue(":duration", $duration);
101 $stmt->bindValue(":addl", $addl);
102 $stmt->bindValue(":omit", false);
103 $stmt->execute();
104 }
105 function omitDrug($id){
106 $stmt=$this->prepare("UPDATE treatment SET end=:end,omit=:omit WHERE rowid=:id;");
107 $stmt->bindValue(":end", time());
108 $stmt->bindValue(":omit", true);
109 $stmt->bindValue(":id", $id);
110 $stmt->execute();
111 }
112 function addRequisition($pid, $test, $date, $time, $room, $form){
113 $stmt=$this->prepare("INSERT INTO requisition (pid, test, time, room, form, status) VALUES (:pid, :test, :time, :room, :form, :status);");
114 $stmt->bindValue(":pid", $pid);
115 $stmt->bindValue(":test", $test);
116 $stmt->bindValue(":time", strtotime($date." ".$time));
117 $stmt->bindValue(":room", $room);
118 $stmt->bindValue(":form", $form);
119 $stmt->bindValue(":status", "active");
120 $stmt->execute();
121 }
122 function omitRequisition($id){
123 $stmt=$this->prepare("UPDATE requisition SET status=:status WHERE rowid=:id;");
124 $stmt->bindValue(":status", "done");
125 $stmt->bindValue(":id", $id);
126 $stmt->execute();
127 }
128 function addAdvice($pid, $name, $dose, $route, $frequency, $duration, $addl){
129 $stmt=$this->prepare("INSERT INTO discharge (pid, name, dose, route, frequency, duration, addl) VALUES (:pid, :name, :dose, :route, :frequency, :duration, :addl);");
130 $stmt->bindValue(":pid", $pid);
131 $stmt->bindValue(":name", $name);
132 $stmt->bindValue(":dose", $dose);
133 $stmt->bindValue(":route", $route);
134 $stmt->bindValue(":frequency", $frequency);
135 $stmt->bindValue(":duration", $duration);
136 $stmt->bindValue(":addl", $addl);
137 $stmt->execute();
138 }
139 function deleteAdvice($id){
140 $stmt=$this->prepare("DELETE FROM discharge WHERE rowid=:id;");
141 $stmt->bindValue(":id", $id);
142 $stmt->execute();
143 }
144 function setDischarged($pid){
145 $stmt=$this->prepare("UPDATE patients SET status=:discharged WHERE pid=:pid;");
146 $stmt->bindValue(":pid", $pid);
147 $stmt->execute();
148 }
149 function setDead($pid, $post){
150 $stmt=$this->prepare("INSERT INTO death (pid, time, data) VALUES (:pid, :time, :data);");
151 $stmt->bindValue(":pid", $pid);
152 $stmt->bindValue(":time", strtotime($post["date"].$post["time"]));
153 $stmt->bindValue(":data", json_encode($post));
154 $stmt->execute();
155 $stmt=$this->prepare("UPDATE patients SET status='expired' WHERE pid=:pid;");
156 $stmt->bindValue(":pid", $pid);
157 $stmt->execute();
158 }
159 function getDrugs($pid){
160 $stmt=$this->prepare("SELECT rowid,* FROM treatment WHERE pid=:pid;");
161 $stmt->bindValue(":pid", $pid);
162 $result=$stmt->execute();
163 return($result);
164 }
165 function getRequisitions($pid){
166 $stmt=$this->prepare("SELECT rowid,* FROM requisition WHERE pid=:pid AND status=:status;");
167 $stmt->bindValue(":pid", $pid);
168 $stmt->bindValue(":status", "active");
169 $result=$stmt->execute();
170 return($result);
171 }
172 function getAdvice($pid){
173 $stmt=$this->prepare("SELECT rowid,* FROM discharge WHERE pid=:pid;");
174 $stmt->bindValue(":pid", $pid);
175 $result=$stmt->execute();
176 return($result);
177 }
178 function getName($pid){
179 $stmt=$this->prepare("SELECT name FROM patients WHERE pid=:pid;");
180 $stmt->bindValue(":pid", $pid);
181 $result=$stmt->execute();
182 return($result);
183 }
184 function getAge($pid){
185 $stmt=$this->prepare("SELECT age FROM patients WHERE pid=:pid;");
186 $stmt->bindValue(":pid", $pid);
187 $result=$stmt->execute();
188 return($result);
189 }
190 function getSex($pid){
191 $stmt=$this->prepare("SELECT sex FROM patients WHERE pid=:pid;");
192 $stmt->bindValue(":pid", $pid);
193 $result=$stmt->execute();
194 return($result);
195 }
196 function getWard($pid){
197 $stmt=$this->prepare("SELECT ward FROM patients WHERE pid=:pid;");
198 $stmt->bindValue(":pid", $pid);
199 $result=$stmt->execute();
200 return($result);
201 }
202 function getBed($pid){
203 $stmt=$this->prepare("SELECT bed FROM patients WHERE pid=:pid;");
204 $stmt->bindValue(":pid", $pid);
205 $result=$stmt->execute();
206 return($result);
207 }
208 function getStatus($pid){
209 $stmt=$this->prepare("SELECT status FROM patients WHERE pid=:pid;");
210 $stmt->bindValue(":pid", $pid);
211 $result=$stmt->execute();
212 return($result);
213 }
214 function getDiagnosis($pid){
215 $stmt=$this->prepare("SELECT diagnosis FROM patients WHERE pid=:pid;");
216 $stmt->bindValue(":pid", $pid);
217 $result=$stmt->execute();
218 return($result);
219 }
220 function getPatientList(){
221 $stmt=$this->prepare("SELECT pid,ward,bed,name,diagnosis FROM patients;");
222 $result=$stmt->execute();
223 return($result);
224 }
225 function getRequisitionList(){
226 $stmt=$this->prepare("SELECT rowid,pid,test,room,time,form FROM requisition WHERE status=:active;");
227 $stmt->bindValue(":active", "active");
228 $result=$stmt->execute();
229 return($result);
230 }
231 function getForm($id){
232 $stmt=$this->prepare("SELECT form FROM reports WHERE rowid=:id;");
233 $stmt->bindValue(":id", $id);
234 $result=$stmt->execute();
235 return($result);
236 }
237 function getAdmission($pid){
238 $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid;");
239 $stmt->bindValue(":pid", $pid);
240 $result=$stmt->execute();
241 return($result);
242 }
243 function getHistory($pid){
244 $stmt=$this->prepare("SELECT history FROM patients WHERE pid=:pid;");
245 $stmt->bindValue(":pid", $pid);
246 $result=$stmt->execute();
247 return($result);
248 }
249 function getData($pid, $id, $cat){
250 if($cat=="physician"){
251 $stmt=$this->prepare("SELECT data FROM physician WHERE pid=:pid AND rowid=:id;");
252 } elseif($cat=="nursing"){
253 $stmt=$this->prepare("SELECT data FROM nursing WHERE pid=:pid AND rowid=:id;");
254 } elseif($cat=="reports"){
255 $stmt=$this->prepare("SELECT data FROM reports WHERE pid=:pid AND rowid=:id;");
256 } else{
257 return(false);
258 }
259 $stmt->bindValue(":pid", $pid);
260 $stmt->bindValue(":id", $id);
261 $result=$stmt->execute();
262 return($result);
263 }
264 function getAllData($pid, $cat){
265 if($cat=="physician"){
266 $stmt=$this->prepare("SELECT rowid,data FROM physician WHERE pid=:pid;");
267 } elseif($cat=="nursing"){
268 $stmt=$this->prepare("SELECT rowid,data FROM nursing WHERE pid=:pid;");
269 } elseif($cat=="reports"){
270 $stmt=$this->prepare("SELECT rowid,data FROM reports WHERE pid=:pid;");
271 } elseif($cat=="info"){
272 $stmt=$this->prepare("SELECT rowid,data FROM patients WHERE pid=:pid;");
273 } elseif($cat=="history"){
274 $stmt=$this->prepare("SELECT rowid,history FROM patients WHERE pid=:pid;");
275 } else{
276 return(false);
277 }
278 $stmt->bindValue(":pid", $pid);
279 $result=$stmt->execute();
280 return($result);
281 }
282 }
283 $db = new DB();
284 ?>