feat(claims): add tracking number and status history for claims

- Introduced `tracking_number` field in the `claims` table to store the insurance tracking number.
- Created `claim_status_logs` table to maintain a history of status changes for claims, including who made the change and when.
- Implemented `ClaimStatusLog` entity and repository for managing status log entries.
- Updated `ClaimService` to log transitions and handle tracking numbers during claim submissions.
- Added new API endpoint for fetching claims by patient, including detailed claim history and status logs.
- Enhanced frontend with a new `ClaimPatientDetailPage` to display claims and their status history.
- Added tests to ensure correct aggregation of claims and proper handling of status transitions.
This commit is contained in:
hamed
2026-07-18 23:38:02 +03:30
parent b3a5cda808
commit 20bdc49e89
15 changed files with 1412 additions and 309 deletions
+41
View File
@@ -66,6 +66,10 @@ class Claim
#[ORM\Column(name: 'reject_reason', type: 'text', nullable: true)]
private ?string $rejectReason = null;
/** شماره پرونده/پیگیری نزد بیمه‌گر — هنگام ارسال وارد می‌شود. */
#[ORM\Column(name: 'tracking_number', type: 'string', length: 60, nullable: true)]
private ?string $trackingNumber = null;
#[ORM\Column(name: 'submitted_at', type: 'integer', nullable: true)]
private ?int $submittedAt = null;
@@ -119,6 +123,41 @@ class Claim
return in_array($status, self::TRANSITIONS[$this->status] ?? [], true);
}
/**
* انتقال‌های مجاز از وضعیت فعلی. پنل دکمه‌ها را از همین می‌سازد تا فهرست
* مجاز فقط یک‌جا تعریف شده باشد.
*
* @return string[]
*/
public function allowedTransitions(): array
{
return self::transitionsFrom($this->status);
}
/**
* همان جدول انتقال، برای مسیرهایی که ردیف خام (array hydration) دارند و
* موجودیت را هیدریت نمی‌کنند.
*
* @return string[]
*/
public static function transitionsFrom(string $status): array
{
return self::TRANSITIONS[$status] ?? [];
}
public function getTrackingNumber(): ?string { return $this->trackingNumber; }
public function getRejectReason(): ?string { return $this->rejectReason; }
public function getSubmittedAt(): ?int { return $this->submittedAt; }
public function getSettledAt(): ?int { return $this->settledAt; }
public function getCreatedAt(): int { return $this->createdAt; }
public function setTrackingNumber(?string $v): self
{
$this->trackingNumber = $v !== null && trim($v) !== '' ? trim($v) : null;
$this->updatedAt = time();
return $this;
}
public function submit(): void
{
$this->status = self::STATUS_SUBMITTED;
@@ -162,6 +201,8 @@ class Claim
'total_paid_rials' => $this->totalPaidRials,
'status' => $this->status,
'reject_reason' => $this->rejectReason,
'tracking_number' => $this->trackingNumber,
'allowed_transitions' => $this->allowedTransitions(),
'submitted_at' => $this->submittedAt,
'settled_at' => $this->settledAt,
'created_at' => $this->createdAt,
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace App\Billing\Entity;
use App\Billing\Repository\ClaimStatusLogRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
/**
* تاریخچه‌ی تغییر وضعیت یک مطالبه.
*
* وضعیت روی خودِ Claim فقط «آخرین حالت» است؛ پیگیری پرونده‌ی بیمه نیاز دارد بداند
* چه کسی، کِی و با چه توضیحی آن را جابه‌جا کرده است.
*/
#[ORM\Entity(repositoryClass: ClaimStatusLogRepository::class)]
#[ORM\Table(name: 'claim_status_logs')]
#[ORM\Index(columns: ['claim_id'], name: 'idx_claim_status_log_claim')]
class ClaimStatusLog
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column(name: 'claim_id', type: 'integer')]
private int $claimId;
/** null فقط برای ردیف ساخت اولیه. */
#[ORM\Column(name: 'from_status', type: 'string', length: 15, nullable: true)]
private ?string $fromStatus = null;
#[ORM\Column(name: 'to_status', type: 'string', length: 15)]
private string $toStatus;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $note = null;
/** null یعنی سیستمی (backfill یا اتوماسیون). */
#[ORM\Column(name: 'created_by_id', type: 'integer', nullable: true)]
private ?int $createdById = null;
#[ORM\Column(name: 'created_by_name', type: 'string', length: 120, nullable: true)]
private ?string $createdByName = null;
#[ORM\Column(name: 'created_at', type: 'integer')]
private int $createdAt;
public function __construct(int $claimId, ?string $fromStatus, string $toStatus)
{
$this->uuid = Uuid::v4()->toRfc4122();
$this->claimId = $claimId;
$this->fromStatus = $fromStatus;
$this->toStatus = $toStatus;
$this->createdAt = time();
}
public function getId(): ?int { return $this->id; }
public function getClaimId(): int { return $this->claimId; }
public function getToStatus(): string { return $this->toStatus; }
public function setNote(?string $note): self
{
$this->note = $note !== null && trim($note) !== '' ? trim($note) : null;
return $this;
}
public function setActor(?int $userId, ?string $name): self
{
$this->createdById = $userId;
$this->createdByName = $name;
return $this;
}
public function setCreatedAt(int $at): self
{
$this->createdAt = $at;
return $this;
}
public function toArray(): array
{
return [
'uuid' => $this->uuid,
'from_status' => $this->fromStatus,
'to_status' => $this->toStatus,
'note' => $this->note,
'by' => $this->createdByName,
'at' => $this->createdAt,
];
}
}