· 5 years ago · Sep 12, 2020, 08:04 AM
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Appointment;
6use Illuminate\Http\Request;
7use App\User;
8use App\Helper;
9use Response;
10use App\Feedback;
11use App\SiteManagement;
12use File;
13use Illuminate\Pagination\Paginator;
14use Carbon\Carbon;
15use App\Team;
16use DB;
17use App\Order;
18use App\OrderMeta;
19use App\Package;
20use App\EmailTemplate;
21use Illuminate\Support\Facades\Mail;
22use App\Mail\GeneralEmailMailable;
23use App\Mail\AdminEmailMailable;
24use App\Mail\DoctorEmailMailable;
25use App\Mail\HospitalEmailMailable;
26use App\Category;
27use App\Forum;
28use App\Article;
29use App\Speciality;
30use Auth;
31use App\Location;
32use App\UserMeta;
33use App\ImprovementOption;
34use App\Message;
35use Session;
36use Hash;
37use Storage;
38use Intervention\Image\Facades\Image;
39
40class RestAPIController extends Controller
41{
42 /**
43 * Get doctor detail data
44 *
45 * @access public
46 *
47 * @return \Illuminate\Http\Response
48 */
49 public function getDoctor()
50 {
51 $json = array();
52 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
53 $auth_id = !empty($_GET['auth_id']) ? $_GET['auth_id'] : '';
54 $user = !empty($profile_id) ? User::find($profile_id) : new User();
55 $role_type = !empty($profile_id) ? Helper::getRoleTypeByUserID($profile_id) : '';
56 $currency = SiteManagement::getMetaValue('payment_settings');
57 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : 'symbol';
58 $user_detail = array();
59 if (!empty($user) && !empty($profile_id)) {
60 $auth_user = !empty($auth_id) ? User::find($auth_id) : '';
61 $saved_doctors = !empty($auth_user) && !empty($auth_user->profile->saved_doctors) ? unserialize($auth_user->profile->saved_doctors) : array();
62 $avg_rating = Feedback::where('user_id', $user->id)->pluck('avg_rating')->first();
63 $specialities = !empty($user->profile->services) ? Helper::getUnserializeData($user->profile->services) : array();
64 $experiences = !empty($user->profile->experiences) ? Helper::getUnserializeData($user->profile->experiences) : array();
65 $educations = !empty($user->profile->educations) ? Helper::getUnserializeData($user->profile->educations) : array();
66 $awards = !empty($user->profile->awards) ? Helper::getUnserializeData($user->profile->awards) : array();
67 $memberships = !empty($user->profile->memberships) ? Helper::getUnserializeData($user->profile->memberships) : array();
68 $registration_details = !empty($user->profile->verify_medical) ? Helper::getUnserializeData($user->profile->verify_medical) : array();
69 $downloads = !empty($user->profile->downloads) ? Helper::getUnserializeData($user->profile->downloads) : array();
70 $gender_title = !empty($user->profile->gender_title) ? $user->profile->gender_title : '';
71 if (!empty($specialities)) {
72 foreach ($specialities as $speciality_key => $user_speciality) {
73 $speciality = Helper::getSpecialityByID($user_speciality['speciality_id']);
74 if (!empty($speciality)) {
75 $user_detail['specialires_data'][$speciality_key]['name'] = $speciality->title;
76 $user_detail['specialires_data'][$speciality_key]['logo'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
77 }
78 if (!empty($user_speciality['services'])) {
79 foreach ($user_speciality['services'] as $spe_ser_key => $speciality_service) {
80 $service = Helper::getServiceByID($speciality_service['service']);
81 if (!empty($service)) {
82 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['title'] = $service->title;
83 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['price'] = !empty($speciality_service['price']) ? (!empty($symbol['symbol']) ? $symbol['symbol'] : '$') . $speciality_service['price'] : '';
84 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['description'] = !empty($speciality_service['description']) ? $speciality_service['description'] : '';
85 }
86 }
87 }
88 }
89 } else {
90 $user_detail['specialires_data'] = '';
91 }
92 if (!empty($experiences)) {
93 foreach ($experiences as $experience_key => $user_experience) {
94 $user_detail['experiences'][$experience_key]['company_name'] = $user_experience['company_title'];
95 $user_detail['experiences'][$experience_key]['job_title'] = $user_experience['start_date'];
96 $user_detail['experiences'][$experience_key]['start'] = $user_experience['end_date'];
97 $user_detail['experiences'][$experience_key]['ending'] = $user_experience['job_title'];
98 $user_detail['experiences'][$experience_key]['description'] = $user_experience['job_desc'];
99 }
100 } else {
101 $user_detail['experiences'] = [];
102 }
103 if (!empty($educations)) {
104 foreach ($educations as $education_key => $education) {
105 $user_detail['educations'][$education_key]['degree_title'] = $education['degree_title'];
106 $user_detail['educations'][$education_key]['institute_name'] = $education['job_title'];
107 $user_detail['educations'][$education_key]['start'] = $education['start_date'];
108 $user_detail['educations'][$education_key]['ending'] = $education['end_date'];
109 $user_detail['educations'][$education_key]['edu_desc'] = $education['job_desc'];
110 }
111 } else {
112 $user_detail['educations'] = [];
113 }
114 if (!empty($awards)) {
115 $award_count = 0;
116 foreach ($awards as $award_key => $award) {
117 $user_detail['awards'][$award_count]['title'] = $award['title'];
118 $user_detail['awards'][$award_count]['year'] = $award['year'];
119 $award_count++;
120 }
121 } else {
122 $user_detail['awards'] = [];
123 }
124 if (!empty($memberships)) {
125 $membership_count = 0;
126 foreach ($memberships as $membership_key => $membership) {
127 $user_detail['memberships'][$membership_count]['title'] = $membership['title'];
128 $membership_count++;
129 }
130 } else {
131 $user_detail['memberships'] = [];
132 }
133 $user_detail['registration_number'] = !empty($registration_details['registration_number']) ? $registration_details['registration_number'] : '';
134 $user_detail['defult_download'] = asset('/images/icon-imgs/img-01.png');
135 if (!empty($downloads)) {
136 foreach ($downloads as $download_key => $download) {
137 $download_name = Helper::formateFileName($download);
138 if (file_exists(public_path('uploads/users/' . $user->id . '/' . $download))) {
139 $download_size = Helper::bytesToHuman(File::size(public_path('uploads/users/' . $user->id . '/' . $download)));
140 } else {
141 $download_size = 0;
142 }
143 $user_detail['downloads'][$download_key]['name'] = $download_name;
144 $user_detail['downloads'][$download_key]['size'] = $download_size;
145 $user_detail['downloads'][$download_key]['url'] = public_path('uploads/users/' . $user->id . '/' . $download);
146 }
147 } else {
148 $user_detail['downloads'] = [];
149 }
150 $user_detail['ID'] = $user->id;
151 $user_detail['contents'] = $user->profile->short_desc;
152 $user_detail['average_rating'] = $avg_rating;
153 $user_detail['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
154 $user_detail['percentage'] = '';
155 $user_detail['medilcal_verified'] = $user->profile->verify_registration == 1 ? 'yes' : 'no';
156 $user_detail['is_verified'] = $user->user_verified == 1 ? 'yes' : 'no';
157 $user_detail['name'] = Helper::getUserName($user->id);
158 $user_detail['sub_heading'] = $user->profile->sub_heading;
159 if (!empty($specialities)) {
160 foreach ($specialities as $sep_speciality_key => $user_speciality) {
161 $speciality = Helper::getSpecialityByID($user_speciality['speciality_id']);
162 if (!empty($speciality)) {
163 $user_detail['specialities'][$sep_speciality_key]['id'] = !empty($speciality->id) ? $speciality->id : '';
164 $user_detail['specialities'][$sep_speciality_key]['name'] = !empty($speciality->title) ? $speciality->title : '';
165 $user_detail['specialities'][$sep_speciality_key]['slug'] = !empty($speciality->slug) ? $speciality->slug : '';
166 }
167 }
168 } else {
169 $user_detail['specialities'] = [];
170 }
171 $user_detail['image'] = asset(Helper::getImage('uploads/users/' . $user->id, $user->profile->avatar, '', 'user.jpg'));
172 $user_detail['featured'] = '';
173 $user_detail['wishlist'] = !empty($saved_doctors) && in_array($user->id, $saved_doctors) ? 'yes' : 'no';
174 $user_detail['role'] = $role_type;
175 return Response::json($user_detail, 200);
176 } else {
177 $json['type'] = 'error';
178 $json['message'] = trans('lang.no_record');
179 return Response::json($json, 203);
180 }
181 }
182
183 /**
184 * Get doctor detail data
185 *
186 * @access public
187 *
188 * @return \Illuminate\Http\Response
189 */
190 public function getGallery()
191 {
192 $json = array();
193 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
194 $user = !empty($profile_id) ? User::find($profile_id) : new User();
195 $user_detail = array();
196 if (!empty($user) && !empty($profile_id)) {
197 $gallery_images = !empty($user->profile->gallery) ? Helper::getUnserializeData($user->profile->gallery) : array();
198 foreach ($gallery_images as $key => $image) {
199 $user_detail['gallery_images'][$key]['image'] = asset(Helper::getImage('uploads/users/' . $user->id . '/gallery/images/', $image, 'small-', ''));
200 }
201 // $user_detail['gallery_images'] = !empty($user->profile->gallery) ? Helper::getUnserializeData($user->profile->gallery) : array();
202 $user_detail['gallery_videos'] = !empty($user->profile->gallery_videos) ? Helper::getUnserializeData($user->profile->gallery_videos) : array();
203 return Response::json($user_detail, 200);
204 } else {
205 $json['type'] = 'error';
206 $json['message'] = trans('lang.no_record');
207 return Response::json($json, 203);
208 }
209 }
210
211 /**
212 * Get search results
213 *
214 * @access public
215 *
216 * @return \Illuminate\Http\Response
217 */
218 public function getUsers()
219 {
220 $json = array();
221 $type = !empty($_GET['listing_type']) ? $_GET['listing_type'] : '';
222 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
223 $login_user = !empty($profile_id) ? User::find($profile_id) : '';
224 $keyword = !empty($_GET['keyword']) ? $_GET['keyword'] : '';
225 $search_locations = !empty($_GET['location']) ? $_GET['location'] : '';
226 $search_speciality = !empty($_GET['specialities']) ? $_GET['specialities'] : '';
227 $search_service = !empty($_GET['services']) ? $_GET['services'] : '';
228 $searchby = !empty($_GET['searchby']) ? $_GET['searchby'] : '';
229 $order_by = !empty($_GET['orderby']) ? $_GET['orderby'] : '';
230 $order = !empty($_GET['order']) ? $_GET['order'] : '';
231 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
232 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
233 $auth_id = !empty($_GET['auth_id']) ? $_GET['auth_id'] : '';
234 $day_list = Helper::getAppointmentDays();
235 Paginator::currentPageResolver(
236 function () use ($page_number) {
237 return $page_number;
238 }
239 );
240 $user_detail = array();
241 if (!empty($type)) {
242 $auth_user = !empty($auth_id) ? User::find($auth_id) : '';
243 if ($type == 'search') {
244 $json = array();
245 $user_id = array();
246 $filters = array();
247 $user_by_role = !empty($searchby) && $searchby != 'both' ? Helper::getUsersByRoleType($searchby) : Helper::getSearchableUsers();
248 $users = DB::table('users')->whereIn('id', $user_by_role);
249 $filters['type'] = $type;
250 if (!empty($keyword)) {
251 $filters['keyword'] = $keyword;
252 $users->where('first_name', 'like', '%' . $keyword . '%');
253 $users->orWhere('last_name', 'like', '%' . $keyword . '%');
254 $users->orWhere('slug', 'like', '%' . $keyword . '%');
255 $users->whereIn('id', $user_by_role);
256 }
257 if (!empty($search_locations)) {
258 $filters['locations'] = $search_locations;
259 $locations = Location::select('id')->where('slug', $search_locations)
260 ->get()->pluck('id')->toArray();
261 $location_user = User::select('id')->whereIn('location_id', $locations)->get()->pluck('id')->toArray();
262 $users->whereIn('id', $location_user)->whereIn('id', $user_by_role);
263 }
264 if (!empty($search_service)) {
265 $filters['service'] = $search_service;
266 $selected_service = Service::select('id')->where('slug', $search_service)
267 ->first();
268 $service = Service::find($selected_service->id);
269 if ($service->users->count() > 0) {
270 foreach ($service->users as $service_key => $user_service) {
271 $user_id[] = $user_service->id;
272 }
273 }
274 $users->whereIn('id', $user_id)->whereIn('id', $user_by_role);
275 }
276 if (!empty($search_speciality)) {
277 $filters['speciality'] = $search_speciality;
278 $selected_speciality = Speciality::select('id')->where('slug', $search_speciality)
279 ->first();
280 $speciality_users = DB::table('user_service')->select('user_id')
281 ->where('speciality', $selected_speciality->id)
282 ->groupBy('user_id')
283 ->get()->pluck('user_id')->toArray();
284 $users->whereIn('id', $speciality_users)->whereIn('id', $user_by_role);
285 }
286 $order = !empty($order) ? $order : 'asc';
287 if (!empty($order_by)) {
288 if ($order_by == 'name') {
289 $users = $users->orderBy('first_name', $order);
290 } elseif ($order_by == 'date') {
291 $users = $users->orderBy('created_at', $order);
292 } else {
293 $users = $users->orderBy($order_by, $order);
294 }
295 }
296 $users = $users->paginate($post_per_page);
297 } else if ($type == 'featured') {
298 // $featured_users = Helper::getFeaturedUsers();
299 // $users = DB::table('users')->whereIn('id', $featured_users);
300 $user_by_role = Helper::getUsersByRoleType('doctor');
301 $users = DB::table('users')->whereIn('id', $user_by_role);
302 $order = !empty($order) ? $order : 'asc';
303 if (!empty($order_by)) {
304 if ($order_by == 'name') {
305 $users = $users->orderBy('first_name', $order);
306 } elseif ($order_by == 'date') {
307 $users = $users->orderBy('created_at', $order);
308 } else {
309 $users = $users->orderBy($order_by, $order);
310 }
311 }
312 $users = $users->paginate($post_per_page);
313 }
314 $featured_count = 0;
315 if (!empty($users)) {
316 foreach ($users as $key => $user) {
317 $user_profile = User::find($user->id);
318 $role_type = !empty($user->id) ? Helper::getRoleTypeByUserID($user->id) : '';
319 $column = !empty($user->id) && Helper::getRoleTypeByUserID($user->id) == 'doctor' ? 'saved_doctors' : 'saved_hospitals';
320 $saved_user = !empty($auth_user) && !empty($auth_user->profile->$column) ? unserialize($auth_user->profile->$column) : array();
321 $user_specialities = DB::table('user_service')->select('speciality')
322 ->where('user_id', $user->id)->groupBy('speciality')->get();
323 if ($user_specialities->count() > 0) {
324 $specialities = $user_specialities->pluck('speciality')->random(1)->toArray();
325 } else {
326 $specialities = '';
327 }
328 if ($type == 'featured') {
329 $current_package = Helper::getCurrentPackage($user_profile);
330 $featured = !empty($current_package) && !empty($current_package['featured']) ? $current_package['featured'] : 'false';
331 if ($featured == 'true') {
332 $user_detail[$featured_count]['ID'] = $user->id;
333 $avg_rating = Feedback::where('user_id', $user->id)->pluck('avg_rating')->first();
334 $user_detail[$featured_count]['average_rating'] = !empty($avg_rating) ? $avg_rating : '0';
335 $user_detail[$featured_count]['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
336 $user_detail[$featured_count]['percentage'] = '0';
337 $user_detail[$featured_count]['medilcal_verified'] = $user_profile->profile->verify_registration == 1 ? 'yes' : 'no';
338 $user_detail[$featured_count]['is_verified'] = $user->user_verified == 1 ? 'yes' : 'no';
339 $user_detail[$featured_count]['name'] = Helper::getUserName($user->id);
340 $user_detail[$featured_count]['sub_heading'] = !empty($user_profile->profile->sub_heading) ? $user_profile->profile->sub_heading : '';
341 $user_detail[$featured_count]['location'] = !empty($user_profile->location->title) ? $user_profile->location->title : '';
342 if (!empty($specialities)) {
343 foreach ($specialities as $sep_speciality_key => $user_speciality) {
344 $speciality = Helper::getSpecialityByID($user_speciality);
345 if (!empty($speciality)) {
346 $user_detail[$featured_count]['specialities'][$sep_speciality_key]['id'] = !empty($speciality->id) ? $speciality->id : '';
347 $user_detail[$featured_count]['specialities'][$sep_speciality_key]['name'] = !empty($speciality->title) ? $speciality->title : '';
348 $user_detail[$featured_count]['specialities'][$sep_speciality_key]['slug'] = !empty($speciality->slug) ? $speciality->slug : '';
349 }
350 }
351 } else {
352 $user_detail[$featured_count]['specialities'] = [];
353 }
354 $user_detail[$featured_count]['image'] = asset(Helper::getImage('uploads/users/' . $user->id, $user_profile->profile->avatar, '', 'user.jpg'));
355 $current_package = Helper::getCurrentPackage($user_profile);
356 $featured = !empty($current_package) && !empty($current_package['featured']) ? $current_package['featured'] : 'false';
357 $user_detail[$featured_count]['featured'] = $featured == 'true' ? 'yes' : 'no';
358 $user_detail[$featured_count]['wishlist'] = !empty($saved_user) && in_array($user->id, $saved_user) ? 'yes' : 'no';
359 $user_detail[$featured_count]['role'] = $role_type;
360 $featured_count++;
361 }
362 } else {
363 $user_detail[$key]['ID'] = $user->id;
364 $avg_rating = Feedback::where('user_id', $user->id)->pluck('avg_rating')->first();
365 $user_detail[$key]['average_rating'] = !empty($avg_rating) ? $avg_rating : '0';
366 $user_detail[$key]['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
367 $user_detail[$key]['percentage'] = '0';
368 $user_detail[$key]['medilcal_verified'] = $user_profile->profile->verify_registration == 1 ? 'yes' : 'no';
369 $user_detail[$key]['is_verified'] = $user->user_verified == 1 ? 'yes' : 'no';
370 $user_detail[$key]['name'] = Helper::getUserName($user->id);
371 $user_detail[$key]['sub_heading'] = !empty($user_profile->profile->sub_heading) ? $user_profile->profile->sub_heading : '';
372 $user_detail[$key]['location'] = !empty($user_profile->location->title) ? $user_profile->location->title : '';
373 if (!empty($specialities)) {
374 foreach ($specialities as $sep_speciality_key => $user_speciality) {
375 $speciality = Helper::getSpecialityByID($user_speciality);
376 if (!empty($speciality)) {
377 $user_detail[$key]['specialities'][$sep_speciality_key]['id'] = !empty($speciality->id) ? $speciality->id : '';
378 $user_detail[$key]['specialities'][$sep_speciality_key]['name'] = !empty($speciality->title) ? $speciality->title : '';
379 $user_detail[$key]['specialities'][$sep_speciality_key]['slug'] = !empty($speciality->slug) ? $speciality->slug : '';
380 }
381 }
382 } else {
383 $user_detail[$key]['specialities'] = [];
384 }
385 $user_detail[$key]['image'] = asset(Helper::getImage('uploads/users/' . $user->id, $user_profile->profile->avatar, '', 'user.jpg'));
386 $current_package = Helper::getCurrentPackage($user_profile);
387 $featured = !empty($current_package) && !empty($current_package['featured']) ? $current_package['featured'] : 'false';
388 $user_detail[$key]['featured'] = $featured == 'true' ? 'yes' : 'no';
389 $user_detail[$key]['total'] = User::count();
390 $user_detail[$key]['wishlist'] = !empty($saved_user) && in_array($user->id, $saved_user) ? 'yes' : 'no';
391 $user_detail[$key]['role'] = $role_type;
392 }
393
394 }
395 if ($type == 'featured') {
396 if ($featured_count > 0) {
397 $user_detail[0]['total'] = $featured_count;
398 } else {
399 unset($json[0]);
400 $json['type'] = 'error';
401 $json['message'] = trans('lang.no_record');
402 return Response::json($json, 203);
403 }
404 }
405 return Response::json($user_detail, 200);
406 } else {
407 unset($json[0]);
408 $json['type'] = 'error';
409 $json['message'] = trans('lang.no_record');
410 return Response::json($json, 203);
411 }
412 } else {
413 $json['type'] = 'error';
414 $json['message'] = trans('lang.listing_type');
415 return Response::json($json, 203);
416 }
417 }
418
419 /**
420 * Get hospital detail data
421 *
422 * @access public
423 *
424 * @return \Illuminate\Http\Response
425 */
426 public function getHospital()
427 {
428 $json = array();
429 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
430 $user = !empty($profile_id) ? User::find($profile_id) : new User();
431 $currency = SiteManagement::getMetaValue('payment_settings');
432 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : 'symbol';
433 $user_detail = array();
434 $auth_id = !empty($_GET['auth_id']) ? $_GET['auth_id'] : '';
435 if (!empty($user) && !empty($profile_id)) {
436 $auth_user = !empty($auth_id) ? User::find($auth_id) : '';
437 $saved_hospitals = !empty($auth_user->profile->saved_hospitals) ? unserialize($auth_user->profile->saved_hospitals) : array();
438 $specialities = !empty($user->profile->services) ? Helper::getUnserializeData($user->profile->services) : array();
439 $registration_details = !empty($user->profile->verify_medical) ? Helper::getUnserializeData($user->profile->verify_medical) : array();
440 $gender_title = !empty($user->profile->gender_title) ? $user->profile->gender_title : '';
441 if (!empty($specialities)) {
442 foreach ($specialities as $speciality_key => $user_speciality) {
443 $speciality = Helper::getSpecialityByID($user_speciality['speciality_id']);
444 if (!empty($speciality)) {
445 $user_detail['specialires_data'][$speciality_key]['name'] = $speciality->title;
446 $user_detail['specialires_data'][$speciality_key]['logo'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
447 }
448 if (!empty($user_speciality['services'])) {
449 foreach ($user_speciality['services'] as $spe_ser_key => $speciality_service) {
450 $service = Helper::getServiceByID($speciality_service['service']);
451 if (!empty($service)) {
452 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['title'] = $service->title;
453 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['price'] = (!empty($symbol['symbol']) ? $symbol['symbol'] : '$') . $speciality_service['price'];
454 $user_detail['specialires_data'][$speciality_key]['services'][$spe_ser_key]['description'] = $speciality_service['description'];
455 }
456 }
457 }
458 }
459 } else {
460 $user_detail['specialires_data'] = '';
461 }
462 $user_detail['registration_number'] = !empty($registration_details['registration_number']) ? $registration_details['registration_number'] : '';
463 $user_detail['ID'] = $user->id;
464 $user_detail['contents'] = $user->profile->short_desc;
465 $user_detail['medilcal_verified'] = $user->profile->verify_registration == 1 ? 'yes' : 'no';
466 $user_detail['is_verified'] = $user->user_verified == 1 ? 'yes' : 'no';
467 $user_detail['name'] = Helper::getUserName($user->id);
468 $user_detail['sub_heading'] = $user->profile->sub_heading;
469 if (!empty($specialities)) {
470 foreach ($specialities as $sep_speciality_key => $user_speciality) {
471 $speciality = Helper::getSpecialityByID($user_speciality['speciality_id']);
472 if (!empty($speciality)) {
473 $user_detail['specialities'][$sep_speciality_key]['id'] = !empty($speciality->id) ? $speciality->id : '';
474 $user_detail['specialities'][$sep_speciality_key]['name'] = !empty($speciality->title) ? $speciality->title : '';
475 $user_detail['specialities'][$sep_speciality_key]['slug'] = !empty($speciality->slug) ? $speciality->slug : '';
476 }
477 }
478 } else {
479 $user_detail['specialities'] = '';
480 }
481 $user_detail['image'] = asset(Helper::getImage('uploads/users/' . $user->id, $user->profile->avatar, '', 'user.jpg'));
482 $user_detail['featured'] = '';
483 $user_detail['wishlist'] = !empty($saved_hospitals) && in_array($user->id, $saved_hospitals) ? 'yes' : 'no';
484 return Response::json($user_detail, 200);
485 } else {
486 $json['type'] = 'error';
487 $json['message'] = trans('lang.no_record');
488 return Response::json($json, 203);
489 }
490 }
491
492 /**
493 * Get doctor consulation data
494 *
495 * @access public
496 *
497 * @return \Illuminate\Http\Response
498 */
499 public function getDoctorConsulation()
500 {
501 $json = array();
502 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
503 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
504 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
505 Paginator::currentPageResolver(
506 function () use ($page_number) {
507 return $page_number;
508 }
509 );
510 $user = !empty($profile_id) ? User::find($profile_id) : new User();
511 $user_detail = array();
512 if (!empty($user) && !empty($profile_id)) {
513 $answers = $user->answers()->paginate($post_per_page);
514 if (!empty($answers) && $user->answers->count() > 0) {
515 foreach ($answers as $key => $forum) {
516 $speciality = Helper::getSpecialityByID($forum->speciality_id);
517 if (!empty($speciality)) {
518 $user_detail[$key]['title'] = $forum->question_title;
519 $user_detail[$key]['description'] = $forum->question_description;
520 $user_detail[$key]['speciality_title'] = $speciality->title;
521 $user_detail[$key]['image_url'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
522 $user_detail[$key]['date'] = Carbon::parse($forum->created_at)->format('M d, Y');
523 $user_detail[$key]['comment'] = $forum->pivot->answer;
524 $user_detail[$key]['name'] = Helper::getUserName($user->id);
525 }
526 }
527 }
528 return Response::json($user_detail, 200);
529 } else {
530 $json['type'] = 'error';
531 $json['message'] = trans('lang.no_record');
532 return Response::json($json, 203);
533 }
534 }
535
536 /**
537 * Get doctor patient reviews
538 *
539 * @access public
540 *
541 * @return \Illuminate\Http\Response
542 */
543 public function getDoctorFeedback()
544 {
545 $json = array();
546 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
547 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
548 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
549 Paginator::currentPageResolver(
550 function () use ($page_number) {
551 return $page_number;
552 }
553 );
554 $user = !empty($profile_id) ? User::find($profile_id) : new User();
555 $user_detail = array();
556 if (!empty($user) && !empty($profile_id)) {
557 $feedbacks = $user->feedbacks()->paginate($post_per_page);
558 if (!empty($feedbacks) && $user->feedbacks->count() > 0) {
559 foreach ($feedbacks as $key => $feedback) {
560 $patient = !empty($feedback->patient_id) ? User::find($feedback->patient_id) : '';
561 $user_detail[$key]['recommend'] = $user->profile->votes > 0 ? 'yes' : 'no';
562 $user_detail[$key]['recommend_text'] = trans('lang.i_recomend');
563 $user_detail[$key]['publicly'] = $feedback->keep_anonymous == 'on' ? 'yes' : 'no';
564 $user_detail[$key]['is_verified'] = $patient->user_verified == 1 ? 'yes' : 'no';
565 $user_detail[$key]['name'] = Helper::getUserName($feedback->patient_id);
566 $user_detail[$key]['tag_line'] = $patient->profile->tagline;
567 $user_detail[$key]['image_url'] = asset(Helper::getImage('uploads/users/' . $patient->id . '/', $patient->profile->avatar, '', 'user-logo-def.jpg'));
568 $user_detail[$key]['date'] = Carbon::parse($feedback->created_at)->format('M d, Y');
569 $user_detail[$key]['content'] = $feedback->comment;
570 }
571 }
572 return Response::json($user_detail, 200);
573 } else {
574 $json['type'] = 'error';
575 $json['message'] = trans('lang.no_record');
576 return Response::json($json, 203);
577 }
578 }
579
580 /**
581 * Get doctor appointment location
582 *
583 * @access public
584 *
585 * @return \Illuminate\Http\Response
586 */
587 public function getDoctorLocation()
588 {
589 $json = array();
590 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
591 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
592 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
593 Paginator::currentPageResolver(
594 function () use ($page_number) {
595 return $page_number;
596 }
597 );
598 $user = !empty($profile_id) ? User::find($profile_id) : new User();
599 $user_detail = array();
600 if (!empty($user) && !empty($profile_id)) {
601 $teams = Team::where('doctor_id', $user->id)->where('status', 'approved')->paginate($post_per_page);
602 $doctor_hospitals = Team::getDoctorHospitals($user->id);
603 if (!empty($teams) && $teams->count() > 0) {
604 foreach ($teams as $key => $hospital_team) {
605 $slots = unserialize($hospital_team->slots);
606 $team = Team::findOrFail($hospital_team->id);
607 $hospital_obj = User::findOrFail($team->hospital->id);
608 $services = !empty($slots['services']) ? $slots['services'] : array();
609 $appointment_days = !empty($slots['days']) ? $slots['days'] : array();
610 $specialities = DB::table('user_service')->select('speciality')
611 ->where('user_id', $hospital_obj->id)->groupBy('speciality')->get()->pluck('speciality')->random(1)->toArray();
612 $role_type = Helper::getRoleTypeByUserID($team->hospital->id);
613 $user_detail[$key]['ID'] = $hospital_obj->id;
614 $user_detail[$key]['location'] = !empty($hospital_obj->location->title) ? $hospital_obj->location->title : '';
615 if (!empty($appointment_days)) {
616 foreach (Helper::getAppointmentDays() as $day_key => $day) {
617 if (in_array($day_key, $appointment_days)) {
618 $user_detail[$key]['bookings_days'][]['name'] = $day['title'];
619 }
620 // $user_detail[$key]['bookings_days'][]['name'] = $day['title'];
621 }
622 }
623 $user_detail[$key]['no_of_teams'] = $hospital_obj->approvedTeams()->count();
624 $user_detail[$key]['availability'] = $hospital_obj->profile->working_time == '24_hours' ? trans('lang.24_hours') : $hospital_obj->profile->working_time;
625 $user_detail[$key]['no_of_teams'] = $hospital_obj->approvedTeams()->count();
626 $user_detail[$key]['medilcal_verified'] = $hospital_obj->profile->verify_registration == 1 ? 'yes' : 'no';
627 $user_detail[$key]['is_verified'] = $hospital_obj->user_verified == 1 ? 'yes' : 'no';
628 $user_detail[$key]['name'] = Helper::getUserName($hospital_obj->id);
629 $user_detail[$key]['sub_heading'] = $hospital_obj->profile->sub_heading;
630 $user_detail[$key]['working_hour'] = $hospital_obj->profile->working_time == '24_hours' ? trans('lang.24_hours') : clean($hospital_obj->profile->working_time);
631 $user_detail[$key]['onboard_doctors'] = clean($hospital_obj->approvedTeams()->count());
632 if (!empty($specialities)) {
633 foreach ($specialities as $sep_speciality_key => $user_speciality) {
634 $speciality = Helper::getSpecialityByID($user_speciality);
635 if (!empty($speciality)) {
636 $user_detail[$key]['specialities'][$sep_speciality_key]['id'] = !empty($speciality->id) ? $speciality->id : '';
637 $user_detail[$key]['specialities'][$sep_speciality_key]['name'] = !empty($speciality->title) ? $speciality->title : '';
638 $user_detail[$key]['specialities'][$sep_speciality_key]['slug'] = !empty($speciality->slug) ? $speciality->slug : '';
639 }
640 }
641 } else {
642 $user_detail[$key]['specialities'] = '';
643 }
644 $user_detail[$key]['image'] = asset(Helper::getImage('uploads/users/' . $hospital_obj->id, $hospital_obj->profile->avatar, '', 'user.jpg'));
645 }
646 }
647 return Response::json($user_detail, 200);
648 } else {
649 $json['type'] = 'error';
650 $json['message'] = trans('lang.no_record');
651 return Response::json($json, 203);
652 }
653 }
654
655 /**
656 * Get doctor articles data
657 *
658 * @access public
659 *
660 * @return \Illuminate\Http\Response
661 */
662 public function getDoctorArticles()
663 {
664 $json = array();
665 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
666 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
667 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
668 $auth_id = !empty($_GET['auth_id']) ? $_GET['auth_id'] : '';
669 Paginator::currentPageResolver(
670 function () use ($page_number) {
671 return $page_number;
672 }
673 );
674 $user = !empty($profile_id) ? User::find($profile_id) : new User();
675 $user_detail = array();
676 if (!empty($user) && !empty($profile_id)) {
677 $auth_user = !empty($auth_id) ? User::find($auth_id) : '';
678 $saved_articles = !empty($auth_user) && !empty($auth_user->profile->saved_articles) ? unserialize($auth_user->profile->saved_articles) : array();
679 $articles = $user->articles()->paginate($post_per_page);
680 if (!empty($articles) && $articles->count() > 0) {
681 foreach ($articles as $key => $article) {
682 $user_detail[$key]['likes'] = !empty($article->likes) ? $article->likes : 0;
683 $user_detail[$key]['views'] = !empty($article->views) ? $article->views : 0;
684 $user_detail[$key]['posted_date'] = Carbon::parse($article->created_at)->format('M d, Y');
685 $user_detail[$key]['ID'] = $article->id;
686 if (!empty($article->categories) && $article->categories->count() > 0) {
687 foreach ($article->categories as $category) {
688 $user_detail[$key]['categories']['id'] = $category->id;
689 $user_detail[$key]['categories']['name'] = $category->title;
690 $user_detail[$key]['categories']['slug'] = $category->slug;
691 }
692 } else {
693 $user_detail[$key]['categories'] = '';
694 }
695 $user_detail[$key]['image_url'] = asset(Helper::getImage('uploads/users/' . $user->id . '/articles/', $article->image, '', 'list-article-default.jpg'));
696 $user_detail[$key]['title'] = $article->title;
697 $user_detail[$key]['post_url'] = route('articleDetail', ['slug' => clean($article->slug)]);
698 $user_detail[$key]['wishlist'] = !empty($saved_articles) && in_array($article->id, $saved_articles) ? 'yes' : 'no';
699 }
700 return Response::json($user_detail, 200);
701 } else {
702 $json['type'] = 'error';
703 $json['message'] = trans('lang.no_record');
704 return Response::json($json, 203);
705 }
706 } else {
707 $json['type'] = 'error';
708 $json['message'] = trans('lang.no_record');
709 return Response::json($json, 203);
710 }
711 }
712
713 /**
714 * Get articles data
715 *
716 * @access public
717 *
718 * @return \Illuminate\Http\Response
719 */
720 public function getArticleDetail()
721 {
722 $json = array();
723 $post_id = !empty($_GET['post_id']) ? $_GET['post_id'] : '';
724 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
725 $auth_id = !empty($_GET['auth_id']) ? $_GET['auth_id'] : '';
726 Paginator::currentPageResolver(
727 function () use ($page_number) {
728 return $page_number;
729 }
730 );
731 $article = !empty($post_id) ? Article::find($post_id) : '';
732 $article_detail = array();
733 if (!empty($article) && !empty($post_id)) {
734 $auth_user = !empty($auth_id) ? User::find($auth_id) : '';
735 $saved_articles = !empty($auth_user) && !empty($auth_user->profile->saved_articles) ? unserialize($auth_user->profile->saved_articles) : array();
736 $article_detail['user_name'] = Helper::getUserName($article->author->id);
737 $article_detail['user_link'] = url('profile/' . $article->author->slug);
738 $article_detail['user_contents'] = $article->author->short_desc;
739 $article_detail['user_image'] = asset(Helper::getImage('uploads/users/' . $article->author->id . '/articles', $article->image, 'blog-single-', 'article-default.jpg'));
740 $article_detail['user_date'] = Carbon::parse($article->author->created_at)->format('M d, Y');
741 $article_detail['likes'] = !empty($article->likes) ? $article->likes : 0;
742 $article_detail['views'] = !empty($article->views) ? $article->views : 0;
743 $article_detail['post_content'] = !empty($article->description) ? html_entity_decode(clean($article->description)) : '';
744 $article_detail['post_tags'] = '';
745 if (!empty($article->categories) && $article->categories->count() > 0) {
746 foreach ($article->categories as $category) {
747 $cat = Category::where('id', $category->id)->select('title', 'slug')->first();
748 $article_detail['categories']['id'] = $cat->id;
749 $article_detail['categories']['name'] = $cat->title;
750 $article_detail['categories']['slug'] = $cat->slug;
751 }
752 } else {
753 $article_detail['categories'] = '';
754 }
755 $article_detail['image_url'] = asset(Helper::getImage('uploads/users/' . $article->author->id . '/articles/', $article->image, '', 'list-article-default.jpg'));
756 $article_detail['title'] = $article->title;
757 $article_detail['post_url'] = route('articleDetail', ['slug' => clean($article->slug)]);
758 $user_detail['wishlist'] = !empty($saved_articles) && in_array($article->id, $saved_articles) ? 'yes' : 'no';
759 return Response::json($article_detail, 200);
760 } else {
761 $json['type'] = 'error';
762 $json['message'] = trans('lang.no_record');
763 return Response::json($json, 203);
764 }
765 }
766
767 /**
768 * Get hospital team
769 *
770 * @access public
771 *
772 * @return \Illuminate\Http\Response
773 */
774 public function getHospitalTeam()
775 {
776 $json = array();
777 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
778 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
779 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
780 $currency = SiteManagement::getMetaValue('payment_settings');
781 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : 'symbol';
782 Paginator::currentPageResolver(
783 function () use ($page_number) {
784 return $page_number;
785 }
786 );
787 $user = !empty($profile_id) ? User::find($profile_id) : new User();
788 $user_detail = array();
789 if (!empty($user) && !empty($profile_id)) {
790 $team = $user->approvedTeams()->paginate($post_per_page);
791 if (!empty($team) && $team->count() > 0) {
792 foreach ($team as $key => $doctor) {
793 $slots = unserialize($doctor->slots);
794 $doctor_obj = User::find($doctor->doctor_id);
795 $services = !empty($slots['services']) ? $slots['services'] : array();
796 $appointment_days = !empty($slots['days']) ? $slots['days'] : array();
797 $specialities = $doctor_obj->services->count() > 0 ? DB::table('user_service')->select('speciality')
798 ->where('user_id', $doctor_obj->id)->groupBy('speciality')->get()->pluck('speciality')->random(1)->toArray() : '';
799 $avg_rating = Feedback::where('user_id', $doctor_obj->id)->pluck('avg_rating')->first();
800 $user_detail[$key]['ID'] = $doctor_obj->id;
801 $user_detail[$key]['average_rating'] = $avg_rating;
802 $user_detail[$key]['total_rating'] = (string) Feedback::where('user_id', $doctor_obj->id)->count();
803 $user_detail[$key]['percentage'] = '';
804 $user_detail[$key]['medilcal_verified'] = $doctor_obj->profile->verify_registration == 1 ? 'yes' : 'no';
805 $user_detail[$key]['is_verified'] = $doctor_obj->user_verified == 1 ? 'yes' : 'no';
806 $user_detail[$key]['name'] = Helper::getUserName($doctor_obj->id);
807 $user_detail[$key]['sub_heading'] = $doctor_obj->profile->sub_heading;
808 if (!empty($specialities)) {
809 foreach ($specialities as $speciality_key => $user_speciality) {
810 $speciality = Helper::getSpecialityByID($user_speciality);
811 if (!empty($speciality)) {
812 $user_detail[$key]['specialities']['id'] = $speciality->id;
813 $user_detail[$key]['specialities']['name'] = $speciality->title;
814 $user_detail[$key]['specialities']['slug'] = $speciality->slug;
815 }
816 }
817 } else {
818 $user_detail[$key]['specialities'] = '';
819 }
820 $user_detail[$key]['image'] = asset(Helper::getImage('uploads/users/' . $doctor_obj->id, $doctor_obj->profile->avatar, '', 'user.jpg'));
821 $user_detail[$key]['featured'] = '';
822 if (!empty($appointment_days)) {
823 foreach (Helper::getAppointmentDays() as $day_key => $day) {
824 $user_detail[$key]['bookings_days'][] = $day['title'];
825 $user_detail[$key]['current_day'] = strtolower(Carbon::now()->format('D'));
826 }
827 }
828 $user_detail[$key]['votes'] = $doctor_obj->profile->votes;
829 $user_detail[$key]['starting_price'] = !empty($doctor_obj->profile->starting_price) ? (!empty($symbol['symbol']) ? $symbol['symbol'] : '$') . $doctor_obj->profile->starting_price : '';
830 }
831 }
832 return Response::json($user_detail, 200);
833 } else {
834 $json['type'] = 'error';
835 $json['message'] = trans('lang.no_record');
836 return Response::json($json, 203);
837 }
838 }
839
840 /**
841 * Login user for application
842 *
843 * @param \Illuminate\Http\Request $request request attributes
844 *
845 * @access public
846 *
847 * @return \Illuminate\Http\Response
848 */
849 public function userLogin(Request $request)
850 {
851 $json = array();
852 $credentials = $request->only('email', 'password');
853 if (auth()->attempt($credentials)) {
854 $json['type'] = 'success';
855 $json['profile']['pmeta']['user_type'] = auth()->user()->getRoleNames()[0];
856 $json['profile']['pmeta']['profile_img'] = asset(Helper::getImage('uploads/users/' . auth()->user()->id, auth()->user()->profile->avatar, '', 'user.jpg'));
857 $json['profile']['pmeta']['am_name_base'] = auth()->user()->profile->tagline;
858 $json['profile']['pmeta']['am_sub_heading'] = !empty(auth()->user()->profile->sub_heading) ? auth()->user()->profile->sub_heading : '';
859 $json['profile']['pmeta']['am_first_name'] = auth()->user()->first_name;
860 $json['profile']['pmeta']['am_last_name'] = auth()->user()->last_name;
861 $json['profile']['pmeta']['am_short_description'] = auth()->user()->profile->short_desc;
862 $json['profile']['pmeta']['full_name'] = Helper::getUserName(auth()->user()->id);
863 $json['profile']['umeta']['profile_id'] = auth()->user()->profile->id;
864 $json['profile']['umeta']['id'] = auth()->user()->id;
865 $json['profile']['umeta']['user_login'] = $request['email'];
866 $json['profile']['umeta']['user_pass'] = $request['password'];
867 $json['profile']['umeta']['user_email'] = $request['email'];
868 return response()->json($json, 200);
869 } else {
870 return response()->json(['error' => 'UnAuthorized'], 203);
871 }
872 }
873
874 /**
875 * Logout user from application
876 *
877 * @param \Illuminate\Http\Request $request request attributes
878 *
879 * @access public
880 *
881 * @return \Illuminate\Http\Response
882 */
883 public function userLogout(Request $request)
884 {
885 // $json = array();
886 // if (auth()->user()) {
887 // auth()->logout();
888 // return response()->json($json, 200);
889 // } else {
890 // return response()->json(['error' => 'UnAuthorized'], 203);
891 // }
892 // auth()->logout();
893 // \Session::flush();
894 // return response()->json($json, 200);
895 }
896
897 /**
898 * Login user for application
899 *
900 * @param \Illuminate\Http\Request $request request attributes
901 *
902 * @access public
903 *
904 * @return \Illuminate\Http\Response
905 */
906 public function resetPassword(Request $request)
907 {
908 $json = array();
909 if ($request->expectsJson()) {
910 return $response = Password::RESET_LINK_SENT
911 ? response()->json(['status' => 'Success', 'message' => 'Reset Password Link Sent'], 201)
912 : response()->json(['status' => 'Fail', 'message' => 'Reset Link Could Not Be Sent'], 401);
913 }
914 }
915
916 /**
917 * Create a new user instance after a valid registration.
918 *
919 * @param array $request returns request
920 *
921 * @return \App\User
922 */
923 protected function createUser(Request $request)
924 {
925 $json = array();
926 $roles = [
927 'first_name' => 'required',
928 'last_name' => 'required',
929 'email' => 'required|email|unique:users',
930 ];
931 $validator = \Validator::make($request->all(), $roles);
932 if ($validator->fails()) {
933 return response()->json($validator->errors(), 203);
934 }
935 if ($request['password'] == $request['verify_password']) {
936 $user = new User();
937 $register_form = SiteManagement::getMetaValue('reg_form_settings');
938 $verification_step = !empty($register_form) && !empty($register_form['enable_verification']) ? $register_form['enable_verification'] : true;
939 $verification_code = '';
940 if ($verification_step == 'true') {
941 $random_number = Helper::generateRandomCode(4);
942 $verification_code = strtoupper($random_number);
943 }
944 $user_id = $user->storeUser($request, $verification_code, $verification_step);
945 $role_type = Helper::getRoleTypeByUserID($user_id);
946 if ($role_type == 'doctor') {
947 $order = new Order();
948 $order->status = 'pending';
949 $order->payment_gateway = 'paypal';
950 $order->user()->associate($user_id);
951 $order->save();
952 $order_id = DB::getPdo()->lastInsertId();
953 $latest_order = Order::find($order_id);
954 $order_type = new OrderMeta();
955 $order_type->meta_key = 'type';
956 $order_type->meta_value = 'package';
957 $latest_order->orderMeta()->save($order_type);
958 $package_data = array();
959 $package = Package::where('trial', 1)->first()->toArray();
960 if (!empty($package)) {
961 $option = !empty($package['options']) ? Helper::getUnserializeData($package['options']) : '';
962 foreach ($package as $package_key => $package_value) {
963 $package_data[$package_key] = $package_value;
964 }
965 $package_meta = new OrderMeta();
966 $package_meta->meta_key = 'package';
967 $package_meta->meta_value = serialize($package_data);
968 $latest_order->orderMeta()->save($package_meta);
969 $expiry = !empty($order) ? $order->created_at->addDays($option['duration']) : '';
970 $expiry_date = !empty($expiry) ? Carbon::parse($expiry)->toDateTimeString() : '';
971 $user = User::find($user_id);
972 $user->package_expiry = $expiry_date;
973 $user->save();
974 }
975 }
976 session()->put(['user_id' => $user_id]);
977 session()->put(['email' => $request['email']]);
978 session()->put(['password' => $request['password']]);
979 //Send Mail
980 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
981 $email_params = array();
982 $template = DB::table('email_types')->select('id')
983 ->where('email_type', 'verification_code')->get()->first();
984 if (!empty($template->id)) {
985 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
986 $email_params['verification_code'] = $user->verification_code;
987 $email_params['name'] = Helper::getUserName($user->id);
988 $email_params['email'] = $user->email;
989 Mail::to($user->email)
990 ->send(
991 new GeneralEmailMailable(
992 'verification_code',
993 $template_data,
994 $email_params
995 )
996 );
997 }
998 $json['id'] = $user_id;
999 $json['message'] = trans('lang.account_register');
1000 return response()->json($json, 200);
1001 } else {
1002 $id = Session::get('user_id');
1003 $user = User::find($id);
1004 Auth::login($user);
1005 $json['email'] = 'not_configured';
1006 $json['url'] = url($role_type . '/dashboard');
1007 }
1008 $json['type'] = 'success';
1009 return $json;
1010 } else {
1011 $json['message'] = trans('lang.password_not_match');
1012 return response()->json(['error' => 'UnAuthorized'], 203);
1013 }
1014 }
1015
1016 /**
1017 * Get user settings API
1018 *
1019 * @access public
1020 *
1021 * @return \Illuminate\Http\Response
1022 */
1023 public function getUserProfileSettings()
1024 {
1025 $json = array();
1026 $id = !empty($_GET['id']) ? $_GET['id'] : '';
1027 $user = !empty($id) ? User::find($id) : new User();
1028 $user_detail = array();
1029 if (!empty($user) && !empty($id)) {
1030 $memberships = !empty($user->profile->memberships) ? Helper::getUnserializeData($user->profile->memberships) : array();
1031 $registration_details = !empty($user->profile->verify_medical) ? Helper::getUnserializeData($user->profile->verify_medical) : array();
1032 if (!empty($registration_details['registration_document'])) {
1033 if (file_exists(public_path('uploads/users/' . $id . '/' . $registration_details['registration_document']))) {
1034 $document_size = Helper::bytesToHuman(File::size(public_path('uploads/users/' . $id . '/' . $registration_details['registration_document'])));
1035 } else {
1036 $document_size = 0;
1037 }
1038 } else {
1039 $document_size = 0;
1040 }
1041
1042 $downloads = !empty($user->profile->downloads) ? Helper::getUnserializeData($user->profile->downloads) : array();
1043 $user_detail['am_name_base'] = !empty($user->profile->gender_title) ? $user->profile->gender_title : '';
1044 $user_detail['am_sub_heading'] = !empty($user->profile->sub_heading) ? $user->profile->sub_heading : '';
1045 $user_detail['am_first_name'] = !empty($user->first_name) ? $user->first_name : '';
1046 $user_detail['am_last_name'] = !empty($user->last_name) ? $user->last_name : '';
1047 $user_detail['display_name'] = Helper::getUserName($id);
1048 $user_detail['address'] = !empty($user->profile->address) ? $user->profile->address : '';
1049 $user_detail['latitude'] = !empty($user->profile->latitude) ? $user->profile->latitude : '';
1050 $user_detail['longitude'] = !empty($user->profile->longitude) ? $user->profile->longitude : '';
1051 $user_detail['location'] = !empty($user->location) && !empty($user->location->title) ? $user->location->title : '';
1052 $user_detail['content'] = !empty($user->profile->description) ? $user->profile->description : '';
1053 $user_detail['profile_attachment_id'] = '';
1054 $user_detail['profile_image_url'] = asset(Helper::getImage('uploads/users/' . $id . '/', $user->profile->avatar, '', 'doc-single-def.jpg'));
1055 $user_detail['am_short_description'] = !empty($user->profile->short_desc) ? $user->profile->short_desc : '';
1056 $user_detail['am_starting_price'] = !empty($user->profile->starting_price) ? $user->profile->starting_price : '';
1057 if (!empty($memberships)) {
1058 $membership_count = 0;
1059 foreach ($memberships as $membership_key => $membership) {
1060 $user_detail['memberships'][$membership_count]['title'] = $membership['title'];
1061 $membership_count++;
1062 }
1063 } else {
1064 $user_detail['am_memberships'] = '';
1065 }
1066 $experiences = !empty($user->profile->experiences) ? Helper::getUnserializeData($user->profile->experiences) : array();
1067 $educations = !empty($user->profile->educations) ? Helper::getUnserializeData($user->profile->educations) : array();
1068 $awards = !empty($user->profile->awards) ? Helper::getUnserializeData($user->profile->awards) : array();
1069 if (!empty($experiences)) {
1070 foreach ($experiences as $experience_key => $user_experience) {
1071 $user_detail['am_experiences'][$experience_key]['company_name'] = $user_experience['company_title'];
1072 $user_detail['am_experiences'][$experience_key]['job_title'] = $user_experience['start_date'];
1073 $user_detail['am_experiences'][$experience_key]['start'] = $user_experience['end_date'];
1074 $user_detail['am_experiences'][$experience_key]['ending'] = $user_experience['job_title'];
1075 $user_detail['am_experiences'][$experience_key]['description'] = $user_experience['job_desc'];
1076 }
1077 } else {
1078 $user_detail['am_experiences'] = '';
1079 }
1080 if (!empty($educations)) {
1081 foreach ($educations as $education_key => $education) {
1082 $user_detail['am_education'][$education_key]['degree_title'] = $education['degree_title'];
1083 $user_detail['am_education'][$education_key]['institute_name'] = $education['job_title'];
1084 $user_detail['am_education'][$education_key]['start'] = $education['start_date'];
1085 $user_detail['am_education'][$education_key]['ending'] = $education['end_date'];
1086 $user_detail['am_education'][$education_key]['edu_desc'] = $education['job_desc'];
1087 }
1088 } else {
1089 $user_detail['am_education'] = '';
1090 }
1091 if (!empty($awards)) {
1092 $award_count = 0;
1093 foreach ($awards as $award_key => $award) {
1094 $user_detail['am_award'][$award_count]['title'] = $award['title'];
1095 $user_detail['am_award'][$award_count]['year'] = $award['year'];
1096 $award_count++;
1097 }
1098 } else {
1099 $user_detail['am_award'] = '';
1100 }
1101 $user_detail['document_url'] = !empty($registration_details['registration_document']) ? url('uploads/users/' . $id . '/' . $registration_details['registration_document']) : '';
1102 $user_detail['document_id'] = '';
1103
1104 $user_detail['document_size'] = $document_size;
1105 $user_detail['document_name'] = !empty($registration_details['registration_document']) ? Helper::formateFileName($registration_details['registration_document']) : '';
1106 $user_detail['document_verified'] = $user->profile->verify_registration == 1 ? 'yes' : 'no';
1107 $user_detail['reg_number'] = !empty($registration_details['registration_number']) ? $registration_details['registration_number'] : '';
1108 $user_detail['am_downloads_image'] = asset('/images/icon-imgs/img-01.png');
1109 if (!empty($downloads)) {
1110 foreach ($downloads as $download_key => $download) {
1111 if (file_exists(public_path('uploads/users/' . $user->id . '/' . $download))) {
1112 $download_name = Helper::formateFileName($download);
1113 $download_size = Helper::bytesToHuman(File::size(public_path('uploads/users/' . $user->id . '/' . $download)));
1114 } else {
1115 $download_name = '';
1116 $download_size = 0;
1117 }
1118 $user_detail['am_downloads'][$download_key]['name'] = $download_name;
1119 $user_detail['am_downloads'][$download_key]['size'] = $download_size;
1120 $user_detail['am_downloads'][$download_key]['media'] = public_path('uploads/users/' . $user->id . '/' . $download);
1121 $user_detail['am_downloads'][$download_key]['id'] = '';
1122 }
1123 } else {
1124 $user_detail['downloads'] = '';
1125 }
1126 return Response::json($user_detail, 200);
1127 } else {
1128 $json['type'] = 'error';
1129 $json['message'] = trans('lang.no_record');
1130 return Response::json($json, 203);
1131 }
1132 }
1133
1134 /**
1135 * Get delete reasons
1136 *
1137 * @access public
1138 *
1139 * @return \Illuminate\Http\Response
1140 */
1141 public function getRemoveReasons()
1142 {
1143 $json = array();
1144 $reasons = Helper::getDeleteAccReason();
1145 $list_detail = array();
1146 $count = 0;
1147 if (!empty($reasons)) {
1148 foreach ($reasons as $key => $title) {
1149 $list_detail[$count]['key'] = $key;
1150 $list_detail[$count]['val'] = $title;
1151 $count++;
1152 }
1153 return Response::json($list_detail, 200);
1154 } else {
1155 $json['type'] = 'error';
1156 $json['message'] = trans('lang.no_record');
1157 return Response::json($json, 203);
1158 }
1159 }
1160
1161 /**
1162 * Get taxonomies data
1163 *
1164 * @access public
1165 *
1166 * @return \Illuminate\Http\Response
1167 */
1168 public function getTeam()
1169 {
1170 $json = array();
1171 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1172 $status = !empty($_GET['status']) ? $_GET['status'] : '';
1173 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
1174 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
1175 Paginator::currentPageResolver(
1176 function () use ($page_number) {
1177 return $page_number;
1178 }
1179 );
1180 $count = 0;
1181 if (!empty($user_id)) {
1182 $hospital = User::findOrFail($user_id);
1183 if (!empty($status)) {
1184 $teams = !empty($hospital) ? $hospital->teams()->where('status', $status)->paginate($post_per_page) : array();
1185 } else {
1186 $teams = !empty($hospital) ? $hospital->teams()->paginate($post_per_page) : array();
1187 }
1188
1189 if (!empty($teams) && $teams->count() > 0) {
1190 foreach ($teams as $key => $team) {
1191 $user = User::findOrFail($team->doctor_id);
1192 $json[$key]['name'] = ucwords(Helper::getUserName($user->id));
1193 $json[$key]['ID'] = $team->id;
1194 $json[$key]['status'] = $team->status;
1195 $json[$key]['image'] = asset(Helper::getImage('uploads/users/' . $user->id, $user->profile->avatar, 'extra-small-', 'user.jpg'));
1196 }
1197 return Response::json($json, 200);
1198 } else {
1199 $json['type'] = 'error';
1200 $json['message'] = trans('lang.no_record');
1201 return Response::json($json, 203);
1202 }
1203 } else {
1204 $json['type'] = 'error';
1205 $json['message'] = trans('lang.no_record');
1206 return Response::json($json, 203);
1207 }
1208 }
1209
1210 /**
1211 * Get taxonomies data
1212 *
1213 * @access public
1214 *
1215 * @return \Illuminate\Http\Response
1216 */
1217 public function getTaxonomies()
1218 {
1219 $json = array();
1220 $list = !empty($_GET['list']) ? $_GET['list'] : '';
1221 $list_detail = array();
1222 $count = 0;
1223 if (!empty($list)) {
1224 if ($list == 'bas_name') {
1225 $gender_titles = Helper::getDoctorArray();
1226 foreach ($gender_titles as $key => $title) {
1227 $list_detail[$count]['key'] = $key;
1228 $list_detail[$count]['val'] = $title;
1229 $count++;
1230 }
1231 } elseif ($list == 'location') {
1232 $locations = Location::all();
1233 if (!empty($locations)) {
1234 foreach ($locations as $key => $location) {
1235 $list_detail[$key]['id'] = $location->id;
1236 $list_detail[$key]['slug'] = $location->slug;
1237 $list_detail[$key]['title'] = $location->title;
1238 }
1239 }
1240 } elseif ($list == 'working_time') {
1241 $working_time = array(
1242 '1' => '0 to 15 min',
1243 '2' => '15 to 30 min',
1244 '3' => '30 to 1 hr',
1245 '4' => 'More then hr'
1246 );
1247 foreach ($working_time as $key => $value) {
1248 $list_detail[$count]['title'] = $value;
1249 $list_detail[$count]['value'] = $key;
1250 $count++;
1251 }
1252 } elseif ($list == 'imrpovement_options') {
1253 $feedback_questions = ImprovementOption::get();
1254 if (!empty($feedback_questions)) {
1255 foreach ($feedback_questions as $key => $option) {
1256 $list_detail[$key]['title'] = $option->title;
1257 }
1258 }
1259 } elseif ($list == 'hospitals') {
1260 $list_detail = User::role('hospital')->select(
1261 DB::raw("CONCAT(users.first_name,' ',users.last_name) AS name"),
1262 "id"
1263 )->get()->toArray();
1264 if (empty($list_detail)) {
1265 $json['type'] = 'error';
1266 return Response::json($json, 203);
1267 }
1268 } elseif ($list == 'intervals') {
1269 $intervals = Helper::getAppointmentIntervals();
1270 foreach ($intervals as $key => $value) {
1271 $list_detail[$count]['title'] = $value;
1272 $list_detail[$count]['value'] = $key;
1273 $count++;
1274 }
1275 } elseif ($list == 'duration') {
1276 $duration = Helper::getAppointmentDuration();
1277 foreach ($duration as $key => $value) {
1278 $list_detail[$count]['title'] = $value;
1279 $list_detail[$count]['value'] = $key;
1280 $count++;
1281 }
1282 } elseif ($list == 'spaces') {
1283 $spaces = Helper::getAppointmentSpaces();
1284 foreach ($spaces as $key => $value) {
1285 $list_detail[] = $value;
1286 }
1287 } elseif ($list == 'days') {
1288 $days = Helper::getAppointmentDays();
1289 foreach ($days as $key => $value) {
1290 $list_detail[$count]['key'] = $key;
1291 $list_detail[$count]['title'] = $value['title'];
1292 $list_detail[$count]['name'] = $value['name'];
1293 $count++;
1294 }
1295 } elseif ($list == 'slots') {
1296 for ($i = 1; $i <= 30; $i++) {
1297 $slot = $i > 1 ? 'slots' : 'slot';
1298 $list_detail[$count]['value'] = $i . ' ' . $slot;
1299 $count++;
1300 }
1301 } elseif ($list == 'services') {
1302 $speciality_id = !empty($_GET['speciality']) ? $_GET['speciality'] : '';
1303 $speciality = Speciality::find($speciality_id);
1304 if (!empty($speciality) && $speciality->services->count() > 0) {
1305 $services = $speciality->services->toArray();
1306 if (!empty($speciality)) {
1307 $list_detail['services'] = $services;
1308 } else {
1309 $json['type'] = 'error';
1310 $json['message'] = trans('lang.something_wrong');
1311 return Response::json($json, 203);
1312 }
1313 } else {
1314 $json['type'] = 'error';
1315 $json['message'] = trans('lang.something_wrong');
1316 return Response::json($json, 203);
1317 }
1318 } elseif ($list == 'article_categories') {
1319 $categories = Category::all()->toArray();
1320 if (!empty($categories)) {
1321 foreach ($categories as $key => $value) {
1322 $list_detail[$key]['id'] = $value['id'];
1323 $list_detail[$key]['title'] = $value['title'];
1324 }
1325 }
1326 }
1327 return Response::json($list_detail, 200);
1328 } else {
1329 $json['type'] = 'error';
1330 $json['message'] = trans('lang.no_record');
1331 return Response::json($json, 203);
1332 }
1333 }
1334
1335 /**
1336 * Get taxonomies data
1337 *
1338 * @access public
1339 *
1340 * @return \Illuminate\Http\Response
1341 */
1342 public function getDoctorAppointments()
1343 {
1344 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1345 $appointment_date = !empty($_GET['appointment_date']) ? $_GET['appointment_date'] : '';
1346 $json = array();
1347 $list = array();
1348 $booking_settings = SiteManagement::getMetaValue('booking_settings');
1349 $online_payment = !empty($booking_settings['enable_booking']) ? $booking_settings['enable_booking'] : '';
1350 if (!empty($user_id)) {
1351 $user = User::find($user_id);
1352 $appointments = $user->appointments;
1353 if ($online_payment == 'true') {
1354 $appointments = $appointments->where('status', 'accepted');
1355 }
1356 if (!empty($appointment_date)) {
1357 $appointments = $appointments->where('appointment_date', $appointment_date);
1358 }
1359 $counter = 0;
1360 if ($appointments->count() > 0) {
1361 foreach ($appointments as $key => $appointment) {
1362 $patient = !empty($appointment->patient_id) ? User::find($appointment->patient_id) : '';
1363 $list[$counter]['patient_id'] = !empty($patient) ? $appointment->patient_id : '';
1364 $list[$counter]['id'] = $appointment->id;
1365 $list[$counter]['appointments'] = $appointments->count();
1366 $list[$counter]['status'] = $appointment->status;
1367 $list[$counter]['name'] = !empty($patient) && !empty($appointment->patient_id)
1368 ? Helper::getUserName($appointment->patient_id) : '';
1369 $list[$counter]['image'] = !empty($patient)
1370 ? asset(Helper::getImage('uploads/users/' . $appointment->patient_id, $patient->profile->avatar, 'small-', 'user.jpg'))
1371 : '';
1372 $date = $appointment->appointment_date;
1373 $patient_date = new Carbon($appointment->appointment_date);
1374 $patient_appointment_date = explode("-", $date);
1375 $list[$counter]['day'] = !empty($patient_appointment_date) ? $patient_appointment_date[2] : '';
1376 $list[$counter]['month'] = !empty($patient_date) ? $patient_date->format('M') : '';
1377 $list[$counter]['post_date'] = !empty($date) ? $date : '';
1378 $counter++;
1379 }
1380 return Response::json($list, 200);
1381 } else {
1382 $json['type'] = 'error';
1383 $json['message'] = trans('lang.no_record');
1384 return Response::json($json, 203);
1385 }
1386 } else {
1387 $json['type'] = 'error';
1388 $json['message'] = trans('lang.no_record');
1389 return $json;
1390 }
1391 }
1392
1393 /**
1394 * Get taxonomies data
1395 *
1396 * @access public
1397 *
1398 * @return \Illuminate\Http\Response
1399 */
1400 public function getDoctorAppointmentSingle()
1401 {
1402 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1403 $booking_id = !empty($_GET['booking_id']) ? $_GET['booking_id'] : '';
1404 $json = array();
1405 $list = array();
1406 $currency = SiteManagement::getMetaValue('payment_settings');
1407 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : 'symbol';
1408 if (!empty($booking_id)) {
1409 $appointment = Appointment::find($booking_id);
1410 $counter = 0;
1411 if (!empty($appointment)) {
1412 $patient = !empty($appointment->patient_id) ? User::find($appointment->patient_id) : '';
1413 $services = !empty($appointment->services) ? Helper::getUnserializeData($appointment->services) : '';
1414 $list['post_status'] = $appointment->status;
1415 $list['name'] = !empty($patient) && !empty($appointment->patient_id)
1416 ? Helper::getUserName($appointment->patient_id) : '';
1417 $list['other_name'] = !empty($appointment->patient_name)
1418 ? $appointment->patient_name : '';
1419 $list['other_relation'] = !empty($appointment->relation)
1420 ? $appointment->relation : '';
1421 $list['image'] = !empty($patient)
1422 ? asset(Helper::getImage('uploads/users/' . $appointment->patient_id, $patient->profile->avatar, 'small-', 'user.jpg'))
1423 : '';
1424 $list['user_verify'] = !empty($patient) ? $patient->user_verified : 0;
1425 $list['country'] = !empty($patient->location) && $patient->location->count() > 0 ? $patient->location->title : '';
1426 $list['user_type'] = !empty($patient) ? $patient->getRoleNames()->first() : '';
1427 $list['loc_title'] = !empty($appointment->hospital_id) ? Helper::getUserName($appointment->hospital_id) : '';
1428 $date = $appointment->appointment_date;
1429 $patient_date = new Carbon($appointment->appointment_date);
1430 $patient_appointment_date = explode("-", $date);
1431 $day = !empty($patient_appointment_date) ? $patient_appointment_date[2] : '';
1432 $month = !empty($patient_date) ? $patient_date->format('F') : '';
1433 $year = !empty($patient_appointment_date) ? $patient_appointment_date[0] : '';
1434 $time = !empty($appointment->appointment_time) ? $appointment->appointment_time : '';
1435 $list['slots'] = $month . ' ' . $day . ', ' . $year . '-' . $time;
1436 $list['content'] = !empty($appointment->comments) ? $appointment->comments : '';
1437 $list['hospital_id'] = !empty($appointment->hospital_id) ? $appointment->hospital_id : '';
1438 $list['user_id'] = !empty($appointment->user_id) ? $appointment->user_id : '';
1439 $list['charges'] = !empty($appointment->charges) ? (!empty($symbol['symbol']) ? $symbol['symbol'] : '$') . $appointment->charges : '';
1440 if (!empty($services)) {
1441 foreach ($services as $service_key => $service) {
1442 if (!empty($service['service'])) {
1443 $speciality = Helper::getSpecialityByID($service['speciality']);
1444 $list['all_sp_serv'][$service_key]['speciality'] = !empty($speciality) ? $speciality->title : '';
1445 foreach ($service['service'] as $speciality_service_key => $speciality_service) {
1446 $service = Helper::getServiceByID($speciality_service);
1447 $list['all_sp_serv'][$service_key]['services'][]['title'] = !empty($service) ? $service->title : '';
1448 }
1449 }
1450 }
1451 }
1452 return Response::json($list, 200);
1453 } else {
1454 $json['type'] = 'error';
1455 $json['message'] = trans('lang.no_record');
1456 return Response::json($json, 203);
1457 }
1458 } else {
1459 $json['type'] = 'error';
1460 $json['message'] = trans('lang.no_record');
1461 return Response::json($json, 203);
1462 }
1463 }
1464
1465 /**
1466 * Accept patient appointment
1467 *
1468 * @param \Illuminate\Http\Request $request request attributes
1469 *
1470 * @access public
1471 *
1472 * @return \Illuminate\Http\Response
1473 */
1474 public function updateAppointmentStatus(Request $request)
1475 {
1476 $json = array();
1477 $booking_id = !empty($request['booking_id']) ? $request['booking_id'] : '';
1478 $status = !empty($request['status']) ? $request['status'] : '';
1479 if (!empty($booking_id) && !empty($status)) {
1480 $appointment = Appointment::find($booking_id);
1481 $patient = User::find($appointment['patient_id']);
1482 $hospital = User::findOrFail($appointment['hospital_id']);
1483 $doctor = User::findOrFail($appointment['user_id']);
1484 DB::table('appointments')->where('id', $booking_id)->update(['status' => $status]);
1485 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
1486 if ($status == 'accepted') {
1487 $email_params = array();
1488 $template = DB::table('email_types')->select('id')->where('email_type', 'user_email_appointment_request_approved')->get()->first();
1489 if (!empty($template->id)) {
1490 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
1491 $email_params['user_name'] = Helper::getUserName($patient->id);
1492 $email_params['hospital_name'] = Helper::getUserName($hospital->id);
1493 $email_params['hospital_link'] = url('profile/' . $hospital->slug);
1494 $email_params['doctor_name'] = Helper::getUserName($doctor->id);
1495 $email_params['doctor_link'] = url('profile/' . $doctor->slug);
1496 $email_params['appointment_date_time'] = Carbon::parse($appointment['appointment_date'])->format('d M, Y') . ' ' . $appointment['appointment_time'];
1497 $email_params['description'] = $appointment['comments'];
1498 Mail::to($patient->email)
1499 ->send(
1500 new GeneralEmailMailable(
1501 'user_email_appointment_request_approved',
1502 $template_data,
1503 $email_params
1504 )
1505 );
1506 } elseif ($status == 'rejected') {
1507 $email_params = array();
1508 $template = DB::table('email_types')->select('id')->where('email_type', 'user_email_appointment_request_rejected')->get()->first();
1509 if (!empty($template->id)) {
1510 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
1511 $email_params['user_name'] = Helper::getUserName($patient->id);
1512 $email_params['doctor_name'] = Helper::getUserName($doctor->id);
1513 Mail::to($patient->email)
1514 ->send(
1515 new GeneralEmailMailable(
1516 'user_email_appointment_request_rejected',
1517 $template_data,
1518 $email_params
1519 )
1520 );
1521 }
1522 }
1523 }
1524 }
1525 $json['type'] = 'success';
1526 $json['message'] = trans('lang.appointment_updated');
1527 $json['status'] = trans($status);
1528 return Response::json($json, 200);
1529 } else {
1530 $json['type'] = 'error';
1531 $json['message'] = trans('lang.something');
1532 return Response::json($json, 203);
1533 }
1534 }
1535
1536 /**
1537 * Get appoinetments for specific date
1538 *
1539 * @param \Illuminate\Http\Request $request request attributes
1540 *
1541 * @access public
1542 *
1543 * @return \Illuminate\Http\Response
1544 */
1545 public function getPatientAppointments(Request $request)
1546 {
1547 $json = array();
1548 $list = array();
1549 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1550 $appointment_date = !empty($_GET['appointment_date']) ? $_GET['appointment_date'] : '';
1551 $booking_settings = SiteManagement::getMetaValue('booking_settings');
1552 $online_payment = !empty($booking_settings['enable_booking']) ? $booking_settings['enable_booking'] : '';
1553 if (!empty($user_id)) {
1554 $user = User::find($user_id);
1555 $counter = 0;
1556 $orders = DB::table('appointments')->where('patient_id', $user_id);
1557 if ($online_payment == 'true') {
1558 $orders = $orders->where('status', 'accepted');
1559 }
1560 if (!empty($appointment_date)) {
1561 $orders = $orders->where('appointment_date', $appointment_date);
1562 }
1563 $orders = $orders->get();
1564 if (!empty($orders)) {
1565 foreach ($orders as $key => $appointment) {
1566 if (!empty($appointment)) {
1567 $doctor = !empty($appointment->user_id) ? User::find($appointment->user_id) : '';
1568 $services = !empty($appointment->services) ? Helper::getUnserializeData($appointment->services) : '';
1569 $list[$counter]['appointments'] = $orders->count();
1570 $list[$counter]['user_id'] = !empty($appointment->patient_id) ? $appointment->patient_id : '';
1571 $list[$counter]['id'] = $appointment->id;
1572 $list[$counter]['status'] = $appointment->status;
1573 $list[$counter]['user_name'] = !empty($doctor) && !empty($appointment->user_id)
1574 ? Helper::getUserName($appointment->user_id) : '';
1575 $list[$counter]['patient_name'] = !empty($appointment->patient_name)
1576 ? $appointment->patient_name : '';
1577 $list[$counter]['relation'] = !empty($appointment->relation)
1578 ? $appointment->relation : '';
1579 $list[$counter]['user_image'] = !empty($doctor)
1580 ? asset(Helper::getImage('uploads/users/' . $doctor->id, $doctor->profile->avatar, 'small-', 'user.jpg'))
1581 : '';
1582 $list[$counter]['user_verify'] = !empty($doctor) ? $doctor->user_verified : 0;
1583 $list[$counter]['user_location'] = !empty($doctor->location) && $doctor->location->count() > 0 ? $doctor->location->title : '';
1584 $list[$counter]['user_type'] = !empty($doctor) ? $doctor->getRoleNames()->first() : '';
1585 $list[$counter]['hospital'] = !empty($appointment->hospital_id) ? Helper::getUserName($appointment->hospital_id) : '';
1586 $date = $appointment->appointment_date;
1587 $patient_date = new Carbon($appointment->appointment_date);
1588 $patient_appointment_date = explode("-", $date);
1589 $list[$counter]['day'] = !empty($patient_appointment_date) ? $patient_appointment_date[2] : '';
1590 $list[$counter]['month'] = !empty($patient_date) ? $patient_date->format('M') : '';
1591 $list[$counter]['appointment_date'] = !empty($appointment->appointment_date) ? $appointment->appointment_date : '';
1592 $list[$counter]['appointment_time'] = !empty($appointment->appointment_time) ? $appointment->appointment_time : '';
1593 }
1594 $counter++;
1595 }
1596 return Response::json($list, 200);
1597 } else {
1598 $json['type'] = 'error';
1599 $json['message'] = trans('lang.something');
1600 return Response::json($json, 203);
1601 }
1602 } else {
1603 $json['type'] = 'error';
1604 $json['message'] = trans('lang.something');
1605 return Response::json($json, 203);
1606 }
1607 }
1608
1609 /**
1610 * Get appoinetments for specific date
1611 *
1612 * @param \Illuminate\Http\Request $request request attributes
1613 *
1614 * @access public
1615 *
1616 * @return \Illuminate\Http\Response
1617 */
1618 public function getPatientAppointmentSingle(Request $request)
1619 {
1620 $json = array();
1621 $list = array();
1622 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1623 $booking_id = !empty($_GET['booking_id']) ? $_GET['booking_id'] : '';
1624 if (!empty($booking_id)) {
1625 $appointment = Appointment::find($booking_id);
1626 if (!empty($appointment)) {
1627 $doctor = !empty($appointment->user_id) ? User::find($appointment->user_id) : '';
1628 $services = !empty($appointment->services) ? Helper::getUnserializeData($appointment->services) : '';
1629 $list['user_id'] = !empty($appointment->patient_id) ? $appointment->patient_id : '';
1630 $list['id'] = $appointment->id;
1631 $list['status'] = $appointment->status;
1632 $list['user_name'] = !empty($doctor) && !empty($appointment->user_id)
1633 ? Helper::getUserName($appointment->user_id) : '';
1634 $list['patient_name'] = !empty($appointment->patient_name)
1635 ? $appointment->patient_name : '';
1636 $list['relation'] = !empty($appointment->relation)
1637 ? $appointment->relation : '';
1638 $list['user_image'] = !empty($doctor)
1639 ? asset(Helper::getImage('uploads/users/' . $doctor->id, $doctor->profile->avatar, 'small-', 'user.jpg'))
1640 : '';
1641 $list['user_verify'] = !empty($doctor) ? $doctor->user_verified : 0;
1642 $list['user_location'] = !empty($doctor->location) && $doctor->location->count() > 0 ? $doctor->location->title : '';
1643 $list['user_type'] = !empty($doctor) ? $doctor->getRoleNames()->first() : '';
1644 $list['hospital'] = !empty($appointment->hospital_id) ? Helper::getUserName($appointment->hospital_id) : '';
1645 $date = $appointment->appointment_date;
1646 $patient_date = new Carbon($appointment->appointment_date);
1647 $patient_appointment_date = explode("-", $date);
1648 $day = !empty($patient_appointment_date) ? $patient_appointment_date[2] : '';
1649 $month = !empty($patient_date) ? $patient_date->format('F') : '';
1650 $year = !empty($patient_appointment_date) ? $patient_appointment_date[0] : '';
1651 $time = !empty($appointment->appointment_time) ? $appointment->appointment_time : '';
1652 $list['slots'] = $month . ' ' . $day . ', ' . $year . '-' . $time;
1653 $list['content'] = !empty($appointment->comments) ? $appointment->comments : '';
1654 if (!empty($services)) {
1655 foreach ($services as $service_key => $service) {
1656 if (!empty($service['service'])) {
1657 $speciality = Helper::getSpecialityByID($service['speciality']);
1658 $list['appointment_services'][$service_key]['speciality'] = !empty($speciality) ? $speciality->title : '';
1659 foreach ($service['service'] as $speciality_service_key => $speciality_service) {
1660 $service = Helper::getServiceByID($speciality_service);
1661 if (!empty($service)) {
1662 $list['appointment_services'][$service_key]['services'][]['title'] = !empty($service) ? $service->title : '';
1663 }
1664 }
1665 }
1666 }
1667 }
1668 }
1669 return Response::json($list, 200);
1670 } else {
1671 $json['type'] = 'error';
1672 $json['message'] = trans('lang.something');
1673 return Response::json($json, 203);
1674 }
1675 }
1676
1677 /**
1678 * Get forum settings data
1679 *
1680 * @access public
1681 *
1682 * @return \Illuminate\Http\Response
1683 */
1684 public function getForumSettings()
1685 {
1686 $json = array();
1687 $forum_settings = SiteManagement::getMetaValue('forum_settings');
1688 $forum_banner_image = !empty($forum_settings) && !empty($forum_settings['hidden_forum_banner_image']) ? $forum_settings['hidden_forum_banner_image'] : '';
1689 $forum_banner_title = !empty($forum_settings) && !empty($forum_settings['forum_banner_title']) ? $forum_settings['forum_banner_title'] : '';
1690 $forum_banner_subtitle = !empty($forum_settings) && !empty($forum_settings['forum_banner_subtitle']) ? $forum_settings['forum_banner_subtitle'] : '';
1691 $forum_banner_desc = !empty($forum_settings) && !empty($forum_settings['forum_banner_desc']) ? $forum_settings['forum_banner_desc'] : '';
1692 if (!empty($forum_settings)) {
1693 $forum_settings = array();
1694 $forum_settings['hf_title'] = $forum_banner_title;
1695 $forum_settings['hf_sub_title'] = $forum_banner_subtitle;
1696 $forum_settings['hf_description'] = $forum_banner_desc;
1697 $forum_settings['hf_btn_text'] = '';
1698 $forum_settings['hf_image'] = asset('uploads/settings/general/' . $forum_banner_image);
1699 return Response::json($forum_settings, 200);
1700 } else {
1701 $json['type'] = 'error';
1702 $json['message'] = trans('lang.no_record');
1703 return Response::json($json, 203);
1704 }
1705 }
1706
1707 /**
1708 * Get Forum list
1709 *
1710 * @access public
1711 *
1712 * @return \Illuminate\Http\Response
1713 */
1714 public function getForumListing()
1715 {
1716 $json = array();
1717 $list = array();
1718 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
1719 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
1720 $sort_by = !empty($_GET['orderby']) ? $_GET['orderby'] : '';
1721 $keyword = !empty($_GET['search']) ? $_GET['search'] : '';
1722 $specialty = !empty($_GET['specialities']) ? $_GET['specialities'] : '';
1723 Paginator::currentPageResolver(
1724 function () use ($page_number) {
1725 return $page_number;
1726 }
1727 );
1728 $forum = new Forum();
1729 if (!empty($keyword)) {
1730 $forum = $forum->where('question_title', 'like', '%' . $keyword . '%');
1731 }
1732 if (!empty($specialty)) {
1733 $forum = $forum->where('speciality_id', $specialty);
1734 }
1735 if (!empty($sort_by)) {
1736 if ($sort_by == 'name') {
1737 $forum = $forum->orderBy('question_title', 'asc');
1738 } elseif ($sort_by == 'date') {
1739 $forum = $forum->orderBy('created_at', 'asc');
1740 } else {
1741 $forum = $forum->orderBy('id', 'asc');
1742 }
1743 }
1744 $forum = $forum->paginate($post_per_page);
1745 if (!empty($forum) && $forum->count() > 0) {
1746 foreach ($forum as $key => $question) {
1747 $speciality = Speciality::find($question->speciality_id);
1748 $speciality_image = !empty($speciality) && !empty($speciality->image) ? $speciality->image : '';
1749 $forum = Forum::findOrFail($question->id);
1750 $list[$key]['image'] = asset(Helper::getImage('uploads/specialities', $speciality_image, 'extra-small-', 'default-speciality.png'));
1751 $list[$key]['title'] = !empty($question->question_title) ? $question->question_title : '';
1752 $list[$key]['content'] = !empty($question->question_description) ? html_entity_decode(clean($question->question_description)) : '';
1753 $list[$key]['ID'] = !empty($question->id) ? $question->id : '';
1754 $list[$key]['post_date'] = Carbon::parse($question->created_at)->format('M d, Y');
1755 $list[$key]['answers'] = $forum->answers->count();
1756 $list[$key]['count'] = Forum::count();
1757 }
1758 return Response::json($list, 200);
1759 } else {
1760 $json['type'] = 'error';
1761 $json['message'] = trans('lang.no_record');
1762 return Response::json($json, 203);
1763 }
1764 }
1765
1766 /**
1767 * Display the specified resource.
1768 *
1769 * @param string $slug slug
1770 *
1771 * @return view
1772 */
1773 public function getForumAnswers()
1774 {
1775 $json = array();
1776 $data = array();
1777 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
1778 $id = !empty($_GET['id']) ? $_GET['id'] : '';
1779 if (!empty($id)) {
1780 $auth_user = User::find($user_id);
1781 $forum = Forum::findOrFail($id);
1782 $user = $forum->questioner->count() > 0 ? User::findOrFail($forum->questioner->first()->id) : '';
1783 $liked_answers = !empty($auth_user->profile->liked_answers) ? unserialize($auth_user->profile->liked_answers) : array();
1784 if ($forum->answers->count() > 0 && !empty($forum->answers)) {
1785 foreach ($forum->answers as $key => $answer) {
1786 $user = User::find($answer->pivot->user_id);
1787 $data[$key]['user_image'] = asset(Helper::getImage('uploads/users/'.$user->id, $user->profile->avatar, 'small-', 'user.jpg'));
1788 $data[$key]['user_name'] = Helper::getUserName($user->id);
1789 $data[$key]['gender_title'] = !empty($user->profile->gender_title) ? $user->profile->gender_title : '';
1790 $data[$key]['verifyUser'] = $user->user_verified;
1791 if (in_array($answer->pivot->id, $liked_answers)) {
1792 $data[$key]['liked'] = 'yes';
1793 } else {
1794 $data[$key]['liked'] = 'no';
1795 }
1796 $data[$key]['answer'] = $answer->pivot->answer;
1797 }
1798 return Response::json($data, 200);
1799 } else {
1800 $json['type'] = 'error';
1801 $json['message'] = trans('lang.no_record');
1802 return Response::json($json, 203);
1803 }
1804 } else {
1805 $json['type'] = 'error';
1806 $json['message'] = trans('lang.no_record');
1807 return Response::json($json, 203);
1808 }
1809 }
1810
1811 /**
1812 * Get Forum list
1813 *
1814 * @access public
1815 *
1816 * @return \Illuminate\Http\Response
1817 */
1818 public function getSpecilities()
1819 {
1820 $json = array();
1821 $list = array();
1822 $specialities = Speciality::all();
1823 if (!empty($specialities) && $specialities->count() > 0) {
1824 foreach ($specialities as $key => $speciality) {
1825 $list[$key]['id'] = $speciality->id;
1826 $list[$key]['name'] = $speciality->title;
1827 $list[$key]['slug'] = $speciality->slug;
1828 $list[$key]['url'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
1829 $random_color = array(
1830 'f44336', 'E91E63', '9C27B0', '673AB7', '3F51B5', '2196F3', '03A9F4', '00BCD4', '009688', '4CAF50',
1831 '8BC34A', 'AFB42B', 'FBC02D', 'FFB300', 'FB8C00', 'F4511E', '795548', '757575', '607D8B', 'ff5252',
1832 'D500F9', '448AFF', '00B8D4', '00C853', 'FFAB00'
1833 );
1834 // $rand_color = '#' . dechex(mt_rand(0, 16777215));
1835 $color_key = array_rand($random_color, 1);
1836 $list[$key]['color'] = '#' . $random_color[$color_key];
1837 }
1838 return Response::json($list, 200);
1839 } else {
1840 $json['type'] = 'error';
1841 $json['message'] = trans('lang.no_record');
1842 return Response::json($json, 203);
1843 }
1844 }
1845
1846 /**
1847 * Create a new user instance after a valid registration.
1848 *
1849 * @param array $request returns request
1850 *
1851 * @return \App\User
1852 */
1853 public function removeAccount(Request $request)
1854 {
1855 if (!empty($request['user_id'])) {
1856 $this->validate(
1857 $request,
1858 [
1859 'old_password' => 'required',
1860 'retype_password' => 'required',
1861 ]
1862 );
1863 $json = array();
1864 $user_id = $request['user_id'];
1865 $user = User::find($user_id);
1866 if (Hash::check($request->old_password, $user->password)) {
1867 if (!empty($user_id)) {
1868 $user->profile()->delete();
1869 $user->roles()->detach();
1870 DB::table('appointments')->where('user_id', $user_id)
1871 ->orWhere('hospital_id', $user_id)->orWhere('patient_id', $user_id)->delete();
1872 if ($user->articles->count() > 0) {
1873 foreach ($user->articles as $user_article) {
1874 $article = Article::find($user_article->id);
1875 if ($article->categories->count() > 0) {
1876 $article->categories()->detach();
1877 }
1878 }
1879 $user->articles()->delete();
1880 }
1881 DB::table('feedbacks')->where('user_id', $user_id)
1882 ->orWhere('patient_id', $user_id)->delete();
1883 DB::table('messages')->where('user_id', $user_id)
1884 ->orWhere('receiver_id', $user_id)->delete();
1885 if ($user->orders->count() > 0) {
1886 foreach ($user->orders as $user_orders) {
1887 DB::table('order_metas')->where('metable_id', $user_orders->id)->delete();
1888 }
1889 $user->orders()->delete();
1890 }
1891 DB::table('payouts')->where('user_id', $user_id)->delete();
1892 DB::table('teams')->where('user_id', $user_id)
1893 ->orWhere('doctor_id', $user_id)->delete();
1894 $user->services()->detach();
1895 if ($user->question->count() > 0) {
1896 foreach ($user->question as $form) {
1897 DB::table('forums')->where('id', $form->id)->delete();
1898 DB::table('user_forum')->where('forum_id', $form->id)->delete();
1899 }
1900 }
1901 DB::table('user_forum')->where('user_id', $user_id)->where('type', 'answer')->delete();
1902 $user->delete();
1903 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
1904 $delete_reason = Helper::getDeleteAccReason($request['delete_reason']);
1905 $email_params = array();
1906 $template = DB::table('email_types')->select('id')->where('email_type', 'admin_email_delete_account')->get()->first();
1907 if (!empty($template->id)) {
1908 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
1909 $email_params['reason'] = $delete_reason;
1910 Mail::to(config('mail.username'))
1911 ->send(
1912 new AdminEmailMailable(
1913 'admin_email_delete_account',
1914 $template_data,
1915 $email_params
1916 )
1917 );
1918 }
1919 }
1920 Auth::logout();
1921 $json['acc_del'] = trans('lang.acc_deleted');
1922 return Response::json($json, 200);
1923 } else {
1924 $json['type'] = 'warning';
1925 $json['msg'] = trans('lang.something_wrong');
1926 return Response::json($json, 203);
1927 }
1928 } else {
1929 $json['type'] = 'warning';
1930 $json['msg'] = trans('lang.pass_mismatched');
1931 return Response::json($json, 203);
1932 }
1933 } else {
1934 $json['type'] = 'error';
1935 $json['message'] = trans('lang.no_record');
1936 return Response::json($json, 203);
1937 }
1938 }
1939
1940 /**
1941 * Create a new user instance after a valid registration.
1942 *
1943 * @param array $request returns request
1944 *
1945 * @return \App\User
1946 */
1947 public function submitQuestion(Request $request)
1948 {
1949 $json = array();
1950 if (!empty($request['user_id'])) {
1951 $server = Helper::doctieIsDemoSiteAjax();
1952 if (!empty($server)) {
1953 $response['type'] = 'error';
1954 $response['message'] = $server->getData()->message;
1955 return $response;
1956 }
1957 if (empty($request['speciality'])) {
1958 $response['type'] = 'error';
1959 $response['message'] = trans('lang.speciality_required');
1960 return Response::json($json, 203);
1961 }
1962 if (empty($request['question_title'])) {
1963 $response['type'] = 'error';
1964 $response['message'] = trans('lang.title_required');
1965 return Response::json($json, 203);
1966 }
1967 if (empty($request['question_desc'])) {
1968 $response['type'] = 'error';
1969 $response['message'] = trans('lang.desc_required');
1970 return Response::json($json, 203);
1971 }
1972 $form = new Forum();
1973 $post_quation = $form->postAPIQuestion($request, $request['user_id']);
1974 if ($post_quation == 'success') {
1975 $json['type'] = 'success';
1976 $json['message'] = trans('lang.quest_post_success');
1977 return Response::json($json, 200);
1978 } else {
1979 $json['type'] = 'error';
1980 $json['message'] = trans('lang.something_went_wrong');
1981 return Response::json($json, 203);
1982 }
1983 } else {
1984 $json['type'] = 'error';
1985 $json['message'] = trans('lang.need_to_reg');
1986 return Response::json($json, 203);
1987 }
1988 }
1989
1990 /**
1991 * Post Answer.
1992 *
1993 * @param \Illuminate\Http\Request $request request attributes
1994 *
1995 * @return \Illuminate\Http\Response
1996 */
1997 public function postAnswer(Request $request)
1998 {
1999 $server = Helper::doctieIsDemoSiteAjax();
2000 if (!empty($server)) {
2001 $response['type'] = 'error';
2002 $response['message'] = $server->getData()->message;
2003 return $response;
2004 }
2005 if (!empty($request['user_id'])) {
2006 if (empty($request['forum_answer'])) {
2007 $response['type'] = 'error';
2008 $response['message'] = trans('lang.empty_field');
2009 return Response::json($json, 203);
2010 }
2011 if (empty($request['forum_id'])) {
2012 $response['type'] = 'error';
2013 $response['message'] = trans('lang.empty_field');
2014 return Response::json($json, 203);
2015 }
2016 $form = new Forum();
2017 $post_answer = $form->postAPIQuestion($request);
2018 if ($post_answer === 'success') {
2019 $json['type'] = 'success';
2020 $json['message'] = trans('lang.answer_post_success');
2021 return Response::json($json, 200);
2022 } else {
2023 $response['type'] = 'error';
2024 $response['message'] = trans('lang.something_went_wrong');
2025 return Response::json($json, 203);
2026 }
2027 } else {
2028 $response['type'] = 'error';
2029 $response['message'] = trans('lang.need_to_reg');
2030 return Response::json($json, 203);
2031 }
2032 }
2033
2034 /**
2035 * Store data in storage
2036 *
2037 * @param \Illuminate\Http\Request $request request attributes
2038 *
2039 * @access public
2040 *
2041 * @return \Illuminate\Http\Response
2042 */
2043 public function bookAppointment(Request $request)
2044 {
2045 $json = array();
2046 $appointment_data = array();
2047 if ($request['patient'] == 'someone') {
2048 if (empty($request['patient_name'])) {
2049 $json['type'] = 'error';
2050 $json['message'] = trans('lang.patient_name_req');
2051 return Response::json($json, 203);
2052 }
2053 if (empty($request['relation'])) {
2054 $json['type'] = 'error';
2055 $json['message'] = trans('lang.select_relation_req');
2056 return Response::json($json, 203);
2057 }
2058 }
2059 if (empty($request['hospital'])) {
2060 $json['type'] = 'error';
2061 $json['message'] = trans('lang.hospital_req');
2062 return Response::json($json, 203);
2063 }
2064 if (empty($request['time'])) {
2065 $json['type'] = 'error';
2066 $json['message'] = trans('lang.select_appointment_time');
2067 return Response::json($json, 203);
2068 }
2069 if (empty($request['doctor_id'])) {
2070 $json['type'] = 'error';
2071 $json['message'] = trans('lang.doctor_id_req');
2072 return Response::json($json, 203);
2073 }
2074 if (empty($request['patient_id'])) {
2075 $json['type'] = 'error';
2076 $json['message'] = trans('lang.patient_id_req');
2077 return Response::json($json, 203);
2078 }
2079 $appointment_speciality = array();
2080 $specialities = !empty($request['speciality']) ? $request['speciality'] : '';
2081 if (!empty($specialities)) {
2082 foreach ($specialities as $key => $speciality) {
2083 $appointment_speciality[$key]['speciality'] = $speciality['speciality'];
2084 if (!empty($speciality['service'])) {
2085 foreach ($speciality['service'] as $service_key => $services) {
2086 $appointment_speciality[$key]['service'][$service_key] = $services;
2087 }
2088 }
2089 }
2090 }
2091 $appointment_data['patient'] = !empty($request['patient']) ? $request['patient'] : '';
2092 $appointment_data['patient_name'] = !empty($request['patient_name']) ? $request['patient_name'] : '';
2093 $appointment_data['relation'] = !empty($request['relation']) ? $request['relation'] : '';
2094 $appointment_data['hospital'] = !empty($request['hospital']) ? $request['hospital'] : '';
2095 $appointment_data['speciality'] = $appointment_speciality;
2096 $appointment_data['total_charges'] = !empty($request['total_charges']) ? $request['total_charges'] : '';
2097 $appointment_data['comments'] = !empty($request['comments']) ? $request['comments'] : '';
2098 $appointment_data['day'] = !empty($request['day']) ? $request['day'] : '';
2099 $appointment_data['date'] = !empty($request['date']) ? $request['date'] : '';
2100 $appointment_data['time'] = !empty($request['time']) ? $request['time'] : '';
2101 $appointment_data['doctor_id'] = !empty($request['doctor_id']) ? $request['doctor_id'] : '';
2102 $appointment_data['patient_id'] = !empty($request['patient_id']) ? $request['patient_id'] : '';
2103 $appointment = new Appointment();
2104 $patient_appointment = $appointment->submitAppointmentAPI($appointment_data);
2105 if ($patient_appointment['type'] == 'success') {
2106 $json['appointment_id'] = $patient_appointment['last_id'];
2107 $json['type'] = 'success';
2108 return Response::json($json, 200);
2109 } else {
2110 $json['type'] = 'error';
2111 $json['message'] = trans('lang.something_went_wrong');
2112 return Response::json($json, 203);
2113 }
2114 }
2115
2116 /**
2117 * Verify Password
2118 *
2119 * @param \Illuminate\Http\Request $request request attributes
2120 *
2121 * @access public
2122 *
2123 * @return \Illuminate\Http\Response
2124 */
2125 public function verifyAppointmentPassword(Request $request)
2126 {
2127 $server = Helper::doctieIsDemoSiteAjax();
2128 if (!empty($server)) {
2129 $response['type'] = 'error';
2130 $response['message'] = $server->getData()->message;
2131 return $response;
2132 }
2133 $json = array();
2134 $user = User::find($request['user_id']);
2135 if (Hash::check($request->password, $user->password)) {
2136 $random_number = Helper::generateRandomCode(4);
2137 $verification_code = strtoupper($random_number);
2138 $user->verification_code = $verification_code;
2139 $user->save();
2140 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
2141 $email_params = array();
2142 $template = DB::table('email_types')->select('id')
2143 ->where('email_type', 'user_email_appointment_booking_verification_code')->get()->first();
2144 if (!empty($template->id)) {
2145 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
2146 $email_params['verification_code'] = $user->verification_code;
2147 $email_params['name'] = Helper::getUserName($user->id);
2148 Mail::to($user->email)
2149 ->send(
2150 new GeneralEmailMailable(
2151 'user_email_appointment_booking_verification_code',
2152 $template_data,
2153 $email_params
2154 )
2155 );
2156 }
2157 }
2158 $json['type'] = 'success';
2159 return Response::json($json, 200);
2160 } else {
2161 $json['type'] = 'error';
2162 $json['message'] = trans('lang.pass_mismatched');
2163 return Response::json($json, 203);
2164 }
2165 }
2166
2167 /**
2168 * Verify Code
2169 *
2170 * @param mixed $request $request->attr
2171 *
2172 * @return \Illuminate\Http\Response
2173 */
2174 public function verifyAppointmentCode(Request $request)
2175 {
2176 $user = User::findOrFail($request['user_id']);
2177 if (!empty($user) && !empty($request['code'])) {
2178 if ($request['code'] === $user->verification_code) {
2179 $user->verification_code = null;
2180 $user->save();
2181 $json['type'] = 'success';
2182 return Response::json($json, 200);
2183 } else {
2184 $json['type'] = 'error';
2185 $json['message'] = trans('lang.verify_code_mismatched');
2186 return Response::json($json, 203);
2187 }
2188 } else {
2189 $json['type'] = 'error';
2190 $json['message'] = trans('lang.verify_code');
2191 return Response::json($json, 203);
2192 }
2193 }
2194
2195 /**
2196 * Get doctor locations
2197 *
2198 * @access public
2199 *
2200 * @return \Illuminate\Http\Response
2201 */
2202 public function getAppointmentHospitals()
2203 {
2204 $json = array();
2205 $doctor_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
2206 if (!empty($doctor_id)) {
2207 $doctor_hospitals = Team::getDoctorHospitals($doctor_id);
2208 if (!empty($doctor_hospitals)) {
2209 foreach ($doctor_hospitals as $key => $hospital) {
2210 $json[$key]['id'] = $hospital['id'];
2211 $json[$key]['name'] = $hospital['name'];
2212 }
2213 return Response::json($json, 200);
2214 } else {
2215 $json['type'] = 'error';
2216 $json['message'] = trans('lang.no_record');
2217 return Response::json($json, 203);
2218 }
2219 } else {
2220 $json['type'] = 'error';
2221 $json['message'] = trans('lang.doctor_id_req');
2222 return Response::json($json, 203);
2223 }
2224 }
2225
2226 /**
2227 * Get doctor hospital services
2228 *
2229 * @param \Illuminate\Http\Request $request request attributes
2230 *
2231 * @access public
2232 *
2233 * @return \Illuminate\Http\Response
2234 */
2235 public function getHospitalServices(Request $request)
2236 {
2237 $json = array();
2238 $hospital_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
2239 if (!empty($hospital_id)) {
2240 $team_info = Team::where('user_id', $hospital_id)->first();
2241 if (!empty($team_info)) {
2242 $slots = Helper::getUnserializeData($team_info['slots']);
2243 $list = array();
2244 if (!empty($slots['services'])) {
2245 $count = 0;
2246 foreach ($slots['services']['speciality'] as $key => $specialities) {
2247 if (!empty($specialities['speciality_services'])) {
2248 if ($key == 0) {
2249 foreach ($slots['days'] as $slot_key => $day) {
2250 $list[$count]['fee'] = !empty($slots[$day]['consultation_fee'])
2251 ? $slots[$day]['consultation_fee']
2252 : '0';
2253 }
2254 }
2255 $speciality = Speciality::find($specialities['speciality_id']);
2256 if (!empty($speciality)) {
2257 $counter = 0;
2258 $list[$count]['speciality_id'] = $speciality->id;
2259 $list[$count]['speciality_title'] = $speciality->title;
2260 $list[$count]['speciality_image'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
2261 foreach ($specialities['speciality_services'] as $service_key => $services) {
2262 $service = Helper::getServiceByID($services['service']);
2263 if (!empty($service)) {
2264 $list[$count]['services'][$counter]['service_id'] = $service->id;
2265 $list[$count]['services'][$counter]['service_title'] = $service->title;
2266 $list[$count]['services'][$counter]['service_price'] = $services['price'];
2267 }
2268 $counter++;
2269 }
2270 }
2271 $count++;
2272 }
2273 }
2274 return Response::json($list, 200);
2275 } else {
2276 $json['type'] = 'error';
2277 $json['message'] = trans('lang.service_not_found');
2278 return Response::json($json, 203);
2279 }
2280 } else {
2281 $json['type'] = 'error';
2282 $json['message'] = trans('lang.something');
2283 return Response::json($json, 203);
2284 }
2285 } else {
2286 $json['type'] = 'error';
2287 $json['message'] = trans('lang.hospital_req');
2288 return Response::json($json, 203);
2289 }
2290 }
2291
2292 /**
2293 * Get doctor's appointment slots
2294 *
2295 * @param \Illuminate\Http\Request $request request attributes
2296 *
2297 * @access public
2298 *
2299 * @return \Illuminate\Http\Response
2300 */
2301 public function getAppointmentSlots(Request $request)
2302 {
2303 $json = array();
2304 $list = array();
2305 $hospital_id = !empty($_GET['hospital_id']) ? $_GET['hospital_id'] : '';
2306 $doctor_id = !empty($_GET['doctor_id']) ? $_GET['doctor_id'] : '';
2307 $appointment_date = !empty($_GET['date']) ? $_GET['date'] : '';
2308 $appointment_day = !empty($_GET['day']) ? $_GET['day'] : '';
2309 if (empty($_GET['doctor_id'])) {
2310 $json['type'] = 'error';
2311 $json['message'] = trans('lang.doctor_id_req');
2312 return Response::json($json, 203);
2313 }
2314 if (empty($_GET['hospital_id'])) {
2315 $json['type'] = 'error';
2316 $json['message'] = trans('lang.hospital_req');
2317 return Response::json($json, 203);
2318 }
2319 if (empty($_GET['date'])) {
2320 $json['type'] = 'error';
2321 $json['message'] = trans('lang.doctor_id_req');
2322 return Response::json($json, 203);
2323 }
2324 if (empty($_GET['day'])) {
2325 $json['type'] = 'error';
2326 $json['message'] = trans('lang.hospital_req');
2327 return Response::json($json, 203);
2328 }
2329 if (!empty($doctor_id) && !empty($hospital_id)) {
2330 $hospital = Team::select('slots')->where('doctor_id', $doctor_id)->where('user_id', $hospital_id)->first();
2331 if (!empty($hospital)) {
2332 $requested_date = Carbon::create($appointment_date);
2333 $date = new Carbon();
2334 $today = $date->now();
2335 $slots = Helper::getUnserializeData($hospital->slots);
2336 $requested_day_slots = !empty($slots[$appointment_day]) ? $slots[$appointment_day]['slots'] : array();
2337 if (!empty($requested_day_slots)) {
2338 $counter = 0;
2339 foreach ($requested_day_slots as $key => $slot) {
2340 $time = explode('-', $key);
2341 $list[$counter]['start_time'] = $time[0];
2342 $bocked_appointments = DB::table('appointments')->where('appointment_time', $time[0])->count();
2343 if ($requested_date->lessThan($today)) {
2344 $list[$counter]['space'] = 0;
2345 } else if ($bocked_appointments > 0) {
2346 $list[$counter]['space'] = $slot['space'] - $bocked_appointments;
2347 } else {
2348 $list[$counter]['space'] = (int) ($slot['space']);
2349 }
2350 $counter++;
2351 }
2352 }
2353 return Response::json($list, 200);
2354 }
2355 } else {
2356 $json['type'] = 'error';
2357 $json['message'] = trans('lang.something');
2358 return Response::json($json, 203);
2359 }
2360 }
2361
2362 /**
2363 * Stote appointment location data in storage
2364 *
2365 * @param mixed $request get req attributes
2366 *
2367 * @access public
2368 *
2369 * @return \Illuminate\Http\Response
2370 */
2371 public function storeAppointmentLocation(Request $request)
2372 {
2373 $server = Helper::doctieIsDemoSiteAjax();
2374 if (!empty($server)) {
2375 $response['type'] = 'error';
2376 $response['message'] = $server->getData()->message;
2377 return Response::json($response, 203);
2378 }
2379 if (!empty($_GET['user_id'])) {
2380 $hospital_location = Team::where('user_id', $_GET['hospital_id'])->where('doctor_id', $_GET['user_id'])->count();
2381 if ($hospital_location > 0) {
2382 $response['type'] = 'error';
2383 $response['message'] = trans('lang.hospital_already_selected');
2384 return Response::json($response, 203);
2385 }
2386 $location = new Team();
2387 $team = $location->saveAppointmentLocation($_GET, $_GET['user_id']);
2388 if ($team == "success") {
2389 //send email to hospital
2390 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
2391 $hospital = User::findOrFail($_GET['hospital_id']);
2392 $slots = $_GET['slots'];
2393 $days = $slots['appointment_days'];
2394 $email_params = array();
2395 $email_params['starttime'] = $slots['start_time'];
2396 $email_params['endtime'] = $slots['end_time'];
2397 $email_params['appt_intervals'] = $slots['intervals'];
2398 $email_params['appt_duration'] = $slots['duration'];
2399 $email_params['appt_days'] = implode(',', $days);
2400 $template_data = Helper::getEmailContent();
2401 Mail::to($hospital->email)
2402 ->send(
2403 new HospitalEmailMailable(
2404 'hospital_appointment_locations_added',
2405 $template_data,
2406 $email_params
2407 )
2408 );
2409 Mail::to(config('mail.username'))
2410 ->send(
2411 new HospitalEmailMailable(
2412 'hospital_appointment_locations_added',
2413 $template_data,
2414 $email_params
2415 )
2416 );
2417 $req_template = DB::table('email_types')->select('id')
2418 ->where('email_type', 'hospital_email_doctor_request_to_hospital')->get()->first();
2419 if (!empty($req_template->id)) {
2420 $doctor = User::find($_GET['user_id']);
2421 $template_data = EmailTemplate::getEmailTemplateByID($req_template->id);
2422 $email_params['doctor_name'] = Helper::getUserName($doctor->id);
2423 $email_params['hospital_name'] = Helper::getUserName($hospital->id);
2424 $email_params['doctor_link'] = url('profile/' . $doctor->slug);
2425 Mail::to($hospital->email)
2426 ->send(
2427 new HospitalEmailMailable(
2428 'hospital_email_doctor_request_to_hospital',
2429 $template_data,
2430 $email_params
2431 )
2432 );
2433 }
2434 }
2435 $json['type'] = 'success';
2436 $json['progressing'] = trans('lang.saving');
2437 $json['message'] = trans('lang.apt_location_saved');
2438 return Response::json($json, 200);
2439 } else {
2440 $json['type'] = 'error';
2441 return Response::json($json, 203);
2442 }
2443 } else {
2444 $json['type'] = 'error';
2445 $json['message'] = trans('lang.something_wrong');
2446 return Response::json($json, 203);
2447 }
2448 }
2449
2450 /**
2451 * Get doctor locations
2452 *
2453 * @access public
2454 *
2455 * @return \Illuminate\Http\Response
2456 */
2457 public function getAppointmentLocation()
2458 {
2459 $json = array();
2460 $user_id = !empty($_GET['doctor_id']) ? $_GET['doctor_id'] : '';
2461 if (!empty($user_id)) {
2462 $locations = Team::where('doctor_id', $user_id)->paginate(4);
2463 if (!empty($locations) && $locations->count() > 0) {
2464 foreach ($locations as $key => $location) {
2465 $team = Team::findOrFail($location->id);
2466 $slots = unserialize($team->slots);
2467 $appointment_days = !empty($slots['days']) ? $slots['days'] : array();
2468 $json[$key]['image'] = asset(Helper::getImage('uploads/users/' . $team->hospital->id, $team->hospital->profile->avatar, 'medium-', 'user.jpg'));
2469 $json[$key]['status'] = $team->status;
2470 $json[$key]['user_name'] = Helper::getUserName($team->hospital->id);
2471 $json[$key]['verify'] = $team->hospital->user_verified;
2472 $json[$key]['location_id'] = $team->id;
2473 if (!empty($appointment_days)) {
2474 foreach (Helper::getAppointmentDays() as $day_key => $day) {
2475 if (in_array($day_key, $appointment_days)) {
2476 $json[$key]['day'][]['title'] = html_entity_decode(clean($day['title']));
2477 }
2478 }
2479 }
2480 }
2481 return Response::json($json, 200);
2482 } else {
2483 $json['type'] = 'error';
2484 $json['message'] = trans('lang.no_record');
2485 return Response::json($json, 203);
2486 }
2487 } else {
2488 $json['type'] = 'error';
2489 $json['message'] = trans('lang.doctor_id_req');
2490 return Response::json($json, 203);
2491 }
2492 }
2493
2494 /**
2495 * Edit doctor appoinement location.
2496 *
2497 * @param string $id id
2498 *
2499 * @access public
2500 *
2501 * @return View
2502 */
2503 public function getLocationDetail()
2504 {
2505 $json = array();
2506 $id = !empty($_GET['id']) ? $_GET['id'] : '';
2507 $day_counter = 0;
2508 $counter = 0;
2509 if (!empty($id)) {
2510 $team = Team::find($id);
2511 if (!empty($team)) {
2512 $slots = unserialize($team->slots);
2513 $days = Helper::getAppointmentDays();
2514 foreach ($days as $key => $value) {
2515 $json['days'][$counter]['title'] = $value['name'];
2516 $counter++;
2517 }
2518 foreach ($slots['days'] as $key => $value) {
2519 $json['selected_day'][$key]['title'] = $value;
2520 }
2521 $json['image'] = asset(Helper::getImage('uploads/users/' . $team->hospital->id, $team->hospital->profile->avatar, 'small-', 'user.jpg'));
2522 $json['status'] = $team->status;
2523 $json['user_name'] = Helper::getUserName($team->hospital->id);
2524 $json['verify'] = $team->hospital->user_verified;
2525 foreach ($days as $key => $day) {
2526 if (!empty($slots[$key]['slots'])) {
2527 // $selected_day = Helper::getAppointmentDays($key);
2528 // $json['selected_day'][$day_counter]['title'] = html_entity_decode(clean($selected_day['name']));
2529 if (!empty($slots[$key]['slots'])) {
2530 $count = 0;
2531 foreach ($slots[$key]['slots'] as $slot_key => $slot) {
2532 $start_slot = explode("-", $slot_key);
2533 $slot_id = $key . '-slot' . '-' . str_replace(array(':', ' '), '', $start_slot[0]);
2534 $json[$key]['slots'][$count]['start_time'] = $start_slot[0];
2535 $json[$key]['slots'][$count]['end_time'] = $start_slot[1];
2536 $json[$key]['slots'][$count]['spaces'] = $slot['space'];
2537 $json[$key]['slots'][$count]['id'] = $slot_id;
2538 $count++;
2539 }
2540 }
2541 } else {
2542 $json[$key]['slots'] = [];
2543 }
2544 $day_counter++;
2545 }
2546
2547 return Response::json($json, 200);
2548 }
2549 } else {
2550 $json['type'] = 'error';
2551 $json['message'] = trans('lang.something_wrong');
2552 return Response::json($json, 203);
2553 }
2554 }
2555
2556 /**
2557 * Edit doctor appoinement location.
2558 *
2559 * @param string $id id
2560 *
2561 * @access public
2562 *
2563 * @return View
2564 */
2565 public function getLocationServices()
2566 {
2567 $json = array();
2568 $id = !empty($_GET['id']) ? $_GET['id'] : '';
2569 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
2570 if (!empty($user_id) && !empty($id)) {
2571 $user = User::find($user_id);
2572 $location = Team::find($id);
2573 $slots = unserialize($location->slots);
2574 $doctor_specialities = !empty($user->profile->services) ? Helper::getUnserializeData($user->profile->services) : array();
2575 $service_price = !empty($slots['services']['price']) ? $slots['services']['price'] : '';
2576 if (!empty($doctor_specialities)) {
2577 foreach ($doctor_specialities as $key => $doctor_speciality) {
2578 $speciality = Helper::getSpecialityByID($doctor_speciality['speciality_id']);
2579 if (!empty($speciality)) {
2580 $json[$key]['id'] = $speciality->id;
2581 $json[$key]['title'] = $speciality->title;
2582 $json[$key]['total_services'] = $speciality->services()->count();
2583 $json[$key]['icon'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
2584 if (!empty($doctor_speciality['services'])) {
2585 foreach ($doctor_speciality['services'] as $service_key => $services) {
2586 $service = Helper::getServiceByID($services['service']);
2587 $checked = !empty($slots['services']['speciality'][$key]['speciality_services'][$service_key]['service']) && $service->id == $slots['services']['speciality'][$key]['speciality_services'][$service_key]['service'] ? true : false;
2588 $json[$key]['services'][$service_key]['id'] = $service->id;
2589 $json[$key]['services'][$service_key]['title'] = $service->title;
2590 $json[$key]['services'][$service_key]['price'] = $service->price;
2591 $json[$key]['services'][$service_key]['selected'] = $checked;
2592 }
2593 }
2594 }
2595 }
2596 return Response::json($json, 200);
2597 } else {
2598 $json['type'] = 'error';
2599 $json['message'] = trans('lang.no_record');
2600 return Response::json($json, 203);
2601 }
2602 } else {
2603 $json['type'] = 'error';
2604 $json['message'] = trans('lang.something_wrong');
2605 return Response::json($json, 203);
2606 }
2607 }
2608
2609 /**
2610 * Delete appointment location time slot
2611 *
2612 * @param string $day day
2613 * @param int $id id
2614 *
2615 * @access public
2616 *
2617 * @return \Illuminate\Http\Response
2618 */
2619 public function deleteAllSlots($day, $id)
2620 {
2621 $day = !empty($_GET['day']) ? $_GET['day'] : '';
2622 $id = !empty($_GET['id']) ? $_GET['id'] : '';
2623 if (Auth::user()) {
2624 if (!empty($day) && !empty($id)) {
2625 $team = new Team();
2626 $team_location = $team->deleteAllAppointmentSlots($day, $id);
2627 if ($team_location == 'success') {
2628 $json['type'] = 'success';
2629 $json['message'] = trans('lang.slot_deleted');
2630 return Response::json($json, 200);
2631 }
2632 } else {
2633 $json['type'] = 'error';
2634 $json['message'] = trans('lang.param_missing');
2635 return Response::json($json, 203);
2636 }
2637 } else {
2638 $json['type'] = 'error';
2639 $json['message'] = trans('lang.something');
2640 return Response::json($json, 203);
2641 }
2642 }
2643
2644 /**
2645 * Delete appointment location selected time slot
2646 *
2647 * @param string $slot slot
2648 * @param string $day day
2649 * @param int $id id
2650 *
2651 * @access public
2652 *
2653 * @return \Illuminate\Http\Response
2654 */
2655 public function deleteSlot()
2656 {
2657 $day = !empty($_GET['day']) ? $_GET['day'] : '';
2658 $slot = !empty($_GET['slot']) ? $_GET['slot'] : '';
2659 $id = !empty($_GET['id']) ? $_GET['id'] : '';
2660 if (Auth::user()) {
2661 $team = new Team();
2662 $team_location = $team->deleteAppointmentSlots($slot, $day, $id);
2663 if ($team_location == 'success') {
2664 $json['type'] = 'success';
2665 $json['message'] = trans('lang.slot_deleted');
2666 return Response::json($json, 200);
2667 }
2668 } else {
2669 $json['type'] = 'error';
2670 $json['message'] = trans('lang.something');
2671 return Response::json($json, 203);
2672 }
2673 }
2674
2675 /**
2676 * Update doctor appointment slots
2677 *
2678 * @param string $id id
2679 * @param mixed $request get req attributes
2680 *
2681 * @access public
2682 *
2683 * @return \Illuminate\Http\Response
2684 */
2685 public function updateSlots()
2686 {
2687 if (Auth::user()) {
2688 $location = new Team();
2689 $update_slots = $location->updateAppointmentSlots($_GET['id'], $_GET);
2690 if ($update_slots == 'success') {
2691 $json['type'] = 'success';
2692 $json['message'] = trans('lang.slot_updated');
2693 return Response::json($json, 200);
2694 }
2695 } else {
2696 $json['type'] = 'error';
2697 $json['message'] = trans('lang.something');
2698 return Response::json($json, 203);
2699 }
2700 }
2701
2702 /**
2703 * Store appointment selected day slots
2704 *
2705 * @param string $id id
2706 * @param \Illuminate\Http\Request $request request attributes
2707 *
2708 * @access public
2709 *
2710 * @return \Illuminate\Http\Response
2711 */
2712 public function storeSelectedDaySlots()
2713 {
2714 if (Auth::user()) {
2715 $location = new Team();
2716 $update_slots = $location->saveSelectedDaySlots($_GET['id'], $_GET);
2717 if ($update_slots == 'success') {
2718 $json['type'] = 'success';
2719 $json['message'] = trans('lang.slot_updated');
2720 return Response::json($json, 200);
2721 }
2722 } else {
2723 $json['type'] = 'error';
2724 $json['message'] = trans('lang.something');
2725 return Response::json($json, 203);
2726 }
2727 }
2728
2729 /**
2730 * Add item in wishlist.
2731 *
2732 * @param mixed $request request->attributes
2733 *
2734 * @return \Illuminate\Http\Response
2735 */
2736 public function addWishlist(Request $request)
2737 {
2738 $server = Helper::doctieIsDemoSiteAjax();
2739 if (!empty($server)) {
2740 $response['message'] = $server->getData()->message;
2741 return $response;
2742 }
2743 $json = array();
2744 $column = !empty($request['column']) ? $request['column'] : '';
2745 $id = !empty($request['id']) ? $request['id'] : '';
2746 $user_id = !empty($request['user_id']) ? $request['user_id'] : '';
2747 if (!empty($user_id)) {
2748 $json['authentication'] = true;
2749 if (!empty($id)) {
2750 if (!empty($column)) {
2751 if ($column === 'saved_hospitals' || $column === 'saved_doctors') {
2752 if ($user_id == $id) {
2753 $json['test'] = 'hello2';
2754 $json['type'] = 'error';
2755 $json['message'] = trans('lang.login_from_different_user');
2756 return Response::json($json, 203);
2757 }
2758 } elseif ($column === 'saved_articles') {
2759 $article = Article::find($id);
2760 if ($user_id == $article->author->id) {
2761 $json['type'] = 'error';
2762 $json['message'] = trans('lang.login_from_different_user');
2763 return Response::json($json, 203);
2764 }
2765 }
2766 }
2767 $user_meta = new UserMeta();
2768 $add_wishlist = $user_meta->addWishlist($column, $id, $user_id);
2769 $article_likes = '';
2770 if ($add_wishlist == "success") {
2771 if ($column == 'saved_articles') {
2772 $article = Article::find($id);
2773 if (!empty($article->likes)) {
2774 $article->likes = $article->likes + 1;
2775 } else {
2776 $article->likes = 1;
2777 }
2778 $article_likes = $article->likes;
2779 $article->save();
2780 $json['likes'] = $article_likes;
2781 }
2782 $json['type'] = 'success';
2783 $json['message'] = trans('lang.added_to_wishlist');
2784 return Response::json($json, 200);
2785 } else {
2786 $json['type'] = 'error';
2787 $json['message'] = trans('lang.something_wrong');
2788 return Response::json($json, 203);
2789 }
2790 }
2791 } else {
2792 $json['test'] = 'hello1';
2793 $json['authentication'] = false;
2794 $json['message'] = trans('lang.need_to_reg');
2795 return Response::json($json, 203);
2796 }
2797 }
2798
2799 /**
2800 * Get user saved item list
2801 *
2802 * @param mixed $request request attributes
2803 * @param int $role role
2804 *
2805 * @access public
2806 *
2807 * @return View
2808 */
2809 public function getSavedItems(Request $request)
2810 {
2811 $json = array();
2812 $profile_id = !empty($_GET['profile_id']) ? $_GET['profile_id'] : '';
2813 $type = !empty($_GET['type']) ? $_GET['type'] : '';
2814 if (!empty($profile_id)) {
2815 $user = User::find($profile_id);
2816 $icons = SiteManagement::getMetaValue('icons');
2817 $hidden_doctor_image = !empty($icons['hidden_doctor_image']) ? $icons['hidden_doctor_image'] : '';
2818 $hidden_hospital_image = !empty($icons['hidden_hospital_image']) ? $icons['hidden_hospital_image'] : '';
2819 $saved_doctors = !empty($user->profile->saved_doctors) ? unserialize($user->profile->saved_doctors) : array();
2820 $saved_hospitals = !empty($user->profile->saved_hospitals) ? unserialize($user->profile->saved_hospitals) : array();
2821 $saved_articles = !empty($user->profile->saved_articles) ? unserialize($user->profile->saved_articles) : array();
2822 $currency = SiteManagement::getMetaValue('payment_settings');
2823 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : array();
2824 if ($type == 'doctors') {
2825 if (!empty($saved_doctors)) {
2826 foreach ($saved_doctors as $key => $user_id) {
2827 $user_obj = User::find($user_id);
2828
2829 $avg_rating = Feedback::where('user_id', $user_obj->id)->pluck('avg_rating')->first();
2830 $specialities = $user_obj->services->count() > 0 ? DB::table('user_service')->select('speciality')
2831 ->where('user_id', $user_obj->id)->groupBy('speciality')->get()->pluck('speciality')->random(1)->toArray() : '';
2832 $json[$key]['id'] = $user_obj->id;
2833 $json[$key]['image'] = asset(Helper::getImage('uploads/users/' . $user_obj->id, $user_obj->profile->avatar, 'saved_items-', 'user-logo-def.jpg'));
2834 $json[$key]['link'] = route('userProfile', ['slug' => $user_obj->slug]);
2835 $json[$key]['name'] = !empty($user_obj->profile->gender_title) ? Helper::getDoctorArray(clean($user_obj->profile->gender_title)) : '' . Helper::getUsername($user_obj->id);
2836 $json[$key]['medilcal_verified'] = $user_obj->profile->verify_registration == 1 ? 'yes' : 'no';
2837 $json[$key]['is_verified'] = $user_obj->user_verified == 1 ? 'yes' : 'no';
2838 $json[$key]['subheading'] = $user_obj->profile->sub_heading;
2839 $user_detail['average_rating'] = $avg_rating;
2840 $user_detail['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
2841 if (!empty($specialities)) {
2842 foreach ($specialities as $speciality_key => $user_speciality) {
2843 $speciality = Helper::getSpecialityByID($user_speciality);
2844 if (!empty($speciality)) {
2845 $json[$key]['specialities']['id'] = $speciality->id;
2846 $json[$key]['specialities']['slug'] = $speciality->slug;
2847 $json[$key]['specialities']['title'] = $speciality->title;
2848 }
2849 }
2850 } else {
2851 $json[$hospital_key]['specialities'] = [];
2852 }
2853 $avg_rating = Feedback::where('user_id', $user_obj->id)->pluck('avg_rating')->first();
2854 $json[$key]['average_rating'] = !empty($avg_rating) ? $avg_rating : '0';
2855 $json[$key]['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
2856 }
2857 return Response::json($json, 200);
2858 } else {
2859 $json['type'] = 'error';
2860 $json['message'] = trans('lang.no_record');
2861 return Response::json($json, 203);
2862 }
2863 } elseif ($type == 'hospitals') {
2864 if (!empty($saved_hospitals)) {
2865 foreach ($saved_hospitals as $hospital_key => $user_id) {
2866 $user_obj = User::find($user_id);
2867 $specialities = $user_obj->services->count() > 0 ? DB::table('user_service')->select('speciality')
2868 ->where('user_id', $user_obj->id)->groupBy('speciality')->get()->pluck('speciality')->random(1)->toArray() : '';
2869 $json[$hospital_key]['id'] = $user_obj->id;
2870 $json[$hospital_key]['image'] = asset(Helper::getImage('uploads/users/' . $user_obj->id, $user_obj->profile->avatar, 'saved_items-', 'user-logo-def.jpg'));
2871 $json[$hospital_key]['link'] = route('userProfile', ['slug' => $user_obj->slug]);
2872 $json[$hospital_key]['name'] = !empty($user_obj->profile->gender_title) ? Helper::getDoctorArray(clean($user_obj->profile->gender_title)) : '' . Helper::getUsername($user_obj->id);
2873 $json[$hospital_key]['subheading'] = $user_obj->profile->sub_heading;
2874 $json[$hospital_key]['medilcal_verified'] = $user_obj->profile->verify_registration == 1 ? 'yes' : 'no';
2875 $json[$hospital_key]['is_verified'] = $user_obj->user_verified == 1 ? 'yes' : 'no';
2876 if (!empty($specialities)) {
2877 foreach ($specialities as $user_speciality_key => $user_speciality) {
2878 $speciality = Helper::getSpecialityByID($user_speciality);
2879 if (!empty($speciality)) {
2880 $json[$hospital_key]['specialities']['id'] = $speciality->id;
2881 $json[$hospital_key]['specialities']['slug'] = $speciality->slug;
2882 $json[$hospital_key]['specialities']['title'] = $speciality->title;
2883 }
2884 }
2885 } else {
2886 $json[$hospital_key]['specialities'] = [];
2887 }
2888 $avg_rating = Feedback::where('user_id', $user_obj->id)->pluck('avg_rating')->first();
2889 $json[$hospital_key]['average_rating'] = !empty($avg_rating) ? $avg_rating : '0';
2890 $json[$hospital_key]['total_rating'] = (string) Feedback::where('user_id', $user->id)->count();
2891 }
2892 return Response::json($json, 200);
2893 } else {
2894 $json['type'] = 'error';
2895 $json['message'] = trans('lang.no_record');
2896 return Response::json($json, 203);
2897 }
2898 } elseif ($type == 'articles') {
2899 if (!empty($saved_articles)) {
2900 foreach ($saved_articles as $article_key => $saved_article) {
2901 $article = Article::find($saved_article);
2902 $json[$article_key]['title'] = $article->title;
2903 $json[$article_key]['image'] = asset(Helper::getImage('uploads/users/' . $article->author->id . '/articles/', $article->image, 'listing-', 'article-default.jpg'));
2904 $json[$article_key]['author_image'] = asset(Helper::getImage('uploads/users/' . $article->author->id, User::find($article->author->id)->profile->avatar, 'extra-small-', 'user-login.png'));
2905 $json[$article_key]['link'] = route('articleDetail', ['slug' => clean($article->slug)]);
2906 $json[$article_key]['author_name'] = Helper::getUserName($article->author_id);
2907
2908 $json[$article_key]['publish_date'] = Carbon::parse($article->created_at)->format('M d, Y');
2909 $json[$article_key]['likes'] = !empty($article->likes) ? clean($article->likes) : 0;
2910 $json[$article_key]['views'] = !empty($article->views) ? clean($article->views) : 0;
2911 $json[$article_key]['id'] = $article->id;
2912 if (!empty($article->categories) && $article->categories->count() > 0) {
2913 foreach ($article->categories as $category) {
2914 $json[$article_key]['category']['link'] = route('articleListing', clean($category->slug));
2915 $json[$article_key]['category']['title'] = clean($category->title);
2916 }
2917 } else {
2918 $json[$article_key]['category']['link'] = '';
2919 $json[$article_key]['category']['title'] = '';
2920 }
2921 }
2922 return Response::json($json, 200);
2923 } else {
2924 $json['type'] = 'error';
2925 $json['message'] = trans('lang.no_record');
2926 return Response::json($json, 203);
2927 }
2928 } else {
2929 $json['type'] = 'error';
2930 $json['message'] = trans('lang.something_wrong');
2931 return Response::json($json, 203);
2932 }
2933 } else {
2934 $json['type'] = 'error';
2935 $json['message'] = trans('lang.something_wrong');
2936 return Response::json($json, 203);
2937 }
2938 }
2939
2940 /**
2941 * Submit feedback.
2942 *
2943 * @param mixed $request request->attr
2944 *
2945 * @access public
2946 *
2947 * @return \Illuminate\Http\Response
2948 */
2949 public function submitFeedack(Request $request)
2950 {
2951 $doctor_id = !empty($request['doctor_id']) ? $request['doctor_id'] : '';
2952 $patient_id = !empty($request['patient_id']) ? $request['patient_id'] : '';
2953 $waiting_time = !empty($request['waiting_time']) ? $request['waiting_time'] : '';
2954 $feedbackpublicly = !empty($request['feedbackpublicly']) ? $request['feedbackpublicly'] : '';
2955 $comments = !empty($request['comments']) ? $request['comments'] : '';
2956 $rating = !empty($request['rating']) ? $request['rating'] : '';
2957 $votes = !empty($request['votes']) ? $request['votes'] : '';
2958 if (!empty($request)) {
2959 $feedback_submission = Feedback::submitFeedback($request, $patient_id);
2960 if ($feedback_submission == 'success') {
2961 $json['type'] = 'success';
2962 $json['message'] = trans('lang.feedback_submitted');
2963 return Response::json($json, 200);
2964 } else {
2965 $json['type'] = 'error';
2966 $json['message'] = trans('lang.something_wrong');
2967 return Response::json($json, 203);
2968 }
2969 } else {
2970 $json['type'] = 'error';
2971 $json['message'] = trans('lang.something_wrong');
2972 return Response::json($json, 203);
2973 }
2974 }
2975
2976 /**
2977 * Store User profile settings.
2978 *
2979 * @param \Illuminate\Http\Request $request request attributes
2980 * @param string $role_type role_type
2981 *
2982 * @return \Illuminate\Http\Response
2983 */
2984 public function storeProfileSettings(Request $request)
2985 {
2986 $server = Helper::doctieIsDemoSiteAjax();
2987 if (!empty($server)) {
2988 $response['type'] = 'error';
2989 $response['message'] = $server->getData()->message;
2990 return $response;
2991 }
2992 $json = array();
2993 $user_id = !empty($request['user_id']) ? $request['user_id'] : '';
2994 $user = User::find($user_id);
2995 $role_type = Helper::getRoleTypeByUserID($user_id);
2996 if (!empty($request['latitude']) || !empty($request['longitude'])) {
2997 $this->validate(
2998 $request,
2999 [
3000 'latitude' => ['regex:/^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,6}$/'],
3001 'longitude' => ['regex:/^-?([1]?[1-7][1-9]|[1]?[1-8][0]|[1-9]?[0-9])\.{1}\d{1,6}$/'],
3002 ]
3003 );
3004 }
3005 if ($role_type == 'admin') {
3006 if ($request['email'] != $user->email) {
3007 $this->validate(
3008 $request,
3009 [
3010 'email' => 'unique:users|email',
3011 ]
3012 );
3013 }
3014 $this->validate(
3015 $request,
3016 [
3017 'first_name' => 'required',
3018 'last_name' => 'required',
3019 ]
3020 );
3021 } else {
3022 $this->validate(
3023 $request,
3024 [
3025 'first_name' => 'required',
3026 'last_name' => 'required',
3027 ]
3028 );
3029 }
3030 if (!empty($user_id)) {
3031 $count = 0;
3032 $user_meta = new UserMeta();
3033 $profile = $user_meta->storeProfile($request, $user_id);
3034 if ($request['experience']) {
3035 return Response::json($request['experience'], 200);
3036 // foreach ($request['experience'] as $key => $experience) {
3037 // if (
3038 // empty($experience['job_title']) || empty($experience['start_date'])
3039 // || empty($experience['end_date']) || empty($experience['company_title'])
3040 // ) {
3041 // $json['type'] = 'error';
3042 // $json['message'] = trans('lang.empty_fields_not_allowed');
3043 // return Response::json($json, 200);
3044 // }
3045
3046 // if ($experience['company_title'] == 'Company Title') {
3047 // $json['type'] = 'error';
3048 // $json['message'] = trans('lang.empty_fields_not_allowed');
3049 // return Response::json($json, 200);
3050 // }
3051 // $request_experience[$count] = $experience;
3052 // $count++;
3053 // }
3054 }
3055 $experience = !empty($request['experience']) ? serialize($request_experience) : '';
3056 $user_meta->user()->associate($user_id);
3057 $user_meta->experiences = $experience;
3058 $user_meta->save();
3059 // $save_experiences = $user_meta->saveExperiences($request, $user_id);
3060 // $save_education = $user_meta->saveEducations($request, $user_id);
3061 // $store_awards_downloads = $user_meta->storeAwardsDownloads($request, $user_id);
3062 // $store_registration = $user_meta->storeRegistration($request, $user_id);
3063 // $save_services = $user_meta->saveServices($request, $user_id);
3064 if (
3065 $profile == 'error'
3066 ) {
3067 $json['type'] = 'error';
3068 $json['message'] = trans('lang.something_wrong');
3069 return Response::json($json, 203);
3070 } else {
3071 $json['type'] = 'success';
3072 $json['role'] = Helper::getAuthRoleType($user_id);
3073 $json['message'] = trans('lang.personal_details_saved');
3074 return Response::json($json, 200);
3075 }
3076 } else {
3077 $json['type'] = 'error';
3078 $json['message'] = trans('lang.not_authorize');
3079 return Response::json($json, 203);
3080 }
3081 }
3082
3083 /**
3084 * Get doctor locations
3085 *
3086 * @access public
3087 *
3088 * @return \Illuminate\Http\Response
3089 */
3090 public function getDoctorServices()
3091 {
3092 $json = array();
3093 $doctor_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3094 if (!empty($doctor_id)) {
3095 $user = User::find($doctor_id);
3096 $specialities = !empty($user->profile->services) ? Helper::getUnserializeData($user->profile->services) : array();
3097 if (!empty($specialities)) {
3098 foreach ($specialities as $speciality_key => $user_speciality) {
3099 $speciality = Helper::getSpecialityByID($user_speciality['speciality_id']);
3100 if (!empty($speciality)) {
3101 $json['speciality'][$speciality_key]['name'] = $speciality->title;
3102 $json['speciality'][$speciality_key]['logo'] = asset(Helper::getImage('uploads/specialities', $speciality->image, '', 'default-speciality.png'));
3103 }
3104 if (!empty($user_speciality['services'])) {
3105 foreach ($user_speciality['services'] as $spe_ser_key => $speciality_service) {
3106 $service = Helper::getServiceByID($speciality_service['service']);
3107 if (!empty($service)) {
3108 $json['speciality'][$speciality_key]['services'][$spe_ser_key]['title'] = $service->title;
3109 $json['speciality'][$speciality_key]['services'][$spe_ser_key]['price'] = !empty($speciality_service['price']) ? (!empty($symbol['symbol']) ? $symbol['symbol'] : '$') . $speciality_service['price'] : '';
3110 $json['speciality'][$speciality_key]['services'][$spe_ser_key]['description'] = !empty($speciality_service['description']) ? $speciality_service['description'] : '';
3111 }
3112 }
3113 }
3114 }
3115 return Response::json($json, 200);
3116 } else {
3117 $json['type'] = 'error';
3118 $json['message'] = trans('lang.no_record');
3119 return Response::json($json, 203);
3120 }
3121 } else {
3122 $json['type'] = 'error';
3123 $json['message'] = trans('lang.doctor_id_req');
3124 return Response::json($json, 203);
3125 }
3126 }
3127
3128 /**
3129 * Update Payout detail
3130 *
3131 * @param mixed $request request attributes
3132 *
3133 * @return \Illuminate\Http\Response
3134 */
3135 public function submitPayoutSettings(Request $request)
3136 {
3137 $user_id = !empty($_GET['id']) ? $_GET['id'] : '';
3138 if (!empty($user_id)) {
3139 $user_meta = new UserMeta();
3140 $payout_setting = $user_meta->savePayoutDetail($request, $user_id);
3141 if ($payout_setting == 'success') {
3142 $json['type'] = 'success';
3143 $json['message'] = trans('lang.payout_saved_success');
3144 return Response::json($json, 200);
3145 } else {
3146 $json['type'] = 'error';
3147 $json['message'] = trans('lang.something_went_wrong');
3148 return Response::json($json, 203);
3149 }
3150 } else {
3151 $json['type'] = 'error';
3152 $json['message'] = trans('lang.verify_code');
3153 return Response::json($json, 203);
3154 }
3155 }
3156
3157 /**
3158 * Get doctor payouts.
3159 *
3160 * @return \Illuminate\Http\Response
3161 */
3162 public function getDoctorPayouts()
3163 {
3164 $post_per_page = !empty($_GET['show_users']) ? $_GET['show_users'] : 10;
3165 $page_number = !empty($_GET['page_number']) ? $_GET['page_number'] : 1;
3166 Paginator::currentPageResolver(
3167 function () use ($page_number) {
3168 return $page_number;
3169 }
3170 );
3171 if (Auth::user()) {
3172 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3173 if (!empty($user_id)) {
3174 $payouts = Payout::where('user_id', $user_id)->paginate($post_per_page);
3175 } else {
3176 $json['type'] = 'error';
3177 $json['message'] = trans('lang.doctor_id_req');
3178 return Response::json($json, 203);
3179 }
3180 } else {
3181 $json['type'] = 'error';
3182 $json['message'] = trans('lang.something_went_wrong');
3183 return Response::json($json, 203);
3184 }
3185 }
3186
3187 /**
3188 * Get Users.
3189 *
3190 * @return \Illuminate\Http\Response
3191 */
3192 public function getChatUsers()
3193 {
3194 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3195 // $role_type = Helper::getRoleTypeByUserID($user_id);
3196 if (!empty($user_id)) {
3197 $unreadNotifyClass = '';
3198 $users = DB::select(
3199 DB::raw(
3200 "SELECT * FROM messages
3201 WHERE id IN (
3202 SELECT MAX(id) AS id
3203 FROM (
3204 SELECT id, user_id AS chat_sender
3205 FROM messages
3206 WHERE receiver_id = $user_id OR user_id = $user_id
3207 UNION ALL
3208 SELECT id, receiver_id AS chat_sender
3209 FROM messages
3210 WHERE user_id = $user_id OR receiver_id = $user_id )
3211 t GROUP BY chat_sender ) ORDER BY id DESC"
3212 )
3213 );
3214 $json = array();
3215 if (!empty($users)) {
3216 foreach ($users as $key => $userVal) {
3217 $chat_user_id = '';
3218 if ($user_id == intval($userVal->user_id)) {
3219 $chat_user_id = intval($userVal->receiver_id);
3220 } else {
3221 $chat_user_id = intval($userVal->user_id);
3222 }
3223 $json[$key]['id'] = $chat_user_id;
3224 $json[$key]['image'] = asset(
3225 Helper::getImage(
3226 'uploads/users/' . $chat_user_id . '/',
3227 User::find($chat_user_id)->profile->avatar,
3228 'medium-',
3229 'user-login.png'
3230 )
3231 );
3232 $json[$key]['name'] = Helper::getUserName($chat_user_id);
3233 $json[$key]['tagline'] = User::find($chat_user_id)->profile->tagline;
3234 $json[$key]['image_name'] = User::find($chat_user_id)->profile->avatar;
3235 }
3236 $message_status = Message::where('receiver_id', $user_id)->where('status', 0)->count();
3237 if ($message_status > 0) {
3238 $unreadNotifyClass = 'wt-dotnotification';
3239 }
3240 $json[$key]['status_class'] = $unreadNotifyClass;
3241 return Response::json($json, 200);
3242 } else {
3243 $json['type'] = 'error';
3244 $json['message'] = trans('lang.user_not_found');
3245 return Response::json($json, 203);
3246 }
3247 } else {
3248 $json['type'] = 'error';
3249 $json['message'] = trans('lang.not_authorize');
3250 return Response::json($json, 203);
3251 }
3252 }
3253
3254 /**
3255 * Get user messages.
3256 *
3257 * @param mixed $request $req->attr
3258 *
3259 * @return \Illuminate\Http\Response
3260 */
3261 public function getUserMessages(Request $request)
3262 {
3263 $json = array();
3264 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3265 $sender_id = !empty($_GET['sender_id']) ? $_GET['sender_id'] : '';
3266 if (!empty($sender_id) && !empty($user_id)) {
3267 // $user_id = auth()->user()->id;
3268 $receiver_id = $sender_id;
3269 $selected_user = User::find($receiver_id);
3270 DB::table('messages')
3271 ->where('user_id', $receiver_id)
3272 ->where('receiver_id', $user_id)
3273 ->update(['status' => 1]);
3274 $messages = DB::table('messages')->select('*')
3275 ->where(
3276 function ($query) use ($user_id, $receiver_id) {
3277 $query->where('user_id', '=', $user_id)
3278 ->Where('receiver_id', '=', $receiver_id);
3279 }
3280 )
3281 ->orWhere(
3282 function ($query) use ($user_id, $receiver_id) {
3283 $query->where('receiver_id', '=', $user_id)
3284 ->Where('user_id', '=', $receiver_id);
3285 }
3286 )
3287 ->get()->toArray();
3288 if (!empty($messages)) {
3289 foreach ($messages as $key => $message) {
3290 $message_read = 'no';
3291 if ($message->status == 1 && $message->user_id == $user_id) {
3292 $message_read = 'yes';
3293 }
3294 $json['messages'][$key]['is_sender'] = 'no';
3295 if ($message->user_id == $user_id) {
3296 $json['messages'][$key]['is_sender'] = 'yes';
3297 }
3298 $json['messages'][$key]['id'] = $message->id;
3299 $json['messages'][$key]['user_id'] = $message->user_id;
3300 $json['messages'][$key]['image'] = asset(
3301 Helper::getImage('uploads/users/' . $message->user_id . '/', User::find($message->user_id)->profile->avatar, 'medium-', 'user-login.png')
3302 );
3303 $json['messages'][$key]['message'] = $message->body;
3304 $json['messages'][$key]['date'] = $message->created_at;
3305 $json['messages'][$key]['read_status'] = $message_read;
3306 }
3307 $json['selected']['selected_user_name'] = Helper::getUserName($receiver_id);
3308 $json['selected']['selected_user_slug'] = $selected_user->slug;
3309 $json['selected']['selected_user_tagline'] = $selected_user->profile->tagline;
3310 $json['selected']['selected_user_image'] = asset(
3311 Helper::getImage(
3312 'uploads/users/' . $receiver_id . '/',
3313 User::find($receiver_id)->profile->avatar,
3314 'medium-',
3315 'user-login.png'
3316 )
3317 );
3318 $json['selected']['selected_user_verified'] = $selected_user->user_verified;
3319 return Response::json($json, 200);
3320 } else {
3321 $json['type'] = 'error';
3322 $json['message'] = trans('lang.no_record');
3323 return Response::json($json, 203);
3324 }
3325 }
3326 }
3327
3328 /**
3329 * Store a newly created resource in storage.
3330 *
3331 * @param \Illuminate\Http\Request $request request attributes
3332 *
3333 * @return \Illuminate\Http\Response
3334 */
3335 public function storeMessage(Request $request)
3336 {
3337 $json = array();
3338 $message = new Message();
3339 if (empty($request['message'])) {
3340 $json['type'] = 'error';
3341 $json['message'] = trans('lang.empty_field');
3342 return Response::json($json, 203);
3343 }
3344 $messsage = $message->sendMessage($request);
3345 $json['data'] = $messsage;
3346 $json['type'] = trans('lang.message_send');
3347 return Response::json($json, 200);
3348 }
3349
3350 /**
3351 * Get chat settings
3352 *
3353 * @return \Illuminate\Http\Response
3354 */
3355 public function getChatSettings()
3356 {
3357 $json = array();
3358 $chat_settings = SiteManagement::getMetaValue('chat_settings');
3359 $host = !empty($chat_settings['host']) ? $chat_settings['host'] : 'http://localhost';
3360 $port = !empty($chat_settings['port']) ? $chat_settings['port'] : 3001;
3361 $json['host'] = $host;
3362 $json['port'] = $port;
3363 return Response::json($json, 200);
3364 }
3365
3366 /**
3367 * Get chat settings
3368 *
3369 * @return \Illuminate\Http\Response
3370 */
3371 public function getPayPalSetting()
3372 {
3373 $json = array();
3374 $existing_payment_settings = SiteManagement::getMetaValue('paypal_settings');
3375 $client_id = !empty($existing_payment_settings['client_id']) ? $existing_payment_settings['client_id'] : '';
3376 $password = !empty($existing_payment_settings['paypal_password']) ? $existing_payment_settings['paypal_password'] : '';
3377 $secret = !empty($existing_payment_settings['paypal_secret']) ? $existing_payment_settings['paypal_secret'] : '';
3378 $sandbox = !empty($existing_payment_settings['enable_sandbox']) ? $existing_payment_settings['enable_sandbox'] : '';
3379 $json['client_id'] = $client_id;
3380 $json['password'] = $password;
3381 $json['secret'] = $secret;
3382 $json['sandbox'] = $sandbox;
3383 return Response::json($json, 200);
3384 }
3385
3386 /**
3387 * Get chat settings
3388 *
3389 * @return \Illuminate\Http\Response
3390 */
3391 public function getStripeSetting()
3392 {
3393 $json = array();
3394 $stripe_settings = SiteManagement::getMetaValue('stripe_settings');
3395 $stripe_key = !empty($stripe_settings) ? $stripe_settings['stripe_key'] : '';
3396 $stripe_secret = !empty($stripe_settings) ? $stripe_settings['stripe_secret'] : '';
3397 $json['stripe_key'] = $stripe_key;
3398 $json['stripe_secret'] = $stripe_secret;
3399 return Response::json($json, 200);
3400 }
3401
3402 /**
3403 * Store a newly created resource in storage.
3404 *
3405 * @param \Illuminate\Http\Request $request request attributes
3406 *
3407 * @return \Illuminate\Http\Response
3408 */
3409 public function createOrder(Request $request)
3410 {
3411 $json = array();
3412 $id = !empty($_GET['product_id']) ? $_GET['product_id'] : '';
3413 $type = !empty($_GET['type']) ? $_GET['type'] : '';
3414 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3415 $payment_gateway = !empty($_GET['payment_gateway']) ? $_GET['payment_gateway'] : '';
3416 if (empty($id)) {
3417 $json['type'] = 'error';
3418 $json['message'] = trans('lang.product_id_req');
3419 return Response::json($json, 203);
3420 }
3421 if (empty($type)) {
3422 $json['type'] = 'error';
3423 $json['message'] = trans('lang.type_req');
3424 return Response::json($json, 203);
3425 }
3426 if (empty($user_id)) {
3427 $json['type'] = 'error';
3428 $json['message'] = trans('lang.user_id_req');
3429 return Response::json($json, 203);
3430 }
3431 $order = new Order();
3432 $order->status = 'pending';
3433 $order->payment_gateway = $payment_gateway;
3434 if ($type == 'appointment') {
3435 $appointment = Appointment::find($id);
3436 $order->appointment_date = $appointment->appointment_date;
3437 }
3438 $order->user()->associate($user_id);
3439 $order->save();
3440 $order_id = DB::getPdo()->lastInsertId();
3441 $latest_order = Order::find($order_id);
3442 $order_type = new OrderMeta();
3443 $order_type->meta_key = 'type';
3444 $order_type->meta_value = $type;
3445 $latest_order->orderMeta()->save($order_type);
3446 if ($type == 'appointment') {
3447 $appointment_data = array();
3448 $appointment = Appointment::find($id);
3449 if (!empty($appointment->toArray())) {
3450 foreach ($appointment->toArray() as $appointment_key => $appointment_value) {
3451 $appointment_data[$appointment_key] = $appointment_value;
3452 }
3453 $appointment_meta = new OrderMeta();
3454 $appointment_meta->meta_key = 'appointment';
3455 $appointment_meta->meta_value = serialize($appointment_data);
3456 $latest_order->orderMeta()->save($appointment_meta);
3457 }
3458 } else if ($type == 'package') {
3459 $package_data = array();
3460 $package = Package::find($id)->toArray();
3461 if (!empty($package)) {
3462 foreach ($package as $package_key => $package_value) {
3463 $package_data[$package_key] = $package_value;
3464 }
3465 $package_meta = new OrderMeta();
3466 $package_meta->meta_key = 'package';
3467 $package_meta->meta_value = serialize($package_data);
3468 $latest_order->orderMeta()->save($package_meta);
3469 }
3470 }
3471 $json['type'] = 'success';
3472 return Response::json($json, 200);
3473 }
3474
3475 /**
3476 * Create invoice
3477 *
3478 * @param mixed $cart cart
3479 * @param mixed $status status
3480 * @param mixed $payment_detail payment_detail
3481 *
3482 * @return \Illuminate\Http\Response
3483 */
3484 protected function createInvoice(Request $request)
3485 {
3486 $json = array();
3487 $id = !empty($_GET['product_id']) ? $_GET['product_id'] : '';
3488 $type = !empty($_GET['type']) ? $_GET['type'] : '';
3489 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3490 $order_id = !empty($_GET['order_id']) ? $_GET['order_id'] : '';
3491 if (empty($id)) {
3492 $json['type'] = 'error';
3493 $json['message'] = trans('lang.product_id_req');
3494 return Response::json($json, 203);
3495 }
3496 if (empty($type)) {
3497 $json['type'] = 'error';
3498 $json['message'] = trans('lang.type_req');
3499 return Response::json($json, 203);
3500 }
3501 if (empty($user_id)) {
3502 $json['type'] = 'error';
3503 $json['message'] = trans('lang.user_id_req');
3504 return Response::json($json, 203);
3505 }
3506 $user = User::find($user_id);
3507 if (!empty($id) && !empty($type)) {
3508 $new_order = Order::find($order_id);
3509 $new_order->status = 'completed';
3510 $new_order->save();
3511 $payment_detail = !empty($request['payment_detail']) ? $request['payment_detail'] : '';
3512 if (!empty($payment_detail)) {
3513 foreach ($payment_detail as $key => $value) {
3514 $meta = new OrderMeta();
3515 $meta->meta_key = $key;
3516 $meta->meta_value = $value;
3517 $new_order->orderMeta()->save($meta);
3518 }
3519 }
3520 if ($type == 'appointment') {
3521 $appointment = Appointment::find($id);
3522 $appointment->status = 'accepted';
3523 $appointment->save();
3524 // appointment mail
3525 $hospital = User::findOrFail($appointment->hospital_id);
3526 $doctor = User::findOrFail($appointment->user_id);
3527 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
3528 $email_params = array();
3529 $template = DB::table('email_types')->select('id')->where('email_type', 'user_email_appointment_request_approved')->get()->first();
3530 if (!empty($template->id)) {
3531 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
3532 $email_params['user_name'] = Helper::getUserName($user_id);
3533 $email_params['hospital_name'] = Helper::getUserName($hospital->id);
3534 $email_params['hospital_link'] = url('profile/' . $hospital->slug);
3535 $email_params['doctor_name'] = Helper::getUserName($doctor->id);
3536 $email_params['doctor_link'] = url('profile/' . $doctor->slug);
3537 $email_params['appointment_date_time'] = Carbon::parse($appointment->appointment_date)->format('d M, Y') . ' ' . $appointment->appointment_time;
3538 $email_params['description'] = $appointment->comments;
3539 Mail::to($user->email)
3540 ->send(
3541 new GeneralEmailMailable(
3542 'user_email_appointment_request_approved',
3543 $template_data,
3544 $email_params
3545 )
3546 );
3547 }
3548 }
3549 } else if ($type == 'package') {
3550 $package = Package::find($id)->toArray();
3551 // Package Mail
3552 $package = Package::find($id);
3553 $option = !empty($package->options) ? unserialize($package->options) : '';
3554 $expiry = !empty($new_order) ? $new_order->created_at->addDays($option['duration']) : '';
3555 $expiry_date = !empty($expiry) ? Carbon::parse($expiry)->toDateTimeString() : '';
3556 $user = User::find($user_id);
3557 $user->package_expiry = $expiry_date;
3558 $user->save();
3559 // send mail
3560 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
3561 $email_params = array();
3562 $template = DB::table('email_types')->select('id')->where('email_type', 'doctor_email_package_subscribed')->get()->first();
3563
3564 if (!empty($template->id)) {
3565 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
3566 $email_params['doctor_name'] = Helper::getUserName($user_id);
3567 $email_params['pkg_title'] = $package->title;
3568 $email_params['amount'] = $package->cost;
3569 $email_params['date'] = Carbon::parse($new_order->created_at)->format('M d, Y');
3570 $email_params['expiry_date'] = !empty($expiry) ? Carbon::parse($expiry)->format('M d, Y') : '';
3571 Mail::to($user->email)
3572 ->send(
3573 new DoctorEmailMailable(
3574 'doctor_email_package_subscribed',
3575 $template_data,
3576 $email_params
3577 )
3578 );
3579 }
3580 }
3581 }
3582 }
3583 $json['type'] = 'success';
3584 return Response::json($json, 200);
3585 }
3586
3587 /**
3588 * Get Doctor Invoices.
3589 *
3590 * @return \Illuminate\Http\Response
3591 */
3592 public function getUserInvoices()
3593 {
3594 $json = array();
3595 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3596 $currency = SiteManagement::getMetaValue('payment_settings');
3597 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : array();
3598 $currency_symbol = !empty($symbol) ? $symbol['symbol'] : '$';
3599 if (!empty($user_id)) {
3600 $user = User::find($user_id);
3601 $invoices = $user->orders()->get();
3602 if (!empty($invoices)) {
3603 foreach ($invoices as $key => $invoice) {
3604 $order = Order::findOrFail($invoice->id);
3605 $expiry_date = '';
3606 if (!empty($order->metaValue('package'))) {
3607 $options = unserialize($order->metaValue('package'));
3608 $package_options = unserialize($options['options']);
3609 if ($package_options['duration'] === '10') {
3610 $expiry_date = !empty($order->created_at) ? $order->created_at->addDays(4) : '';
3611 } elseif ($package_options['duration'] === '30') {
3612 $expiry_date = !empty($order->created_at) ? $order->created_at->addDays(30) : '';
3613 } elseif ($package_options['duration'] === '360') {
3614 $expiry_date = !empty($order->created_at) ? $order->created_at->addDays(360) : '';
3615 }
3616 } else {
3617 $expiry_date = '';
3618 }
3619 if (!empty($invoice)) {
3620 $json[$key]['invoice_id'] = !empty($order->metaValue('invoice_id')) ? $order->metaValue('invoice_id') : trans('lang.not_available');
3621 $json[$key]['purchase_date'] = Carbon::parse($order->created_at)->format('M d, Y');
3622 $json[$key]['expiry_date'] = Carbon::parse($expiry_date)->format('M d, Y');
3623 $json[$key]['amount'] = $currency_symbol . intVal($options['cost']);
3624 $json[$key]['status'] = $order->status;
3625 $json[$key]['id'] = intVal(clean($order->id));
3626 }
3627 }
3628 return Response::json($json, 200);
3629 } else {
3630 $json['type'] = 'error';
3631 $json['message'] = trans('lang.no_record');
3632 return Response::json($json, 203);
3633 }
3634 } else {
3635 $json['type'] = 'error';
3636 $json['message'] = trans('lang.user_id_req');
3637 return Response::json($json, 203);
3638 }
3639 }
3640
3641 /**
3642 * Get Invoices.
3643 *
3644 * @param integer $id roletype
3645 *
3646 * @return \Illuminate\Http\Response
3647 */
3648 public function showInvoice()
3649 {
3650 $json = array();
3651 $id = !empty($_GET['id']) ? $_GET['id'] : '';
3652 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3653 if (!empty($id)) {
3654 $order = Order::findOrFail($id);
3655 $currency_code = !empty($order->metaValue('currency_code')) ? strtoupper($order->metaValue('currency_code')) : 'USD';
3656 $code = Helper::currencyList($currency_code);
3657 $symbol = !empty($code) ? $code['symbol'] : '$';
3658 $role_type = Helper::getRoleTypeByUserID($user_id);
3659 if ($role_type === 'doctor') {
3660 $options = unserialize($order->metaValue('package'));
3661 $package_options = unserialize($options['options']);
3662 } else if ($role_type === 'regular') {
3663 $options = unserialize($order->metaValue('appointment'));
3664 } else {
3665 $json['type'] = 'error';
3666 $json['message'] = trans('lang.not_authorize');
3667 return Response::json($json, 203);
3668 }
3669 if (!empty($order)) {
3670 $json['payer_name'] = !empty($order->metaValue('payer_name')) ? $order->metaValue('payer_name') : '';
3671 $json['payment_date'] = Carbon::parse($order->created_at)->diffForHumans() . ' ' . Carbon::parse($order->created_at)->format('l \\a\\t H:i:s');
3672 $json['transaction_id'] = !empty($order->metaValue('transaction_id')) ? $order->metaValue('transaction_id') : '';
3673 $json['customer_id'] = !empty($order->metaValue('customer_id')) ? $order->metaValue('customer_id') : '';
3674 $json['price'] = $options['cost'];
3675 $json['symbol'] = $symbol;
3676 $json['currency_code'] = $currency_code;
3677 $json['customer_id'] = !empty($order->metaValue('customer_id')) ? $order->metaValue('customer_id') : '';
3678 $json['status'] = !empty($order->status) ? $order->status : '';
3679 $json['purchase_total'] = $symbol . $options['cost'] . ' ' . $currency_code;
3680 $json['sales_tax'] = !empty($order->metaValue('sales_tax')) ? $symbol . $order->metaValue('sales_tax') . ' ' . $currency_code : '';
3681 $json['shiping_amnt'] = !empty($order->metaValue('shiping_amnt')) ? $symbol . $order->metaValue('shiping_amnt') . ' ' . $currency_code : '';
3682 $json['handling_amnt'] = !empty($order->metaValue('handling_amnt')) ? $symbol . $order->metaValue('handling_amnt') . ' ' . $currency_code : '';
3683 $json['insurance_amount'] = !empty($order->metaValue('insurance_amount')) ? $symbol . $order->metaValue('insurance_amount') . ' ' . $currency_code : '';
3684 $json['net_amnt'] = $symbol . $options['cost'] . ' ' . $currency_code;
3685 $json['invoice_id'] = !empty($order->metaValue('invoice_id')) ? $order->metaValue('invoice_id') : '';
3686 $json['paid_by'] = trans('lang.pay_sender_note');
3687 if ($order->payment_gateway == "paypal") {
3688 $json['need_help'] = trans('lang.need_help');
3689 $json['paypal_note'] = trans('lang.paypal_note');
3690 $json['paypal_warning_note'] = trans('lang.paypal_warning_note');
3691 }
3692 $json['memo'] = trans('lang.memo');
3693 return Response::json($json, 200);
3694 }
3695 } else {
3696 $json['type'] = 'error';
3697 $json['message'] = trans('lang.no_record');
3698 return Response::json($json, 203);
3699 }
3700 }
3701
3702 /**
3703 * Display a listing of the resource.
3704 *
3705 * @return \Illuminate\Http\Response
3706 */
3707 public function getPackages()
3708 {
3709 $json = array();
3710
3711 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3712 $role_type = Helper::getRoleTypeByUserID($user_id);
3713 $counter = 0;
3714 if (!empty($user_id) && $role_type == "doctor") {
3715 $package_options = Helper::getPackageOptions();
3716 $packages = Package::all()->where('trial', 0);
3717 $currency = SiteManagement::getMetaValue('payment_settings');
3718 $symbol = !empty($currency) && !empty($currency['currency']) ? Helper::currencyList($currency['currency']) : array();
3719 if (!empty($packages) && $packages->count() > 0) {
3720 foreach ($packages as $key => $package) {
3721 $options = unserialize($package->options);
3722 if (!empty($package)) {
3723 $json[$counter]['title'] = !empty($package->title) ? $package->title : '';
3724 $json[$counter]['slug'] = !empty($package->slug) ? $package->slug : '';
3725 $json[$counter]['subtitle'] = !empty($package->subtitle) ? $package->subtitle : '';
3726 $json[$counter]['symbol'] = !empty($symbol['symbol']) ? $symbol['symbol'] : '$';
3727 $json[$counter]['price'] = !empty($package->cost) ? $package->cost : '';
3728 $json[$counter]['id'] = $package->id;
3729 $features = array();
3730 $count = 0;
3731 foreach ($options as $option_key => $option) {
3732 if ($option_key == 'featured' || $option_key == 'private_chat' || $option_key == 'bookings') {
3733 $class = $option == 'true' ? 'true' : 'false';
3734 $json[$counter]['features'][$count]['title'] = $option_key;
3735 $json[$counter]['features'][$count]['value'] = $class;
3736 } else if ($option_key == 'duration') {
3737 $json[$counter]['features'][$count]['title'] = $option_key;
3738 $json[$counter]['features'][$count]['value'] = Helper::getPackageDurationList($options['duration']);
3739 } else {
3740 $json[$counter]['features'][$count]['title'] = $option_key;
3741 $json[$counter]['features'][$count]['value'] = $option;
3742 }
3743 $count++;
3744 }
3745 // $json[$counter]['features'] = $features;
3746 }
3747 $counter++;
3748 }
3749 return Response::json($json, 200);
3750 }
3751 } else {
3752 $json['type'] = 'error';
3753 $json['message'] = trans('lang.not_authorize');
3754 return Response::json($json, 203);
3755 }
3756 }
3757
3758 /**
3759 * Post Article.
3760 *
3761 * @param \Illuminate\Http\Request $request request
3762 *
3763 * @return \Illuminate\Http\Response
3764 */
3765 public function postArticle(Request $request)
3766 {
3767 $this->validate(
3768 $request,
3769 [
3770 'title' => 'required',
3771 'description' => 'required'
3772 ]
3773 );
3774 if (empty($request['categories'])) {
3775 $response['type'] = 'cat-required';
3776 $response['message'] = trans('lang.cat_required');
3777 return $response;
3778 }
3779 $server = Helper::doctieIsDemoSiteAjax();
3780 if (!empty($server)) {
3781 $response['type'] = 'error';
3782 $response['message'] = $server->getData()->message;
3783 return $response;
3784 }
3785 $json = array();
3786 if (!empty($request)) {
3787 if (!empty($request['id'])) {
3788 $image_size = Helper::getImageSizes('articles');
3789 $article = new Article();
3790 $post_article = $article->createArticleAPI($request, $image_size);
3791 if ($post_article == "success") {
3792 $json['message'] = trans('lang.article_created');
3793 return Response::json($json, 200);
3794 } else {
3795 $json['type'] = 'error';
3796 $json['message'] = trans('lang.something_wrong');
3797 return Response::json($json, 203);
3798 }
3799 } else {
3800 $json['type'] = 'error';
3801 $json['message'] = trans('lang.something_wrong');
3802 return Response::json($json, 203);
3803 }
3804 } else {
3805 $json['type'] = 'error';
3806 $json['message'] = trans('lang.something_wrong');
3807 return Response::json($json, 203);
3808 }
3809 }
3810
3811 /**
3812 * Show hospital team listing
3813 *
3814 * @param \Illuminate\Http\Request $request request attributes
3815 *
3816 * @access public
3817 *
3818 * @return View
3819 */
3820 public function approveUser(Request $request)
3821 {
3822 $json = array();
3823 $server = Helper::doctieIsDemoSiteAjax();
3824 if (!empty($server)) {
3825 $response['type'] = 'error';
3826 $response['message'] = $server->getData()->message;
3827 return $response;
3828 }
3829 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3830 $role_type = !empty($user_id) ? Helper::getRoleTypeByUserID($user_id) : '';
3831 if (!empty($role_type) && $role_type === 'hospital') {
3832 $team = Team::findOrFail($request['id']);
3833 $team->status = 'approved';
3834 $team->save();
3835 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
3836 $email_params = array();
3837 $doctor_approve_req_template = DB::table('email_types')->select('id')
3838 ->where('email_type', 'doctor_email_doctor_request_approved')->get()->first();
3839 if (!empty($doctor_approve_req_template->id)) {
3840 $hospital = User::findOrFail($team->user_id);
3841 $doctor = User::findOrFail($team->doctor_id);
3842 $template_data = EmailTemplate::getEmailTemplateByID($doctor_approve_req_template->id);
3843 $email_params['doctor_name'] = Helper::getUserName($doctor->id);
3844 $email_params['hospital_name'] = Helper::getUserName($hospital->id);
3845 $email_params['hospital_link'] = url('profile/'.$hospital->slug);
3846 Mail::to($doctor->email)
3847 ->send(
3848 new DoctorEmailMailable(
3849 'doctor_email_doctor_request_approved',
3850 $template_data,
3851 $email_params
3852 )
3853 );
3854 }
3855 }
3856 $json['message'] = 'updated';
3857 return Response::json($json, 200);
3858 } else {
3859 $json['type'] = 'error';
3860 $json['message'] = trans('lang.something_wrong');
3861 return Response::json($json, 203);
3862 }
3863 }
3864
3865 /**
3866 * Show hospital team listing
3867 *
3868 * @access public
3869 *
3870 * @return View
3871 */
3872 public function doctorListing()
3873 {
3874 $json = array();
3875 $server = Helper::doctieIsDemoSiteAjax();
3876 if (!empty($server)) {
3877 $response['type'] = 'error';
3878 $response['message'] = $server->getData()->message;
3879 return $response;
3880 }
3881 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
3882 $role_type = !empty($user_id) ? Helper::getRoleTypeByUserID($user_id) : '';
3883 if (!empty($role_type) && $role_type === 'hospital') {
3884 $hospital = User::findOrFail($user_id);
3885 $teams = !empty($hospital) ? $hospital->teams()->paginate(8) : array();
3886 $json['team'] = $teams;
3887 return Response::json($json, 200);
3888 } else {
3889 $json['type'] = 'error';
3890 $json['message'] = trans('lang.something_wrong');
3891 return Response::json($json, 203);
3892 }
3893 }
3894
3895 /**
3896 * Set slug before saving in DB
3897 *
3898 * @param \Illuminate\Http\Request $request request attributes
3899 *
3900 * @access public
3901 *
3902 * @return \Illuminate\Http\Response
3903 */
3904 public function verifyUserCode(Request $request)
3905 {
3906 $json = array();
3907 $id = $request['user_id'];
3908 $email = $request['email'];
3909 $password = $request['password'];
3910 $user = User::find($id);
3911 if (!empty($request['code'])) {
3912 if ($request['code'] === $user->verification_code) {
3913 $user->user_verified = 1;
3914 $user->verification_code = null;
3915 $user->save();
3916 $json['type'] = 'success';
3917 //send mail
3918 if (!empty(config('mail.username')) && !empty(config('mail.password'))) {
3919 $email_params = array();
3920 $template = DB::table('email_types')->select('id')->where('email_type', 'new_user')->get()->first();
3921 if (!empty($template->id)) {
3922 $template_data = EmailTemplate::getEmailTemplateByID($template->id);
3923 $email_params['site'] = env('APP_NAME');
3924 $email_params['name'] = Helper::getUserName($id);
3925 $email_params['email'] = $email;
3926 $email_params['password'] = $password;
3927 Mail::to($email)
3928 ->send(
3929 new GeneralEmailMailable(
3930 'new_user',
3931 $template_data,
3932 $email_params
3933 )
3934 );
3935 }
3936 $admin_template = DB::table('email_types')->select('id')->where('email_type', 'admin_email_registration')->get()->first();
3937 if (!empty($admin_template->id)) {
3938 $template_data = EmailTemplate::getEmailTemplateByID($admin_template->id);
3939 $email_params['name'] = Helper::getUserName($id);
3940 $email_params['email'] = $email;
3941 $email_params['link'] = url('profile/' . $user->slug);
3942 Mail::to(config('mail.username'))
3943 ->send(
3944 new AdminEmailMailable(
3945 'admin_email_registration',
3946 $template_data,
3947 $email_params
3948 )
3949 );
3950 }
3951 }
3952 return $json;
3953 } else {
3954 $json['type'] = 'error';
3955 $json['message'] = trans('lang.invalid_verified_code');
3956 return $json;
3957 }
3958 } else {
3959 $json['type'] = 'error';
3960 $json['message'] = trans('lang.verify_code');
3961 return $json;
3962 }
3963 }
3964
3965 /**
3966 * Get selected speciality service
3967 *
3968 * @param mixed $request request attributes
3969 *
3970 * @return \Illuminate\Http\Response
3971 */
3972 public function getServices()
3973 {
3974 $json = array();
3975 $speciality = Speciality::find($_GET['id']);
3976 if (!empty($speciality) && $speciality->services->count() > 0) {
3977 $services = $speciality->services->toArray();
3978 if (!empty($speciality)) {
3979 if (!empty($speciality)) {
3980 $json['services'] = $services;
3981 return Response::json($json, 200);
3982 } else {
3983 $json['type'] = 'error';
3984 $json['message'] = trans('lang.something_wrong');
3985 return Response::json($json, 203);
3986 }
3987 } else {
3988 $json['type'] = 'error';
3989 $json['message'] = trans('lang.something_wrong');
3990 return Response::json($json, 203);
3991 }
3992 } else {
3993 $json['type'] = 'error';
3994 $json['message'] = trans('lang.something_wrong');
3995 return Response::json($json, 203);
3996 }
3997 }
3998
3999 /**
4000 * Get forum settings data
4001 *
4002 * @access public
4003 *
4004 * @return \Illuminate\Http\Response
4005 */
4006 public function getBookingSettings()
4007 {
4008 $json = array();
4009 $booking_settings = SiteManagement::getMetaValue('booking_settings');
4010 $online_payment = !empty($booking_settings['enable_booking']) ? $booking_settings['enable_booking'] : '';
4011 if (!empty($online_payment)) {
4012 return Response::json($online_payment, 200);
4013 } else {
4014 $online_payment = false;
4015 return Response::json($online_payment, 203);
4016 }
4017 }
4018
4019 /**
4020 * Send payment link
4021 *
4022 * @access public
4023 *
4024 * @return \Illuminate\Http\Response
4025 */
4026 public function paymentLink(Request $request)
4027 {
4028 // $json = array();
4029 // $product_id = $_GET['product_id'];
4030 // $product_name = $_GET['product_name'];
4031 // $price = $_GET['price'];
4032 // $user_id = $_GET['user_id'];
4033 // $type = $_GET['type'];
4034
4035 // session()->put(['product_id' => $product_id]);
4036 // session()->put(['price' => $price]);
4037 // session()->put(['name' => $product_name]);
4038 // session()->put(['type' => $type]);
4039
4040 }
4041}
4042