]>
Softwares of Agnibho - simpleipd.git/blob - lib/db.php
2 class DB
extends SQLite3
{
3 function __construct (){
4 $this -> open ( "data/data.db" );
7 $quer = $this -> prepare ( "SELECT count(rowid) FROM patients WHERE pid=:pid" );
8 $quer -> bindValue ( ":pid" , $post [ "pid" ]);
9 $exist = $quer -> execute ();
10 if ( $exist -> fetchArray ()[ 0 ]== 0 ){
11 $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);" );
14 $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;" );
16 $stmt -> bindValue ( ":pid" , $post [ "pid" ]);
17 $stmt -> bindValue ( ":name" , $post [ "name" ]);
18 $stmt -> bindValue ( ":age" , $post [ "age" ]);
19 $stmt -> bindValue ( ":sex" , $post [ "sex" ]);
20 $stmt -> bindValue ( ":status" , "admitted" );
21 $stmt -> bindValue ( ":ward" , $post [ "ward" ]);
22 $stmt -> bindValue ( ":bed" , $post [ "bed" ]);
23 $stmt -> bindValue ( ":diagnosis" , $post [ "diagnosis" ]);
24 $stmt -> bindValue ( ":summary" , $post [ "summary" ]);
25 $stmt -> bindValue ( ":data" , json_encode ( $post ));
28 function updateHistory ( $post , $pid ){
29 $stmt = $this -> prepare ( "UPDATE patients SET history=:history WHERE pid=:pid;" );
30 $stmt -> bindValue ( ":history" , json_encode ( $post ));
31 $stmt -> bindValue ( ":pid" , $pid );
34 function addClinical ( $post , $pid ){
35 $stmt = $this -> prepare ( "INSERT INTO clinical (pid, time, data) VALUES (:pid, :time, :data);" );
36 $stmt -> bindValue ( ":pid" , $pid );
37 $stmt -> bindValue ( ":time" , strtotime ( $post [ "date" ]. $post [ "time" ]));
38 $stmt -> bindValue ( ":data" , json_encode ( $post ));
41 function editClinical ( $post , $pid , $id ){
42 $stmt = $this -> prepare ( "UPDATE clinical SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;" );
43 $stmt -> bindValue ( ":pid" , $pid );
44 $stmt -> bindValue ( ":id" , $id );
45 $stmt -> bindValue ( ":time" , strtotime ( $post [ "date" ]. $post [ "time" ]));
46 $stmt -> bindValue ( ":data" , json_encode ( $post ));
49 function addReport ( $post , $pid , $form ){
50 $stmt = $this -> prepare ( "INSERT INTO reports (pid, time, form, data) VALUES (:pid, :time, :form, :data);" );
51 $stmt -> bindValue ( ":pid" , $pid );
52 $stmt -> bindValue ( ":time" , strtotime ( $post [ "date" ]. $post [ "time" ]));
53 $stmt -> bindValue ( ":form" , $post [ "form" ]);
54 $stmt -> bindValue ( ":data" , json_encode ( $post ));
57 function editReport ( $post , $pid , $id , $form ){
58 $stmt = $this -> prepare ( "UPDATE reports SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;" );
59 $stmt -> bindValue ( ":pid" , $pid );
60 $stmt -> bindValue ( ":id" , $id );
61 $stmt -> bindValue ( ":time" , strtotime ( $post [ "date" ]. $post [ "time" ]));
62 $stmt -> bindValue ( ":data" , json_encode ( $post ));
65 function addDrug ( $pid , $name , $dose , $route , $frequency , $date , $time , $duration , $addl ){
66 $stmt = $this -> prepare ( "INSERT INTO treatment (pid, name, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :name, :dose, :route, :frequency, :start, :duration, :omit, :addl);" );
67 $stmt -> bindValue ( ":pid" , $pid );
68 $stmt -> bindValue ( ":name" , $name );
69 $stmt -> bindValue ( ":dose" , $dose );
70 $stmt -> bindValue ( ":route" , $route );
71 $stmt -> bindValue ( ":frequency" , $frequency );
72 $stmt -> bindValue ( ":start" , strtotime ( $date . " " . $time ));
73 $stmt -> bindValue ( ":duration" , $duration );
74 $stmt -> bindValue ( ":addl" , $addl );
75 $stmt -> bindValue ( ":omit" , false );
78 function omitDrug ( $id ){
79 $stmt = $this -> prepare ( "UPDATE treatment SET omit=:omit WHERE rowid=:id;" );
80 $stmt -> bindValue ( ":omit" , true );
81 $stmt -> bindValue ( ":id" , $id );
84 function addAdvice ( $pid , $name , $dose , $route , $frequency , $duration , $addl ){
85 $stmt = $this -> prepare ( "INSERT INTO discharge (pid, name, dose, route, frequency, duration, addl) VALUES (:pid, :name, :dose, :route, :frequency, :duration, :addl);" );
86 $stmt -> bindValue ( ":pid" , $pid );
87 $stmt -> bindValue ( ":name" , $name );
88 $stmt -> bindValue ( ":dose" , $dose );
89 $stmt -> bindValue ( ":route" , $route );
90 $stmt -> bindValue ( ":frequency" , $frequency );
91 $stmt -> bindValue ( ":duration" , $duration );
92 $stmt -> bindValue ( ":addl" , $addl );
95 function deleteAdvice ( $id ){
96 $stmt = $this -> prepare ( "DELETE FROM discharge WHERE rowid=:id;" );
97 $stmt -> bindValue ( ":id" , $id );
100 function setDischarged ( $pid ){
101 $stmt = $this -> prepare ( "UPDATE patients SET status=:discharged WHERE pid=:pid;" );
102 $stmt -> bindValue ( ":pid" , $pid );
105 function setDead ( $pid , $post ){
106 $stmt = $this -> prepare ( "INSERT INTO death (pid, time, data) VALUES (:pid, :time, :data);" );
107 $stmt -> bindValue ( ":pid" , $pid );
108 $stmt -> bindValue ( ":time" , strtotime ( $post [ "date" ]. $post [ "time" ]));
109 $stmt -> bindValue ( ":data" , json_encode ( $post ));
111 $stmt = $this -> prepare ( "UPDATE patients SET status='expired' WHERE pid=:pid;" );
112 $stmt -> bindValue ( ":pid" , $pid );
115 function getDrugs ( $pid ){
116 $stmt = $this -> prepare ( "SELECT rowid,* FROM treatment WHERE pid=:pid;" );
117 $stmt -> bindValue ( ":pid" , $pid );
118 $result = $stmt -> execute ();
121 function getAdvice ( $pid ){
122 $stmt = $this -> prepare ( "SELECT rowid,* FROM discharge WHERE pid=:pid;" );
123 $stmt -> bindValue ( ":pid" , $pid );
124 $result = $stmt -> execute ();
127 function getName ( $pid ){
128 $stmt = $this -> prepare ( "SELECT name FROM patients WHERE pid=:pid;" );
129 $stmt -> bindValue ( ":pid" , $pid );
130 $result = $stmt -> execute ();
133 function getAge ( $pid ){
134 $stmt = $this -> prepare ( "SELECT age FROM patients WHERE pid=:pid;" );
135 $stmt -> bindValue ( ":pid" , $pid );
136 $result = $stmt -> execute ();
139 function getSex ( $pid ){
140 $stmt = $this -> prepare ( "SELECT sex FROM patients WHERE pid=:pid;" );
141 $stmt -> bindValue ( ":pid" , $pid );
142 $result = $stmt -> execute ();
145 function getWard ( $pid ){
146 $stmt = $this -> prepare ( "SELECT ward FROM patients WHERE pid=:pid;" );
147 $stmt -> bindValue ( ":pid" , $pid );
148 $result = $stmt -> execute ();
151 function getBed ( $pid ){
152 $stmt = $this -> prepare ( "SELECT bed FROM patients WHERE pid=:pid;" );
153 $stmt -> bindValue ( ":pid" , $pid );
154 $result = $stmt -> execute ();
157 function getStatus ( $pid ){
158 $stmt = $this -> prepare ( "SELECT status FROM patients WHERE pid=:pid;" );
159 $stmt -> bindValue ( ":pid" , $pid );
160 $result = $stmt -> execute ();
163 function getDiagnosis ( $pid ){
164 $stmt = $this -> prepare ( "SELECT diagnosis FROM patients WHERE pid=:pid;" );
165 $stmt -> bindValue ( ":pid" , $pid );
166 $result = $stmt -> execute ();
170 $stmt = $this -> prepare ( "SELECT pid FROM patients;" );
171 $result = $stmt -> execute ();
174 function getForm ( $id ){
175 $stmt = $this -> prepare ( "SELECT form FROM reports WHERE rowid=:id;" );
176 $stmt -> bindValue ( ":id" , $id );
177 $result = $stmt -> execute ();
180 function getAdmission ( $pid ){
181 $stmt = $this -> prepare ( "SELECT data FROM patients WHERE pid=:pid;" );
182 $stmt -> bindValue ( ":pid" , $pid );
183 $result = $stmt -> execute ();
186 function getHistory ( $pid ){
187 $stmt = $this -> prepare ( "SELECT history FROM patients WHERE pid=:pid;" );
188 $stmt -> bindValue ( ":pid" , $pid );
189 $result = $stmt -> execute ();
192 function getData ( $pid , $id , $cat ){
193 if ( $cat == "clinical" ){
194 $stmt = $this -> prepare ( "SELECT data FROM clinical WHERE pid=:pid AND rowid=:id;" );
195 } elseif ( $cat == "reports" ){
196 $stmt = $this -> prepare ( "SELECT data FROM reports WHERE pid=:pid AND rowid=:id;" );
200 $stmt -> bindValue ( ":pid" , $pid );
201 $stmt -> bindValue ( ":id" , $id );
202 $result = $stmt -> execute ();
205 function getAllData ( $pid , $cat ){
206 if ( $cat == "clinical" ){
207 $stmt = $this -> prepare ( "SELECT rowid,data FROM clinical WHERE pid=:pid;" );
208 } elseif ( $cat == "reports" ){
209 $stmt = $this -> prepare ( "SELECT rowid,data FROM reports WHERE pid=:pid;" );
210 } elseif ( $cat == "info" ){
211 $stmt = $this -> prepare ( "SELECT rowid,data FROM patients WHERE pid=:pid;" );
212 } elseif ( $cat == "history" ){
213 $stmt = $this -> prepare ( "SELECT rowid,history FROM patients WHERE pid=:pid;" );
217 $stmt -> bindValue ( ":pid" , $pid );
218 $result = $stmt -> execute ();