initial commit
This commit is contained in:
913
app/Http/Controllers/Agent/AppointmentController.php
Normal file
913
app/Http/Controllers/Agent/AppointmentController.php
Normal file
@@ -0,0 +1,913 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Classes\Constant;
|
||||
use App\Events\DeviceCurrentStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Doctor;
|
||||
use App\Models\DoctorAppointment;
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemHistory;
|
||||
use App\Models\Lab;
|
||||
use App\Models\LabKit;
|
||||
use App\Models\LicenseNumberModel;
|
||||
use App\Models\Patient;
|
||||
use App\Models\PatientAnswer;
|
||||
use App\Models\PatientLab;
|
||||
use App\Models\PatientNote;
|
||||
use App\Models\PatientPrescription;
|
||||
use App\Models\PatientTask;
|
||||
use App\Models\Prescription;
|
||||
use App\Models\Question;
|
||||
use App\Models\QuestionBuilder;
|
||||
use App\Models\QuestionGroup;
|
||||
use App\Models\Telemedpro;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Prompts\Note;
|
||||
|
||||
class AppointmentController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$data = [];
|
||||
$appointments = Appointment::where('telemed_pros_id', $user->id)->get();
|
||||
foreach ($appointments as $appointment) {
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
array_push($data, [
|
||||
'id' => $appointment->id,
|
||||
'patient_name' => $patient->first_name . " " . $patient->last_name,
|
||||
'patient_id' => $appointment->patient_id,
|
||||
'telemed_pros_id ' => $appointment->telemed_pros_id,
|
||||
'appointment_time' => $appointment->appointment_time,
|
||||
'meeting_id' => $appointment->meeting_id,
|
||||
'created_at' => $appointment->created_at,
|
||||
'updated_at' => $appointment->updated_at,
|
||||
'in_call' => $appointment->in_call
|
||||
]);
|
||||
}
|
||||
// dd($data);
|
||||
return view('agent.appointments.index', ['appointments' => $data]);
|
||||
}
|
||||
|
||||
public function profile(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
return response()->json(['profile' => $user], 200);
|
||||
}
|
||||
public function profileImageUpload(Patient $patient, Request $request)
|
||||
{
|
||||
$user = $patient;
|
||||
$image = $request->get('image');
|
||||
$fileName = 'profile-' . time();
|
||||
|
||||
$logo = base64_decode($image);
|
||||
$ext = (explode('/', finfo_buffer(finfo_open(), $logo, FILEINFO_MIME_TYPE))[1]);
|
||||
|
||||
$imageName = $fileName . '.' . $ext;
|
||||
Storage::disk('local')->put("public/profile_pictures/" . $imageName, $logo);
|
||||
$user->profile_picture = $imageName;
|
||||
$user->save();
|
||||
return response()->json(['profile' => $user], 200);
|
||||
}
|
||||
|
||||
public function delete($id, Request $request)
|
||||
{
|
||||
Appointment::where('id', $id)->delete();
|
||||
$request->session()->flash('message', 'Appointment deleted successfully');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function patientDetails($id)
|
||||
{
|
||||
$appointment = Appointment::where('id', $id)->first();
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
return view('agent.appointments.patient-details', ['patient' => $patient, 'appointment_id' => $appointment->id]);
|
||||
}
|
||||
public function patientProfileDetails(Patient $patient)
|
||||
{
|
||||
return response()->json(['patient' => $patient], 200);
|
||||
}
|
||||
|
||||
|
||||
public function patientAddress($id)
|
||||
{
|
||||
$patient = Patient::where('id', $id)->first();
|
||||
return view('agent.appointments.patient-address', ['patient' => $patient]);
|
||||
}
|
||||
|
||||
public function savePatientAddress($id, Request $request)
|
||||
{
|
||||
$appointment = Appointment::where('id', $id)->first();
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
|
||||
$address = $request->input('address');
|
||||
$city = $request->input('city');
|
||||
$state = $request->input('state');
|
||||
$zip_code = $request->input('zip_code');
|
||||
|
||||
$patient->address = $address;
|
||||
$patient->city = $city;
|
||||
$patient->state = $state;
|
||||
$patient->zip_code = $zip_code;
|
||||
$patient->save();
|
||||
|
||||
$request->session()->flash('message', 'Address saved successfully');
|
||||
|
||||
|
||||
return view('agent.appointments.patient-details', ['patient' => $patient, 'appointment_id' => $appointment->id]);
|
||||
}
|
||||
|
||||
public function patientLabs($id)
|
||||
{
|
||||
$patient = Patient::where('id', $id)->first();
|
||||
$labs = Lab::where('city', 'like', '%' . $patient->city . '%')
|
||||
->orWhere('state', 'like', '%' . $patient->state . '%')
|
||||
->orWhere('zip_code', 'like', '%' . $patient->zip_code . '%')
|
||||
->get();
|
||||
return view('agent.appointments.patient-labs', ['patient' => $patient, 'labs' => $labs]);
|
||||
}
|
||||
|
||||
public function patientBookLab(Appointment $appointment, Request $request)
|
||||
{
|
||||
|
||||
$lab = new Lab();
|
||||
$lab->address = $request->input('lab_address');
|
||||
$lab->name = $request->input('lab_name');
|
||||
$lab->city = $request->input('lab_city');
|
||||
$lab->state = $request->input('lab_state');
|
||||
$lab->distance = $request->input('lab_distance');
|
||||
$lab->contact_no = $request->input('lab_contact_no');
|
||||
$lab->lang = $request->input('lab_lang');
|
||||
$lab->lat = $request->input('lab_lat');
|
||||
|
||||
$lab->slot_date = $request->input('slot_date');
|
||||
$lab->slot_time = $request->input('slot_time');
|
||||
$lab->booking_time = Carbon::now()->format('Y-m-d H:i:s');
|
||||
|
||||
$lab->appointment_id = $appointment->id;
|
||||
$lab->save();
|
||||
|
||||
return ['message' => 'Lab booked successfully'];
|
||||
}
|
||||
public function patientBookLabGet(Appointment $appointment)
|
||||
{
|
||||
$lab = Lab::where("appointment_id", $appointment->id)->first();
|
||||
return response()->json([
|
||||
'lab_name' => $lab->name,
|
||||
'lab_address' => $lab->address,
|
||||
'lab_city' => $lab->city,
|
||||
'lab_state' => $lab->state,
|
||||
'lab_distance' => $lab->distance,
|
||||
'lab_contact_no' => $lab->contact_no,
|
||||
'lab_lang' => $lab->lang,
|
||||
'lab_lat' => $lab->lat,
|
||||
'slot_date' => $lab->slot_date,
|
||||
'slot_time' => $lab->slot_time,
|
||||
'booking_time' => $lab->booking_time,
|
||||
]);
|
||||
}
|
||||
|
||||
public function doctorAppointment($id)
|
||||
{
|
||||
$appointment = Appointment::where('id', $id)->first();
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
$doctors = Doctor::all();
|
||||
return view('agent.appointments.doctor-appointment', ['patient' => $patient, 'doctors' => $doctors, 'appointment' => $appointment]);
|
||||
}
|
||||
public function pendingAppointmentDetail()
|
||||
{
|
||||
|
||||
$appointments = Appointment::whereNull('end_time')
|
||||
->where(function ($query) {
|
||||
$startTimeM = Carbon::now()->subHours(12)->format('Y-m-d');
|
||||
$endTimeM = Carbon::now()->addHours(12)->format('Y-m-d');
|
||||
$startTime = Carbon::now()->subHours(12)->format('H:i:s');
|
||||
$endTime = Carbon::now()->addHours(12)->format('H:i:s');
|
||||
$query //->where('appointment_time', '>=', $startTime)
|
||||
//->where('appointment_time', '<=', $endTime)
|
||||
->where('appointment_date', '>=', $startTimeM)
|
||||
->where('appointment_date', '<=', $endTimeM);
|
||||
})
|
||||
->with('patient:id,first_name,last_name,address,city,state,zip_code,country')
|
||||
->get([
|
||||
'id',
|
||||
'patient_id',
|
||||
'appointment_time',
|
||||
'appointment_date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'duration',
|
||||
'timezone'
|
||||
])
|
||||
->groupBy('patient_id', 'appointment_time', 'appointment_date', 'start_time')
|
||||
->map(function ($group) {
|
||||
$patient = $group->first()->patient;
|
||||
$appointments = $group->sortByDesc('id');
|
||||
$array = [];
|
||||
foreach ($appointments as $appointment) {
|
||||
$filePath = public_path("assets/profiles/{$patient->id}.png");
|
||||
|
||||
if (File::exists($filePath)) {
|
||||
$patient->url = "/assets/profiles/{$patient->id}.png";
|
||||
} else {
|
||||
$patient->url = null;
|
||||
}
|
||||
$cart = Cart::where("appointment_id", $appointment->id)->first();
|
||||
$array[] = [
|
||||
'id' => $patient->id,
|
||||
'patient_timezone' => $patient->timezone,
|
||||
'appointment_timezone' => $appointment->timezone,
|
||||
'name' => $patient->first_name . ' ' . $patient->last_name,
|
||||
'address' => $patient->address,
|
||||
'city' => $patient->city,
|
||||
'state' => $patient->state,
|
||||
'zip_code' => $patient->zip_code,
|
||||
'url' => $patient->url,
|
||||
'country' => $patient->country,
|
||||
'time' => time(),
|
||||
'order_id' => $cart->id ?? "",
|
||||
'appointment' => [
|
||||
'id' => $appointment->id,
|
||||
'appointment_time' => $appointment->appointment_time,
|
||||
'appointment_date' => $appointment->appointment_date,
|
||||
'start_time' => $appointment->start_time,
|
||||
'end_time' => $appointment->end_time,
|
||||
'duration' => $appointment->duration,
|
||||
'timezone' => $appointment->timezone
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
return $array;
|
||||
})->flatten(1);
|
||||
|
||||
return response()->json($appointments, 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function doctorAppointmentSave($id, Request $request)
|
||||
{
|
||||
$appointment_date = $request->input('appointment_date');
|
||||
$appointment_time = $request->input('appointment_time');
|
||||
$appointment_date = new DateTime($appointment_date);
|
||||
$appointment_date = $appointment_date->format('Y-m-d');
|
||||
$doctor_id = $request->input('doctor_id');
|
||||
|
||||
$appointment = Appointment::where('id', $id)->first();
|
||||
|
||||
$doctorAppointment = DoctorAppointment::where('patient_id', $appointment->patient_id)
|
||||
->where('doctor_id', $doctor_id)
|
||||
->where('appointment_id', $id)
|
||||
->where('appointment_date', $appointment_date)
|
||||
->where('appointment_time', $appointment_time)
|
||||
->first();
|
||||
|
||||
if (empty($doctorAppointment)) {
|
||||
DoctorAppointment::create([
|
||||
'patient_id' => $appointment->patient_id,
|
||||
'doctor_id' => $doctor_id,
|
||||
'appointment_id' => $id,
|
||||
'appointment_date' => $appointment_date,
|
||||
'appointment_time' => $appointment_time
|
||||
]);
|
||||
|
||||
|
||||
return response()->json(['message' => 'Doctor appointment booked'], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Error in booking Appointment!'], 200);
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function patientTasks($id)
|
||||
{
|
||||
$appointment = Appointment::where('id', $id)->first();
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
$patientTasks = PatientTask::where('patient_id', $appointment->patient_id)->get();
|
||||
return view('agent.appointments.patient-tasks', ['patient' => $patient, 'appointment' => $appointment, 'patientTasks' => $patientTasks]);
|
||||
}
|
||||
|
||||
public function patientTasksSave($id, Request $request)
|
||||
{
|
||||
$description = $request->input('description');
|
||||
|
||||
PatientTask::create([
|
||||
'patient_id' => $id,
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$request->session()->flash('message', 'Task saved successfully');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function patientTaskDelete($id, Request $request)
|
||||
{
|
||||
PatientTask::where('id', $id)->delete();
|
||||
$request->session()->flash('message', 'Task deleted successfully');
|
||||
return redirect()->back();
|
||||
}
|
||||
public function questions()
|
||||
{
|
||||
return 'ddd';
|
||||
}
|
||||
public function questionsList()
|
||||
{
|
||||
$questionsData = [];
|
||||
$groups = QuestionGroup::all();
|
||||
foreach ($groups as $group) {
|
||||
$questions = Question::where('group_id', $group->id)->get()->toArray();
|
||||
$questionsData[$group->title] = $questions;
|
||||
}
|
||||
return response()->json(
|
||||
$questionsData
|
||||
);
|
||||
}
|
||||
public function questionsAnswers($patient_id, $appointment_id)
|
||||
{
|
||||
$questionsData = [];
|
||||
$answers = [];
|
||||
$groups = QuestionGroup::all();
|
||||
foreach ($groups as $group) {
|
||||
$questions = Question::where('group_id', $group->id)->get();
|
||||
foreach ($questions as $question) {
|
||||
|
||||
$answer = PatientAnswer::where('question_id', $question->id)->where('patient_id', $patient_id)->where('appointment_id', $appointment_id)->first();
|
||||
if (isset($answer->answer))
|
||||
$question['answer'] = $answer->answer;
|
||||
else
|
||||
$question['answer'] = null;
|
||||
}
|
||||
$questionsData[$group->title] = $questions;
|
||||
}
|
||||
return response()->json(
|
||||
$questionsData
|
||||
);
|
||||
}
|
||||
|
||||
public function storeAnswers(Patient $patient, Appointment $appointment, Request $request)
|
||||
{
|
||||
|
||||
$data = $request->input("data");
|
||||
|
||||
foreach ($data as $row) {
|
||||
if (isset($row['answer']))
|
||||
PatientAnswer::create([
|
||||
'patient_id' => $patient->id,
|
||||
'appointment_id' => $appointment->id,
|
||||
'question_id' => $row['question_id'],
|
||||
'answer' => $row['answer']
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Answers stored successfully'
|
||||
]);
|
||||
}
|
||||
public function getQuestions(Patient $patient, Appointment $appointment, Request $request)
|
||||
{
|
||||
$questions = PatientAnswer::select('questions.*', 'patient_answers.answer')
|
||||
->leftJoin('questions', 'questions.id', '=', 'patient_answers.question_id')
|
||||
->where('patient_answers.patient_id', $patient->id)
|
||||
->where('patient_answers.appointment_id', $appointment->id)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'questions' => $questions
|
||||
]);
|
||||
}
|
||||
public function switchButton(Telemedpro $agent, $switch)
|
||||
{
|
||||
if ($switch == 1)
|
||||
$agent->recording_switch = $switch;
|
||||
else
|
||||
$agent->recording_switch = 0;
|
||||
$agent->save();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Recording Switched: ' . $switch
|
||||
]);
|
||||
}
|
||||
public function switchButtonGet(Telemedpro $agent)
|
||||
{
|
||||
return response()->json([
|
||||
'recording_switch' => $agent->recording_switch,
|
||||
]);
|
||||
}
|
||||
public function switchAiButton(Telemedpro $agent, $switch)
|
||||
{
|
||||
if ($switch == 1)
|
||||
$agent->ai_switch = $switch;
|
||||
else
|
||||
$agent->ai_switch = 0;
|
||||
$agent->save();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'AI Switched: ' . $switch
|
||||
]);
|
||||
}
|
||||
public function switchAiButtonGet(Telemedpro $agent)
|
||||
{
|
||||
return response()->json([
|
||||
'ai_switch' => $agent->ai_switch,
|
||||
]);
|
||||
}
|
||||
public function getProfile(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
return response()->json([
|
||||
'ai_switch' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function questionsListV1()
|
||||
{
|
||||
$questionGroups = QuestionGroup::with('questions')->get();
|
||||
|
||||
$formattedGroups = [];
|
||||
|
||||
foreach ($questionGroups as $group) {
|
||||
$formattedGroups[$group->title] = [];
|
||||
foreach ($group->questions as $question) {
|
||||
$formattedGroups[$group->title][$question->question] = [$question->type => unserialize($question->options)];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($formattedGroups);
|
||||
}
|
||||
public function DeviceCurrentStatus(Request $request)
|
||||
{
|
||||
/* $patient = Patient::where("id", $patient_id)->firstOrFail(); */
|
||||
$micStatus = $request->input('micStatus');
|
||||
$camStatus = $request->input('camStatus');
|
||||
event(new DeviceCurrentStatus($micStatus, $camStatus));
|
||||
|
||||
return true;
|
||||
}
|
||||
public function getAnalytics($filter = '12_months')
|
||||
{
|
||||
$currentMonth = Carbon::now();
|
||||
|
||||
// Filter logic
|
||||
switch ($filter) {
|
||||
case 'current_month':
|
||||
$startDate = $currentMonth->copy()->startOfMonth();
|
||||
break;
|
||||
case '1_month':
|
||||
$startDate = $currentMonth->copy()->subMonth()->startOfMonth();
|
||||
break;
|
||||
case '2_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(2)->startOfMonth();
|
||||
break;
|
||||
case '3_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(3)->startOfMonth();
|
||||
break;
|
||||
case '6_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(6)->startOfMonth();
|
||||
break;
|
||||
default: // Default to 12 months
|
||||
$startDate = $currentMonth->copy()->subMonths(12)->startOfMonth();
|
||||
}
|
||||
|
||||
$endDate = $currentMonth->endOfMonth();
|
||||
|
||||
|
||||
$appointments = Appointment::with('patient')
|
||||
->where("telemed_pros_id", Auth::user()->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->get();
|
||||
|
||||
$totalSessions = $appointments->count();
|
||||
$totalCallTime = 10; // Assuming you have some logic to calculate this
|
||||
if ($totalSessions != 0) {
|
||||
$avgSessionTime = $totalCallTime / $totalSessions;
|
||||
$avgSessionTime = round(($avgSessionTime / 60), 2);
|
||||
} else
|
||||
$avgSessionTime = '';
|
||||
|
||||
|
||||
$monthlyData = [];
|
||||
|
||||
// Loop through each month in the last 12 months
|
||||
for ($date = $startDate->copy(); $date->lte($endDate); $date->addMonth()) {
|
||||
$monthStart = $date->startOfMonth()->format('Y-m-d');
|
||||
$monthEnd = $date->copy()->endOfMonth()->format('Y-m-d'); // Key change here!
|
||||
|
||||
$monthAppointments = Appointment::with('patient')
|
||||
->where("telemed_pros_id", Auth::user()->id)
|
||||
->whereBetween('created_at', [$monthStart, $monthEnd])
|
||||
->get();
|
||||
|
||||
|
||||
// Calculate any metrics you need from $monthAppointments
|
||||
$monthlyData[] = [
|
||||
'month' => $date->format('M'), // Example: Jan 2024
|
||||
'appointment_count' => $monthAppointments->count()
|
||||
// Add other metrics as needed
|
||||
];
|
||||
}
|
||||
$monthsList = [];
|
||||
$monthlySessionCount = [];
|
||||
|
||||
foreach ($monthlyData as $dataPoint) {
|
||||
$monthsList[] = $dataPoint['month'];
|
||||
$monthlySessionCount[] = $dataPoint['appointment_count'];
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'total_sessions' => $totalSessions,
|
||||
'total_call_time' => $totalCallTime,
|
||||
'avg_session_time' => $avgSessionTime,
|
||||
'data' => array_values($monthlySessionCount), // Ensure consistent order
|
||||
'months_list' => $monthsList,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMeetingHistory($filter = '12_months')
|
||||
{
|
||||
$currentMonth = Carbon::now();
|
||||
|
||||
// Filter logic
|
||||
switch ($filter) {
|
||||
case 'current_month':
|
||||
$startDate = $currentMonth->copy()->startOfMonth();
|
||||
break;
|
||||
case '1_month':
|
||||
$startDate = $currentMonth->copy()->subMonth()->startOfMonth();
|
||||
break;
|
||||
case '2_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(2)->startOfMonth();
|
||||
break;
|
||||
case '3_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(3)->startOfMonth();
|
||||
break;
|
||||
case '6_months':
|
||||
$startDate = $currentMonth->copy()->subMonths(6)->startOfMonth();
|
||||
break;
|
||||
default: // Default to 12 months
|
||||
$startDate = $currentMonth->copy()->subMonths(12)->startOfMonth();
|
||||
}
|
||||
|
||||
$endDate = $currentMonth->endOfMonth();
|
||||
|
||||
// Fetch patient names and appointment counts directly from the database
|
||||
$monthlyData = Appointment::select(
|
||||
'appointments.patient_id',
|
||||
/* DB::raw('COUNT(*) as appointment_count'), */
|
||||
'appointment_time',
|
||||
'appointment_date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'duration',
|
||||
'appointments.id as appointment_id',
|
||||
'carts.id as order_id'
|
||||
)
|
||||
->leftJoin('carts', 'carts.appointment_id', 'appointments.id')
|
||||
->where("appointments.telemed_pros_id", Auth::user()->id)
|
||||
->whereBetween('appointments.created_at', [$startDate, $endDate])
|
||||
|
||||
->get();
|
||||
|
||||
$patients = [];
|
||||
|
||||
foreach ($monthlyData as $dataPoint) {
|
||||
$patient = $dataPoint->patient;
|
||||
/* $appointmentCount = $dataPoint->appointment_count; */
|
||||
$start_time = $dataPoint->start_time;
|
||||
$end_time = $dataPoint->end_time;
|
||||
$duration = $dataPoint->duration;
|
||||
$appointment_time = $dataPoint->appointment_time;
|
||||
$appointment_date = $dataPoint->appointment_date;
|
||||
$appointment_id = $dataPoint->appointment_id;
|
||||
$order_id = $dataPoint->order_id;
|
||||
|
||||
$patients[] = [
|
||||
'patient' => $patient,
|
||||
'appointment_time' => $appointment_time,
|
||||
'appointment_date' => $appointment_date,
|
||||
/* 'appointment_count' => $appointmentCount, */
|
||||
'start_time' => $start_time,
|
||||
'end_time' => $end_time,
|
||||
'duration' => $duration,
|
||||
'appointment_id' => $appointment_id,
|
||||
'order_id' => $order_id
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'patients' => $patients,
|
||||
]);
|
||||
}
|
||||
public function sessionHistory(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
// Assuming user can be either telemedPro or patient
|
||||
$history = Appointment::select(
|
||||
'appointments.*',
|
||||
'appointments.patient_id',
|
||||
'patients.first_name as patient_name',
|
||||
'carts.id as order_id'
|
||||
)
|
||||
->leftJoin('patients', 'appointments.patient_id', '=', 'patients.id')
|
||||
->leftJoin('carts', 'carts.appointment_id', '=', 'appointments.id')
|
||||
->where(function ($query) use ($user) {
|
||||
$query->where('appointments.telemed_pros_id', $user->id);
|
||||
})
|
||||
->whereNotNull("appointments.end_time")
|
||||
->orderBy('appointments.appointment_date', 'desc')
|
||||
->get();
|
||||
|
||||
return response()->json(['history' => $history]);
|
||||
|
||||
return response()->json(['history' => $history]);
|
||||
}
|
||||
public function getAppointmentByid($patient, $appointment, Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
// Assuming user can be either telemedPro or patient
|
||||
$data = Appointment::select(
|
||||
'appointments.*',
|
||||
'telemed_pros.name as agent_name',
|
||||
)
|
||||
->leftJoin('telemed_pros', 'appointments.telemed_pros_id', '=', 'telemed_pros.id')
|
||||
->where('appointments.telemed_pros_id', $user->id)
|
||||
->where('appointments.patient_id', $patient)
|
||||
->where('appointments.id', $appointment)
|
||||
->first();
|
||||
$order = Cart::where('appointment_id', $data->id)->first();
|
||||
$orderItems = Item::leftJoin('plans_v1', 'plans_v1.id', 'items.plans_id')
|
||||
->where('cart_id', $order->id)->get();
|
||||
$data->order = $order;
|
||||
$data->telemedPro;
|
||||
// $data->order_items = $orderItems;
|
||||
$totalPrice = 0;
|
||||
$total_products = 0;
|
||||
$quantity = [];
|
||||
$totalShippingCost = 0;
|
||||
$data->order_notes = PatientNote::where('appointment_id', $appointment)->get();
|
||||
foreach ($orderItems as $item) {
|
||||
$totalShippingCost += $item->shipping_cost;
|
||||
$item->total_price = $item->quantity * $item->price;
|
||||
$totalPrice += $item->total_price;
|
||||
$order->order_total_amount = $totalPrice;
|
||||
$order->order_total_shipping = $totalShippingCost;
|
||||
$item->plansV1->qty = $item->quantity;
|
||||
}
|
||||
$data->order_items = $orderItems;
|
||||
|
||||
$data->shipping_activity = ItemHistory::where('cart_id', $order->id)->get();
|
||||
return response()->json(['data' => $data]);
|
||||
}
|
||||
public function addNotePatient(Patient $patient, Appointment $appointment, Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$addNotePatient = PatientNote::create([
|
||||
'note' => $request->input('note'),
|
||||
'note_type' => $request->input('note_type'),
|
||||
'patient_id' => $patient->id,
|
||||
'appointment_id' => $appointment->id,
|
||||
'telemed_pros_id' => $user->id
|
||||
]);
|
||||
$addNotePatient->file_url = "";
|
||||
if ($request->hasFile('file')) {
|
||||
$file = $request->file('file');
|
||||
|
||||
$filename = $addNotePatient->id . '.' . $file->getClientOriginalExtension();
|
||||
|
||||
$file->move(public_path('assets/files'), $filename);
|
||||
|
||||
$addNotePatient->file_url = "assets/files" . $addNotePatient->id . '.' . $file->getClientOriginalExtension();
|
||||
}
|
||||
$patient = $addNotePatient->patient;
|
||||
$setting = Setting::find(1);
|
||||
Mail::send('emails.noteAdded', ['patient' => $patient, 'agent' => $user, 'setting' => $setting], function ($message) use ($patient, $user) {
|
||||
$message->to($patient->email, $patient->first_name)
|
||||
->subject('You Have a New Note from ' . $user->name);
|
||||
});
|
||||
return response()->json([
|
||||
'message' => 'Note created',
|
||||
'data' => $addNotePatient
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getNotePatient(Patient $patient, Appointment $appointment, Request $request)
|
||||
{
|
||||
$patientNotes = PatientNote::where("patient_id", $patient->id)
|
||||
->where("appointment_id", $appointment->id)
|
||||
->with('appointment')
|
||||
->get();
|
||||
|
||||
$data = $patientNotes->map(function ($patientNote) {
|
||||
$fileUrl = "/assets/files/{$patientNote->id}.png";
|
||||
$filePath = public_path($fileUrl);
|
||||
|
||||
if (File::exists($filePath)) {
|
||||
$fileUrl = "/assets/files/{$patientNote->id}.png";
|
||||
} else {
|
||||
$fileUrl = null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $patientNote->id,
|
||||
'note' => $patientNote->note,
|
||||
'note_type' => $patientNote->note_type,
|
||||
'created_at' => $patientNote->created_at,
|
||||
'patient_id' => $patientNote->patient_id,
|
||||
'appointment' => $patientNote->appointment,
|
||||
'telemedPro' => $patientNote->telemedPro,
|
||||
'file_url' => $fileUrl,
|
||||
'telemedPro' => $patientNote->appointment?->telemedPro
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Patient notes retrieved',
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getQuestionBuilderStore(Patient $patient, Request $request)
|
||||
{
|
||||
|
||||
$questionBuilder = QuestionBuilder::select('key', 'value')->where("customer_id", $patient->id)->get();
|
||||
$jsonData = $questionBuilder->mapWithKeys(function ($item) {
|
||||
return [$item->key => $item->value];
|
||||
});
|
||||
// Store data
|
||||
return response()->json([
|
||||
'message' => 'Data Sent',
|
||||
'data' => $jsonData
|
||||
], 200);
|
||||
}
|
||||
public function getPrescription()
|
||||
{
|
||||
$prescriptions = Prescription::all();
|
||||
return response()->json($prescriptions);
|
||||
}
|
||||
public function storePrescription(Request $request)
|
||||
{
|
||||
$prescription = Prescription::create($request->all());
|
||||
return response()->json($prescription, 200);
|
||||
}
|
||||
public function storePatientPrescription(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$prescription = PatientPrescription::create($request->all());
|
||||
$prescription->status = "pending";
|
||||
$prescription->save();
|
||||
$patient = $prescription->patient;
|
||||
$setting = Setting::find(1);
|
||||
Mail::send('emails.prescriptionAdd', ['patient' => $patient, 'prescription' => $prescription, 'setting' => $setting], function ($message) use ($patient, $user) {
|
||||
$message->to($patient->email, $patient->first_name)
|
||||
->subject('New Prescription Details from ' . $user->name);
|
||||
});
|
||||
return response()->json($prescription, 200);
|
||||
}
|
||||
public function updateStatusPrescription($patient_prescription_id, Request $request)
|
||||
{
|
||||
$status = $request->input("status");
|
||||
$prescription = PatientPrescription::find($patient_prescription_id);
|
||||
$prescription->status = $status;
|
||||
$prescription->save();
|
||||
$patient = $prescription->patient;
|
||||
$setting = Setting::find(1);
|
||||
Mail::send('emails.prescriptionUpdated', ['patient' => $patient, 'setting' => $setting], function ($message) use ($patient) {
|
||||
$message->to($patient->email, $patient->first_name)
|
||||
->subject('Prescription updated.');
|
||||
});
|
||||
return response()->json($prescription, 200);
|
||||
}
|
||||
|
||||
public function getStatusPrescription($patient_prescription_id)
|
||||
{
|
||||
$prescription = PatientPrescription::find($patient_prescription_id);
|
||||
return response()->json($prescription, 200);
|
||||
}
|
||||
public function getPatientPrescription($patient_id, $appointment_id)
|
||||
{
|
||||
$patientPrescription = PatientPrescription::with('prescription')
|
||||
->where('patient_id', $patient_id)
|
||||
->where('appointment_id', $appointment_id)
|
||||
->get();
|
||||
|
||||
$prescriptionData = [];
|
||||
foreach ($patientPrescription as $prescription) {
|
||||
$prescriptionData[] = [
|
||||
'patient' => $prescription->patient,
|
||||
'prescription' => $prescription->prescription,
|
||||
'created_at' => $prescription->created_at,
|
||||
'updated_at' => $prescription->updated_at,
|
||||
'direction_one' => $prescription->direction_one,
|
||||
'direction_two' => $prescription->direction_two,
|
||||
'dont_substitute' => $prescription->dont_substitute,
|
||||
'comments' => $prescription->comments,
|
||||
'appointment_id' => $prescription->appointment_id,
|
||||
'status' => $prescription->status,
|
||||
'appointment' => $prescription->appointment,
|
||||
'telemedPro' => $prescription->appointment->telemedPro,
|
||||
'licenseNumber' => LicenseNumberModel::where("provider_id", $patient_id)->orderBy('id', 'DESC')->first()
|
||||
];
|
||||
}
|
||||
if (!$patientPrescription->isEmpty()) {
|
||||
return response()->json($prescriptionData);
|
||||
} else {
|
||||
return response()->json(['message' => 'Prescription not found'], 404);
|
||||
}
|
||||
}
|
||||
public function getOrderData(Cart $cart, Request $request)
|
||||
{
|
||||
$cart = Cart::with("patient")->get();
|
||||
return response()->json(['cart' => $cart], 200);
|
||||
}
|
||||
|
||||
public function getLabKit(Cart $cart, Request $request)
|
||||
{
|
||||
$kit = LabKit::all();
|
||||
return response()->json(['kit' => $kit], 200);
|
||||
}
|
||||
|
||||
public function orderLabKit(LabKit $labkit, Patient $patient, Request $request)
|
||||
{
|
||||
|
||||
|
||||
$user = $patient;
|
||||
$cart = new Cart();
|
||||
$cart->lab_kit_id = $labkit->id;
|
||||
$cart->first_name = $patient->first_name;
|
||||
$cart->last_name = $patient->last_name;
|
||||
$cart->email = $patient->email;
|
||||
$cart->phone = $patient->phone_no;
|
||||
$cart->status = "pending";
|
||||
|
||||
$cart->date_of_birth = $patient->dob ?? null;
|
||||
|
||||
$cart->patient_id = $user->id;
|
||||
|
||||
$cart->shipping_address1 = $patient->address;
|
||||
$cart->shipping_city = $patient->city;
|
||||
$cart->shipping_state = $patient->state;
|
||||
$cart->shipping_zipcode = $patient->zip_code;
|
||||
$cart->shipping_country = $patient->country;
|
||||
|
||||
|
||||
$cart->shipping_amount = $labkit->amount;
|
||||
$cart->total_amount = $labkit->amount;
|
||||
|
||||
$cart->save();
|
||||
return response()->json(['status' => 'Success', 'cart' => $cart], 200);
|
||||
}
|
||||
|
||||
public function getorderedLabKit(LabKit $labkit, Patient $patient, Request $request)
|
||||
{
|
||||
$detail = Cart::select("carts.*", "lab_kit.name")->leftJoin("lab_kit", "carts.lab_kit_id", "=", "lab_kit.id")
|
||||
->where("carts.lab_kit_id", $labkit->id)
|
||||
->where("carts.patient_id", $patient->id)
|
||||
->get();
|
||||
|
||||
return response()->json(['order' => $detail], 200);
|
||||
}
|
||||
public function getorderedLabKitBasedOnPatient(Patient $patient, Request $request)
|
||||
{
|
||||
$detail = Cart::select("carts.*", "lab_kit.name")->leftJoin("lab_kit", "carts.lab_kit_id", "=", "lab_kit.id")
|
||||
->where("carts.patient_id", $patient->id)
|
||||
->get();
|
||||
|
||||
return response()->json(['order' => $detail], 200);
|
||||
}
|
||||
public function updateStatusOrderData(Cart $cart, Request $request)
|
||||
{
|
||||
|
||||
$cart = Cart::where("id", $cart->id)->firstOrFail();
|
||||
$cart->status = $request->input("status");
|
||||
$cart->save();
|
||||
|
||||
return response()->json(['status' => 'Success', 'cart' => $cart], 200);
|
||||
}
|
||||
public function PatientAppointment()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$data = [];
|
||||
$appointments = Appointment::select('patient_id')->where('telemed_pros_id', $user->id)->groupBy('patient_id')->get();
|
||||
foreach ($appointments as $appointment) {
|
||||
$patient = Patient::where('id', $appointment->patient_id)->first();
|
||||
array_push($data, $patient->toArray());
|
||||
}
|
||||
return response()->json(['status' => 'Success', 'patient' => $data], 200);
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||
|
||||
class ConfirmPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Confirm Password Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password confirmations and
|
||||
| uses a simple trait to include the behavior. You're free to explore
|
||||
| this trait and override any functions that require customization.
|
||||
|
|
||||
*/
|
||||
|
||||
use ConfirmsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users when the intended url fails.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
}
|
22
app/Http/Controllers/Agent/Auth/ForgotPasswordController.php
Normal file
22
app/Http/Controllers/Agent/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
}
|
104
app/Http/Controllers/Agent/Auth/LoginController.php
Normal file
104
app/Http/Controllers/Agent/Auth/LoginController.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Telemedpro;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/agent';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('agent.auth.login');
|
||||
}
|
||||
|
||||
protected function login(Request $request)
|
||||
{
|
||||
$credentials = $request->only('email', 'password');
|
||||
|
||||
$user = Telemedpro::where($this->username(), $credentials['email'])->first();
|
||||
|
||||
if ($user && Hash::check($credentials['password'], $user->password)) {
|
||||
// Auth::guard('agent')->login($user, $request->has('remember'));
|
||||
if ($this->guard('agent')->attempt(
|
||||
$this->credentials($request),
|
||||
$request->has('remember')
|
||||
)) {
|
||||
// dd($this->guard());
|
||||
return redirect($this->redirectTo);
|
||||
}
|
||||
dd($this->guard());
|
||||
// dd($user && Hash::check($credentials['password'], $user->password));
|
||||
return redirect($this->redirectTo);
|
||||
}
|
||||
|
||||
return back()->withErrors(['email' => 'Invalid credentials']);
|
||||
}
|
||||
|
||||
public function redirectPath()
|
||||
{
|
||||
return "/agent";
|
||||
}
|
||||
public function loginAgent(Request $request)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'email' => 'required|email',
|
||||
'password' => 'required'
|
||||
]);
|
||||
|
||||
$patient = Telemedpro::where('email', $validatedData['email'])->first();
|
||||
|
||||
if (!$patient || !Hash::check($validatedData['password'], $patient->password)) {
|
||||
return response()->json([
|
||||
'message' => 'Invalid credentials'
|
||||
], 422);
|
||||
}
|
||||
if (!$patient || $patient->status == 0) {
|
||||
return response()->json([
|
||||
'message' => 'Your account is undergoing verification.'
|
||||
], 422);
|
||||
}
|
||||
$token = $patient->createToken('auth_token')->plainTextToken;
|
||||
|
||||
return response()->json([
|
||||
'data' => $patient,
|
||||
'access_token' => $token,
|
||||
'token_type' => 'Bearer',
|
||||
]);
|
||||
}
|
||||
}
|
80
app/Http/Controllers/Agent/Auth/RegisterController.php
Normal file
80
app/Http/Controllers/Agent/Auth/RegisterController.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Telemedpro;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function showRegisterForm()
|
||||
{
|
||||
return view('agent.auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\Models\Telemedpro
|
||||
*/
|
||||
protected function register(Request $request)
|
||||
{
|
||||
Telemedpro::create([
|
||||
'name' => $request->input('name'),
|
||||
'email' => $request->input('email'),
|
||||
'password' => bcrypt($request->input('password')),
|
||||
]);
|
||||
return back();
|
||||
}
|
||||
}
|
30
app/Http/Controllers/Agent/Auth/ResetPasswordController.php
Normal file
30
app/Http/Controllers/Agent/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
}
|
42
app/Http/Controllers/Agent/Auth/VerificationController.php
Normal file
42
app/Http/Controllers/Agent/Auth/VerificationController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email Verification Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling email verification for any
|
||||
| user that recently registered with the application. Emails may also
|
||||
| be re-sent if the user didn't receive the original email message.
|
||||
|
|
||||
*/
|
||||
|
||||
use VerifiesEmails;
|
||||
|
||||
/**
|
||||
* Where to redirect users after verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('signed')->only('verify');
|
||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||
}
|
||||
}
|
204
app/Http/Controllers/Agent/DashboardController.php
Normal file
204
app/Http/Controllers/Agent/DashboardController.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Classes\Constant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\DoctorAppointment;
|
||||
use App\Models\Telemedpro;
|
||||
use App\Models\LicenseNumberModel;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
protected $user_id;
|
||||
protected $url;
|
||||
public function __construct(UrlGenerator $url)
|
||||
{
|
||||
// $this->middleware('auth');
|
||||
// if (isset(Auth::guard('agent')->user()->id))
|
||||
// $this->user_id = Auth::guard('agent')->user()->id;
|
||||
$this->url = $url;
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
return view('agent.dashboard');
|
||||
}
|
||||
public function register(Request $request)
|
||||
{
|
||||
// Validate the request data
|
||||
$validator = Validator::make($request->all(), [
|
||||
'first_name' => ['required', 'string', 'max:255'],
|
||||
'last_name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
$first_name = $request->input('first_name');
|
||||
$last_name = $request->input('last_name');
|
||||
$email = $request->input('email');
|
||||
$digits = 4;
|
||||
$code = rand(pow(10, $digits - 1), pow(10, $digits) - 1);
|
||||
// Create the new user
|
||||
$setting = Setting::find(1);
|
||||
Mail::send('emails.providerVerificationEmail', ['name' => $first_name . " " . $last_name, "code" => $code, 'setting' => $setting], function ($message) use ($first_name, $last_name, $email) {
|
||||
$message->to($email, $first_name . " " . $last_name)
|
||||
->subject('Verify Your Email ');
|
||||
});
|
||||
$user = Telemedpro::create([
|
||||
'name' => $first_name . " " . $last_name,
|
||||
'first_name' => $request->input('first_name'),
|
||||
'last_name' => $request->input('last_name'),
|
||||
'email' => $request->input('email'),
|
||||
'password' => Hash::make($request->input('password')),
|
||||
'status' => 0,
|
||||
"email_verification" => $code
|
||||
]);
|
||||
$token = $user->createToken('auth_token')->plainTextToken;
|
||||
return response()->json([
|
||||
'user' => $user,
|
||||
'message' => 'User registered successfully',
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function emailVerify($id, Request $request)
|
||||
{
|
||||
|
||||
$providerData = Telemedpro::where('email_verification', $request->get('token'))->where('id', $id)->first();
|
||||
|
||||
if ($providerData) {
|
||||
$providerData->email_verification = '';
|
||||
$providerData->email_verified_at = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$providerData->save();
|
||||
return response()->json([
|
||||
'message' => 'Account verified',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'already verified',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
public function saveProfile($id, Request $request)
|
||||
{
|
||||
$providerData = Telemedpro::find($id);
|
||||
if (!$providerData) {
|
||||
return response()->json([
|
||||
'message' => 'Provider not found',
|
||||
], 404);
|
||||
}
|
||||
$providerData->practice_state = $request->input('practice_state');
|
||||
$providerData->phone_number = $request->input('phone');
|
||||
$providerData->gender = $request->input('gender');
|
||||
$providerData->specialty = $request->input('specialty');
|
||||
$availabilityFrom = $request->input('availabilityFrom');
|
||||
if ($availabilityFrom && Carbon::hasFormat($availabilityFrom, 'H:i')) {
|
||||
$providerData->availability_from = Carbon::createFromFormat('H:i', $availabilityFrom)->format('H:i:s');
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'Invalid format for availability_from',
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Validate and format availability_to
|
||||
$availability_to = $request->input('availabilityTo');
|
||||
if ($availability_to && Carbon::hasFormat($availability_to, 'H:i')) {
|
||||
$providerData->availability_to = Carbon::createFromFormat('H:i', $availability_to)->format('H:i:s');
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'Invalid format for availability_to',
|
||||
], 400);
|
||||
}
|
||||
$providerData->home_address = $request->input('home_address');
|
||||
$providerData->medical_license_number = $request->input('medical_license_number');
|
||||
$providerData->years_of_experience = $request->input('years_of_experience');
|
||||
$providerData->city = $request->input('city');
|
||||
$providerData->state = $request->input('state');
|
||||
$providerData->zip_code = $request->input('zip_code');
|
||||
$providerData->save();
|
||||
$this->saveLicenseNumber($id, $request->input('medical_license_number'));
|
||||
return response()->json([
|
||||
'user' => $providerData,
|
||||
'message' => 'Data saved ',
|
||||
], 201);
|
||||
}
|
||||
public function saveLicenseNumber($id, $licences)
|
||||
{
|
||||
foreach ($licences as $key => $value) {
|
||||
LicenseNumberModel::create([
|
||||
"provider_id" => $id,
|
||||
"state" => $key,
|
||||
"license_number" => $value,
|
||||
"status" => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function resendCode($id)
|
||||
{
|
||||
$digits = 4;
|
||||
$code = rand(pow(10, $digits - 1), pow(10, $digits) - 1);
|
||||
$providerData = Telemedpro::find($id);
|
||||
$providerData->email_verification = $code; //update code in database
|
||||
$email = $providerData->email;
|
||||
$first_name = $providerData->first_name;
|
||||
$last_name = $providerData->last_time;
|
||||
$setting = Setting::find(1);
|
||||
Mail::send('emails.providerVerificationEmail', ['name' => $first_name . " " . $last_name, "code" => $code, 'setting' => $setting], function ($message) use ($first_name, $last_name, $email) {
|
||||
$message->to($email, $first_name . " " . $last_name)
|
||||
->subject('Verify Your Email ');
|
||||
});
|
||||
$providerData->save();
|
||||
return response()->json([
|
||||
'message' => 'Verification code sent! ',
|
||||
], 201);
|
||||
}
|
||||
public function getProviderMeetings()
|
||||
{
|
||||
$appointments = Appointment::select(
|
||||
"patients.profile_picture",
|
||||
"patients.first_name",
|
||||
"patients.last_name",
|
||||
"appointments.id as appointment_id",
|
||||
"appointments.start_time",
|
||||
"appointments.end_time",
|
||||
"appointments.timezone",
|
||||
"appointments.duration",
|
||||
"appointments.appointment_date",
|
||||
"appointments.appointment_time",
|
||||
"appointments.status as appointment_status",
|
||||
"appointments.patient_name",
|
||||
"carts.id as order_id",
|
||||
"appointments.id as appointment_id",
|
||||
"appointments.patient_id"
|
||||
)
|
||||
->leftJoin("patients", "patients.id", "appointments.patient_id")
|
||||
->leftJoin("carts", "carts.appointment_id", "appointments.id")
|
||||
->where('telemed_pros_id', Auth::guard('agent')->user()->id)
|
||||
->where('start_time', "!=", null)
|
||||
->where('end_time', "!=", null)
|
||||
->orderBy('appointments.created_at', 'desc')
|
||||
->get();
|
||||
|
||||
foreach ($appointments as $appointment) {
|
||||
if ($appointment->profile_picture)
|
||||
$appointment->profile_picture = $this->url->to("storage/profile_pictures/", $appointment->profile_picture);
|
||||
else
|
||||
$appointment->profile_picture = asset('img/avatars/1.png');
|
||||
}
|
||||
|
||||
return response()->json($appointments, 200);
|
||||
}
|
||||
}
|
14
app/Http/Controllers/Agent/HomeController.php
Normal file
14
app/Http/Controllers/Agent/HomeController.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('agent.home');
|
||||
}
|
||||
}
|
423
app/Http/Controllers/Agent/MeetingController.php
Normal file
423
app/Http/Controllers/Agent/MeetingController.php
Normal file
@@ -0,0 +1,423 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Agence104\LiveKit\AccessToken;
|
||||
use Agence104\LiveKit\AccessTokenOptions;
|
||||
use Agence104\LiveKit\EgressServiceClient;
|
||||
use Agence104\LiveKit\RoomCreateOptions;
|
||||
use Agence104\LiveKit\RoomServiceClient;
|
||||
use Agence104\LiveKit\VideoGrant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\JassJWT;
|
||||
use App\Events\AppointmentCallEnded;
|
||||
use App\Events\AppointmentCreated;
|
||||
use App\Events\DeviceCurrentStatus;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Doctor;
|
||||
use App\Models\DoctorAppointment;
|
||||
use App\Models\Lab;
|
||||
use App\Models\Patient;
|
||||
use App\Models\PatientNote;
|
||||
use App\Models\Telemedpro;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Error;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livekit\EncodedFileOutput;
|
||||
use Livekit\EncodedFileType;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class MeetingController extends Controller
|
||||
{
|
||||
public function getAsseblyAiToekn()
|
||||
{
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => '0014470a9fa14b598a73cc0133acca8c',
|
||||
])->post('https://api.assemblyai.com/v2/realtime/token', [
|
||||
'expires_in' => 1600
|
||||
]);
|
||||
|
||||
return $response->body();
|
||||
}
|
||||
public function show($meeting_id)
|
||||
{
|
||||
return view('agent.jetsi', compact('meeting_id'));
|
||||
}
|
||||
public function joinMeeting($meeting_id)
|
||||
{
|
||||
$jassToken = JassJWT::generate();
|
||||
$appoinement = Appointment::where("meeting_id", $meeting_id)->firstOrFail();
|
||||
|
||||
return view('agent.join-meeting', compact('meeting_id'), compact('jassToken'));
|
||||
}
|
||||
public function startCall($patient_id, $agent_id, $appointment_id, Request $request)
|
||||
{
|
||||
$call_type = $request->input('call_type');
|
||||
$telemed_pro = Telemedpro::where("id", $agent_id)->firstOrFail();
|
||||
$appointment = Appointment::find($appointment_id);
|
||||
$appointment->in_call = 1;
|
||||
$appointment->start_time = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$appointment_booking_tokens = $this->bookAppointmentApi($appointment, $telemed_pro);
|
||||
$appointment->agent_call_token = $appointment_booking_tokens['tokenAgent'];
|
||||
$appointment->patient_call_token = $appointment_booking_tokens['tokenPatient'];
|
||||
$appointment->telemed_pros_id = $agent_id;
|
||||
$appointment->save();
|
||||
|
||||
event(new AppointmentCreated($patient_id, $appointment->id, $appointment->patient_call_token, $call_type));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Appointment created!',
|
||||
'appointment_id' => $appointment->id,
|
||||
'meeting_id' => $appointment->agent_call_token,
|
||||
'call_type' => $call_type
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
public function startRecording(Appointment $appointment)
|
||||
{
|
||||
$telemed = Telemedpro::find($appointment->telemed_pros_id);
|
||||
if ($telemed->recording_switch == 0) {
|
||||
return response()->json([
|
||||
'message' => "Recording Off",
|
||||
'Response' => 'Error',
|
||||
], 200);
|
||||
}
|
||||
$roomName = 'appointment-' . $appointment->id;
|
||||
$video_token = md5(rand(100000000, 999999999) . rand(1, 9));
|
||||
$appointment->video_token = $video_token;
|
||||
$appointment->save();
|
||||
|
||||
$client = new EgressServiceClient("https://plugnmeet.codelfi.com", config('app.LK_API_KEY'), config('app.LK_API_SECRET'));
|
||||
try {
|
||||
$info = $client->startRoomCompositeEgress($roomName, 'speaker', new EncodedFileOutput([
|
||||
"filepath" => "/out/recordings/" . $video_token . ".mp4",
|
||||
"file_type" => EncodedFileType::MP4,
|
||||
]));
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'message' => $e->getMessage(),
|
||||
'Response' => 'Error',
|
||||
], 200);
|
||||
}
|
||||
return response()->json([
|
||||
'message' => "Success",
|
||||
'Response' => 'Success',
|
||||
], 200);
|
||||
}
|
||||
public function bookAppointmentApi($appointment, $availableTelemedPros)
|
||||
{
|
||||
$roomName = 'appointment-' . $appointment->id . "-" . uniqid();
|
||||
$opts = (new RoomCreateOptions())
|
||||
->setName($roomName)
|
||||
->setEmptyTimeout(30)
|
||||
->setMaxParticipants(5);
|
||||
$host = "https://plugnmeet.codelfi.com";
|
||||
$svc = new RoomServiceClient($host, config('app.LK_API_KEY'), config('app.LK_API_SECRET'));
|
||||
try {
|
||||
$svc->deleteRoom($roomName);
|
||||
} catch (Exception | Error $e) {
|
||||
}
|
||||
|
||||
$room = $svc->createRoom($opts);
|
||||
|
||||
$participantPatientName = "patient-" . uniqid() . $appointment->patient->first_name . " " . $appointment->patient->last_name;
|
||||
|
||||
$tokenOptionsPatient = (new AccessTokenOptions())
|
||||
->setIdentity($participantPatientName);
|
||||
$videoGrantPatient = (new VideoGrant())
|
||||
->setRoomJoin()
|
||||
->setRoomName($roomName);
|
||||
$tokenPatient = (new AccessToken(config('app.LK_API_KEY'), config('app.LK_API_SECRET')))
|
||||
->init($tokenOptionsPatient)
|
||||
->setGrant($videoGrantPatient)
|
||||
->toJwt();
|
||||
|
||||
$participantAgentName = "agent-" . uniqid() . $availableTelemedPros->name;
|
||||
$tokenOptionsAgent = (new AccessTokenOptions())
|
||||
->setIdentity($participantAgentName);
|
||||
$videoGrantAgent = (new VideoGrant())
|
||||
->setRoomJoin()
|
||||
->setRoomName($roomName);
|
||||
$tokenAgent = (new AccessToken(config('app.LK_API_KEY'), config('app.LK_API_SECRET')))
|
||||
->init($tokenOptionsAgent)
|
||||
->setGrant($videoGrantAgent)
|
||||
->toJwt();
|
||||
return [
|
||||
'tokenPatient' => $tokenPatient,
|
||||
'tokenAgent' => $tokenAgent,
|
||||
];
|
||||
}
|
||||
public function endCall($patient_id, $appointment_id)
|
||||
{
|
||||
$appointment = Appointment::find($appointment_id);
|
||||
$appointment->in_call = 0;
|
||||
$appointment->end_time = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$appointment->save();
|
||||
|
||||
event(new AppointmentCallEnded($patient_id, $appointment->id));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Call ended',
|
||||
'appointment_id' => $appointment->id,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function searchLabsByAddress(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
|
||||
try {
|
||||
$labs = Lab::where('address', 'like', '%' . $address . '%')
|
||||
->orWhere('city', 'like', '%' . $address . '%')
|
||||
->orWhere('state', 'like', '%' . $address . '%')
|
||||
->orWhere('zip_code', 'like', '%' . $address . '%')
|
||||
->get(['id', 'name', 'city', 'state', 'zip_code', 'lang', 'lat']);
|
||||
|
||||
return response()->json($labs, 200);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Failed to search labs'], 500);
|
||||
}
|
||||
}
|
||||
public function bookAppointment(Request $request)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'telemed_pros_id' => 'required|exists:telemed_pros,id',
|
||||
'patient_id' => 'required|exists:patients,id',
|
||||
'doctor_id' => 'required|exists:doctors,id',
|
||||
'appointment_id' => 'required',
|
||||
'appointment_time' => 'required|date_format:Y-m-d H:i:s',
|
||||
]);
|
||||
|
||||
$appointment = DoctorAppointment::create($validatedData);
|
||||
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Appointment booked successfully',
|
||||
'meeting_id' => $appointment->meeting_id,
|
||||
'appointment_time' => $validatedData['appointment_time']
|
||||
]);
|
||||
}
|
||||
public function updateInfo(Request $request, $patientId)
|
||||
{
|
||||
try {
|
||||
$patient = Patient::find($patientId);
|
||||
$patient->update($request->only(['city', 'state', 'address', 'zip_code', 'dob', 'country']));
|
||||
$patient->save();
|
||||
|
||||
return response()->json(['message' => 'Patient address updated successfully'], 200);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 400);
|
||||
}
|
||||
}
|
||||
public function getInfo(Request $request, $patientId)
|
||||
{
|
||||
try {
|
||||
$patient = Patient::find($patientId)->makeHidden(['password', 'remember_token']);
|
||||
if ($patient->dob) {
|
||||
$birthDate = new DateTime($patient->dob);
|
||||
$today = new DateTime(date('Y-m-d'));
|
||||
$age = $today->diff($birthDate)->y;
|
||||
$patient->age = $age;
|
||||
} else {
|
||||
$patient->age = 0;
|
||||
}
|
||||
|
||||
return response()->json($patient);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 400);
|
||||
}
|
||||
}
|
||||
public function getDoctorList()
|
||||
{
|
||||
try {
|
||||
// Fetch only the necessary columns for efficiency
|
||||
$doctors = Doctor::select('id', 'name', 'designation')->get()->makeHidden(['password', 'remember_token']);
|
||||
|
||||
// Return a successful JSON response with the doctors
|
||||
return response()->json($doctors, 200);
|
||||
} catch (\Exception $e) {
|
||||
// Handle exceptions gracefully
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
public function getAppointmentList()
|
||||
{
|
||||
try {
|
||||
$appointments = Appointment::select("patients.first_name", "patients.last_name", "telemed_pros.name as agent_name", "appointments.*") // Eager load the associated telemed pro
|
||||
->leftJoin("telemed_pros", "telemed_pros.id", "appointments.telemed_pros_id")
|
||||
->leftJoin("patients", "patients.id", "appointments.patient_id")
|
||||
/* ->orderBy('appointment_time', 'desc') */ // Optional: sort by appointment time
|
||||
->get();
|
||||
|
||||
return response()->json($appointments, 200);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return response()->json(['error' => 'Failed to retrieve appointments'], 500);
|
||||
}
|
||||
}
|
||||
public function getDoctorAppointmentList()
|
||||
{
|
||||
try {
|
||||
$appointments = DoctorAppointment::select("patients.first_name", "patients.last_name", "doctor_appointments.*") // Eager load the associated telemed pro
|
||||
->leftJoin("patients", "patients.id", "doctor_appointments.patient_id")
|
||||
->orderBy('doctor_appointments.created_at', 'desc') // Optional: sort by appointment time
|
||||
->get();
|
||||
|
||||
return response()->json($appointments, 200);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return response()->json(['error' => 'Failed to retrieve appointments'], 500);
|
||||
}
|
||||
}
|
||||
public function availableSlots($date)
|
||||
{
|
||||
// Ensure date is in a valid format
|
||||
$date = Carbon::parse($date);
|
||||
|
||||
// Generate all possible 30-minute slots between 9 AM and 4 PM
|
||||
$slots = collect();
|
||||
$startTime = Carbon::parse($date)->setTime(9, 0, 0);
|
||||
$endTime = Carbon::parse($date)->setTime(16, 0, 0);
|
||||
while ($startTime < $endTime) {
|
||||
$slots->push($startTime->format('Y-m-d H:i:s'));
|
||||
$startTime->addMinutes(30);
|
||||
}
|
||||
// Filter out booked slots
|
||||
$bookedAppointments = Appointment::where('appointment_date', '>=', $date->format('Y-m-d'))
|
||||
->where('appointment_date', '<', $date->addDay()->format('Y-m-d'))
|
||||
->pluck('appointment_date');
|
||||
$availableSlots = $slots->diff($bookedAppointments);
|
||||
|
||||
$formattedSlots = $availableSlots->map(function ($slot) {
|
||||
|
||||
$start = Carbon::parse($slot);
|
||||
|
||||
// Add AM/PM
|
||||
$startTime = $start->format('g:i A');
|
||||
|
||||
$end = (clone $start)->addMinutes(29);
|
||||
|
||||
// Add AM/PM
|
||||
$endTime = $end->format('g:i A');
|
||||
|
||||
return $startTime /* . ' - ' . $endTime */;
|
||||
});
|
||||
|
||||
// Additional checking if slot is booked
|
||||
$formattedSlots = $formattedSlots->filter(function ($slot) {
|
||||
|
||||
$startTime = Carbon::parse($slot);
|
||||
/*$startTime = Carbon::parse(explode(' - ', $slot)[0]);
|
||||
$endTime = Carbon::parse(explode(' - ', $slot)[1]); */
|
||||
|
||||
//return !Appointment::whereBetween('appointment_time', [$startTime/* , $endTime */])->exists();
|
||||
return !Appointment::where('appointment_time', $startTime)->exists();
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'available_slots' => $formattedSlots->toArray()
|
||||
]);
|
||||
}
|
||||
public function appointmentDetail(Appointment $appointment)
|
||||
{
|
||||
$patient = Patient::find($appointment->patient_id);
|
||||
$telemedPro = Telemedpro::find($appointment->telemed_pros_id);
|
||||
$doctor_appointment = DoctorAppointment::select("id", "appointment_date", "appointment_time", "appointment_id")->where('appointment_id', $appointment->id)->first();
|
||||
if (!$doctor_appointment)
|
||||
$doctor_appointment = [];
|
||||
else
|
||||
$doctor_appointment = $doctor_appointment->toArray();
|
||||
|
||||
if ($patient) {
|
||||
if ($patient->dob) {
|
||||
$birthDate = new DateTime($patient->dob);
|
||||
$today = new DateTime(date('Y-m-d'));
|
||||
$age = $today->diff($birthDate)->y;
|
||||
$patient->age = $age;
|
||||
} else {
|
||||
$patient->age = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'patient' => $patient->toArray() ?? [],
|
||||
'telemedPro' => $telemedPro->toArray() ?? [],
|
||||
'doctor_appointment' => $doctor_appointment ?? [],
|
||||
'agent_appointment' => $appointment,
|
||||
'video_url' => "https://plugnmeet.codelfi.com/recordings/" . $appointment->video_token . ".mp4",
|
||||
]);
|
||||
}
|
||||
public function labDetail(Appointment $appointment)
|
||||
{
|
||||
$lab = Lab::where("appointment_id", $appointment->id)->first();
|
||||
return response()->json([
|
||||
'lab_name' => $lab->name,
|
||||
'lab_address' => $lab->address,
|
||||
'lab_city' => $lab->city,
|
||||
'lab_state' => $lab->state,
|
||||
'lab_distance' => $lab->distance,
|
||||
'lab_contact_no' => $lab->contact_no,
|
||||
'lab_lang' => $lab->lang,
|
||||
'lab_lat' => $lab->lat,
|
||||
'slot_date' => $lab->slot_date,
|
||||
'slot_time' => $lab->slot_time,
|
||||
'booking_time' => $lab->booking_time,
|
||||
]);
|
||||
}
|
||||
public function getRoomList()
|
||||
{
|
||||
$svc = new RoomServiceClient("https://plugnmeet.codelfi.com", config('app.LK_API_KEY'), config('app.LK_API_SECRET'));
|
||||
|
||||
// List rooms.
|
||||
$rooms = $svc->listRooms();
|
||||
|
||||
dd($rooms);
|
||||
}
|
||||
|
||||
public function addNotePatient(Request $request)
|
||||
{
|
||||
// Validation (adjust as needed)
|
||||
|
||||
$patient = Auth::guard('patient')->user();
|
||||
|
||||
$addNotePatient = PatientNote::create([
|
||||
'note' => $request->input('note'),
|
||||
'note_type' => $request->input('note_type'),
|
||||
'patient_id' => $patient->id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Note created',
|
||||
'data' => $addNotePatient
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getNotePatient(Request $request)
|
||||
{
|
||||
// Validation (adjust as needed)
|
||||
|
||||
$patient = Auth::guard('patient')->user();
|
||||
|
||||
$addNotePatient = PatientNote::where("patient_id", $patient->id)->get();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Note created',
|
||||
'data' => $addNotePatient
|
||||
], 200);
|
||||
}
|
||||
public function markAppointmentsStatus($id)
|
||||
{
|
||||
$appointment = Appointment::find($id);
|
||||
$appointment->status = 'completed';
|
||||
$appointment->save();
|
||||
return response()->json([
|
||||
'message' => 'status updated !'
|
||||
], 200);
|
||||
}
|
||||
}
|
195
app/Http/Controllers/Agent/OrderController.php
Normal file
195
app/Http/Controllers/Agent/OrderController.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Agence104\LiveKit\AccessToken;
|
||||
use Agence104\LiveKit\AccessTokenOptions;
|
||||
use Agence104\LiveKit\EgressServiceClient;
|
||||
use Agence104\LiveKit\RoomCreateOptions;
|
||||
use Agence104\LiveKit\RoomServiceClient;
|
||||
use Agence104\LiveKit\VideoGrant;
|
||||
use App\Classes\Constant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\JassJWT;
|
||||
use App\Events\AppointmentCallEnded;
|
||||
use App\Events\AppointmentCreated;
|
||||
use App\Events\DeviceCurrentStatus;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Doctor;
|
||||
use App\Models\DoctorAppointment;
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemHistory;
|
||||
use App\Models\Lab;
|
||||
use App\Models\Patient;
|
||||
use App\Models\PatientNote;
|
||||
use App\Models\PatientPrescription;
|
||||
use App\Models\Telemedpro;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Error;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livekit\EncodedFileOutput;
|
||||
use Livekit\EncodedFileType;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
protected $user_id;
|
||||
protected $url;
|
||||
public function __construct(UrlGenerator $url)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->user_id = Auth::guard('agent')->user()->id;
|
||||
$this->url = $url;
|
||||
}
|
||||
public function orderList(Request $request)
|
||||
{
|
||||
|
||||
$fromDate = $request->get('from_date');
|
||||
$toDate = $request->get('to_date');
|
||||
$orderList = Cart::select("appointments.*", 'appointments.id as appointment_id', 'carts.*', 'carts.id as order_id')->leftJoin('appointments', 'appointments.id', 'carts.appointment_id')
|
||||
->where('appointments.telemed_pros_id', $this->user_id);
|
||||
if ($fromDate != "") {
|
||||
$from_date = Carbon::createFromFormat('m-d-Y', $fromDate)->format('Y-m-d');
|
||||
$orderList->where('created_at', ">=", $from_date . " 00:00:00");
|
||||
}
|
||||
if ($toDate != "") {
|
||||
$to_date = Carbon::createFromFormat('m-d-Y', $toDate)->format('Y-m-d');
|
||||
$orderList->where('created_at', "<=", $to_date . " 23:59:59");
|
||||
}
|
||||
|
||||
$orderListData = $orderList->get();
|
||||
$totalPrice = 0;
|
||||
$totalShippingCost = 0;
|
||||
foreach ($orderListData as $order) {
|
||||
$order->order_id = $order->id;
|
||||
$totalPrice = 0;
|
||||
$total_products = 0;
|
||||
$quantity = [];
|
||||
$totalShippingCost = 0;
|
||||
$order->order_total_amount = $totalPrice;
|
||||
$order->order_total_shipping = $totalShippingCost;
|
||||
$items = Item::leftJoin('plans_v1', 'items.plans_id', 'plans_v1.id')
|
||||
->where('cart_id', $order->id)
|
||||
->get();
|
||||
$appointment = Appointment::where('id', $order->appointment_id)->first();
|
||||
|
||||
$order->appointment_status = $appointment->status;
|
||||
|
||||
|
||||
|
||||
$orderItems = [];
|
||||
foreach ($items as $item) {
|
||||
array_push($orderItems, $item->plansV1);
|
||||
$totalShippingCost += $item->shipping_cost;
|
||||
$item->total_price = $item->quantity * $item->price;
|
||||
$totalPrice += $item->total_price;
|
||||
$order->order_total_amount = $totalPrice;
|
||||
$order->order_total_shipping = $totalShippingCost;
|
||||
$item->plansV1->qty = $item->quantity;
|
||||
$item->plansV1->status = $item->status;
|
||||
}
|
||||
|
||||
$order->total_items = $total_products;
|
||||
$order->order_items = $orderItems;
|
||||
}
|
||||
return response()
|
||||
->json([
|
||||
'order_data' => $orderListData
|
||||
]);
|
||||
}
|
||||
public function orderDetails($id)
|
||||
{
|
||||
$orderItems = $this->getOrderItems($id);
|
||||
|
||||
$orderDetails = Cart::find($id);
|
||||
$items = Item::where('cart_id', $orderDetails->id)->get();
|
||||
|
||||
|
||||
$appointments = Appointment::select(
|
||||
'appointments.*',
|
||||
'telemed_pros.name as provider_name',
|
||||
'telemed_pros.email as provider_email',
|
||||
'telemed_pros.phone_number as provider_phone'
|
||||
)
|
||||
->leftJoin('telemed_pros', 'telemed_pros.id', 'appointments.telemed_pros_id')
|
||||
->where('appointments.id', $orderDetails->appointment_id)
|
||||
->first();
|
||||
$prescription = PatientPrescription::select(
|
||||
'patient_prescription.direction_quantity',
|
||||
'patient_prescription.refill_quantity',
|
||||
'patient_prescription.dosage',
|
||||
'patient_prescription.status',
|
||||
'patient_prescription.direction_one',
|
||||
'patient_prescription.direction_two',
|
||||
'patient_prescription.dont_substitute',
|
||||
'patient_prescription.comments',
|
||||
'patient_prescription.brand',
|
||||
'patient_prescription.from',
|
||||
'patient_prescription.quantity',
|
||||
'patient_prescription.created_at as prescription_date',
|
||||
'prescriptions.name as prescription_name',
|
||||
'patient_prescription.prescription_id',
|
||||
'telemed_pros.name as provide_name',
|
||||
'telemed_pros.id as provider_id'
|
||||
)
|
||||
->where("appointment_id", $orderDetails->appointment_id)
|
||||
->leftJoin('appointments', 'appointments.id', 'patient_prescription.appointment_id')
|
||||
->leftJoin('prescriptions', 'prescriptions.id', 'patient_prescription.prescription_id')
|
||||
->leftJoin('telemed_pros', 'appointments.telemed_pros_id', 'telemed_pros.id')
|
||||
->get();
|
||||
$patientNotes = PatientNote::where("appointment_id", $orderDetails->appointment_id)->get();
|
||||
$appointments->provider_id = $appointments->telemed_pros_id;
|
||||
$patient = $orderDetails->patient;
|
||||
$patient->profile_picture = $this->url->to("storage/profile_pictures/" . $patient->profile_picture);
|
||||
|
||||
return response()
|
||||
->json([
|
||||
'order_details' => $orderDetails,
|
||||
'order_items' => $orderItems,
|
||||
'patient_details' => $patient,
|
||||
'appointment_details' => $appointments,
|
||||
'items_activity' => $this->getShippingActivity($id),
|
||||
'appointment_notes' => $patientNotes,
|
||||
'prescription' => $prescription
|
||||
]);
|
||||
}
|
||||
public function getOrderItems($id)
|
||||
{
|
||||
$items = Item::leftJoin('plans_v1', 'items.plans_id', 'plans_v1.id')
|
||||
->where('cart_id', $id)
|
||||
->get();
|
||||
$totalPrice = 0;
|
||||
$totalShippingCost = 0;
|
||||
$total_products = 0;
|
||||
foreach ($items as $item) {
|
||||
|
||||
$totalShippingCost += $item->shipping_cost;
|
||||
$item->total_price = $item->quantity * $item->price;
|
||||
$totalPrice += $item->total_price;
|
||||
$total_products += $item->quantity;
|
||||
$item->image_url = $this->url->to("product/" . $item->image_url);
|
||||
}
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'total_amount' => $totalPrice,
|
||||
'total_shipping_cost' => $totalShippingCost,
|
||||
'total_products' => $total_products,
|
||||
'total' => $totalPrice + $totalShippingCost
|
||||
];
|
||||
}
|
||||
public function getShippingActivity($id)
|
||||
{
|
||||
$itemsHistory = ItemHistory::select('items_history.*', 'plans_v1.title as item_name')
|
||||
->where('items_history.cart_id', $id)
|
||||
->leftJoin('items', 'items.id', 'items_history.item_id')
|
||||
->leftJoin('plans_v1', 'plans_v1.id', 'items.plans_id')
|
||||
->get();
|
||||
return $itemsHistory;
|
||||
}
|
||||
}
|
183
app/Http/Controllers/Agent/PatientProfileController.php
Normal file
183
app/Http/Controllers/Agent/PatientProfileController.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Agence104\LiveKit\AccessToken;
|
||||
use Agence104\LiveKit\AccessTokenOptions;
|
||||
use Agence104\LiveKit\EgressServiceClient;
|
||||
use Agence104\LiveKit\RoomCreateOptions;
|
||||
use Agence104\LiveKit\RoomServiceClient;
|
||||
use Agence104\LiveKit\VideoGrant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\JassJWT;
|
||||
use App\Events\AppointmentCallEnded;
|
||||
use App\Events\AppointmentCreated;
|
||||
use App\Events\DeviceCurrentStatus;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Doctor;
|
||||
use App\Models\DoctorAppointment;
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemHistory;
|
||||
use App\Models\Lab;
|
||||
use App\Models\LabKit;
|
||||
use App\Models\LabkitOrderItem;
|
||||
use App\Models\Patient;
|
||||
use App\Models\PatientNote;
|
||||
use App\Models\PatientPrescription;
|
||||
use App\Models\Telemedpro;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Error;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livekit\EncodedFileOutput;
|
||||
use Livekit\EncodedFileType;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class PatientProfileController extends Controller
|
||||
{
|
||||
protected $user_id;
|
||||
protected $url;
|
||||
public function __construct(UrlGenerator $url)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->user_id = Auth::guard('agent')->user()->id;
|
||||
$this->url = $url;
|
||||
}
|
||||
public function index($id)
|
||||
{
|
||||
$patient = Patient::where('id', $id)->first();
|
||||
if ($patient->profile_picture)
|
||||
$patient->profile_picture = $this->url->to("storage/profile_pictures/", $patient->profile_picture);
|
||||
else
|
||||
$patient->profile_picture = asset('img/avatars/1.png');;
|
||||
|
||||
$notes = PatientNote::select(
|
||||
'patient_notes.note',
|
||||
'telemed_pros.name as provider_name',
|
||||
'patient_notes.appointment_id',
|
||||
'patient_notes.created_at as note_date'
|
||||
)
|
||||
->leftJoin('telemed_pros', 'telemed_pros.id', 'patient_notes.telemed_pros_id')
|
||||
->where('patient_id', $id)->get();
|
||||
$prescriptions = PatientPrescription::select(
|
||||
'appointments.appointment_date',
|
||||
'appointments.appointment_time',
|
||||
'appointments.timezone',
|
||||
'appointments.start_time',
|
||||
'patient_prescription.direction_quantity',
|
||||
'patient_prescription.refill_quantity',
|
||||
'patient_prescription.dosage',
|
||||
'patient_prescription.status',
|
||||
'patient_prescription.direction_one',
|
||||
'patient_prescription.direction_two',
|
||||
'patient_prescription.dont_substitute',
|
||||
'patient_prescription.comments',
|
||||
'patient_prescription.brand',
|
||||
'patient_prescription.from',
|
||||
'patient_prescription.quantity',
|
||||
'patient_prescription.created_at as prescription_date',
|
||||
'telemed_pros.name',
|
||||
'telemed_pros.email as provider_email',
|
||||
'telemed_pros.gender as provider_gender',
|
||||
'telemed_pros.specialty as provider_specialty',
|
||||
'telemed_pros.years_of_experience',
|
||||
'prescriptions.name as prescription_name',
|
||||
'carts.id as order_id',
|
||||
// 'prescriptions.price as prescription_price',
|
||||
// 'prescriptions.shipping_cost as prescription_shipping_cost',
|
||||
'patient_prescription.prescription_id'
|
||||
)
|
||||
->leftJoin('appointments', 'appointments.id', 'patient_prescription.appointment_id')
|
||||
->leftJoin('carts', 'carts.appointment_id', '=', 'appointments.id')
|
||||
->leftJoin('telemed_pros', 'appointments.telemed_pros_id', 'telemed_pros.id')
|
||||
->leftJoin('prescriptions', 'prescriptions.id', 'patient_prescription.prescription_id')
|
||||
->where('patient_prescription.patient_id', $id)->get();
|
||||
return response()->json(
|
||||
[
|
||||
'notes_history' => $notes,
|
||||
'prescriptions' => $prescriptions,
|
||||
'patient_details' => $patient
|
||||
],
|
||||
200
|
||||
);
|
||||
}
|
||||
public function labkitOrderItemStore(Request $request)
|
||||
{
|
||||
// Validate the request data
|
||||
$validator = Validator::make($request->all(), [
|
||||
'cart_id' => 'required|exists:carts,id',
|
||||
'item_id' => 'required|exists:items,id',
|
||||
'lab_kit_id' => 'required|exists:lab_kit,id',
|
||||
|
||||
/* 'result' => 'nullable|string', */
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
// Create a new LabkitOrderItem
|
||||
$labkitOrderItem = LabkitOrderItem::create([
|
||||
'cart_id' => $request['cart_id'],
|
||||
'item_id' => $request['item_id'],
|
||||
'lab_kit_id' => $request['lab_kit_id'],
|
||||
/* 'result' => $request['result'], */
|
||||
'status' => "Ordered",
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Order detail stored successfully',
|
||||
'data' => $labkitOrderItem,
|
||||
], 201);
|
||||
}
|
||||
public function labkitOrderItemGet(Request $request)
|
||||
{
|
||||
$labkitOrderItems = LabkitOrderItem::where('labkit_order_items.cart_id', $request->input('cart_id'))
|
||||
->leftJoin(
|
||||
'lab_kit',
|
||||
'labkit_order_items.lab_kit_id',
|
||||
'=',
|
||||
'lab_kit.id'
|
||||
)
|
||||
->leftJoin(
|
||||
'items',
|
||||
'items.id',
|
||||
'labkit_order_items.item_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'plans_v1',
|
||||
'plans_v1.id',
|
||||
'items.plans_id'
|
||||
)
|
||||
->select(
|
||||
'labkit_order_items.id',
|
||||
'labkit_order_items.status',
|
||||
'labkit_order_items.result',
|
||||
'lab_kit.name as lab_kit_name',
|
||||
'plans_v1.title as item_name'
|
||||
)
|
||||
->get();
|
||||
foreach ($labkitOrderItems as $labKit) {
|
||||
|
||||
if ($labKit->result != "")
|
||||
$labKit->result = $this->url->to('storage/lab_results/' . $labKit->result);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $labkitOrderItems,
|
||||
]);
|
||||
}
|
||||
public function getLabKit(Cart $cart, Request $request)
|
||||
{
|
||||
$kit = LabKit::all();
|
||||
return response()->json(['kit' => $kit], 200);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user