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
<?php function assignDoctors(){
if(isset($_POST) && !empty($_POST)){
$insert_array = array();
$not_available_day = array();
$flag = 0;
$request = $_POST;
$this->Clinic_model->update_duration($request['doctors'],$request['duration']);
if(!empty($request['day'])){
$result = $this->Clinic_model->checkDoctorExist($request['doctors'],$request['clinicId']);
//echo "<pre>"; print_r($result); echo "</pre>";
//print_r($result);exit();
if(!empty($result)){
foreach ($result as $key => $value) {
foreach ($request['doctors'] as $key_docId => $value_docId) {
if($value['doctor_id'] == $value_docId){
$insert_array_exist = array();
foreach ($request['day'] as $key_day => $value_day) {
if(isset($value['date'])){
$decode_time = json_decode($value['date'],true);
$startTime = $value_day.'_startTime';
$endTime = $value_day.'_endTime';
//$interval = $value_day.'_intervalTime';
$breakfrom = $value_day.'_Breakfrom';
$breakto = $value_day.'_Breakto';
if($request[$breakfrom] != ''){
$break_from = $request[$breakfrom];
}
else{
$break_from = '';
}
if($request[$breakto] != ''){
$break_to = $request[$breakto];
}
else{
$break_to = '';
}
if(!empty($decode_time)){
foreach ($decode_time as $k => $v) {
if($value_day == $v['day']){
if((strtotime($this->string->default_date.$v['time']['start']) <= strtotime($this->string->default_date.$request[$startTime ]) && strtotime($this->string->default_date.$request[$startTime ]) <= strtotime($this->string->default_date.$v['time']['end'])) || (strtotime($this->string->default_date.$v['time']['start']) <= strtotime($this->string->default_date.$request[$endTime]) && strtotime($this->string->default_date.$request[$endTime ]) <= strtotime($this->string->default_date.$v['time']['end'])) || (strtotime($this->string->default_date.$request[$startTime ]) <= strtotime($this->string->default_date.$v['time']['start']) && strtotime($this->string->default_date.$v['time']['start']) <=strtotime($this->string->default_date.$request[$endTime])) || (strtotime($this->string->default_date.$request[$startTime ]) <= strtotime($this->string->default_date.$v['time']['end']) && strtotime($this->string->default_date.$v['time']['end']) <= strtotime($this->string->default_date.$request[$endTime]))){
array_push($not_available_day , array('day'=>$value_day,'id'=>$value_docId));
$flag = 1;
}
else{
$res = array('day'=>$value_day,
'time'=>array('start'=>$request[$startTime ],
'end'=>$request[$endTime],
'interval'=>$request['duration']),
'break_from'=>$break_from,
'break_to'=>$break_to
);
array_push($insert_array_exist,$res);
}
}
else if(!in_array($value_day, $v)){
$res = array('day'=>$value_day,
'time'=>array('start'=>$request[$startTime ],
'end'=>$request[$endTime],
'interval'=>$request['duration'],
'break_from'=>$break_from,
'break_to'=>$break_to));
array_push($insert_array_exist,$res);
}
}
}
}
}
}
}
}
if($flag ==0 && !empty($insert_array_exist))
{
$this->Clinic_model->assignDoctors($request['doctors'],$request['clinicId']);
$this->Clinic_model->set_new_consultation($insert_array_exist,$request['clinicId'],$request['doctors']);
$this->session->set_flashdata('message', array('message' => 'Successfully assigned', 'title' => 'Success !', 'class' => 'success'));
redirect(base_url()."ManageClinic/view");
}
else
{
$this->session->set_flashdata('message', array('message' => 'Selected Doctors are not available at this time schedule', 'title' => 'Error !', 'class' => 'danger'));
redirect(base_url()."ManageClinic/addDoctor?id=".$request['clinicId']);
}
}
else{
foreach ($request['day'] as $key_elseDay => $value_elseDay) {
$start = $value_elseDay.'_startTime';
$end = $value_elseDay.'_endTime';
//$interval = $value_elseDay.'_intervalTime';
$breakfrom = $value_elseDay.'_Breakfrom';
$breakto = $value_elseDay.'_Breakto';
if($request[$breakfrom] != ''){
$break_from = $request[$breakfrom];
}
else{
$break_from = '';
}
if($request[$breakto] != ''){
$break_to = $request[$breakto];
}
else{
$break_to = '';
}
$res = array('day'=>$value_elseDay,
'time'=>array('start'=>$request[$start],
'end'=>$request[$end],
'interval'=>$request['duration'],
'break_from'=>$break_from,
'break_to'=>$$break_to));
array_push($insert_array, $res);
}
$this->Clinic_model->assignDoctors($request['doctors'],$request['clinicId']);
$this->Clinic_model->set_new_consultation($insert_array,$request['clinicId'],$request['doctors']);
$this->session->set_flashdata('message', array('message' => 'Successfully assigned', 'title' => 'Success !', 'class' => 'success'));
if($this->session->userdata('logged_in')['uType'] != 'clinic'){
redirect(base_url()."ManageClinic/view");
}
else{
redirect(base_url()."ManageDoctors/view");
}
}
}
else{
$this->Clinic_model->assignDoctors($request['doctors'],$request['clinicId']);
$this->Clinic_model->set_new_consultation('',$request['clinicId'],$request['doctors']);
$this->session->set_flashdata('message', array('message' => 'Successfully assigned', 'title' => 'Success !', 'class' => 'success'));
if($this->session->userdata('logged_in')['uType'] != 'clinic'){
redirect(base_url()."ManageClinic/view");
}
else
{
redirect(base_url()."ManageDoctors/view");
}
}
}
else{
redirect(base_url()."error");
}
}
?>