File: /var/www/html/sarvodayahospital/app/Http/Controllers/ReportController.php
<?php
namespace App\Http\Controllers;
use App\AppointmentBook;
use App\listUsers;
use App\Models\Appointment;
use App\Models\Doctor;
use App\Models\Hospital;
use App\Models\Patient;
use App\Reports;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\AppointmentController as AC;
use App\Models\CancelledAppointment;
use Artesaos\SEOTools\Facades\OpenGraph;
use Artesaos\SEOTools\Facades\SEOMeta;
class ReportController extends Controller
{
public function index()
{
$user = Auth::user();
$listUsers = new listUsers();
$arrayfacilityGUID = Hospital::pluck('FacilityGUID')->toArray();
$a = array_unique($arrayfacilityGUID);
$facility = [];
foreach ($a as $key => $value) {
$facility[] = $value;
}
$phone = $user->Phone;
$resp = $listUsers->getUsers($phone, $facility);
$data = json_decode($resp, false);
$repo = new Reports();
$response = $repo->bookings($phone, "", "", 1, 10);
$bookingHistory = json_decode($response, false);
//return view('pages.reports.index', compact('data', 'phone'));
if (($data) && ($data->success) || count(collect($bookingHistory->data->data))) {
return view('pages.reports.index', compact('data', 'phone'));
} else {
// $data = Appointment::with(['doctors', 'hospitals'])->where('patient_mobile', $user->Phone)
// ->orderBy('created_at', 'DESC')
// ->paginate(10);
return view('pages.reports.need-appointment');
//return view('pages.reports.user', compact('data', 'phone'));
}
}
public function bookings(Request $request)
{
$repo = new Reports();
$booking = '';
$recordsPerPage = $request->recordsPerPage ? $request->recordsPerPage : 10; //10
$pageNumber = $request->pageNumber ? $request->pageNumber : 1;
$response = $repo->bookings($request->mobileNo, $request->facilityGUID, $request->mrn, $pageNumber, $recordsPerPage);
$dataJson = json_decode($response, false);
if ($dataJson->success) {
if ($dataJson->data->success) {
$data = $dataJson->data->data;
if (count($data) > 0) {
$pagination = $dataJson->data->pagination;
foreach ($data as $d) {
$booking .= $this->bookingHTML($d, $recordsPerPage, $pageNumber);
}
if ($pagination->page_count > 1) {
$booking .= $this->doPagination($pagination, 'bookings', $request->mobileNo, $request->facilityGUID, $request->mrn, $pageNumber, $recordsPerPage);
}
}
}
}
return json_encode($booking);
}
public function labreports(Request $request)
{
$repo = new Reports();
$labreports = '';
$pagination = '';
$page = '';
$recordsPerPage = $request->recordsPerPage ? $request->recordsPerPage : 10; //10
$pageNumber = $request->pageNumber ? $request->pageNumber : 1;
$response = $repo->labreports($request->mobileNo, $request->facilityGUID, $request->mrn, $pageNumber, $recordsPerPage);
$dataJson = json_decode($response, false);
if ($dataJson->success) {
if ($dataJson->data->success) {
$data = $dataJson->data->data;
if (count($data) > 0) {
foreach ($data as $d) {
$labreports .= '<tr>
<td>' . $d->documentName . '</td>
<td>' . ucwords($d->patientName) . '</td>
<td>' . $d->mrn . '</td>
<td>' . $d->formattedRecordReceivedDate . '</td>
<td class="text-center"><a target="_blank" href="' . $d->pdfFilePath . '"
class="btn text-white bgBlueDark download-btn-report">Download</a></td>
</tr>';
}
$pagination = $dataJson->data->pagination;
if ($pagination->page_count > 1) {
$page = $this->doPagination($pagination, 'labreports', $request->mobileNo, $request->facilityGUID, $request->mrn, $request->pageNumber, $recordsPerPage);
}
}
}
}
return json_encode(['labreports' => $labreports, 'page' => $page]);
}
public function bookingHTML($data, $recordsPerPage, $pageNumber)
{
$doctor = Doctor::where('PersonID', $data->personID)->first();
$doctorPhoto = asset('img/default-doctor-male.jpg');
if (!is_null($doctor)) {
if (!is_null($doctor->doctorPhoto)) {
if ($doctor->gender->Gender == 'Male') {
$doctorPhoto = asset('img/default-doctor-male.jpg');
} else {
$doctorPhoto = asset('img/default-doctor-female.jpg');
}
} elseif ($doctor->gender->Gender == 'Male') {
$doctorPhoto = asset('img/default-doctor-male.jpg');
} else {
$doctorPhoto = asset('img/default-doctor-female.jpg');
}
}
$hospital = Hospital::where('FacilityGUID', $data->facilityGUID)->first();
$hospital_img = asset('img/SH-icon.svg');
$html = '
<div class="doctor-booking-box mb-4">
<div class="row align-items-center">
<div class="col-lg-3 mb-lg-0 mb-2">
<h4 class="clr545454 f-16 mb-3 fw-500">Doctor Information</h4>
<div class="d-md-flex align-items-start d-lg-block">
<div class="d-flex booking-dr-profile mb-3 align-items-center">
<div
class="text-center report-sh-icon align-items-center d-flex justify-content-center me-3">
<img src="' . $doctorPhoto . '" class="img-fluid" alt="...">
</div>
<div>
<p class="clr5c f-14 mb-0">' . $data->doctorName . '</p>
</div>
</div>
<div class="d-flex booking-SH-img align-items-center ps-md-4 ps-lg-0">
<div
class="text-center report-sh-icon align-items-center d-flex justify-content-center me-3">
<img src="' . $hospital_img . '"
class="img-fluid rounded-0 shadow-none" alt="...">
</div>
<div>
<p class="clr5c f-14 mb-0">' . $hospital->HospitalShortName . '</p>
<p class="clrAc f-12 mb-0">' . $hospital->Location . '</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="pateint-info-box bg-f7f7f7">
<h3 class="clrBlueDark f-16 fw-500 py-2 mb-0">Patient Information</h3>
<table class="table">
<tbody>
<tr>
<td class="fw-500 clr545454 f-14">Name</td>
<td class="fw-500 clr545454 f-14">Appointment ID</td>
<td class="fw-500 clr545454 f-14">Booking Timing</td>
</tr>
<tr>
<td class="clr8e8e8e f-14">' . ucwords($data->patientName) . '</td>
<td class="clr8e8e8e f-14">' . $data->appointmentID . '</td>
<td class="clr8e8e8e f-14">' . $data->appointmentDate . ' / ' . $data->appointmentTime . '</td>
</tr>
<tr>
<td class="fw-500 clr545454 f-14">Type</td>
<td class="fw-500 clr545454 f-14">Payment Status</td>
<td class="fw-500 clr545454 f-14">Appointment Status</td>
</tr>
<tr>
<td class="clr8e8e8e f-14">' . $data->appointmentType . '</td>
<td class="clr8e8e8e f-14">' . $data->paymentStatus . '</td>
<td class="clr8e8e8e f-14">' . $data->appointmentStatus . '</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-lg-3">
<!--<a href="javascript:void(0)" class="btn schedule-appointment-report d-block mb-md-4 mb-2">Schedule an Appointment</a>-->';
if ($data->appointmentStatus == 'BOOKED') {
$html .= '<button data-appointmentID="' . $data->appointmentID . '" data-recordsPerPage="' . $recordsPerPage . '" data-pageNumber="' . $pageNumber . '" data-mrn="' . $data->patientMRN . '" data-facilityGUID="' . $data->facilityGUID . '" data-mobileNo="' . $data->patientContactNumber . '" data-hospital="' . $hospital->HospitalShortName . '" class="btn schedule-appointment-report d-block cancel-appointment-btn">Cancel Appointment</button>';
}
$html .= '</div>
</div>
</div>';
return $html;
}
public function doPagination($pagination, $reportType = '', $mobileNo = '', $facilityGUID = '', $mrn = '', $pageNumber = 1, $recordsPerPage = 10)
{
$html = '<ul class="pagination">';
$current_page = $pagination->current_page;
if ($pagination->has_prev_page == false) {
$html .= '<li class="page-item"><button class="page-link page-back" href="javascript:void(0)"><i class="fa-solid fa-angle-left"></i></button></li>';
} else {
$html .= '<li class="page-item"><button class="page-link page-back btn-' . $reportType . '" href="javascript:void(0)" data-recordsPerPage="' . $recordsPerPage . '" data-pageNumber="' . ($current_page - 1) . '" data-mrn="' . $mrn . '" data-facilityGUID="' . $facilityGUID . '" data-mobileNo="' . $mobileNo . '" ><i class="fa-solid fa-angle-left"></i></button></li>';
}
for ($i = 1; $i <= $pagination->page_count; ++$i) {
if ($current_page == $i) {
$html .= '<li class="page-item active"><button class="page-link" href="javascript:void(0)">' . $i . '</button></li>';
} else {
$html .= '<li class="page-item"><button class="page-link btn-' . $reportType . '" data-recordsPerPage="' . $recordsPerPage . '" data-pageNumber="' . $i . '" data-mrn="' . $mrn . '" data-facilityGUID="' . $facilityGUID . '" data-mobileNo="' . $mobileNo . '" >' . $i . '</button></li>';
}
}
if ($pagination->has_next_page == false) {
$html .= '<li class="page-item"><button class="page-link next-page" href="javascript:void(0)"><i class="fa-solid fa-angle-right"></i></button></li>';
} else {
$html .= '<li class="page-item"><button class="page-link next-page btn-' . $reportType . '" href="javascript:void(0)" data-recordsPerPage="' . $recordsPerPage . '" data-pageNumber="' . ($current_page + 1) . '" data-mrn="' . $mrn . '" data-facilityGUID="' . $facilityGUID . '" data-mobileNo="' . $mobileNo . '" ><i class="fa-solid fa-angle-right"></i></button></li>';
}
$html .= '</ul>';
return $html;
}
/**
* This method shows login page in appointment.
*
* @param Request $request request variable
*
* @return View view view pages
*/
public function login(Request $request)
{
$user = Auth::user();
if (is_null($user)) {
SEOMeta::setTitle('Best Hospital in Faridabad Delhi NCR India | Sarvodaya Hospital', false)
->setDescription('Sarvodaya hospital is best multi-speciality hospital in Faridabad and Greater Noida. We have best doctors that use the latest technology and advanced treatment in Delhi NCR, India. Call on 18003131414 for any medical assistance.')
->setKeywords('Best Hospital in Faridabad, Best Hospital in Greater Noida, Best Hospital in Delhi NCR');
OpenGraph::setTitle('Best Hospital in Faridabad Delhi NCR India | Sarvodaya Hospital')
->setDescription('Sarvodaya hospital is best multi-speciality hospital in Faridabad and Greater Noida. We have best doctors that use the latest technology and advanced treatment in Delhi NCR, India. Call on 18003131414 for any medical assistance.');
return view('pages.reports.login');
} else {
return redirect()->route('patient.report.index');
}
}
/**
* Validate login with OTP and redirect to specified page.
*
* @param Request $request Request variables
*
* @return View
*/
public function loginWithOtp(Request $request)
{
/* Validation */
$request->validate(
[
'Phone' => 'required',
'otp' => 'required',
]
);
$otp_expire_at = session()->get('patient.otp_expire_at');
$now = carbon::now();
if ($now->gt($otp_expire_at)) {
//$result = (new AC)->generate($request);
return response()->json(['Your OTP expired, please click on resend otp.'], 401);
}
$sphone = session()->get('patient.Phone');
$sotp = (int) session()->get('patient.otp');
$otp = explode(',', $request->otp);
$otp = implode('', $otp);
$phone = $request->Phone;
if (($sotp == $otp) && ($phone == $sphone)) {
session()->forget('patient.otp');
session()->forget('patient.otp_expire_at');
session()->put('patient.should_login', true);
return response()->json(['message' => route('report.should-login')], 200);
} else {
return response()->json(['Your Otp is not correct.'], 401);
}
}
public function shouldLogin(Request $request)
{
$shouldlogin = session()->get('patient.should_login');
if (!$shouldlogin) {
return view('pages.reports.login');
}
session()->forget('patient.should_login');
//check API user or not
$hospitals = Hospital::get();
foreach ($hospitals as $h) {
$arrayfacilityGUID[] = $h->FacilityGUID;
}
$phone = session()->get('patient.Phone');
$listUsers = new listUsers();
$resp = $listUsers->getUsers($phone, array_values(array_unique($arrayfacilityGUID)));
$data = json_decode($resp, false);
//check Patient
$patient = Patient::where('Phone', $phone)->first();
$listUsers = new listUsers();
$resp = $listUsers->getUsers($phone, array_values(array_unique($arrayfacilityGUID)));
$data = json_decode($resp, false);
//check Patient
$patient = Patient::where('Phone', $phone)->first();
if ($data->success) {
if (is_null($patient)) {
$patient = Patient::create(
[
'FirstName' => $data->data[0]->personName,
//'LastName' => $request->LastName,
//'Email' => $request->Email,
'Phone' => $request->session()->get('patient.Phone'),
'Gender' => (($data->data[0]->gender) == 'M') ? '1' : '2',
'DOB' => Carbon::parse($data->data[0]->formattedDOB)->format('Y-m-d'),
'published_at' => Carbon::now(),
]
);
}
Auth::login($patient);
session()->regenerate();
return redirect()->route('patient.report.index');
} else {
if (is_null($patient)) {
return redirect()->route('user.details');
} else {
Auth::login($patient);
session()->regenerate();
return redirect()->route('patient.report.index');
}
}
}
public function needAppointment()
{
return view('pages.reports.need-appointment');
}
public function getUserDetails()
{
$phone = session()->get('patient.Phone');
//$phone = '9657494757'; //session()->get('patient.Phone');
if (is_null($phone) || ($phone == '')) {
return redirect()->route('report.login');
}
$hospitals = Hospital::get();
foreach ($hospitals as $h) {
$arrayfacilityGUID[] = $h->FacilityGUID;
}
$listUsers = new listUsers();
//$arrayfacilityGUID = ['ce968cc1-9305-4933-a875-QA', 'a59a4397-8d03-464f-8b97-e1a3fcb4d215'];
$resp = $listUsers->getUsers($phone, array_values(array_unique($arrayfacilityGUID)));
$data = json_decode($resp, false);
if ($data->success) {
return view('pages.reports.patient-select', compact('data', 'phone'));
} else {
return view('pages.user-detail', compact('phone'));
}
}
/**
* This method save patient details in DB.
*
* @param Request $request request variable
*
* @return View view view pages
*/
public function saveUserDetails(Request $request)
{
$user = Auth::user();
if (is_null($user)) {
/* Validation */
$request->validate(
[
'FirstName' => ['required', 'string', 'max:255'],
'LastName' => ['string', 'max:255', 'nullable'],
'DOB' => ['required'],
'gender' => ['required'],
'Email' => ['email:rfc,dns', 'nullable'],
//'Phone' => ['required', 'numeric', 'digits:10', 'unique:patients'],
]
);
$patient = Patient::create(
[
'FirstName' => $request->FirstName,
'LastName' => $request->LastName,
'Email' => $request->Email,
'Phone' => $request->session()->get('patient.Phone'),
'Gender' => $request->gender,
'DOB' => Carbon::parse($request->DOB)->format('Y-m-d'),
'published_at' => Carbon::now(),
]
);
Auth::login($patient);
}
session()->regenerate();
return redirect()->route('patient.report.index');
}
public function saveAPIUserDetails(Request $request)
{
$user = Auth::user();
if (is_null($user)) {
/* Validation */
$request->validate(
[
'dataName' => ['required', 'string', 'max:255'],
//'dataFormattedDOB' => ['required'],
//'dataGender' => ['required'],
//'Phone' => ['required', 'numeric', 'digits:10', 'unique:patients'],
]
);
$patient = Patient::create(
[
'FirstName' => $request->dataName,
//'LastName' => $request->LastName,
//'Email' => $request->Email,
'Phone' => $request->session()->get('patient.Phone'),
'Gender' => $request->dataGender,
'DOB' => Carbon::parse($request->dataFormattedDOB)->format('Y-m-d'),
'published_at' => Carbon::now(),
]
);
Auth::login($patient);
}
session()->regenerate();
return redirect()->route('patient.report.index');
}
/**
* Cancel Booking.
*
* @return redirect request
*/
public function cancelBooking(Request $request)
{
//cancel booking
$appointment_api = new AppointmentBook();
$response = $appointment_api->cancelBooking($request->appointmentID, $request->facilityGUID, $request->hospital, $request->cancellationNote);
$data = json_decode($response, false);
if (($data) && ($data->success)) {
//UPDATE APPOINTMENT TABLE
$status = Appointment::where('id', $request->id)->update(
[
'UserAppointmentStatus' => 'CancelledByUser',
]
);
/**
* update Cancelled_appointment table for manual entry/reverse payment of sarvodaya team
* Update RefundStatus col to Pending [Pending, Initiated, Inprocess, Completed]
* Update PaymentType to [Online, PayAtHospital]
*/
$appointment = Appointment::where('id', $request->id)->first();
$cancelledAppointment = CancelledAppointment::create(
[
'OrderID' => $appointment->OrderID,
'AppointmentID' => $appointment->id,
'RefundStatus' => 'Pending',
'PaymentType' => ((int)$appointment->PayAtHospital == 1) ? 'PayAtHospital' : 'Online',
'published_at' => Carbon::now(),
]
);
}
return $data;
}
}