feat(hospitalportal): add provider and request log schema

This commit is contained in:
2026-05-13 16:34:54 +07:00
parent 5042cd7800
commit cf831c4602
6 changed files with 373 additions and 0 deletions

39
app/Models/Provider.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Provider extends Model
{
use HasFactory, SoftDeletes, Blameable;
protected $fillable = [
'organization_id',
'username',
'password',
'code',
'status',
'header_token',
'token',
];
protected $hidden = [
'password',
'created_at',
'updated_at',
'deleted_at',
'created_by',
'updated_by',
'deleted_by',
];
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
}

106
app/Models/RequestLog.php Normal file
View File

@@ -0,0 +1,106 @@
<?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');
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class RequestLogBenefit extends Model
{
use HasFactory, SoftDeletes, Blameable;
protected $fillable = [
'request_log_id',
'benefit_id',
'amount_incurred',
'amount_approved',
'amount_not_approved',
'excess_paid',
'keterangan',
];
public function requestLog()
{
return $this->belongsTo(RequestLog::class, 'request_log_id');
}
public function benefit()
{
return $this->belongsTo(Benefit::class, 'benefit_id');
}
}

View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('providers', function (Blueprint $table) {
$table->id();
$table->foreignId('organization_id')->nullable()->index();
$table->string('username')->index();
$table->string('password');
$table->string('code')->index();
$table->string('status')->default('active');
$table->text('header_token')->nullable();
$table->text('token')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable()->index();
$table->unsignedBigInteger('updated_by')->nullable()->index();
$table->unsignedBigInteger('deleted_by')->nullable()->index();
$table->unique(['organization_id', 'username']);
$table->unique(['organization_id', 'code']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('providers');
}
};

View File

@@ -0,0 +1,93 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('request_logs')) {
Schema::create('request_logs', function (Blueprint $table) {
$table->id();
$table->uuid('uuid');
$table->string('code')->index();
$table->foreignId('organization_id')->nullable()->index();
$table->foreignId('member_id')->nullable()->index();
$table->foreignId('plan_id')->nullable()->index();
$table->string('service_code')->nullable()->comment('IP / OP');
$table->string('status')->nullable()->default('approved');
$table->boolean('final_log')->default(false);
$table->string('status_final_log')->nullable();
$table->string('source')->nullable()->default('api');
$table->text('keterangan')->nullable();
$table->string('penempatan_kamar')->nullable();
$table->decimal('total_cob', 18, 2)->nullable();
$table->string('nomor_sep')->nullable();
$table->string('inacbgs_code')->nullable();
$table->decimal('inacbgs_amount', 18, 2)->nullable();
$table->string('no_transaksi_provider')->nullable();
$table->dateTime('admission_date')->nullable();
$table->dateTime('discharge_date')->nullable();
$table->string('diagnosis')->nullable();
$table->string('nomor_rujukan')->nullable();
$table->string('status_rujukan')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable()->index();
$table->unsignedBigInteger('updated_by')->nullable()->index();
$table->unsignedBigInteger('deleted_by')->nullable()->index();
});
return;
}
Schema::table('request_logs', function (Blueprint $table) {
if (!Schema::hasColumn('request_logs', 'plan_id')) {
$table->foreignId('plan_id')->nullable()->index()->after('member_id');
}
if (!Schema::hasColumn('request_logs', 'nomor_sep')) {
$table->string('nomor_sep')->nullable()->after('penempatan_kamar');
}
if (!Schema::hasColumn('request_logs', 'inacbgs_code')) {
$table->string('inacbgs_code')->nullable()->after('nomor_sep');
}
if (!Schema::hasColumn('request_logs', 'inacbgs_amount')) {
$table->decimal('inacbgs_amount', 18, 2)->nullable()->after('inacbgs_code');
}
if (!Schema::hasColumn('request_logs', 'no_transaksi_provider')) {
$table->string('no_transaksi_provider')->nullable()->after('inacbgs_amount');
}
if (!Schema::hasColumn('request_logs', 'admission_date')) {
$table->dateTime('admission_date')->nullable()->after('submission_date');
}
if (!Schema::hasColumn('request_logs', 'nomor_rujukan')) {
$table->string('nomor_rujukan')->nullable()->after('nomor_sep');
}
if (!Schema::hasColumn('request_logs', 'status_rujukan')) {
$table->string('status_rujukan')->nullable()->after('nomor_rujukan');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('request_logs');
}
};

View File

@@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('request_log_benefits')) {
Schema::create('request_log_benefits', function (Blueprint $table) {
$table->id();
$table->foreignId('request_log_id')->index();
$table->foreignId('benefit_id')->index();
$table->decimal('amount_incurred', 18, 2)->nullable()->default(0);
$table->decimal('amount_approved', 18, 2)->nullable()->default(0);
$table->decimal('excess_paid', 18, 2)->nullable()->default(0);
$table->string('keterangan')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable()->index();
$table->unsignedBigInteger('updated_by')->nullable()->index();
$table->unsignedBigInteger('deleted_by')->nullable()->index();
$table->unique(['request_log_id', 'benefit_id']);
});
return;
}
Schema::table('request_log_benefits', function (Blueprint $table) {
if (!Schema::hasColumn('request_log_benefits', 'keterangan')) {
$table->string('keterangan')->nullable()->after('excess_paid');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('request_log_benefits');
}
};