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

This commit is contained in:
Linksehat Staging Server
2024-06-14 08:32:47 +07:00
40 changed files with 2955 additions and 132 deletions

View File

@@ -135,7 +135,7 @@ class DrugController extends Controller
]);
}
}
public function downloadTemplate()
public function downloadTemplate()
{
return Helper::responseJson([
'file_name' => "Template - Drugs.xlsx",
@@ -149,7 +149,6 @@ class DrugController extends Controller
$data = Excel::toArray([], $file);
$processedData = $this->processCategoryNames($data);
$importedRows = 0;
$failedRows = [];
@@ -170,6 +169,7 @@ class DrugController extends Controller
'type' => $row['type'],
'dosage' => $row['dosage'],
'remark' => $row['remark'],
'price' => $row['price'],
]
);
$importedRows++;
@@ -201,7 +201,7 @@ class DrugController extends Controller
$row[] = $data[0][$i];
$header[] = $data[0][0];
}
$filed = [];
foreach ($header[0] as $value)
{
@@ -212,16 +212,16 @@ class DrugController extends Controller
$filed[] = $modelColumn;
}
}
$result = [];
foreach ($row as $subarray) {
$trimmedSubarray = [];
for ($i = 0; $i < count($filed); $i++) {
$trimmedSubarray[$filed[$i]] = $subarray[$i] ? $subarray[$i] : null;
}
$result[] = $trimmedSubarray;
}
return $result;
}
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Modules\Internal\Http\Controllers\Api;
use App\Models\Navigations;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class NavigationController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index(Request $request)
{
// Ambil semua navigasi dari tabel dan ubah menjadi array
$navigations = Navigations::all()->toArray();
$navigationMaster = [];
if ($navigations) {
// Buat array untuk menyimpan menu utama
foreach ($navigations as $navigation) {
if ($navigation['parent_id'] == 0) {
// Tambahkan menu utama ke $navigationMaster
$navigation['children'] = []; // Siapkan array untuk children
$navigationMaster[$navigation['id']] = $navigation;
}
}
// Tambahkan submenu ke menu utama yang sesuai
foreach ($navigations as $navigation) {
if ($navigation['parent_id'] != 0 && isset($navigationMaster[$navigation['parent_id']])) {
$navigationMaster[$navigation['parent_id']]['children'][] = $navigation;
}
}
}
// Ubah array menjadi list tanpa indeks id
$navigationMaster = array_values($navigationMaster);
// Transformasi data untuk sesuai dengan format yang diinginkan
$formattedNavigation = [
'items' => array_map(function ($navItem) {
return [
'title' => $navItem['title'],
'path' => $navItem['path'],
'children' => array_map(function ($child) {
return [
'title' => $child['title'],
'path' => $child['path'],
'icon' => $child['icon'], // Asumsikan Anda memiliki field 'icon' di tabel navigasi
'permission' => $child['permission'],
];
}, $navItem['children']),
'permission' => $navItem['permission'],
];
}, $navigationMaster)
];
return response()->json($formattedNavigation);
}
/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view('internal::create');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
//
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
return view('internal::show');
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view('internal::edit');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}

View File

