]> Softwares of Agnibho - simpleipd.git/blob - lib/db.php
Frontend polish
[simpleipd.git] / lib / db.php
1 <?php
2 class DB extends SQLite3 {
3 function __construct(){
4 $this->open("data/data.db");
5 }
6 function admit($post){
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);");
12 }
13 else{
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;");
15 }
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));
26 $stmt->execute();
27 }
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);
32 $stmt->execute();
33 }
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));
39 $stmt->execute();
40 }
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));
47 $stmt->execute();
48 }
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));
55 $stmt->execute();
56 }
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));
63 $stmt->execute();
64 }
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);
76 $stmt->execute();
77 }
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);
82 $stmt->execute();
83 }
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);
93 $stmt->execute();
94 }
95 function deleteAdvice($id){
96 $stmt=$this->prepare("DELETE FROM discharge WHERE rowid=:id;");
97 $stmt->bindValue(":id", $id);
98 $stmt->execute();
99 }
100 function setDischarged($pid){
101 $stmt=$this->prepare("UPDATE patients SET status=:discharged WHERE pid=:pid;");
102 $stmt->bindValue(":pid", $pid);
103 $stmt->execute();
104 }
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));
110 $stmt->execute();
111 $stmt=$this->prepare("UPDATE patients SET status='expired' WHERE pid=:pid;");
112 $stmt->bindValue(":pid", $pid);
113 $stmt->execute();
114 }
115 function getDrugs($pid){
116 $stmt=$this->prepare("SELECT rowid,* FROM treatment WHERE pid=:pid;");
117 $stmt->bindValue(":pid", $pid);
118 $result=$stmt->execute();
119 return($result);
120 }
121 function getAdvice($pid){
122 $stmt=$this->prepare("SELECT rowid,* FROM discharge WHERE pid=:pid;");
123 $stmt->bindValue(":pid", $pid);
124 $result=$stmt->execute();
125 return($result);
126 }
127 function getName($pid){
128 $stmt=$this->prepare("SELECT name FROM patients WHERE pid=:pid;");
129 $stmt->bindValue(":pid", $pid);
130 $result=$stmt->execute();
131 return($result);
132 }
133 function getAge($pid){
134 $stmt=$this->prepare("SELECT age FROM patients WHERE pid=:pid;");
135 $stmt->bindValue(":pid", $pid);
136 $result=$stmt->execute();
137 return($result);
138 }
139 function getSex($pid){
140 $stmt=$this->prepare("SELECT sex FROM patients WHERE pid=:pid;");
141 $stmt->bindValue(":pid", $pid);
142 $result=$stmt->execute();
143 return($result);
144 }
145 function getWard($pid){
146 $stmt=$this->prepare("SELECT ward FROM patients WHERE pid=:pid;");
147 $stmt->bindValue(":pid", $pid);
148 $result=$stmt->execute();
149 return($result);
150 }
151 function getBed($pid){
152 $stmt=$this->prepare("SELECT bed FROM patients WHERE pid=:pid;");
153 $stmt->bindValue(":pid", $pid);
154 $result=$stmt->execute();
155 return($result);
156 }
157 function getStatus($pid){
158 $stmt=$this->prepare("SELECT status FROM patients WHERE pid=:pid;");
159 $stmt->bindValue(":pid", $pid);
160 $result=$stmt->execute();
161 return($result);
162 }
163 function getDiagnosis($pid){
164 $stmt=$this->prepare("SELECT diagnosis FROM patients WHERE pid=:pid;");
165 $stmt->bindValue(":pid", $pid);
166 $result=$stmt->execute();
167 return($result);
168 }
169 function getList(){
170 $stmt=$this->prepare("SELECT pid FROM patients;");
171 $result=$stmt->execute();
172 return($result);
173 }
174 function getForm($id){
175 $stmt=$this->prepare("SELECT form FROM reports WHERE rowid=:id;");
176 $stmt->bindValue(":id", $id);
177 $result=$stmt->execute();
178 return($result);
179 }
180 function getAdmission($pid){
181 $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid;");
182 $stmt->bindValue(":pid", $pid);
183 $result=$stmt->execute();
184 return($result);
185 }
186 function getHistory($pid){
187 $stmt=$this->prepare("SELECT history FROM patients WHERE pid=:pid;");
188 $stmt->bindValue(":pid", $pid);
189 $result=$stmt->execute();
190 return($result);
191 }
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;");
197 } else{
198 return(false);
199 }
200 $stmt->bindValue(":pid", $pid);
201 $stmt->bindValue(":id", $id);
202 $result=$stmt->execute();
203 return($result);
204 }
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;");
214 } else{
215 return(false);
216 }
217 $stmt->bindValue(":pid", $pid);
218 $result=$stmt->execute();
219 return($result);
220 }
221 }
222 $db = new DB();
223 ?>