-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.php
More file actions
273 lines (225 loc) · 5.91 KB
/
Copy pathconfig.php
File metadata and controls
273 lines (225 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
date_default_timezone_set("Asia/Bangkok");
class ConfigDB
{
function connectDBMaster($dbName)
{
try {
$con = new PDO(
"mysql:host=IPHOSXP;dbname=hos",
"u", //username
"p", //password
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
return $con;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
function connectDBSlave($dbName)
{
try {
$con = new PDO(
"mysql:host=IPQ4U;dbname=queue",
"u", //username
"p", //password
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
return $con;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
class Query extends ConfigDB
{
function selectDBSlave($sql, $dbName)
{
try {
$pdo = $this->connectDBSlave($dbName);
$stmt = $pdo->query($sql);
//$sql = mysql_query($sql);
$data = array();
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$data[] = $row;
}
/*while ($row = mysql_fetch_object($sql)) {
$data[] = $row;
}*/
return $data;
} catch (PDOException $e) {
return false;
}
}
function selectDBMaster($sql, $dbName)
{
try {
$pdo = $this->connectDBMaster($dbName);
$stmt = $pdo->query($sql);
//$sql = mysql_query($sql);
$data = array();
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$data[] = $row;
}
/*while ($row = mysql_fetch_object($sql)) {
$data[] = $row;
}*/
return $data;
} catch (PDOException $e) {
return false;
}
}
function queryDbMaster()
{
}
function queryDbSlave($sql, $dbName)
{
try {
$pdo = $this->connectDBSlave($dbName);
$stmt = $pdo->exec($sql);
return true;
} catch (PDOException $e) {
return false;
}
}
}
class getData extends Query
{
function getQueueHosXp($type)
{
$date = date('Y-m-d');
$sql = "SELECT " . $type . " from ovst o WHERE o.vstdate ='$date' and o.main_dep in (001,002,058,010,043,061,062,055) ORDER BY o.vsttime";
$row = $this->selectDBMaster($sql, 'hos');
return $row;
}
function getOvstHosXp()
{
$date = date('Y-m-d');
$vn = $this->getVnQ4u();
$sql = "SELECT vn,hn,vstdate,main_dep,cur_dep from ovst where vstdate='$date' and vn not in ($vn)";
$row = $this->selectDBMaster($sql, 'hos');
return $row;
}
function getQueueQ4u()
{
$date = date('Y-m-d');
$sql = "SELECT vn from q4u_queue q WHERE q.date_serv ='$date'";
$row = $this->selectDBSlave($sql, 'queue');
return $row;
}
function getVnQ4u()
{
$row = $this->getQueueQ4u();
$notinVN = "";
for ($i = 0; $i < count($row); $i++) {
if ($i == count($row) - 1) {
$notinVN .= "'" . $row[$i]->vn . "'";
} else {
$notinVN .= "'" . $row[$i]->vn . "',";
}
}
if ($notinVN == '') {
$notinVN = 0;
} else {
$notinVN = $notinVN;
}
return $notinVN;
}
function getQ4uServicePoint($code)
{
$sql = "SELECT service_point_id from q4u_service_points WHERE local_code ='$code'";
$row = $this->selectDBSlave($sql, 'queue');
return $row[0]->service_point_id;
}
function getQ4uPerson()
{
$sql = "SELECT q.hn from q4u_person q ";
$row = $this->selectDBSlave($sql, 'queue');
return $row;
}
function getQ4uPersonCount($hn)
{
$sql = "SELECT count(q.hn) as cc from q4u_person q WHERE q.hn='$hn'";
$row = $this->selectDBSlave($sql, 'queue');
return $row[0]->cc;
}
function intersecHosXpQ4u()
{
$getQueueHosXp = $this->getQueueHosXp('vn');
$getQueueQ4u = $this->getQueueQ4u();
$intersec = array_diff($this->convertObjectToArrayHN($getQueueHosXp, 'vn'), $this->convertObjectToArrayHN($getQueueQ4u, 'vn'));
return $intersec;
}
function intersecHosXpQ4uPerson()
{
$getQueueHosXp = $this->getQueueHosXp('hn');
$getQ4uPerson = $this->getQ4uPerson();
$intersec = array_diff($this->convertObjectToArrayHN($getQueueHosXp, 'hn'), $this->convertObjectToArrayHN($getQ4uPerson, 'hn'));
return $intersec;
}
function convertObjectToArrayHN($object, $type)
{
$data = array();
for ($i = 0; $i < count($object); $i++) {
$data[$i] = $object[$i]->$type;
}
return $data;
}
function prepareDataQ4u($vn)
{
$sql = "SELECT o.hn,o.vn,k.opd_qs_room_id as service_point_id,o.pt_priority+1 as priority_id,o.vstdate as date_serv,o.vsttime as time_serv,
concat(k.display_text,o.oqueue) as queue_number,k.depcode
from ovst o
INNER JOIN kskdepartment k on o.main_dep = k.depcode
WHERE o.vn ='$vn'";
/*$sql = "SELECT o.hn,o.vn,k.opd_qs_room_id as service_point_id,o.pt_priority+1 as priority_id,o.vstdate as date_serv,o.vsttime as time_serv,
o.oqueue as queue_number,k.depcode
from ovst o
INNER JOIN kskdepartment k on o.main_dep = k.depcode
WHERE o.vn ='$vn'";*/
$row = $this->selectDBMaster($sql, 'hos');
return $row;
}
function prepareDataPersonQ4u($hn)
{
$sql = "SELECT hn,pname as title,fname as first_name,lname as last_name,birthday as birthdate,sex from patient WHERE hn='$hn'";
$row = $this->selectDBMaster($sql, 'hos');
return $row;
}
function getQueueInterView()
{
$date = date('Y-m-d');
$sql = "SELECT count(q.queue_id)+1 as cc from q4u_queue q WHERE q.date_serv ='$date'";
$row = $this->selectDBSlave($sql, 'queue');
return $row[0]->cc;
}
function checkCurrentHosxPQ($vn)
{
$sql = "SELECT main_dep,cur_dep from ovst WHERE vn= '$vn'";
$row = $this->selectDBMaster($sql, 'hos');
return $row;
}
function getServicePointHosxp($depcode)
{
$sql = "SELECT opd_qs_room_id from kskdepartment WHERE depcode='$depcode'";
$row = $this->selectDBMaster($sql, 'hos');
return $row[0]->opd_qs_room_id;
}
function getServicepoint()
{
$sql = "SELECT * from q4u_service_points";
$row = $this->selectDBSlave($sql, 'queue');
return $row;
}
function clearQueue()
{
$date = date('Y-m-d');
$sql = "DELETE from q4u_queue where date_serv <> '$date'";
$sql2 = "DELETE from q4u_queue_detail where date_serv <> '$date'";
$sql3 = "DELETE from q4u_queue_group_detail where date_serv <> '$date'";
$this->queryDbSlave($sql, 'queue');
$this->queryDbSlave($sql2, 'queue');
$this->queryDbSlave($sql3, 'queue');
}
}
?>