107 lines
2.5 KiB
PHP
107 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Blameable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
|
|
class RequestLog extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, Blameable;
|
|
|
|
protected static $codePrefix = 'RLG';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'code',
|
|
'organization_id',
|
|
'member_id',
|
|
'plan_id',
|
|
'policy_id',
|
|
'payment_type',
|
|
'submission_date',
|
|
'service_code',
|
|
'type_of_member',
|
|
'status',
|
|
'final_log',
|
|
'status_final_log',
|
|
'source',
|
|
'keterangan',
|
|
'penempatan_kamar',
|
|
'total_cob',
|
|
'nominal',
|
|
'import_system',
|
|
'nomor_sep',
|
|
'inacbgs_code',
|
|
'inacbgs_amount',
|
|
'no_transaksi_provider',
|
|
'admission_date',
|
|
'discharge_date',
|
|
'diagnosis',
|
|
'reason',
|
|
'reason_final',
|
|
'hak_kamar_pasien',
|
|
'catatan',
|
|
'nomor_rujukan',
|
|
'status_rujukan',
|
|
];
|
|
|
|
protected $casts = [
|
|
'final_log' => 'boolean',
|
|
'admission_date' => 'datetime',
|
|
'discharge_date' => 'datetime',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function (self $model) {
|
|
if (empty($model->uuid)) {
|
|
$model->uuid = (string) Str::orderedUuid();
|
|
}
|
|
|
|
if (empty($model->code)) {
|
|
$model->code = self::getNextCode();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static function getNextCode(): string
|
|
{
|
|
$lastCode = (string) self::withTrashed()->max('code');
|
|
preg_match('/(\d+)$/', $lastCode, $matches);
|
|
$nextNumber = isset($matches[1]) ? ((int) $matches[1] + 1) : (self::withTrashed()->count() + 1);
|
|
|
|
return self::makeCode($nextNumber);
|
|
}
|
|
|
|
public static function makeCode(int $nextNumber): string
|
|
{
|
|
return self::$codePrefix . '-' . str_pad((string) $nextNumber, 5, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
public function organization()
|
|
{
|
|
return $this->belongsTo(Organization::class, 'organization_id');
|
|
}
|
|
|
|
public function member()
|
|
{
|
|
return $this->belongsTo(Member::class, 'member_id');
|
|
}
|
|
|
|
public function plan()
|
|
{
|
|
return $this->belongsTo(Plan::class, 'plan_id');
|
|
}
|
|
|
|
public function requestLogBenefits()
|
|
{
|
|
return $this->hasMany(RequestLogBenefit::class, 'request_log_id');
|
|
}
|
|
}
|