update message summary

This commit is contained in:
2024-06-10 10:00:46 +07:00
parent 36ca4925d9
commit 8956d8c13f
4 changed files with 57 additions and 2 deletions

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;
@@ -234,8 +237,6 @@ class ChatController extends Controller
if($address){
$address = $address->sAlamat;
}
}
// Ini Untul Chat
@@ -259,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',
@@ -292,6 +306,7 @@ class ChatController extends Controller
'to' => $data->lastItem(),
],
'summary' => $consultationSummary,
'prescription' => $prescriptions
]
]);

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
{
@@ -249,6 +250,14 @@ class ChatDoctorController extends Controller
$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();
@@ -287,6 +296,7 @@ class ChatDoctorController extends Controller
'organization_id' => $livechat->organization_id,
]);
$prescriptionItem = [];
if ($request->prescriptions) {
foreach ($request->prescriptions as $prescription) {
$prescriptionItem = PrescriptionItem::create([
@@ -299,6 +309,27 @@ 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' => 'summary',
'from_user' => $livechat->doctor_id,
'channel_id' => $channel->id,
'type' => 'summary'
]);
ChatMessageSent::dispatch($message);
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return response()->json(['message' => 'Livechat not found'], 404);

View File

@@ -15,4 +15,9 @@ class Prescription extends Model
'organization_id',
'icd_code'
];
public function items()
{
return $this->hasMany(PrescriptionItem::class, 'prescription_id');
}
}

View File

@@ -17,4 +17,8 @@ class PrescriptionItem extends Model
'signa',
'direction'
];
public function drug(){
return $this->hasOne(Drug::class, 'id');
}
}