@@ -135,6 +135,7 @@ class PrescriptionController extends Controller
'sKodeResep' => $kodeResep,
'sDiagnose' => $sDiagnosis,
'sKodeRS' => $hospital,
'sStatus' => 1, // bayar'
];
$prescription = Prescription::updateOrCreate([
@@ -164,9 +165,11 @@ class PrescriptionController extends Controller
$drugData = Drug::where('id', $value['drug_id'])->first();
$drug = '';
$drugCode = '';
$drugPrice = 0;
if ($drugData){
$drug = $drugData->name;
$drugCode = $drugData->code;
$drugPrice = $drugData->price;
}
$unitData = Unit::where('id', $value['unit_id'])->first();
$unit = '';
@@ -192,6 +195,7 @@ class PrescriptionController extends Controller
'sSatuan' => $unit,
'sSigna' => $value['signa'],
'sNote' => $value['note'],
'nHarga' => $drugPrice
];
try {
// Insert to ASO

View File

@@ -6,12 +6,159 @@ use App\Helpers\Helper;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Permission;
use App\Models\User;
use App\Models\Person;
use Crypt;
class UserManagemet extends Controller
class UserManagementController extends Controller
{
public function index(Request $request){
$user = User::all();
return Helper::responseJson(data: $user);
public function index(Request $request)
{
$query = Role::query();
if ($request->has('search')) {
$search = $request->get('search');
$query->where('name', 'like', "%{$search}%");
}
$userRole = $query->paginate(10);
return Helper::paginateResources($userRole);
}
}
public function permission_list(Request $request)
{
$permissions = Permission::all();
return response()->json($permissions);
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'guard_name' => 'required|string|max:255', // Pastikan setiap permission ada di tabel permissions
]);
$newRole = Role::create([
'name' => $validated['name'],
'guard_name' => $validated['guard_name'],
]);
if (isset($request->permission_check)) {
$newRole->syncPermissions($request->permission_check);
}
return response()->json($newRole, 201);
}
public function edit($id)
{
$role = Role::with('permissions')->findOrFail($id);
return response()->json($role);
}
public function update(Request $request, $id)
{
$role = Role::with('permissions')->findOrFail($id);
$validated = $request->validate([
'name' => 'required|string|max:255',
'guard_name' => 'required|string|max:255',
'permission_check' => 'nullable|array',
'permission_check.*' => 'exists:permissions,id', // Pastikan setiap permission ada di tabel permissions
]);
$role->update([
'name' => $validated['name'],
'guard_name' => $validated['guard_name'],
]);
if (isset($validated['permission_check'])) {
$permissions = Permission::whereIn('id', $validated['permission_check'])
->where('guard_name', $validated['guard_name'])
->get();
if ($permissions->count() !== count($validated['permission_check'])) {
return response()->json(['error' => 'One or more permissions are invalid for the specified guard.'], 422);
}
$role->syncPermissions($permissions);
}
return response()->json($role);
}
public function list_role(Request $request)
{
$query = Role::all();
$data = [
'data' => $query
];
return response()->json($data);
}
public function store_access(Request $request){
$user = User::create([
'email' => $request->email,
'username' => $request->username,
'role_id' => $request->roles,
'password' => Hash::make($request->password),
]);
$person = Person::updateOrCreate(
[
'id' => $user->person_id
],
[
'name' => $request->name ?? null
]
);
$user->person_id = $person->id;
$user->save();
return response()->json($user);
}
// List Access
public function list_access(Request $request){
$userAccess = User::query();
if ($request->has('search')) {
$search = $request->get('search');
$userAccess->where('name', 'like', "%{$search}%");
}
$userAccess = $userAccess->paginate(10);
return Helper::paginateResources($userAccess);
}
public function edit_access($id){
$userAccess = User::findOrFail($id);
return response()->json($userAccess);
}
public function update_access(Request $request, $id){
$userAccess = User::findOrFail($id);
if (!$userAccess) {
return response()->json(['error' => 'User Not found.'], 404);
}
$userAccess->email = $request->email;
$userAccess->username = $request->username;
$userAccess->role_id = $request->roles;
if ($request->password){
$userAccess->password = Hash::make($request->password);
}
$person = Person::updateOrCreate(
[
'id' => $userAccess->person_id
],
[
'name' => $request->name ?? null
]
);
$userAccess->person_id = $person->id;
$userAccess->save();
return response()->json($userAccess);
}
}

View File

@@ -39,10 +39,12 @@ use Modules\Internal\Http\Controllers\Api\ServiceController;
use Modules\Internal\Http\Controllers\Api\PrescriptionController;
use Modules\Internal\Http\Controllers\Api\SpecialityController;
use Modules\Internal\Http\Controllers\Api\VillageController;
use Modules\Internal\Http\Controllers\Api\NavigationController;
use Modules\Internal\Http\Controllers\Api\AuditTrailController;
use Modules\Internal\Http\Controllers\Api\DailyMonitoringController;
use Modules\Internal\Http\Controllers\Api\LaboratoriumResultController;
use Modules\Internal\Http\Controllers\Api\CorporateManageController;
use Modules\Internal\Http\Controllers\Api\UserManagementController;
use Modules\Internal\Http\Controllers\ClaimEncounterController;
// Report
@@ -70,6 +72,10 @@ Route::prefix('internal')->group(function () {
Route::get('linksehat/payments', [PaymentController::class, 'index']);
Route::get('linksehat/payments/generate-excel', [PaymentController::class, 'generateExcel']);
Route::get('diagnosis', [RequestLogController::class, 'diagnosis']);
Route::get('drugs', [DrugController::class, 'drugList']);
Route::get('units', [DrugController::class, 'unitList']);
Route::middleware('auth:sanctum')->group(function () {
@@ -288,11 +294,10 @@ Route::prefix('internal')->group(function () {
Route::post('customer-service/request/final-log', [RequestLogController::class, 'updateFinalLog']);
// search diagnosis
Route::get('diagnosis', [RequestLogController::class, 'diagnosis']);
// Route::get('diagnosis', [RequestLogController::class, 'diagnosis']);
Route::get('hospitals', [RequestLogController::class, 'hospitals']);
Route::get('drugs', [DrugController::class, 'drugList']);
Route::get('units', [DrugController::class, 'unitList']);
// Route::get('drugs', [DrugController::class, 'drugList']);
// Route::get('units', [DrugController::class, 'unitList']);
// insert benefit
Route::post('customer-service/request/insert-benefit', [RequestLogBenefitController::class, 'store']);
@@ -355,6 +360,23 @@ Route::prefix('internal')->group(function () {
});
});
// User Management Role
Route::get('user/role', [UserManagementController::class, 'index']);
Route::post('user/role', [UserManagementController::class, 'store']);
Route::get('user/role/{id}', [UserManagementController::class, 'edit']);
Route::put('user/role/{id}', [UserManagementController::class, 'update']);
Route::get('permission_list', [UserManagementController::class, 'permission_list']);
// User Role Access
Route::get('user/access', [UserManagementController::class, 'list_access']);
Route::post('user/access', [UserManagementController::class, 'store_access']);
Route::get('user/access/{id}', [UserManagementController::class, 'edit_access']);
Route::put('user/access/{id}', [UserManagementController::class, 'update_access']);
Route::get('role-list', [UserManagementController::class, 'list_role']);
// Navigation
Route::get('navigations', [NavigationController::class, 'index']);
});
Route::get('province', [ProvinceController::class, 'index']);

View File

@@ -10,6 +10,9 @@ use App\Models\Message;
use App\Models\File;
use App\Models\Livechat;
use App\Models\Person;
use App\Models\Prescription;
use App\Models\PrescriptionItem;
use App\Models\Drug;
use App\Models\OLDLMS\User;
use App\Models\OLDLMS\UserDetail;
use Illuminate\Http\Request;
@@ -34,7 +37,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 +95,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);
}
@@ -232,8 +237,6 @@ class ChatController extends Controller
if($address){
$address = $address->sAlamat;
}
}
// Ini Untul Chat
@@ -257,6 +260,19 @@ class ChatController extends Controller
if ($livechat->health_certificate_start && $livechat->health_certificate_end){
$healthSertificate = True;
}
$prescription = Prescription::where('livechat_id', $livechat->id)->first();
$prescriptionItems = PrescriptionItem::with('drug')->where('prescription_id',$prescription->id)->get();
$prescriptions = [];
if ($prescriptionItems){
foreach($prescriptionItems as $item){
$row['medicine'] = $item->drug->name;
$row['direction'] = $item->direction;
$row['signa'] = $item->signa;
$row['note'] = $item->note;
array_push($prescriptions, $row);
}
}
// Berikan respons yang sesuai ke klien
return response()->json([
'message' => 'Message sent successfully',
@@ -290,6 +306,7 @@ class ChatController extends Controller
'to' => $data->lastItem(),
],
'summary' => $consultationSummary,
'prescription' => $prescriptions
]
]);

