Enums
The CPR backend uses PHP 8.1 string-backed enums for type-safe constants. There are 17 enum classes covering statuses, types, and domain-specific values.
Directory Structure
app/Enums/
├── StatusEnum.php
├── PatientVisitStatus.php
├── PatientGenderEnum.php
├── PatientCivilStatusEnum.php
├── PatientStatusEnum.php
├── QueueTicketStatus.php
├── QueuePriorityType.php
├── TransferPriorityType.php
├── EyeEnum.php
├── TypeEnum.php # Medicine type (N/E)
├── UnitEnum.php # Medicine unit
├── DeliveryStatusEnum.php
├── InsurancePlanTypeEnum.php
├── StockAvailableStatusEnum.php
├── StockMovementReasonEnum.php
├── SurgeryStatusEnum.php
└── BranchBillItemStatusEnum.phpEnum Pattern
Most enums follow this pattern — a string-backed enum with label() and color() helper methods:
php
enum StatusEnum: string
{
case ACTIVE = 'active';
case INACTIVE = 'inactive';
public function label(): string
{
return match ($this) {
self::ACTIVE => 'Active',
self::INACTIVE => 'Inactive',
};
}
public function color(): string
{
return match ($this) {
self::ACTIVE => 'green',
self::INACTIVE => 'red',
};
}
}value— The raw string stored in the databaselabel()— Human-readable text for the UIcolor()— UI color code for badges/tags
All Enums Reference
StatusEnum
General active/inactive status used by medicines, procedures, pharmacy items, etc.
| Case | Value | Label | Color |
|---|---|---|---|
ACTIVE | active | Active | green |
INACTIVE | inactive | Inactive | red |
PatientVisitStatus
| Case | Value | Label | Color |
|---|---|---|---|
ACTIVE | active | Active | green |
COMPLETED | completed | Completed | blue |
QueueTicketStatus
| Case | Value | Label | Color |
|---|---|---|---|
WAITING | waiting | Waiting | yellow |
CALLED | called | Called | blue |
SERVING | serving | Serving | green |
COMPLETED | completed | Completed | gray |
SKIPPED | skipped | Skipped | orange |
NO_SHOW | no_show | No Show | red |
TRANSFERRED | transferred | Transferred | purple |
CANCELLED | cancelled | Cancelled | red |
ON_HOLD | on_hold | On Hold | yellow |
EyeEnum
| Case | Value | Label |
|---|---|---|
LEFT | left | OS (Left) |
RIGHT | right | OD (Right) |
BOTH | both | OU (Both) |
PatientGenderEnum
| Case | Value |
|---|---|
MALE | male |
FEMALE | female |
TypeEnum (Medicine)
| Case | Value | Label |
|---|---|---|
N | N | N |
E | E | E |
UnitEnum (Medicine)
| Case | Value | Label |
|---|---|---|
TABLET | tablet | Tablet |
DROP | drop | Drop |
APPLICATION | application | Application |
Using Enums
In Models (Casting)
Enums are cast automatically in Eloquent models:
php
class Medicine extends Model
{
protected $casts = [
'type' => TypeEnum::class,
'unit' => UnitEnum::class,
'status' => StatusEnum::class,
];
}This means $medicine->status returns a StatusEnum instance, not a raw string.
In Form Request Validation
php
'sex' => ['required', new Enum(PatientGenderEnum::class)],
'status' => ['required', new Enum(StatusEnum::class)],In API Resources
php
'status' => $this->status?->value, // "active"
'status_label' => $this->status?->label(), // "Active"
'status_color' => $this->status?->color(), // "green"In Queries
php
Patient::where('status', PatientStatusEnum::ACTIVE)->get();
// Or with scope
$medicine->isActive(); // Checks status === StatusEnum::ACTIVEGetting All Values
php
StatusEnum::cases();
// [StatusEnum::ACTIVE, StatusEnum::INACTIVE]
// Get values as array
array_column(StatusEnum::cases(), 'value');
// ['active', 'inactive']The /api/v1/enums endpoint returns all enum definitions for the frontend.
DynamicEnumTrait
For database-backed enums (lookup tables like payment methods, PO statuses), the DynamicEnumTrait mimics PHP enum behavior:
php
class PaymentMethod extends Model
{
use DynamicEnumTrait;
}
// Usage (similar to PHP enums)
PaymentMethod::cases(); // Returns all records as objects
PaymentMethod::names(); // Returns array of names
PaymentMethod::slugs(); // Returns array of slugsThis is used for reference data that may change without a code deployment.
Creating a New Enum
php
namespace App\Enums;
enum NewStatusEnum: string
{
case PENDING = 'pending';
case APPROVED = 'approved';
case REJECTED = 'rejected';
public function label(): string
{
return match ($this) {
self::PENDING => 'Pending',
self::APPROVED => 'Approved',
self::REJECTED => 'Rejected',
};
}
public function color(): string
{
return match ($this) {
self::PENDING => 'yellow',
self::APPROVED => 'green',
self::REJECTED => 'red',
};
}
}Then use it in:
- Model casts:
'status' => NewStatusEnum::class - Validation:
new Enum(NewStatusEnum::class) - Resources:
$this->status?->label()