]>
Softwares of Agnibho - simpleipd.git/blob - lib/db.php
2 class DB
extends SQLite3
{
3 function __construct (){
4 $this -> open ( "data/data.db" );
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 ();
12 return ( password_verify ( $password , $hash [ "hash" ]));
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);" );
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;" );
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 ));
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 );
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 ));
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 ));
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 ));
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 ));
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 ));
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 ));
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 );
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 );
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" );
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 );
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 );
139 function deleteAdvice ( $id ){
140 $stmt = $this -> prepare ( "DELETE FROM discharge WHERE rowid=:id;" );
141 $stmt -> bindValue ( ":id" , $id );
144 function setDischarged ( $pid ){
145 $stmt = $this -> prepare ( "UPDATE patients SET status=:discharged WHERE pid=:pid;" );
146 $stmt -> bindValue ( ":pid" , $pid );
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 ));
155 $stmt = $this -> prepare ( "UPDATE patients SET status='expired' WHERE pid=:pid;" );
156 $stmt -> bindValue ( ":pid" , $pid );
159 function getDrugs ( $pid ){
160 $stmt = $this -> prepare ( "SELECT rowid,* FROM treatment WHERE pid=:pid;" );
161 $stmt -> bindValue ( ":pid" , $pid );
162 $result = $stmt -> execute ();
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 ();
172 function getAdvice ( $pid ){
173 $stmt = $this -> prepare ( "SELECT rowid,* FROM discharge WHERE pid=:pid;" );
174 $stmt -> bindValue ( ":pid" , $pid );
175 $result = $stmt -> execute ();
178 function getName ( $pid ){
179 $stmt = $this -> prepare ( "SELECT name FROM patients WHERE pid=:pid;" );
180 $stmt -> bindValue ( ":pid" , $pid );
181 $result = $stmt -> execute ();
184 function getAge ( $pid ){
185 $stmt = $this -> prepare ( "SELECT age FROM patients WHERE pid=:pid;" );
186 $stmt -> bindValue ( ":pid" , $pid );
187 $result = $stmt -> execute ();
190 function getSex ( $pid ){
191 $stmt = $this -> prepare ( "SELECT sex FROM patients WHERE pid=:pid;" );
192 $stmt -> bindValue ( ":pid" , $pid );
193 $result = $stmt -> execute ();
196 function getWard ( $pid ){
197 $stmt = $this -> prepare ( "SELECT ward FROM patients WHERE pid=:pid;" );
198 $stmt -> bindValue ( ":pid" , $pid );
199 $result = $stmt -> execute ();
202 function getBed ( $pid ){
203 $stmt = $this -> prepare ( "SELECT bed FROM patients WHERE pid=:pid;" );
204 $stmt -> bindValue ( ":pid" , $pid );
205 $result = $stmt -> execute ();
208 function getStatus ( $pid ){
209 $stmt = $this -> prepare ( "SELECT status FROM patients WHERE pid=:pid;" );
210 $stmt -> bindValue ( ":pid" , $pid );
211 $result = $stmt -> execute ();
214 function getDiagnosis ( $pid ){
215 $stmt = $this -> prepare ( "SELECT diagnosis FROM patients WHERE pid=:pid;" );
216 $stmt -> bindValue ( ":pid" , $pid );
217 $result = $stmt -> execute ();
220 function getPatientList (){
221 $stmt = $this -> prepare ( "SELECT pid,ward,bed,name,diagnosis FROM patients;" );
222 $result = $stmt -> execute ();
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 ();
231 function getForm ( $id ){
232 $stmt = $this -> prepare ( "SELECT form FROM reports WHERE rowid=:id;" );
233 $stmt -> bindValue ( ":id" , $id );
234 $result = $stmt -> execute ();
237 function getAdmission ( $pid ){
238 $stmt = $this -> prepare ( "SELECT data FROM patients WHERE pid=:pid;" );
239 $stmt -> bindValue ( ":pid" , $pid );
240 $result = $stmt -> execute ();
243 function getHistory ( $pid ){
244 $stmt = $this -> prepare ( "SELECT history FROM patients WHERE pid=:pid;" );
245 $stmt -> bindValue ( ":pid" , $pid );
246 $result = $stmt -> execute ();
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;" );
259 $stmt -> bindValue ( ":pid" , $pid );
260 $stmt -> bindValue ( ":id" , $id );
261 $result = $stmt -> execute ();
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;" );
278 $stmt -> bindValue ( ":pid" , $pid );
279 $result = $stmt -> execute ();