Files
ladill-care/app/Models/FinancialObligation.php
T
isaaccladandCursor 86bfce1e17
Deploy Ladill Care / deploy (push) Failing after 45s
Add workflow-centric patient journey with financial gates.
Introduces a facility workflow engine as Care's primary configuration
object: onboarding now leads with a facility category (which modules to
enable) and a workflow template (how patients move + where money is
collected), including standard herbal hospital/clinic templates.

Templates materialize into care_facility_workflows/care_workflow_stages.
The engine tracks a visit's position via care_visit_stage_advances and,
with FinancialGateService, gates a stage's queue behind a cleared
FinancialObligation (paid/authorized/waived/deferred) for "before"
payment timing while leaving "after" (pay-at-exit) flows unblocked.
Gated behavior is opt-in behind the workflow_engine/financial_gates
rollout flags; legacy orgs keep current behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 20:47:33 +00:00

92 lines
2.3 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class FinancialObligation extends Model
{
use BelongsToOwner, SoftDeletes;
public const STATUS_PENDING = 'pending';
public const STATUS_AUTHORIZED = 'authorized';
public const STATUS_PAID = 'paid';
public const STATUS_WAIVED = 'waived';
public const STATUS_DEFERRED = 'deferred';
public const STATUS_VOID = 'void';
/** Statuses that satisfy a financial gate. */
public const CLEARED_STATUSES = [
self::STATUS_AUTHORIZED,
self::STATUS_PAID,
self::STATUS_WAIVED,
self::STATUS_DEFERRED,
];
protected $table = 'care_financial_obligations';
protected $fillable = [
'uuid', 'owner_ref', 'organization_id', 'branch_id', 'visit_id', 'patient_id',
'workflow_stage_id', 'bill_id', 'stage_code', 'charge_code', 'label',
'amount_minor', 'status', 'clearance_method', 'payment_mode',
'external_reference', 'cleared_by', 'cleared_at', 'meta',
];
protected function casts(): array
{
return [
'amount_minor' => 'integer',
'cleared_at' => 'datetime',
'meta' => 'array',
];
}
protected static function booted(): void
{
static::creating(function (FinancialObligation $obligation) {
if (! $obligation->uuid) {
$obligation->uuid = (string) Str::uuid();
}
});
}
public function getRouteKeyName(): string
{
return 'uuid';
}
public function visit(): BelongsTo
{
return $this->belongsTo(Visit::class, 'visit_id');
}
public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class, 'patient_id');
}
public function stage(): BelongsTo
{
return $this->belongsTo(WorkflowStage::class, 'workflow_stage_id');
}
public function bill(): BelongsTo
{
return $this->belongsTo(Bill::class, 'bill_id');
}
public function isCleared(): bool
{
return in_array($this->status, self::CLEARED_STATUSES, true);
}
}