diff --git a/Modules/Linksehat/Http/Controllers/Api/ChatController.php b/Modules/Linksehat/Http/Controllers/Api/ChatController.php index b1659599..2aa3efaa 100644 --- a/Modules/Linksehat/Http/Controllers/Api/ChatController.php +++ b/Modules/Linksehat/Http/Controllers/Api/ChatController.php @@ -34,7 +34,8 @@ class ChatController extends Controller // Buat dan simpan data channel ke dalam tabel $channel = Channel::updateOrCreate([ - 'name' => $request->member_id .'_' . $request->doctor_id, + 'member_id' => $request->member_id, + 'doctor_id' => $request->doctor_id, ], [ 'name' => $request->member_id .'_' . $request->doctor_id, @@ -91,6 +92,7 @@ class ChatController extends Controller $arr['avatar'] = $avatarMember; $arr['name'] = $user->sFirstName .' '.$user->sLastName; $arr['last_message'] = $lastMessage; + $arr['channel_id'] = $d['id']; array_push($data, $arr); } diff --git a/Modules/Linksehat/Http/Controllers/Api/Doctor/AuthDoctorController.php b/Modules/Linksehat/Http/Controllers/Api/Doctor/AuthDoctorController.php index 14c36b91..0606b30c 100644 --- a/Modules/Linksehat/Http/Controllers/Api/Doctor/AuthDoctorController.php +++ b/Modules/Linksehat/Http/Controllers/Api/Doctor/AuthDoctorController.php @@ -67,7 +67,8 @@ class AuthDoctorController extends Controller $res_data = [ // 'user' => $user, - 'token' => $user->createToken('app')->plainTextToken + 'token' => $user->createToken('app')->plainTextToken, + 'id' => $user->person->id ]; return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200); diff --git a/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php b/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php index 7b4848db..b979e00e 100644 --- a/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php +++ b/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php @@ -47,6 +47,7 @@ class ChatDoctorController extends Controller if($chat) { foreach($chat as $c){ $patient = UserLMS::where('nID',$c->patient_id)->with('detail')->first(); + $channel = Channel::where(['doctor_id'=> $c->doctor_id, 'member_id' => $c->patient_id])->first(); if ( $patient->detail) { $urlAvatarDefault = $patient->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png'; $avatarMember = $patient->detail->sImage ?? $urlAvatarDefault; @@ -56,14 +57,19 @@ class ChatDoctorController extends Controller $arr['id'] = $c->id; $arr['patient_id'] = $patient->nID; $arr['avatar'] = $avatarMember; - $arr['name'] = $patient->sFirstName .' '.$patient->sLastName; ; + $arr['name'] = $patient->sFirstName .' '.$patient->sLastName; + $arr['channel_id'] = $channel->id; array_push($dataIncomingChat, $arr); } } $dataChannel = Channel::where('doctor_id',$user->person_id)->get()->toArray(); $dataOnGoing = []; - if ($dataChannel){ + $chatOngoing = Livechat::where([ + 'doctor_id'=> $user->person_id, + 'status' => 5 + ])->get()->first(); + if ($chatOngoing && $dataChannel){ foreach($dataChannel as $d){ $user = UserLMS::with('detail')->where('nID', $d['member_id'])->first(); $lastMessage = Message::where('channel_id', $d['id']) @@ -80,6 +86,7 @@ class ChatDoctorController extends Controller $arr['avatar'] = $avatarMember; $arr['name'] = $user->sFirstName .' '.$user->sLastName; $arr['last_message'] = $lastMessage; + $arr['channel_id'] = $d['id']; array_push($dataOnGoing, $arr); } @@ -145,13 +152,16 @@ class ChatDoctorController extends Controller 'doctor_id' => $livechat->doctor_id ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string) $channel->id, + 'livechat_id' => (string) $livechat->id, 'type' => 'decline-chat' ]; $user = UserLMS::where('nID',$livechat->patient_id)->first(); if ($user) { + if ($user->nIDUser) { // Jika Dependent yang request + $user = UserLMS::where('nIDUser',$livechat->patient_id)->first(); + } $user->notify(new SendNotification($title, $body, $dataNotif)); return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200); } else { @@ -188,13 +198,16 @@ class ChatDoctorController extends Controller 'doctor_id' => $livechat->doctor_id ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string)$channel->id, + 'livechat_id' => (string)$livechat->id, 'type' => 'approve-chat' ]; $user = UserLMS::where('nID',$livechat->patient_id)->first(); if ($user) { + if ($user->nIDUser) { // Jika Dependent yang request + $user = UserLMS::where('nIDUser',$livechat->patient_id)->first(); + } $user->notify(new SendNotification($title, $body, $dataNotif)); return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200); } else { @@ -229,14 +242,17 @@ class ChatDoctorController extends Controller 'doctor_id' => $livechat->doctor_id ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string)$channel->id, + 'livechat_id' => (string)$livechat->id, 'type' => 'end-chat' ]; $user = UserLMS::where('nID',$livechat->patient_id)->first(); if ($user) { + if ($user->nIDUser) { // Jika Dependent yang request + $user = UserLMS::where('nIDUser',$livechat->patient_id)->first(); + } $user->notify(new SendNotification($title, $body, $dataNotif)); return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200); } else { diff --git a/Modules/Linksehat/Http/Controllers/Api/DuitkuController.php b/Modules/Linksehat/Http/Controllers/Api/DuitkuController.php index 964a45ff..8a9be088 100644 --- a/Modules/Linksehat/Http/Controllers/Api/DuitkuController.php +++ b/Modules/Linksehat/Http/Controllers/Api/DuitkuController.php @@ -297,44 +297,11 @@ class DuitkuController extends Controller // Update start chat $livechat->start_date = date('Y-m-d H:i:s'); $livechat->save(); - // Buat dan simpan data channel ke dalam tabel - $channel = Channel::updateOrCreate([ - 'name' => $livechat->patient_id .'_' . $request->doctor_id, - ], - [ - 'name' => $livechat->patient_id .'_' . $livechat->doctor_id, - 'type' => 'Private', - 'member_id' => $livechat->patient_id, - 'doctor_id' => $livechat->doctor_id, - ]); - // Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk member_id - $userChannelMember = UserChannel::updateOrCreate( - [ - 'user_id' => $livechat->patient_id, - 'channel_id' => $channel->id - ], - [ - 'user_id' => $livechat->patient_id, - 'channel_id' => $channel->id - ] - ); - - // Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk doctor_id - $userChannelDoctor = UserChannel::updateOrCreate( - [ - 'user_id' => $livechat->doctor_id, - 'channel_id' => $channel->id - ], - [ - 'user_id' => $livechat->doctor_id, - 'channel_id' => $channel->id - ] - ); // Send Notification $doctorId = $livechat->doctor_id; - $userDokter = UserAso::find($doctorId); + $userDokter = UserAso::where('person_id',$doctorId)->first(); $title = 'Payment Succes Livechat'; $patient = User::where('nID', $livechat->patient_id)->first(); $body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName; @@ -343,11 +310,12 @@ class DuitkuController extends Controller 'doctor_id' => $livechat->doctor_id ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string) $channel->id, + 'livechat_id' => (string) $livechat->id, 'type' => 'success-payment' ]; $userDokter->notify(new SendNotification($title, $body, $dataNotif)); + $patient->notify(new SendNotification($title, $body, $dataNotif)); // Berikan respons yang sesuai ke klien return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]); @@ -362,7 +330,7 @@ class DuitkuController extends Controller // Send Notification $doctorId = $livechat->doctor_id; - $userDokter = UserAso::find($doctorId); + $userDokter = UserAso::where('person_id',$doctorId)->first(); $title = 'Payment Failed Livechat'; $patient = User::where('nID', $livechat->patient_id)->first(); $body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName; @@ -371,11 +339,12 @@ class DuitkuController extends Controller 'doctor_id' => $livechat->doctor_id ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string) $channel->id, + 'livechat_id' => (string) $livechat->id, 'type' => 'failed-payment' ]; $userDokter->notify(new SendNotification($title, $body, $dataNotif)); + $patient->notify(new SendNotification($title, $body, $dataNotif)); return response()->json(['message' => 'User Gagal melakukan pembayaran']); } diff --git a/Modules/Linksehat/Http/Controllers/Api/LivechatController.php b/Modules/Linksehat/Http/Controllers/Api/LivechatController.php index 8a240e38..8c99b4e8 100644 --- a/Modules/Linksehat/Http/Controllers/Api/LivechatController.php +++ b/Modules/Linksehat/Http/Controllers/Api/LivechatController.php @@ -21,7 +21,7 @@ use Illuminate\Support\Facades\Http; use Modules\Linksehat\Transformers\Livechat\LivechatResource; use Illuminate\Support\Facades\Validator; use App\Http\Controllers\DuitkuController; - +use App\Models\UserChannel; use DB; use Illuminate\Contracts\Filesystem\Cloud; use Kreait\Firebase\Messaging\CloudMessage; @@ -156,7 +156,6 @@ class LivechatController extends Controller * Status Livechat * 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat, 7=Payment Failed */ - $timezone = date_default_timezone_get(); $data['request_date'] = date('Y-m-d H:i:s'); $data['timezone'] = $timezone; @@ -171,19 +170,55 @@ class LivechatController extends Controller 'image_path' => 'https' // Ganti dengan path yang benar jika ada ]; + // Buat dan simpan data channel ke dalam tabel + $channel = Channel::updateOrCreate([ + 'member_id' => $livechat->patient_id, + 'doctor_id' => $livechat->doctor_id, + ], + [ + 'name' => $livechat->patient_id .'_' . $livechat->doctor_id, + 'type' => 'Private', + 'member_id' => $livechat->patient_id, + 'doctor_id' => $livechat->doctor_id, + ]); + + // Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk member_id + UserChannel::updateOrCreate( + [ + 'user_id' => $livechat->patient_id, + 'channel_id' => $channel->id + ], + [ + 'user_id' => $livechat->patient_id, + 'channel_id' => $channel->id + ] + ); + + // Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk doctor_id + UserChannel::updateOrCreate( + [ + 'user_id' => $livechat->doctor_id, + 'channel_id' => $channel->id + ], + [ + 'user_id' => $livechat->doctor_id, + 'channel_id' => $channel->id + ] + ); + // Send Notification $doctorId = $livechat->doctor_id; - $user = UserAso::find($doctorId); + $user = UserAso::where('person_id',$doctorId)->first(); $title = 'New Request Livechat'; $patient = User::where('nID', $livechat->patient_id)->first(); $body = 'Request Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName; - $channel = Channel::where([ - 'member_id' => $livechat->patient_id, - 'doctor_id' => $livechat->doctor_id - ])->first(); + // $channel = Channel::where([ + // 'member_id' => $livechat->patient_id, + // 'doctor_id' => $livechat->doctor_id + // ])->first(); $dataNotif = [ - 'channel_id' => $channel->id, - 'livechat_id' => $livechat->id, + 'channel_id' => (string) $channel->id, + 'livechat_id' => (string) $livechat->id, 'type' => 'request-chat' ]; diff --git a/Modules/Linksehat/Transformers/Home/HomeResource.php b/Modules/Linksehat/Transformers/Home/HomeResource.php index 274ca362..fa8b560b 100644 --- a/Modules/Linksehat/Transformers/Home/HomeResource.php +++ b/Modules/Linksehat/Transformers/Home/HomeResource.php @@ -99,11 +99,11 @@ class HomeResource extends JsonResource }; if (count($memberProfile) > 0){ - + $urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png'; $avatarMember = $this->detail->sImage ?? $urlAvatarDefault; $relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $this->nIDHubunganKeluarga)->first('sHubunganKeluarga'); - + $dataUser = [ 'id' => $this->nID, 'name' => $this->sFirstName . ' ' . $this->sLastName, @@ -117,7 +117,7 @@ class HomeResource extends JsonResource $urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png'; $avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault; $relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga'); - + $data = [ 'id' => $m['nID'], 'name' => $m['full_name'], @@ -135,17 +135,17 @@ class HomeResource extends JsonResource $memberProfile = User::with('detail')->where('nIDUser', $nID)->get()->toArray(); $dataMember = User::with('detail')->where('nID', $nID)->get()->first(); - + if ($this->detail){ $urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png'; } else { $urlAvatarDefault = 'https://linksehat.dev/assets/img/users/male-avatar.png'; } $avatar = $this->detail->sImage ?? $urlAvatarDefault; - + $avatarMember = $dataMember->detail->sImage ?? $urlAvatarDefault; $relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $this->nIDHubunganKeluarga)->first('sHubunganKeluarga'); - + $dataUser = [ 'id' => $dataMember->nID, 'name' => $dataMember->sFirstName . ' ' . $dataMember->sLastName, @@ -159,14 +159,14 @@ class HomeResource extends JsonResource $urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png'; $avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault; $relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga'); - + $data = [ 'id' => $m['nID'], 'name' => $m['full_name'], 'relationship' => $relationship->sHubunganKeluarga, 'avatar' => $avatarMember, ]; - + array_push( $dataMemberProfile, $data); } } @@ -195,6 +195,7 @@ class HomeResource extends JsonResource $specialist = 'Umum'; $year = 0; $price = 0; + $organizationId = 0; if (!empty($doctor['person']['start_date_work'])) { $starExperience = Carbon::parse($doctor['person']['start_date_work'])->format('Y-m-d'); $experience = Carbon::createFromFormat('Y-m-d', $starExperience); @@ -203,15 +204,19 @@ class HomeResource extends JsonResource if ($doctor['practitioner_roles']) { if ($doctor['practitioner_roles'][0]['speciality']){ $specialist = $doctor['practitioner_roles'][0]['speciality']['name']; - } + } if ($doctor['practitioner_roles'][0]['price']){ $price = $doctor['practitioner_roles'][0]['price']; - } + } + if ($doctor['practitioner_roles'][0]['organization_id']){ + $organizationId = $doctor['practitioner_roles'][0]['organization_id']; + } } $data = [ - 'id' => $doctor['id'], + 'id' => $doctor['person']['id'], 'full_name' => $doctor['person']['name'], 'specialist' => $specialist, + 'organization_id' => $organizationId, 'experience' => $year, 'review' => $doctor['person']['review'], 'price' => $price, @@ -224,8 +229,8 @@ class HomeResource extends JsonResource $hospitalList = []; $hospitals = Organization::where([ - 'type' => 'hospital', - 'status' => 'active', + 'type' => 'hospital', + 'status' => 'active', ]) ->with('currentAddress') ->get()->toArray(); @@ -248,7 +253,7 @@ class HomeResource extends JsonResource if ($lat && $lang && $request->longitude && $request->latitude){ $radius = round(Helper::calculateDistance($lat, $lang, $request->latitude, $request->longitude), 2); } - + $data = [ 'name' => $hospital['name'], 'radius' => $radius, @@ -259,7 +264,7 @@ class HomeResource extends JsonResource array_push($hospitalList, $data); } - + usort($hospitalList, function($a, $b) { return $a['radius'] <=> $b['radius']; }); diff --git a/Modules/Linksehat/Transformers/Livechat/LivechatResource.php b/Modules/Linksehat/Transformers/Livechat/LivechatResource.php index e1d974d1..0ab7c56c 100644 --- a/Modules/Linksehat/Transformers/Livechat/LivechatResource.php +++ b/Modules/Linksehat/Transformers/Livechat/LivechatResource.php @@ -48,6 +48,7 @@ class LivechatResource extends JsonResource $specialist = 'Umum'; $year = 0; $price = 0; + $organizationId = 0; if (!empty($doctor['person']['start_date_work'])) { $starExperience = Carbon::parse($doctor['person']['start_date_work'])->format('Y-m-d'); $experience = Carbon::createFromFormat('Y-m-d', $starExperience); @@ -56,15 +57,19 @@ class LivechatResource extends JsonResource if ($doctor['practitioner_roles']) { if ($doctor['practitioner_roles'][0]['speciality']){ $specialist = $doctor['practitioner_roles'][0]['speciality']['name']; - } + } if ($doctor['practitioner_roles'][0]['price']){ $price = $doctor['practitioner_roles'][0]['price']; - } + } + if ($doctor['practitioner_roles'][0]['organization_id']){ + $organizationId = $doctor['practitioner_roles'][0]['organization_id']; + } } $data = [ - 'id' => $doctor['id'], + 'id' => $doctor['person']['id'], 'full_name' => $doctor['person']['name'], 'specialist' => $specialist, + 'organization_id' => $organizationId, 'experience' => $year, 'review' => $doctor['person']['review'], 'price' => $price, @@ -76,7 +81,7 @@ class LivechatResource extends JsonResource return [ 'jadwal_weekday' => 'Senin - Jumat (08:00 - 17:30)', 'jadwal_weekend' => 'Sabtu (08:00 - 12:00)', - 'doctors_livechat' => + 'doctors_livechat' => $doctorsLivechat , 'specialist' => $specialists