⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.94
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
/
Models
/
View File Name :
BedType.php
<?php namespace App\Models; use App\Traits\PopulateTenantID; use Eloquent as Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Carbon; use Stancl\Tenancy\Database\Concerns\BelongsToTenant; /** * Class Bed_Type * * @version February 17, 2020, 8:08 am UTC * * @property int $id * @property string $title * @property string $description * @property Carbon|null $created_at * @property Carbon|null $updated_at * * @method static Builder|BedType newModelQuery() * @method static Builder|BedType newQuery() * @method static Builder|BedType query() * @method static Builder|BedType whereCreatedAt($value) * @method static Builder|BedType whereDescription($value) * @method static Builder|BedType whereId($value) * @method static Builder|BedType whereTitle($value) * @method static Builder|BedType whereUpdatedAt($value) * * @mixin Model * * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Bed[] $beds * @property-read int|null $beds_count * @property int $is_default * * @method static Builder|BedType whereIsDefault($value) */ class BedType extends Model { use BelongsToTenant, PopulateTenantID; /** * @var string */ public $table = 'bed_types'; /** * @var array */ public $fillable = [ 'title', 'description', ]; /** * Validation rules * * @var array */ public static $rules = [ 'title' => 'required|is_unique:bed_types,title', ]; /** * Get the attributes that should be cast. * * @return array<string, string> */ protected function casts(): array { return [ 'id' => 'integer', ]; } public function beds(): HasMany { return $this->hasMany(Bed::class, 'bed_type'); } public function patientNameRetrieved($beds) { $data = []; foreach ($beds as $bed) { $data[] = [ 'id' => $bed->id, 'name' => ! $bed->is_available ? ! $bed->bedAssigns->isEmpty() && $bed->bedAssigns[0]->discharge_date == null ? $bed->bedAssigns[0]->patient->patientUser->full_name : $this->preparePatientAdmissionData($bed->patientAdmission, $bed->id) : $bed->name, 'status' => (bool) $bed->is_available, ]; } return $data; } public function preparePatientAdmissionData($patientAdmissions, $id) { foreach ($patientAdmissions as $patientAdmission) { if ($patientAdmission->bed->id == $id && ! $patientAdmission->bed->is_available && ($patientAdmission->discharge_date == null)) { return $patientAdmission->patient->patientUser->full_name; } } } public function prepareData() { return [ 'bed_title' => $this->title, 'bed' => $this->patientNameRetrieved($this->beds) ?? [], ]; } public function bedNameRetrieved($beds) { $data = []; foreach ($beds as $bed) { if (getLoggedInUser()->tenant_id == $bed->tenant_id) { $data[] = [ 'id' => $bed->id, 'name' => $bed->name, 'status' => (bool) $bed->is_available, ]; } } return $data; } public function prepareBedData(): array { return [ 'bed_title' => $this->title, 'bed' => $this->bedNameRetrieved($this->beds) ?? [], ]; } }