Rules become data instead of code: a clinic can say "laser under 18 requires parental consent" without a deploy. Engine - Policy / PolicyVersionLog entities, closed field/operator/effect lists per category (PolicySchema), condition validation at write time - PolicyResolver: priority -> specificity -> age, combining effects by veto / max / sum / union - A missing fact fails its clause instead of silently passing it - Policies are drafts until activated, and are versioned rather than edited Wiring - selection -> ServiceSelectionValidator - eligibility + spacing -> BookingPolicyGuard, at hold time not confirm time - resource + timing -> AppointmentPlanBuilder, including template-less services - pricing -> PricingEngine, alongside (not replacing) the manual discount The condition column is named condition_json: `condition` is a MariaDB keyword and broke every INSERT. Tests: 17 in tests/Policy including NoPolicyRegressionTest, which pins that a clinic with no policies sees byte-identical output to task 08. Docs: docs/api/policy.md (real captured JSON) + docs/architecture/policy-engine.md. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Policy\Entity;
|
|
|
|
use App\Policy\Repository\PolicyVersionLogRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* عکس هر نسخهٔ یک قانون.
|
|
*
|
|
* نوبتی که دیروز ثبت شده، نسخهای را در `applied_policies` نگه میدارد که ممکن است
|
|
* امروز دیگر متن فعلی قانون نباشد. بدون این جدول، «چرا آن نوبت این قیمت را گرفت؟»
|
|
* سه ماه بعد بیجواب میماند.
|
|
*
|
|
* فرزند aggregate با ریشهٔ {@see Policy}؛ فقط نوشته میشود و هرگز ویرایش نمیشود.
|
|
*/
|
|
#[ORM\Entity(repositoryClass: PolicyVersionLogRepository::class)]
|
|
#[ORM\Table(name: 'policy_version_logs')]
|
|
#[ORM\UniqueConstraint(name: 'uniq_policy_version', columns: ['policy_id', 'version'])]
|
|
class PolicyVersionLog
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Policy::class)]
|
|
#[ORM\JoinColumn(name: 'policy_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private Policy $policy;
|
|
|
|
#[ORM\Column(type: 'smallint')]
|
|
private int $version;
|
|
|
|
#[ORM\Column(type: 'json')]
|
|
private array $snapshot;
|
|
|
|
#[ORM\Column(name: 'created_at', type: 'integer')]
|
|
private int $createdAt;
|
|
|
|
public function __construct(Policy $policy, int $version, array $snapshot)
|
|
{
|
|
$this->policy = $policy;
|
|
$this->version = $version;
|
|
$this->snapshot = $snapshot;
|
|
$this->createdAt = time();
|
|
}
|
|
|
|
public function getId(): ?int { return $this->id; }
|
|
public function getPolicy(): Policy { return $this->policy; }
|
|
public function getVersion(): int { return $this->version; }
|
|
public function getSnapshot(): array { return $this->snapshot; }
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'version' => $this->version,
|
|
'snapshot' => $this->snapshot,
|
|
'created_at' => $this->createdAt,
|
|
];
|
|
}
|
|
}
|