|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Room; |
|
6
|
|
|
use Illuminate\Support\Facades\DB; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use App\Hospital; |
|
9
|
|
|
use App\City; |
|
10
|
|
|
|
|
11
|
|
|
class HospitalController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Display a listing of the resource. |
|
15
|
|
|
* |
|
16
|
|
|
* @return \Illuminate\Http\Response |
|
17
|
|
|
*/ |
|
18
|
|
|
public function index() |
|
19
|
|
|
{ |
|
20
|
|
|
$hospital = Hospital::orderBy('city_id','asc')->paginate(10); |
|
21
|
|
|
$data = [ |
|
22
|
|
|
'role' => session('role'), |
|
23
|
|
|
'hospital' => $hospital |
|
24
|
|
|
]; |
|
25
|
|
|
return view('pages.hospital')->with('data',$data); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Show the form for creating a new resource. |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Illuminate\Http\Response |
|
32
|
|
|
*/ |
|
33
|
|
|
public function create() |
|
34
|
|
|
{ |
|
35
|
|
|
$city_id = City::pluck('name', 'id'); |
|
36
|
|
|
return view('pages.ext.add-hospital')->with('city_id', $city_id); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Store a newly created resource in storage. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Request $request |
|
43
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
|
44
|
|
|
* @throws \Illuminate\Validation\ValidationException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function store(Request $request) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->validate($request, [ |
|
49
|
|
|
'name'=>'required|min:3', |
|
50
|
|
|
'city_id'=>'required', |
|
51
|
|
|
'biography'=>'required', |
|
52
|
|
|
'address'=>'required|min:3', |
|
53
|
|
|
'medical_services'=>'required', |
|
54
|
|
|
'public_services'=>'required', |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$hospital = new Hospital; |
|
58
|
|
|
$hospital->name = $request->input('name'); |
|
59
|
|
|
$hospital->city_id = $request->input('city_id'); |
|
60
|
|
|
$hospital->biography = $request->input('biography'); |
|
61
|
|
|
$hospital->address = $request->input('address'); |
|
62
|
|
|
$hospital->medical_services = $request->input('medical_services'); |
|
63
|
|
|
$hospital->public_services = $request->input('public_services'); |
|
64
|
|
|
$hospital->cover_images_id = 1; |
|
65
|
|
|
|
|
66
|
|
|
if($hospital->save()) { |
|
67
|
|
|
return redirect (route('hospital.index'))->with('success', 'Rumah sakit berhasil di tambahkan !'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return redirect (route('hospital.index'))->with('failed', 'Gagal menambahkan rumah sakit !'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Display the specified resource. |
|
75
|
|
|
* |
|
76
|
|
|
* @param int $id |
|
77
|
|
|
* @return \Illuminate\Http\Response |
|
78
|
|
|
*/ |
|
79
|
|
|
public function show($id) |
|
80
|
|
|
{ |
|
81
|
|
|
$hospital = Hospital::find($id); |
|
82
|
|
|
if(!$hospital) { |
|
83
|
|
|
abort(401); |
|
84
|
|
|
} |
|
85
|
|
|
$data = [ |
|
86
|
|
|
'hospital' => $hospital, |
|
87
|
|
|
'rooms' => $this->getRooms($id), |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
return view('pages.ext.view-hospital')->with('data', $data); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Show the form for editing the specified resource. |
|
95
|
|
|
* |
|
96
|
|
|
* @param int $id |
|
97
|
|
|
* @return \Illuminate\Http\Response |
|
98
|
|
|
*/ |
|
99
|
|
|
public function edit($id) |
|
100
|
|
|
{ |
|
101
|
|
|
$hospital = Hospital::find($id); |
|
102
|
|
|
$city_id = City::pluck('name', 'id'); |
|
103
|
|
|
$data = [ |
|
104
|
|
|
'role' => session('role'), |
|
105
|
|
|
'hospital' => $hospital, |
|
106
|
|
|
'city_id' => $city_id |
|
107
|
|
|
]; |
|
108
|
|
|
return view('pages.ext.edit-hospital')->with('data', $data); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Update the specified resource in storage. |
|
113
|
|
|
* |
|
114
|
|
|
* @param Request $request |
|
115
|
|
|
* @param $id |
|
116
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
|
117
|
|
|
* @throws \Illuminate\Validation\ValidationException |
|
118
|
|
|
*/ |
|
119
|
|
|
public function update(Request $request, $id) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->validate($request, [ |
|
122
|
|
|
'name'=>'required|min:3', |
|
123
|
|
|
'city_id'=>'required', |
|
124
|
|
|
'biography'=>'required', |
|
125
|
|
|
'address'=>'required|min:3', |
|
126
|
|
|
'medical_services'=>'required', |
|
127
|
|
|
'public_services'=>'required', |
|
128
|
|
|
]); |
|
129
|
|
|
|
|
130
|
|
|
$hospital = Hospital::find($id); |
|
131
|
|
|
$hospital->name = $request->input('name'); |
|
132
|
|
|
$hospital->city_id = $request->input('city_id'); |
|
133
|
|
|
$hospital->biography = $request->input('biography'); |
|
134
|
|
|
$hospital->address = $request->input('address'); |
|
135
|
|
|
$hospital->medical_services = $request->input('medical_services'); |
|
136
|
|
|
$hospital->public_services = $request->input('public_services'); |
|
137
|
|
|
$hospital->cover_images_id = 1; |
|
138
|
|
|
|
|
139
|
|
|
if($hospital->save()) { |
|
140
|
|
|
return redirect (route('hospital.index'))->with('success', 'Rumah sakit berhasil di perbaharui'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return redirect (route('hospital.edit', $id))->with('failed', 'Gagal memperbaharui rumah sakit !'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Remove the specified resource from storage. |
|
148
|
|
|
* |
|
149
|
|
|
* @param int $id |
|
150
|
|
|
* @return \Illuminate\Http\Response |
|
151
|
|
|
*/ |
|
152
|
|
|
public function destroy($id) |
|
153
|
|
|
{ |
|
154
|
|
|
$hospital = Hospital::find($id); |
|
155
|
|
|
$rooms = $this->deleteRoomsAndRoomDetail($id); |
|
156
|
|
|
|
|
157
|
|
|
if($hospital->delete() && $rooms) { |
|
158
|
|
|
return redirect(route('hospital.index')); |
|
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param $hospital_id |
|
165
|
|
|
* @return bool |
|
166
|
|
|
*/ |
|
167
|
|
|
private function deleteRoomsAndRoomDetail($hospital_id) |
|
168
|
|
|
{ |
|
169
|
|
|
$rooms = $this->getRooms($hospital_id); |
|
170
|
|
|
$ids = $rooms->pluck('id')->toArray(); |
|
171
|
|
|
|
|
172
|
|
|
$delroom = Room::whereIn('id', $ids)->delete(); |
|
173
|
|
|
$deldetail = DB::table('room_details') |
|
174
|
|
|
->where('hospital_id', '=', $hospital_id) |
|
175
|
|
|
->delete(); |
|
176
|
|
|
|
|
177
|
|
|
if($delroom && $deldetail) { |
|
178
|
|
|
return true; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return false; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param $hospital_id |
|
186
|
|
|
* @return \Illuminate\Support\Collection |
|
187
|
|
|
*/ |
|
188
|
|
|
private function getRooms($hospital_id) |
|
189
|
|
|
{ |
|
190
|
|
|
$rooms = DB::table('rooms') |
|
191
|
|
|
->selectRaw(DB::raw('rooms.*')) |
|
192
|
|
|
->leftJoin('room_details', 'rooms.id', '=', 'room_details.room_id') |
|
193
|
|
|
->where('room_details.hospital_id','=',$hospital_id) |
|
194
|
|
|
->get(); |
|
195
|
|
|
|
|
196
|
|
|
return $rooms; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function indexUser() |
|
200
|
|
|
{ |
|
201
|
|
|
$location = City::orderBy('name','asc')->pluck('name', 'id'); |
|
202
|
|
|
$img = 'storage/images/hospital-icon.jpg'; |
|
203
|
|
|
$data = [ |
|
204
|
|
|
'img' => $img, |
|
205
|
|
|
'location' => $location |
|
206
|
|
|
]; |
|
207
|
|
|
return view ('SearchRS')->with('data',$data); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function showList() |
|
211
|
|
|
{ |
|
212
|
|
|
return view('LSRumahSakit'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public function searchHospital(Request $request) |
|
216
|
|
|
{ |
|
217
|
|
|
if($request->nama == null AND $request->location != null){ |
|
218
|
|
|
$hospital = Hospital::where('city_id',$request->location)->orderBy('name','asc')->paginate(5); |
|
219
|
|
|
}elseif ($request->location == null AND $request->nama != null){ |
|
220
|
|
|
$hospital = Hospital::where('biography','LIKE','%'.$request->nama.'%')->orderBy('name','asc')->paginate(5); |
|
221
|
|
|
}else{ |
|
222
|
|
|
$hospital = Hospital::where('biography','LIKE','%'.$request->nama.'%')->where('city_id',$request->location)->orderBy('name','asc')->paginate(5); |
|
223
|
|
|
} |
|
224
|
|
|
$location = City::orderBy('name','asc')->pluck('name','id'); |
|
225
|
|
|
$data = [ |
|
226
|
|
|
'hospital' => $hospital, |
|
227
|
|
|
'location' => $location |
|
228
|
|
|
]; |
|
229
|
|
|
return view ('listHospital')->with('data',$data); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
public function searchContent($content) |
|
233
|
|
|
{ |
|
234
|
|
|
$hospital = Hospital::where('biography','LIKE','%'.$content.'%')->orderBy('name','asc')->paginate(5); |
|
235
|
|
|
$location = City::orderBy('name','asc')->pluck('name','id'); |
|
236
|
|
|
$data = [ |
|
237
|
|
|
'hospital' => $hospital, |
|
238
|
|
|
'location' => $location |
|
239
|
|
|
]; |
|
240
|
|
|
return view ('listHospital')->with('data',$data); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function viewHospital($id) |
|
244
|
|
|
{ |
|
245
|
|
|
$hospital = Hospital::find($id); |
|
246
|
|
|
$data = [ |
|
247
|
|
|
'hospital' => $hospital, |
|
248
|
|
|
'room' => $this->getRooms($id), |
|
249
|
|
|
]; |
|
250
|
|
|
return view ('viewhospital')->with('data',$data); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|