api chat, send summary, health sertificate, callback duitku
This commit is contained in:
@@ -4,7 +4,12 @@ namespace Modules\Linksehat\Http\Controllers\Api\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\OLDLMS\User as UserLMS;
|
||||
use App\Models\Livechat;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Message;
|
||||
use App\Models\Prescription;
|
||||
use App\Models\PrescriptionItem;
|
||||
use Crypt;
|
||||
use Error;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -32,42 +37,165 @@ class ChatDoctorController extends Controller
|
||||
$chat = Livechat::where([
|
||||
'doctor_id'=> $user->person_id,
|
||||
'accept_date'=> null,
|
||||
])->get()->toArray();
|
||||
dd($chat);
|
||||
'status' => 1
|
||||
])->get();
|
||||
|
||||
return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200);
|
||||
$dataIncomingChat = [];
|
||||
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;
|
||||
$arr['id'] = $c->id;
|
||||
$arr['patient_id'] = $patient->nID;
|
||||
$arr['avatar'] = $avatarMember;
|
||||
$arr['name'] = $patient->sFirstName .' '.$patient->sLastName; ;
|
||||
array_push($dataIncomingChat, $arr);
|
||||
}
|
||||
}
|
||||
|
||||
$dataChannel = Channel::where('doctor_id',$user->person_id)->get()->toArray();
|
||||
$dataOnGoing = [];
|
||||
if ($dataChannel){
|
||||
foreach($dataChannel as $d){
|
||||
$user = UserLMS::with('detail')->where('nID', $d['member_id'])->first();
|
||||
$lastMessage = Message::where('channel_id', $d['id'])
|
||||
->latest('created_at')
|
||||
->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;
|
||||
|
||||
array_push($dataOnGoing, $arr);
|
||||
}
|
||||
}
|
||||
$channel = $data;
|
||||
|
||||
$data = [
|
||||
'incoming_chat' => $dataIncomingChat,
|
||||
'ongoing_chat' => $dataOnGoing
|
||||
];
|
||||
|
||||
return ApiResponse::apiResponse("Success", $data, trans('Message.success'), 200);
|
||||
|
||||
}
|
||||
public function fWorkExperience($start, $end)
|
||||
|
||||
public function getChatDetail($id){
|
||||
$livechat = Livechat::find($id);
|
||||
$user = UserLMS::with('detail')->where('nID', $livechat->patient_id)->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;
|
||||
$gender = DB::connection('oldlms')->table('tm_jenis_kelamin')->where('nID', $user->detail->nIDJenisKelamin)->first('sJenisKelamin');
|
||||
$maritalStaus = DB::connection('oldlms')->table('tm_status_pernikahan')->where('nID', $user->detail->sMartialStatus)->first('sStatusPernikahan');
|
||||
$data = [];
|
||||
if ($livechat->status != 2){
|
||||
$data = [
|
||||
'id' => $user->nID,
|
||||
'name' => $user->sFirstName . ' ' . $user->sLastName,
|
||||
'avatar' => $avatarMember,
|
||||
'gender' => $gender->sJenisKelamin,
|
||||
'marital_status' => $maritalStaus->sStatusPernikahan,
|
||||
'age' => Helper::calculateAge($user->detail->dTanggalLahir),
|
||||
'weight' => $user->detail->sWeight,
|
||||
'height' => $user->detail->sHeight,
|
||||
'question' => $livechat->descriptions,
|
||||
'diseases' => [],
|
||||
'medications' => [],
|
||||
'allergy' => [],
|
||||
'family_history' => []
|
||||
];
|
||||
} else if ($livechat->status == 2){ // sudah accept, tinggal tunggu bayar pasient
|
||||
$data = [
|
||||
'message' => 'waiting payment'
|
||||
];
|
||||
}
|
||||
return ApiResponse::apiResponse("Success", $data, trans('Message.success'), 200);
|
||||
}
|
||||
|
||||
public function declineChat(Request $request)
|
||||
{
|
||||
$startDateString = $start; // Tanggal dan waktu awal
|
||||
$endDateString = $end ; // Tanggal dan waktu akhir
|
||||
|
||||
// Mengubah string tanggal ke timestamp UNIX
|
||||
$startTime = strtotime($startDateString);
|
||||
$endTime = strtotime($endDateString);
|
||||
|
||||
// Menghitung selisih waktu dalam detik
|
||||
$timeDifference = $endTime - $startTime;
|
||||
|
||||
// Menghitung jumlah tahun, bulan, dan hari dari selisih waktu
|
||||
$years = floor($timeDifference / (365 * 24 * 60 * 60));
|
||||
$months = floor(($timeDifference - ($years * 365 * 24 * 60 * 60)) / (30 * 24 * 60 * 60));
|
||||
$days = floor(($timeDifference - ($years * 365 * 24 * 60 * 60) - ($months * 30 * 24 * 60 * 60)) / (24 * 60 * 60));
|
||||
|
||||
// Formatkan hasilnya
|
||||
$experience = '';
|
||||
if ($years > 0) {
|
||||
$experience .= $years . ' years ';
|
||||
}
|
||||
if ($months > 0) {
|
||||
$experience .= $months . ' months ';
|
||||
}
|
||||
if ($days > 0) {
|
||||
$experience .= $days . ' days';
|
||||
$livechat = Livechat::find($request->id);
|
||||
if ($livechat) {
|
||||
// Memperbarui atribut model
|
||||
$livechat->status = 3; // Decline
|
||||
// Menyimpan perubahan ke database
|
||||
$livechat->save();
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
return $experience;
|
||||
public function approveChat(Request $request)
|
||||
{
|
||||
$livechat = Livechat::find($request->id);
|
||||
if ($livechat) {
|
||||
// Memperbarui atribut model
|
||||
$livechat->status = 2; // Accept
|
||||
$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);
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function endChat(Request $request)
|
||||
{
|
||||
$livechat = Livechat::find($request->id);
|
||||
if ($livechat) {
|
||||
// Memperbarui atribut model
|
||||
$livechat->status = 6; // End Chat
|
||||
$livechat->end_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);
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function summaryChat(Request $request)
|
||||
{
|
||||
|
||||
$livechat = Livechat::find($request->id);
|
||||
if ($livechat) {
|
||||
// Memperbarui atribut model
|
||||
$livechat->subject = $request->subject; // Subject
|
||||
$livechat->object = $request->object; // Object
|
||||
$livechat->assessment = $request->assessment; // Assessment
|
||||
$livechat->plan = $request->plan; // Plan
|
||||
|
||||
$livechat->health_certificate_start = $request->health_certificate_start; // start
|
||||
$livechat->health_certificate_end = $request->health_certificate_end; // end
|
||||
// Menyimpan perubahan ke database
|
||||
$livechat->save();
|
||||
|
||||
$prescriptions = Prescription::create([
|
||||
'livechat_id' => $livechat->id,
|
||||
'organization_id' => $livechat->organization_id,
|
||||
]);
|
||||
|
||||
if ($request->prescriptions) {
|
||||
foreach ($request->prescriptions as $prescription) {
|
||||
$prescriptionItem = PrescriptionItem::create([
|
||||
'prescription_id' => $prescriptions->id,
|
||||
'drug_id' => $prescription['medicine'],
|
||||
'signa' => $prescription['dosis'],
|
||||
'direction' => $prescription['direction'],
|
||||
'note' => $prescription['note'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user