⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
OpdPatientDepartmentRepository.php
<?php namespace App\Repositories; use App\Models\Category; use App\Models\Doctor; use App\Models\Notification; use App\Models\OpdPatientDepartment; use App\Models\Patient; use App\Models\PatientCase; use App\Models\Prescription; use Exception; use Filament\Notifications\Notification as FilamentNotification; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class OpdPatientDepartmentRepository * * @version September 8, 2020, 6:42 am UTC */ class OpdPatientDepartmentRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'patient_id', 'ipd_number', 'height', 'weight', 'bp', 'symptoms', 'notes', 'admission_date', 'case_id', 'is_old_patient', 'doctor_id', 'standard_charge', 'payment_mode', ]; /** * Return searchable fields */ public function getFieldsSearchable(): array { return $this->fieldSearchable; } /** * Configure the Model **/ public function model() { return OpdPatientDepartment::class; } /** * @return mixed */ public function getAssociatedData() { $data['patients'] = Patient::with('patientUser')->get()->where('patientUser.status', '=', 1)->where('tenant_id', getLoggedInUser()->tenant_id)->pluck( 'patientUser.full_name', 'id' )->sort(); $data['doctors'] = Doctor::with('doctorUser')->get()->where('doctorUser.status', '=', 1)->where('tenant_id', getLoggedInUser()->tenant_id)->pluck( 'doctorUser.full_name', 'id' )->sort(); $data['opdNumber'] = $this->model->generateUniqueOpdNumber(); $data['paymentMode'] = $this->model::PAYMENT_MODES; return $data; } public function getPatientCases(int $patientId): Collection { $opdPatient = OpdPatientDepartment::pluck('case_id')->toArray(); return PatientCase::where('patient_id', $patientId)->whereNotIn('id', array_map('intval', $opdPatient))->where('status', 1)->pluck('case_id', 'id'); } public function getDoctorsData(): Collection { return Doctor::with('doctorUser')->get()->where('doctorUser.status', '=', 1)->pluck('doctorUser.full_name', 'id'); } public function getDoctorsList(): array { $result = Doctor::with('user')->get() ->where('user.status', '=', 1)->pluck('user.full_name', 'id')->toArray(); $doctors = []; foreach ($result as $key => $item) { $doctors[] = [ 'key' => $key, 'value' => $item, ]; } return $doctors; } public function store(array $input) { try { $input['is_old_patient'] = isset($input['is_old_patient']) ? true : false; $jsonFields = []; foreach ($input as $key => $value) { if (strpos($key, 'field') === 0) { $jsonFields[$key] = $value; } } $input['custom_field'] = ! empty($jsonFields) ? $jsonFields : null; $opdPatientDepartment = OpdPatientDepartment::create($input); } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } return $opdPatientDepartment; } public function updateOpdPatientDepartment(array $input, OpdPatientDepartment $opdPatientDepartment): bool { try { $input['standard_charge'] = removeCommaFromNumbers($input['standard_charge']); $input['is_old_patient'] = isset($input['is_old_patient']) ? true : false; $jsonFields = []; foreach ($input as $key => $value) { if (strpos($key, 'field') === 0) { $jsonFields[$key] = $value; } } $input['custom_field'] = ! empty($jsonFields) ? $jsonFields : null; $opdPatientDepartment->update($input); } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } return true; } public function createNotification(array $input) { try { $patient = Patient::with('patientUser')->where('id', $input['patient_id'])->first(); $doctor = Doctor::with('doctorUser')->where('id', $input['doctor_id'])->first()->user->fullname; if (isset($input['revisit'])) { $title = $patient->patientUser->full_name.' you are visited doctor '.$doctor.'.'; } else { $title = $patient->patientUser->full_name.' your OPD record has been created.'; } addNotification([ Notification::NOTIFICATION_TYPE['OPD Patient'], $patient->user_id, Notification::NOTIFICATION_FOR[Notification::PATIENT], $title, ]); } catch (Exception $e) { FilamentNotification::make() ->danger() ->title($e->getMessage()) ->send(); // throw new UnprocessableEntityHttpException($e->getMessage()); } } public function getMedicinesCategoriesData(): Collection { return Category::where('is_active', '=', 1)->pluck('name', 'id'); } public function getMedicineCategoriesList(): array { $result = Category::where('tenant_id', getLoggedInUser()->tenant_id)->where('is_active', '=', 1)->pluck('name', 'id')->toArray(); return $result; } public function getDoseDurationList() { $result = Prescription::DOSE_DURATION; $doseDuration = []; foreach ($result as $key => $item) { $doseDuration[] = [ 'key' => $key, 'value' => $item, ]; } return $doseDuration; } public function getDoseIntervalList() { $result = Prescription::DOSE_INTERVAL; $doseInterval = []; foreach ($result as $key => $item) { $doseInterval[] = [ 'key' => $key, 'value' => $item, ]; } return $doseInterval; } public function getMealList() { $result = Prescription::MEAL_ARR; $meal = []; foreach ($result as $key => $item) { $meal[] = [ 'key' => $key, 'value' => $item, ]; } return $meal; } }