236 lines
9.3 KiB
PHP
236 lines
9.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Linksehat\Http\Controllers\Api;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Helpers\DuitkuHelper;
|
|
use App\Models\Organization;
|
|
use App\Models\PractitionerRole;
|
|
use App\Models\PaymentsMethods;
|
|
use App\Models\Livechat;
|
|
use App\Models\OLDLMS\User;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Modules\Linksehat\Transformers\Livechat\LivechatResource;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use DB;
|
|
use Str;
|
|
|
|
class LivechatController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$user = User::with('detail')
|
|
->where('nId', $request->id)
|
|
->first();
|
|
return Helper::responseJson([
|
|
'livechat' => LivechatResource::make($user, $request),
|
|
]);
|
|
}
|
|
|
|
public function consultation(Request $request)
|
|
{
|
|
$dataMemberProfile = [];
|
|
$user = User::with('detail')
|
|
->where('nId', $request->member_id)
|
|
->first();
|
|
$memberProfile = User::with('detail')->where('nIDUser', $request->member_id)->get()->toArray();
|
|
if (count($memberProfile) > 0){
|
|
$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,
|
|
'relationship' => $relationship ? $relationship->sHubunganKeluarga : '-',
|
|
'avatar' => $avatarMember
|
|
];
|
|
|
|
array_push($dataMemberProfile, $dataUser);
|
|
|
|
foreach($memberProfile as $m){
|
|
$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 ? $relationship->sHubunganKeluarga : '-',
|
|
'avatar' => $avatarMember,
|
|
];
|
|
|
|
array_push($dataMemberProfile, $data);
|
|
}
|
|
} else {
|
|
$nID = $user->nIDUser ? $user->nIDUser : $user->nID;
|
|
if ($nID){
|
|
$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,
|
|
'relationship' => 'Me',
|
|
'avatar' => $avatarMember
|
|
];
|
|
array_push($dataMemberProfile, $dataUser);
|
|
|
|
if (count($memberProfile) > 0){
|
|
foreach($memberProfile as $m){
|
|
$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
|
|
]);
|
|
}
|
|
|
|
public function consultation_request(Request $request)
|
|
{
|
|
$data = [
|
|
'doctor_id' => $request->doctor_id,
|
|
'patient_id' => $request->patient_id,
|
|
'organization_id' => $request->organization_id,
|
|
'descriptions' => $request->descriptions
|
|
];
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
'doctor_id' => 'required',
|
|
'patient_id' => 'required',
|
|
'descriptions' => 'required',
|
|
], [
|
|
'doctor_id.required' => 'ID Dokter harus diisi',
|
|
'patient_id.required' => 'ID Dokter harus diisi',
|
|
'descriptions.required' => 'Description harus diisi',
|
|
]);
|
|
|
|
if ($validator->fails()){
|
|
return Helper::responseJson(
|
|
status: 'Bad Request',
|
|
statusCode: 400,
|
|
message: $validator->errors()
|
|
);
|
|
} else {
|
|
// insert table livechat
|
|
$timezone = date_default_timezone_get();
|
|
$data['request_date'] = date('Y-m-d H:i:s');
|
|
$data['timezone'] = $timezone;
|
|
$data['uuid'] = (string) Str::orderedUuid();
|
|
$livechat = Livechat::create($data);
|
|
$doctor = $livechat->doctor;
|
|
$data = [
|
|
'id' => $livechat->id,
|
|
'request_date' => $livechat->request_date,
|
|
'image_path' =>'https'
|
|
];
|
|
|
|
|
|
return Helper::responseJson(data: $data);
|
|
}
|
|
}
|
|
public function consultation_request_show($id){
|
|
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
|
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
|
|
|
$price = $practitionerRole->price ? $practitionerRole->price : 30000;
|
|
$discount = 0;
|
|
$adminFee = 5000;
|
|
$totalPay = $price + $adminFee - $discount;
|
|
$data = [
|
|
'id' => $livechat->id,
|
|
'code_transaksi' => $livechat->uuid,
|
|
'doctor_id' => $livechat->doctor_id,
|
|
'doctor_name' => $livechat->doctor->name,
|
|
'doctor_specialist' => 'Umum',
|
|
'price' => $price,
|
|
'admin_price' => $adminFee,
|
|
'promo' => [
|
|
[
|
|
'id' => 1,
|
|
'code' => 'SEHATBERSAMA',
|
|
'discount_percent' => 20
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'code' => 'MARET MERIAH',
|
|
'discount_percent' => 5
|
|
],
|
|
],
|
|
'total' => $totalPay
|
|
|
|
];
|
|
return Helper::responseJson(data: $data);
|
|
}
|
|
public function consultation_payment_choose($id){
|
|
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
|
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
|
$eWallet = PaymentsMethods::where(
|
|
[
|
|
'active' => 1,
|
|
'config_pmc_id' => 3,
|
|
])->get()->toArray();
|
|
$va = PaymentsMethods::where(
|
|
[
|
|
'active' => 1,
|
|
'config_pmc_id' => 2,
|
|
])->get()->toArray();
|
|
|
|
$payment = DuitkuHelper::paymentMethod();
|
|
|
|
$price = $practitionerRole->price ? $practitionerRole->price : 30000;
|
|
$discount = 0;
|
|
$adminFee = 5000;
|
|
$totalPay = $price + $adminFee - $discount;
|
|
$data = [
|
|
'id' => $livechat->id,
|
|
'code_transaksi' => $livechat->uuid,
|
|
'price' => $price,
|
|
'admin_price' => $adminFee,
|
|
'total' => $totalPay,
|
|
'payment_method' => [
|
|
'ewallet' => $eWallet,
|
|
'va' => $va
|
|
]
|
|
// 'payment_method' => json_decode($payment)
|
|
|
|
];
|
|
return Helper::responseJson(data: $data);
|
|
}
|
|
|
|
public function consultation_payment(Request $request){
|
|
|
|
$duitku = DuitkuHelper::paymentMethod();
|
|
dd($duitku);
|
|
}
|
|
}
|