api chat, send summary, health sertificate, callback duitku
This commit is contained in:
@@ -2,17 +2,22 @@
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Channel;
|
||||
use App\Events\ChatMessageSent;
|
||||
use App\Models\UserChannel;
|
||||
use App\Models\Message;
|
||||
use App\Models\File;
|
||||
use App\Models\Livechat;
|
||||
use App\Models\Person;
|
||||
use App\Models\OLDLMS\User;
|
||||
use App\Models\OLDLMS\UserDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
use Pusher\Pusher;
|
||||
|
||||
class ChatController extends Controller
|
||||
@@ -36,7 +41,6 @@ class ChatController extends Controller
|
||||
'type' => $request->type,
|
||||
'member_id' => $request->member_id,
|
||||
'doctor_id' => $request->doctor_id,
|
||||
// Jika ada kolom tambahan, tambahkan di sini
|
||||
]);
|
||||
|
||||
// Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk member_id
|
||||
@@ -166,34 +170,144 @@ class ChatController extends Controller
|
||||
public function getMessage(Request $request)
|
||||
{
|
||||
// Buat instance Pusher dengan konfigurasi yang sesuai
|
||||
$pusher = new Pusher(
|
||||
env('PUSHER_APP_KEY'),
|
||||
env('PUSHER_APP_SECRET'),
|
||||
env('PUSHER_APP_ID'),
|
||||
[
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'useTLS' => true,
|
||||
]
|
||||
);
|
||||
$channel = Channel::where('id',$request->channel_id)->first();
|
||||
$livechat = Livechat::where([
|
||||
'doctor_id' => $channel->doctor_id,
|
||||
'patient_id' => $channel->member_id,
|
||||
])->latest('created_at')->first();
|
||||
|
||||
if($channel->member_id == $request->user_id){
|
||||
// Get nama dokter
|
||||
$person = Person::where('id', $channel->doctor_id)->first();
|
||||
$name = $person->name;
|
||||
$avatar = '';
|
||||
$age = '';
|
||||
$gender = '';
|
||||
$question = '';
|
||||
|
||||
$consultationStart = $livechat->start_date;
|
||||
$consultationEnd = $livechat->end_date;
|
||||
$work = '';
|
||||
$address = '';
|
||||
} else {
|
||||
// Get nama pasien
|
||||
$person = User::where('nID', $channel->member_id)->first();
|
||||
$name = $person->sFirstName . ' ' . $person->sLastName;
|
||||
$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;
|
||||
}
|
||||
$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
|
||||
$data = Message::where('channel_id', $request->channel_id)->get()->toArray();
|
||||
|
||||
// Data Consultation Summary
|
||||
$consultationSummary = [
|
||||
'subject' => $livechat->subject,
|
||||
'object' => $livechat->object,
|
||||
'assessment' => $livechat->assessment,
|
||||
'plan' => $livechat->plan,
|
||||
];
|
||||
|
||||
$healthSertificate = false;
|
||||
if ($livechat->health_certificate_start && $livechat->health_certificate_end){
|
||||
$healthSertificate = True;
|
||||
}
|
||||
|
||||
$data = Message::where('channel_id', $request->channel_id)->get()->toArray();
|
||||
// Berikan respons yang sesuai ke klien
|
||||
return response()->json([
|
||||
'message' => 'Message sent successfully',
|
||||
'data' => [
|
||||
'header' => $name,
|
||||
'chat' => $data
|
||||
'avatar' => $avatar,
|
||||
'gender' => $gender,
|
||||
'age' => $age,
|
||||
'question' => $question,
|
||||
'start' => $consultationStart,
|
||||
'end' => $consultationEnd,
|
||||
'work' => $work,
|
||||
'address' => $address,
|
||||
'chat' => $data,
|
||||
'summary' => $consultationSummary,
|
||||
'livechat_id' => $livechat->id,
|
||||
'health_sertificate' => $healthSertificate
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function downloadHealtcare($id){
|
||||
$pdf = new Dompdf();
|
||||
|
||||
$options = new Options();
|
||||
$options->set('isHtml5ParserEnabled', true);
|
||||
$options->set('isPhpEnabled', true);
|
||||
$options->set(['isRemoteEnabled' => true]);
|
||||
$pdf->setOptions($options);
|
||||
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
$livechat = Livechat::where([
|
||||
'id' => $id
|
||||
])->latest('created_at')->first();
|
||||
|
||||
$user = User::where('nID', $livechat->patient_id)->with('detail')->first();
|
||||
$name = $user->sFirstName . ' ' . $user->sLastName;
|
||||
$age = Helper::calculateAge($user->detail->dTanggalLahir);
|
||||
|
||||
$person = Person::where('id', $livechat->doctor_id)->first();
|
||||
$doctorName = $person->name;
|
||||
|
||||
$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;
|
||||
}
|
||||
// Memuat view pdf_view.php ke dalam variabel
|
||||
$calculateDate = Helper::calculateDateDifference($livechat->health_certificate_start, $livechat->health_certificate_end);
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'age' => $age,
|
||||
'work' => $work,
|
||||
'address' => $address,
|
||||
'doctor_name' => $doctorName,
|
||||
'date' => $livechat->created_at,
|
||||
'start_date' => $livechat->health_certificate_start,
|
||||
'end_date' => $livechat->health_certificate_end,
|
||||
'calculate_date' => $calculateDate
|
||||
];
|
||||
// Halaman 1
|
||||
$html1 = view('pdf.health_sertificate', $data);
|
||||
$htmlCombined = $html1 ;
|
||||
|
||||
$pdf->loadHtml($htmlCombined);
|
||||
$pdf->render();
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="file.pdf"',
|
||||
];
|
||||
|
||||
return response($pdf->output(), 200, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user