View File

@@ -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);

View File

@@ -26,6 +26,7 @@ use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Laravel\Firebase\Facades\Firebase;
use App\Events\ChatMessageSent;
class ChatDoctorController extends Controller
{
@@ -47,6 +48,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 +58,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 +87,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 +153,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,15 +199,18 @@ 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) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
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 {
return Helper::responseJson(
status: 'Not Found',
@@ -229,14 +243,25 @@ 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();
// Ambil Send End Chat
$message = Message::create([
'content' => 'end-chat',
'from_user' => $livechat->doctor_id,
'channel_id' => $channel->id,
'type' => 'end-chat'
]);
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 {
@@ -271,6 +296,7 @@ class ChatDoctorController extends Controller
'organization_id' => $livechat->organization_id,
]);
$prescriptionItem = [];
if ($request->prescriptions) {
foreach ($request->prescriptions as $prescription) {
$prescriptionItem = PrescriptionItem::create([
@@ -283,6 +309,44 @@ class ChatDoctorController extends Controller
}
}
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$data = [
'livechat' => $livechat,
'prescription_items' => $prescriptionItem
];
// Ambil data dari request
$message = Message::create([
'content' => json_encode($data),
'from_user' => $livechat->doctor_id,
'channel_id' => $channel->id,
'type' => 'summary'
]);
// Send Pusher
ChatMessageSent::dispatch($message);
$title = 'Decline Livechat';
$body = 'Decline Livechat';
$dataNotif = [
'channel_id' => (string) $channel->id,
'livechat_id' => (string) $livechat->id,
'type' => 'summary-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);
}
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return response()->json(['message' => 'Livechat not found'], 404);

View File

@@ -8,6 +8,7 @@ use App\Models\Organization;
use App\Models\Speciality;
use App\Models\Livechat;
use App\Models\Channel;
use App\Models\Message;
use App\Models\UserChannel;
use App\Models\User as UserAso;
use App\Models\OLDLMS\User;
@@ -277,7 +278,8 @@ class DuitkuController extends Controller
header('Content-Type: application/json');
$notif = json_decode($callback);
// $notif = $request; ini untuk di local
// $notif = $request; //ini untuk di local
// $callback = $notif; //ini untuk di local
DB::table('api_logs')
->insert([
@@ -297,44 +299,10 @@ 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 +311,22 @@ 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'
];
$question = $livechat->descriptions;
// Ambil data dari request
$message = Message::create([
'content' => $question,
'from_user' => $livechat->patient_id,
'channel_id' => $channel->id,
'type' => 'first_chat'
]);
$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 +341,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 +350,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']);
}

View File

@@ -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'
];

View File

@@ -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'];
});

View File

@@ -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