Merge remote-tracking branch 'origin/staging' into origin/production

This commit is contained in:
Linksehat Staging Server
2024-05-28 10:56:28 +07:00
51 changed files with 3643 additions and 377 deletions

View File

@@ -19,33 +19,47 @@ class AuthController extends Controller
{
private $url;
public function __construct() {
public function __construct()
{
$this->url = $_ENV['LMS_APP_URL'];
}
public function login(Request $request)
{
{
$request->validate([
// 'email' => 'email',
'phone_or_email' => 'required',
// 'phone' => '',
// 'otp' => 'required_with:phone',
'password' => 'required',
'fcm_token' => 'required'
// 'otp' => 'required'
]);
// Login hit ke API linksehat, karena encrypt nya pake CI
$response = Http::post($this->url.'login', [
$response = Http::post($this->url . 'login', [
'sEmail' => $request->phone_or_email,
'sPassword' => $request->password,
'sRemember' => $request->remember
]);
$response = $response->json();
if ($response['success']){
if ($response['success']) {
$user = User::with('detail')
->where('sEmail', $request->phone_or_email)
->first();
->where('sEmail', $request->phone_or_email)
->first();
$user->notificationTokens()->updateOrCreate([
'device_id' => $request->device_id,
'token' => $request->fcm_token,
], [
'origin' => $request->origin,
'device_id' => $request->device_id,
'type' => $request->type,
'token' => $request->fcm_token,
'status' => $request->status,
]);
return Helper::responseJson(
data: [
'token' => $user->createToken('app')->plainTextToken,
@@ -58,18 +72,19 @@ class AuthController extends Controller
};
}
public function forgetPassword(Request $request){
public function forgetPassword(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
// Login hit ke API linksehat, karena encrypt nya pake CI
$response = Http::post($this->url.'forgot_password', [
$response = Http::post($this->url . 'forgot_password', [
'sEmail' => $request->email,
]);
$response = $response->json();
if ($response['success']){
if ($response['success']) {
return Helper::responseJson(
data: [],
message: 'Message has been sent.'
@@ -79,7 +94,8 @@ class AuthController extends Controller
};
}
public function resetPassword(Request $request){
public function resetPassword(Request $request)
{
$request->validate([
'email' => 'required|email',
'code' => 'required',
@@ -87,14 +103,14 @@ class AuthController extends Controller
]);
// Login hit ke API linksehat, karena encrypt nya pake CI
$response = Http::post($this->url.'reset_password', [
$response = Http::post($this->url . 'reset_password', [
'sCode' => $request->code,
'sEmail' => $request->email,
'sPassword' => $request->password,
]);
$response = $response->json();
if ($response['success']){
if ($response['success']) {
return Helper::responseJson(
data: [],
message: 'Password telah di reset'
@@ -105,7 +121,7 @@ class AuthController extends Controller
}
public function loginPhone(Request $request)
{
{
$request->validate([
'phone_or_email' => 'required',
'otp' => 'required',
@@ -116,10 +132,9 @@ class AuthController extends Controller
'sPhone' => $request->phone_or_email,
'sVerificationCode' => $request->otp
])
->first();
if ($user){
->first();
if ($user) {
$updateVericationCode = User::with('detail')
->where([
'sPhone' => $request->phone_or_email,
@@ -127,6 +142,9 @@ class AuthController extends Controller
])->update([
'sVerificationCode' => null,
]);
$user->fcm_token = $request->fcm_token;
$user->save();
return Helper::responseJson(
data: [
'token' => $user->createToken('app')->plainTextToken,
@@ -145,15 +163,15 @@ class AuthController extends Controller
$user = User::with('detail')
->where('sPhone', $request->phone_or_email)
->first();
if ($user){
if ($user) {
// Request OTP ke API linksehat
$response = Http::post($this->url.'generate_code', [
$response = Http::post($this->url . 'generate_code', [
'sPhone' => $request->phone_or_email
]);
$response = $response->json();
return Helper::responseJson(
data: [
'otp' => $response['message'],
@@ -168,9 +186,6 @@ class AuthController extends Controller
message: 'Nomor tidak ditemukan'
);
}
}
public function register(Request $request)
@@ -209,7 +224,7 @@ class AuthController extends Controller
return Helper::responseJson(message: 'Behasil Logout.');
}
public function mockOtp(Request $request)
{
$request->validate([
@@ -256,4 +271,32 @@ class AuthController extends Controller
'token' => $user->createToken('app')->plainTextToken
], message: 'Selamat Datang');
}
public function notificationToken(Request $request)
{
$user = Auth::user();
$origin = $request->origin;
$device_id = $request->device_id;
$type = $request->type;
$token = $request->token;
$status = $request->status;
$user->fcm_token = $request->token;
$user->save();
// $userUpdate = User::where
$user->notificationTokens()->updateOrCreate([
'device_id' => $device_id,
], [
'origin' => $origin,
'device_id' => $device_id,
'type' => $type,
'token' => $token,
'status' => $status,
]);
return response()->json([
'message' => 'Token berhasil disimpan',
]);
}
}

View File

@@ -74,7 +74,7 @@ class ChatController extends Controller
public function listChannel(Request $request){
// Validasi request jika diperlukan
$channel = Channel::where('member_id',$request->user_id)->get()->toArray();
if (!$channel) {
$dataChannel = Channel::where('doctor_id',$request->user_id)->get()->toArray();
$data = [];
@@ -86,11 +86,11 @@ class ChatController extends Controller
->first();
$urlAvatarDefault = $user->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatarMember = $user->detail->sImage ?? $urlAvatarDefault;
$arr['id'] = $d['id'];
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
$arr['id'] = $d['id'];
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
array_push($data, $arr);
}
@@ -101,14 +101,14 @@ class ChatController extends Controller
return response()->json(['message' => 'Get List Channel successfully', 'channel' => $channel]);
}
public function sendMessage(Request $request)
{
// Validasi request jika diperlukan
$validatedData = $request->validate([
'user_id' => 'required'
]);
// Ambil data dari request
$message = Message::create([
'content' => $request->message,
@@ -142,7 +142,7 @@ class ChatController extends Controller
]);
}
// Berikan respons yang sesuai ke klien
$channel = Channel::where('id',$request->channel_id)->first();
if($channel->member_id == $request->user_id){
// Get nama dokter
@@ -151,13 +151,13 @@ class ChatController extends Controller
} else {
// Get nama pasien
$person = User::where('nID', $channel->member_id)->first();
$name = $person->sFirstName . ' ' . $person->sLastName;
$name = $person->sFirstName . ' ' . $person->sLastName;
}
ChatMessageSent::dispatch($message);
return response()->json([
'message' => 'Message sent successfully',
'message' => 'Message sent successfully',
'data' => [
'header' => $name,
]
@@ -169,8 +169,8 @@ class ChatController extends Controller
// Buat instance Pusher dengan konfigurasi yang sesuai
$channel = Channel::where('id',$request->channel_id)->first();
$livechat = Livechat::where([
'doctor_id' => $channel->doctor_id,
'patient_id' => $channel->member_id,
'doctor_id' => $channel->doctor_id,
'patient_id' => $channel->member_id,
])->latest('created_at')->first();
if($channel->member_id == $request->user_id){
@@ -181,37 +181,61 @@ class ChatController extends Controller
$age = '';
$gender = '';
$question = '';
$consultationStart = $livechat->start_date;
$consultationEnd = $livechat->end_date;
$work = '';
$weight = '-';
$height = '-';
$address = '';
$maritalStatus = '';
} else {
// Get nama pasien
$user = User::where('nID', $channel->member_id)->with('detail')->first();
$name = $user->sFirstName . ' ' . $user->sLastName;
$urlAvatarDefault = $user->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatar = $user->detail->sImage ?? $urlAvatarDefault;
$gender = DB::connection('oldlms')->table('tm_jenis_kelamin')->where('nID', $user->detail->nIDJenisKelamin)->first('sJenisKelamin');
if ($gender){
$gender = $gender->sJenisKelamin;
$name = $user->sFirstName . ' ' . $user->sLastName;
$gender = null;
if ($user->detail) {
$urlAvatarDefault = $user->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatar = $user->detail->sImage ?? $urlAvatarDefault;
$gender = DB::connection('oldlms')->table('tm_jenis_kelamin')->where('nID', $user->detail->nIDJenisKelamin)->first('sJenisKelamin');
$age = Helper::calculateAge($user->detail->dTanggalLahir);
if ($gender){
$gender = $gender->sJenisKelamin;
}
$work = DB::connection('oldlms')->table('tm_pekerjaan')->where('nID', $user->detail->nIDPekerjaan)->first('sPekerjaan');
if($work){
$work = $work->sPekerjaan;
}
$maritalStatus = DB::connection('oldlms')->table('tm_status_pernikahan')->where('nID', $user->detail->sMartialStatus)->first('sStatusPernikahan');
if($maritalStatus){
$maritalStatus = $maritalStatus->sStatusPernikahan;
}
$weight = $user->detail->sWeight;
$height = $user->detail->sWeight;
} else {
$avatar = 'https://linksehat.dev/assets/img/users/male-avatar.png';
$age = '-';
$work = '-';
$maritalStatus = '-';
$weight = '-';
$height = '-';
}
$age = Helper::calculateAge($user->detail->dTanggalLahir);
$question = $livechat->descriptions;
$consultationStart = $livechat->start_date;
$consultationEnd = $livechat->end_date;
$work = DB::connection('oldlms')->table('tm_pekerjaan')->where('nID', $user->detail->nIDPekerjaan)->first('sPekerjaan');
if($work){
$work = $work->sPekerjaan;
}
$address = DB::connection('oldlms')->table('tm_users_address')->where('nIDUser', $user->nID)->first('sAlamat');
if($address){
$address = $address->sAlamat;
}
}
// Ini Untul Chat
$perPage = $request->input('per_page', 10); // Default 10 pesan per halaman
$page = $request->input('page', 1); // Default halaman 1
@@ -220,7 +244,7 @@ class ChatController extends Controller
->where('type', '!=', 'trigger')
->orderBy('created_at', 'desc') // Urutkan berdasarkan created_at secara descending
->paginate($perPage, ['*'], 'page', $page);
// Data Consultation Summary
$consultationSummary = [
'subject' => $livechat->subject,
@@ -240,12 +264,22 @@ class ChatController extends Controller
'header' => $name,
'avatar' => $avatar,
'gender' => $gender,
'marital_status' => $maritalStatus,
'age' => $age,
'weight' => $weight,
'height' => $height,
'question' => $question,
'diseases' => [],
'medications' => [],
'allergy' => [],
'family_history' => [],
'start' => $consultationStart,
'end' => $consultationEnd,
'work' => $work,
'address' => $address,
'consultation_id' => $livechat->id,
'consultation_status' => Helper::getStatusLivechat($livechat->status),
'health_sertificate' => $healthSertificate,
'chat' => $data->items(),
'pagination' => [
'total' => $data->total(),
@@ -256,8 +290,7 @@ class ChatController extends Controller
'to' => $data->lastItem(),
],
'summary' => $consultationSummary,
'livechat_id' => $livechat->id,
'health_sertificate' => $healthSertificate,
]
]);
}
@@ -278,7 +311,7 @@ class ChatController extends Controller
])->latest('created_at')->first();
$user = User::where('nID', $livechat->patient_id)->with('detail')->first();
$name = $user->sFirstName . ' ' . $user->sLastName;
$name = $user->sFirstName . ' ' . $user->sLastName;
$age = Helper::calculateAge($user->detail->dTanggalLahir);
$person = Person::where('id', $livechat->doctor_id)->first();
@@ -294,7 +327,7 @@ class ChatController extends Controller
}
// Memuat view pdf_view.php ke dalam variabel
$calculateDate = Helper::calculateDateDifference($livechat->health_certificate_start, $livechat->health_certificate_end);
$data = [
'name' => $name,
'age' => $age,

View File

@@ -24,15 +24,18 @@ class AuthDoctorController extends Controller
{
$data = [
'email' => $request->email,
'password' => $request->password
'password' => $request->password,
'fcm_token' => $request->fcm_token,
];
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required'
'password' => 'required',
'fcm_token' => 'required'
], [
'email.required' => trans('Validation.required',['attribute' => 'Email']),
'email.email' => trans('Validation.email'),
'password.required' => trans('Validation.required',['attribute' => 'Password']),
'fcm_token.required' => trans('Validation.required',['attribute' => 'FCM Token']),
]);
if ($validator->fails())
@@ -50,6 +53,18 @@ class AuthDoctorController extends Controller
return ApiResponse::apiResponse('Bad Request', $data, trans('Message.password'), 400);
}
$user->notificationTokens()->updateOrCreate([
'device_id' => $request->device_id,
'token' => $request->fcm_token,
], [
'origin' => $request->origin,
'device_id' => $request->device_id,
'type' => $request->type,
'token' => $request->fcm_token,
'status' => $request->status,
]);
$res_data = [
// 'user' => $user,
'token' => $user->createToken('app')->plainTextToken

View File

@@ -3,6 +3,7 @@
namespace Modules\Linksehat\Http\Controllers\Api\Doctor;
use App\Http\Controllers\Controller;
use App\Notifications\SendNotification;
use App\Models\User;
use App\Models\OLDLMS\User as UserLMS;
use App\Models\Livechat;
@@ -23,6 +24,8 @@ use Modules\HospitalPortal\Helpers\ApiResponse;
use App\Helpers\Helper;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Laravel\Firebase\Facades\Firebase;
class ChatDoctorController extends Controller
{
@@ -44,8 +47,12 @@ class ChatDoctorController extends Controller
if($chat) {
foreach($chat as $c){
$patient = UserLMS::where('nID',$c->patient_id)->with('detail')->first();
$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;
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;
} else {
$avatarMember = 'https://linksehat.dev/assets/img/users/male-avatar.png';
}
$arr['id'] = $c->id;
$arr['patient_id'] = $patient->nID;
$arr['avatar'] = $avatarMember;
@@ -68,11 +75,11 @@ class ChatDoctorController extends Controller
} else {
$avatarMember = 'https://linksehat.dev/assets/img/users/male-avatar.png';
}
$arr['id'] = $d['id'];
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
$arr['id'] = $d['id'];
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
array_push($dataOnGoing, $arr);
}
@@ -119,7 +126,7 @@ class ChatDoctorController extends Controller
}
return ApiResponse::apiResponse("Success", $data, trans('Message.success'), 200);
}
public function declineChat(Request $request)
{
$livechat = Livechat::find($request->id);
@@ -128,6 +135,34 @@ class ChatDoctorController extends Controller
$livechat->status = 3; // Decline
// Menyimpan perubahan ke database
$livechat->save();
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'Decline Livechat';
$body = 'Decline Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'decline-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return response()->json(['message' => 'Livechat not found'], 404);
@@ -143,7 +178,33 @@ class ChatDoctorController extends Controller
$livechat->accept_date = date('Y-m-d H:i:s'); // Accept
// Menyimpan perubahan ke database
$livechat->save();
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'Approve Request Livechat';
$body = 'Approve Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'approve-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
} else {
return response()->json(['message' => 'Livechat not found'], 404);
}
@@ -155,10 +216,36 @@ class ChatDoctorController extends Controller
if ($livechat) {
// Memperbarui atribut model
$livechat->status = 6; // End Chat
$livechat->end_date = date('Y-m-d H:i:s'); // Accept
$livechat->end_date = date('Y-m-d H:i:s'); // Endchat
// Menyimpan perubahan ke database
$livechat->save();
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'End Livechat';
$body = 'End Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'end-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
} else {
return response()->json(['message' => 'Livechat not found'], 404);
}
@@ -166,7 +253,6 @@ class ChatDoctorController extends Controller
public function summaryChat(Request $request)
{
$livechat = Livechat::find($request->id);
if ($livechat) {
// Memperbarui atribut model

View File

@@ -3,11 +3,14 @@
namespace Modules\Linksehat\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Notifications\SendNotification;
use App\Models\Organization;
use App\Models\Speciality;
use App\Models\Livechat;
use App\Models\Channel;
use App\Models\UserChannel;
use App\Models\User as UserAso;
use App\Models\OLDLMS\User;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
@@ -285,16 +288,15 @@ class DuitkuController extends Controller
'created_at' => date('Y-m-d H:i:s')
]);
if ($notif->resultCode == "00") {
if ($notif->resultCode == "00") { // berhasil melakukan pembayaran
// Action Success
$livechat = Livechat::where('uuid', $notif->merchantOrderId)->first();
// Update status pembayaran
$livechat->payment_method = $notif->paymentCode;
$livechat->status = 5; // success payment
$livechat->save();
// 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,
@@ -330,9 +332,26 @@ class DuitkuController extends Controller
]
);
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Succes Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'success-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
// Berikan respons yang sesuai ke klien
return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]);
} else if ($notif->resultCode == "01") {
// Action Failed
$livechat = Livechat::where('uuid', $notif->merchantOrderId)->first();
@@ -341,6 +360,22 @@ class DuitkuController extends Controller
$livechat->status = 7; // failed payment
$livechat->save();
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Failed Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'failed-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
return response()->json(['message' => 'User Gagal melakukan pembayaran']);
}

View File

@@ -2,6 +2,7 @@
namespace Modules\Linksehat\Http\Controllers\Api;
use App\Notifications\SendNotification;
use App\Helpers\Helper;
use App\Helpers\DuitkuHelper;
use App\Services\Duitku;
@@ -9,8 +10,10 @@ use App\Models\Organization;
use App\Models\PractitionerRole;
use App\Models\Invoice;
use App\Models\PaymentsMethods;
use App\Models\Channel;
use App\Models\Livechat;
use App\Models\OLDLMS\User;
use App\Models\User as UserAso;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -20,6 +23,9 @@ use Illuminate\Support\Facades\Validator;
use App\Http\Controllers\DuitkuController;
use DB;
use Illuminate\Contracts\Filesystem\Cloud;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Laravel\Firebase\Facades\Firebase;
use Str;
class LivechatController extends Controller
@@ -45,7 +51,7 @@ class LivechatController extends Controller
$urlAvatarDefault = $user->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatarMember = $user->detail->sImage ?? $urlAvatarDefault;
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $user->nIDHubunganKeluarga)->first('sHubunganKeluarga');
$dataUser = [
'id' => $user->nID,
'name' => $user->sFirstName . ' ' . $user->sLastName,
@@ -59,7 +65,7 @@ class LivechatController extends Controller
$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'],
@@ -75,17 +81,17 @@ class LivechatController extends Controller
$memberProfile = User::with('detail')->where('nIDUser', $nID)->get()->toArray();
$dataMember = User::with('detail')->where('nID', $nID)->get()->first();
if ($user->detail){
$urlAvatarDefault = $user->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 = $user->detail->sImage ?? $urlAvatarDefault;
$avatarMember = $dataMember->detail->sImage ?? $urlAvatarDefault;
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $user->detail->nIDHubunganKeluarga)->first('sHubunganKeluarga');
$dataUser = [
'id' => $dataMember->nID,
'name' => $dataMember->sFirstName . ' ' . $dataMember->sLastName,
@@ -99,20 +105,20 @@ class LivechatController extends Controller
$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);
}
}
}
}
}
return Helper::responseJson([
'member' => $dataMemberProfile
]);
@@ -133,11 +139,11 @@ class LivechatController extends Controller
'descriptions' => 'required',
], [
'doctor_id.required' => 'ID Dokter harus diisi',
'patient_id.required' => 'ID Dokter harus diisi',
'descriptions.required' => 'Description harus diisi',
'patient_id.required' => 'ID Pasien harus diisi',
'descriptions.required' => 'Deskripsi harus diisi',
]);
if ($validator->fails()){
if ($validator->fails()) {
return Helper::responseJson(
status: 'Bad Request',
statusCode: 400,
@@ -148,27 +154,52 @@ class LivechatController extends Controller
/**
* Status Livechat
* 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat
* 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;
$data['uuid'] = (string) Str::orderedUuid();
$data['status'] = 1;
$data['status'] = 1; // Request
$livechat = Livechat::create($data);
$doctor = $livechat->doctor;
$data = [
$responseData = [
'id' => $livechat->id,
'request_date' => $livechat->request_date,
'image_path' =>'https'
'image_path' => 'https' // Ganti dengan path yang benar jika ada
];
return Helper::responseJson(data: $data);
// Send Notification
$doctorId = $livechat->doctor_id;
$user = UserAso::find($doctorId);
$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();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'request-chat'
];
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return Helper::responseJson(data: $responseData);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
}
}
public function consultation_request_show($id){
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
@@ -198,7 +229,7 @@ class LivechatController extends Controller
],
],
'total' => $totalPay
];
return Helper::responseJson(data: $data);
}
@@ -216,9 +247,9 @@ class LivechatController extends Controller
'active' => 1,
'config_pmc_id' => 2,
])->get()->toArray();
$payment = DuitkuHelper::paymentMethod();
$price = $practitionerRole->price ? $practitionerRole->price : 30000;
$discount = 0;
$adminFee = 5000;
@@ -234,7 +265,7 @@ class LivechatController extends Controller
'va' => $va
]
// 'payment_method' => json_decode($payment)
];
return Helper::responseJson(data: $data);
}
@@ -290,7 +321,6 @@ class LivechatController extends Controller
// Membuat invoice menggunakan DuitkuHelper
$duitku = DuitkuHelper::createInvoice($data);
return response()->json(['success' => true, 'data' => $duitku], 200);
} catch (Exception $e) {
// Menangkap error dan mengembalikan respon error

View File

@@ -34,7 +34,7 @@ use Modules\Linksehat\Http\Controllers\Api\Doctor\ChatDoctorController;
Broadcast::routes(['middleware' => ['auth:sanctum']]);
Route::prefix('linksehat')->group(function () {
Route::get('dashboard/{query}/{limit?}', [DashboardController::class, 'index']);
Route::controller(SearchController::class)->group(function () {
@@ -72,13 +72,14 @@ Route::prefix('linksehat')->group(function () {
Route::get('doctors/{id}', 'show')->name('doctors.show');
});
Route::middleware('auth:sanctum')->group(function () {
Route::middleware(['auth:sanctum', 'linksehat.old.auth'])->group(function () {
Route::post('notification-token', [AuthController::class,'notificationToken']);
Route::get('profile/{id}', [ProfileController::class, 'index'])->name('profile');
Route::get('change-profile/{id}', [ProfileController::class, 'changeProfile'])->name('change-profile');
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
Route::post('profile-add', [ProfileController::class, 'store'])->name('profile.store');
Route::post('notification-tokens/delete/{id}', [NotificationTokenController::class, 'destroy'])->name('profile.delete.token');
Route::post('notification-tokens', [NotificationTokenController::class, 'store'])->name('profile.store.token');
// Route::post('notification-tokens/delete/{id}', [NotificationTokenController::class, 'destroy'])->name('profile.delete.token');
// Route::post('notification-tokens', [NotificationTokenController::class, 'store'])->name('profile.store.token');
Route::apiResource('appointment', AppointmentController::class);
Route::apiResource('families', PersonController::class)->except(['destroy']);
@@ -99,7 +100,7 @@ Route::prefix('linksehat')->group(function () {
Route::get('home', 'index')->name('homes.index');
Route::get('home/hospital', 'listHospital')->name('homes.listHospital');
});
Route::controller(LivechatController::class)->group(function () {
Route::get('livechat', 'index')->name('livechats.index');
Route::get('livechat/consultation', 'consultation')->name('livechats.consultation');
@@ -114,15 +115,14 @@ Route::prefix('linksehat')->group(function () {
Route::controller(ChatController::class)->group(function () {
Route::post('livechat/send-message', 'sendMessage');
Route::get('livechat/get-message', 'getMessage');
Route::post('livechat/channel','createChannel');
Route::get('livechat/channel','listChannel');
Route::get('livechat/{id}/health-sertificate','downloadHealtcare');
Route::post('livechat/channel', 'createChannel');
Route::get('livechat/channel', 'listChannel');
Route::get('livechat/{id}/health-sertificate', 'downloadHealtcare');
});
Route::post('create-invoice-duitku', [DuitkuController::class, 'createInvoice']);
Route::post('check-status-duitku', [DuitkuController::class, 'checkStatus']);
});
Route::post('payment-method-duitku', [DuitkuController::class, 'paymentMethod']);
@@ -130,9 +130,9 @@ Route::prefix('linksehat')->group(function () {
Route::get('redirect-duitku', [DuitkuController::class, 'redirect']);
//DOCTOR API
Route::prefix('doctor')->group(function() {
Route::prefix('doctor')->group(function () {
//Version 1.0
Route::prefix('v1')->group(function() {
Route::prefix('v1')->group(function () {
Route::middleware(Authentication::class)->group(function () {
Route::controller(AuthDoctorController::class)->group(function () {
Route::post('login', 'login');
@@ -163,7 +163,6 @@ Route::prefix('linksehat')->group(function () {
Route::post('resend-code', 'forgotPassword');
Route::post('reset-password', 'resetPassword');
});
});
});
;});
});;
});