Issue cashier booth tickets when financial gates block service.
Deploy Ladill Care / deploy (push) Successful in 41s
Deploy Ladill Care / deploy (push) Successful in 41s
Pay-before-service holds now create a billing queue ticket (via an open bill) so cashiers can Call next / Serve; clearance completes the ticket and releases the clinical line as before. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,8 +9,10 @@ use App\Models\Payment;
|
|||||||
use App\Models\WorkflowStage;
|
use App\Models\WorkflowStage;
|
||||||
use App\Services\Care\AuditLogger;
|
use App\Services\Care\AuditLogger;
|
||||||
use App\Services\Care\BillService;
|
use App\Services\Care\BillService;
|
||||||
|
use App\Services\Care\BranchContext;
|
||||||
use App\Services\Care\CareFeatures;
|
use App\Services\Care\CareFeatures;
|
||||||
use App\Services\Care\CarePermissions;
|
use App\Services\Care\CarePermissions;
|
||||||
|
use App\Services\Care\CareQueueBridge;
|
||||||
use App\Services\Care\CareQueueContexts;
|
use App\Services\Care\CareQueueContexts;
|
||||||
use App\Services\Care\OrganizationResolver;
|
use App\Services\Care\OrganizationResolver;
|
||||||
use App\Services\Care\Workflow\FinancialGateService;
|
use App\Services\Care\Workflow\FinancialGateService;
|
||||||
@@ -35,6 +37,8 @@ class FinancialObligationController extends Controller
|
|||||||
protected WorkflowQueueReleaseService $queueRelease,
|
protected WorkflowQueueReleaseService $queueRelease,
|
||||||
protected WorkflowStageCompletionService $workflowCompletion,
|
protected WorkflowStageCompletionService $workflowCompletion,
|
||||||
protected BillService $bills,
|
protected BillService $bills,
|
||||||
|
protected CareQueueBridge $queueBridge,
|
||||||
|
protected BranchContext $branchContext,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
@@ -43,7 +47,10 @@ class FinancialObligationController extends Controller
|
|||||||
$organization = $this->organization($request);
|
$organization = $this->organization($request);
|
||||||
abort_unless($this->features->enabled($organization, CareFeatures::WORKFLOW_ENGINE), 404);
|
abort_unless($this->features->enabled($organization, CareFeatures::WORKFLOW_ENGINE), 404);
|
||||||
|
|
||||||
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
|
$member = $this->member($request);
|
||||||
|
$permissions = app(CarePermissions::class);
|
||||||
|
$branchScope = app(OrganizationResolver::class)->branchScope($member);
|
||||||
|
$branchId = $this->branchContext->resolve($request, $organization, $member);
|
||||||
$status = (string) $request->query('status', FinancialObligation::STATUS_PENDING);
|
$status = (string) $request->query('status', FinancialObligation::STATUS_PENDING);
|
||||||
|
|
||||||
$obligations = FinancialObligation::owned($this->ownerRef($request))
|
$obligations = FinancialObligation::owned($this->ownerRef($request))
|
||||||
@@ -61,8 +68,13 @@ class FinancialObligationController extends Controller
|
|||||||
'clearanceMethods' => config('care_workflows.clearance_methods', []),
|
'clearanceMethods' => config('care_workflows.clearance_methods', []),
|
||||||
'paymentModes' => config('care_workflows.payment_modes', []),
|
'paymentModes' => config('care_workflows.payment_modes', []),
|
||||||
'paymentMethods' => collect(config('care.payment_methods', []))->except(['gateway'])->all(),
|
'paymentMethods' => collect(config('care.payment_methods', []))->except(['gateway'])->all(),
|
||||||
'canClear' => app(CarePermissions::class)
|
'canClear' => $permissions->can($member, 'payments.manage'),
|
||||||
->can($this->member($request), 'payments.manage'),
|
'branchId' => $branchId,
|
||||||
|
'queueIntegration' => $branchId && $permissions->handlesFloorCare($member)
|
||||||
|
? $this->queueBridge->listMeta($organization, CareQueueContexts::BILLING, $branchId)
|
||||||
|
: ['enabled' => false],
|
||||||
|
'canManageQueue' => $permissions->can($member, 'service_queues.console')
|
||||||
|
&& $permissions->handlesFloorCare($member),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,19 +151,21 @@ class FinancialObligationController extends Controller
|
|||||||
return $locked->fresh();
|
return $locked->fresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$organization = $this->organization($request);
|
||||||
|
|
||||||
$visit = $settled->visit;
|
$visit = $settled->visit;
|
||||||
if ($visit) {
|
if ($visit) {
|
||||||
$advance = $this->workflows->refreshGate($visit);
|
$advance = $this->workflows->refreshGate($visit);
|
||||||
if ($advance?->stage?->type === 'payment') {
|
if ($advance?->stage?->type === 'payment') {
|
||||||
$this->workflowCompletion->complete(
|
$this->workflowCompletion->complete(
|
||||||
$this->organization($request),
|
$organization,
|
||||||
$visit,
|
$visit,
|
||||||
CareQueueContexts::BILLING,
|
CareQueueContexts::BILLING,
|
||||||
$this->ownerRef($request),
|
$this->ownerRef($request),
|
||||||
$this->ownerRef($request),
|
$this->ownerRef($request),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->queueRelease->releaseCurrent($this->organization($request), $visit);
|
$this->queueRelease->releaseCurrent($organization, $visit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ use App\Services\Care\CarePricingService;
|
|||||||
* A "before" gate blocks entry to the stage's service queue until the stage's
|
* A "before" gate blocks entry to the stage's service queue until the stage's
|
||||||
* obligation is cleared (paid / authorized / waived / deferred). An "after"
|
* obligation is cleared (paid / authorized / waived / deferred). An "after"
|
||||||
* gate never blocks entry but is created so the balance is collected at exit.
|
* gate never blocks entry but is created so the balance is collected at exit.
|
||||||
|
*
|
||||||
|
* When Care Queue Engine is enabled, WorkflowEngine / WorkflowQueueReleaseService
|
||||||
|
* place awaiting_payment visits on the billing (cashier) queue via an open bill.
|
||||||
*/
|
*/
|
||||||
class FinancialGateService
|
class FinancialGateService
|
||||||
{
|
{
|
||||||
@@ -143,7 +146,17 @@ class FinancialGateService
|
|||||||
'cleared_at' => now(),
|
'cleared_at' => now(),
|
||||||
])->save();
|
])->save();
|
||||||
|
|
||||||
return $obligation;
|
$organization = Organization::query()->find($obligation->organization_id);
|
||||||
|
if ($organization) {
|
||||||
|
// Lazy resolve avoids a constructor cycle with WorkflowQueueReleaseService.
|
||||||
|
app(WorkflowQueueReleaseService::class)->completeCashier(
|
||||||
|
$organization,
|
||||||
|
$obligation->fresh(['bill']) ?? $obligation,
|
||||||
|
$method,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obligation->fresh() ?? $obligation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function void(FinancialObligation $obligation): FinancialObligation
|
public function void(FinancialObligation $obligation): FinancialObligation
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ class WorkflowEngine
|
|||||||
|
|
||||||
$this->gate->obligationFor($visit, $advance->stage);
|
$this->gate->obligationFor($visit, $advance->stage);
|
||||||
$satisfied = $this->gate->isSatisfied($visit, $advance->stage);
|
$satisfied = $this->gate->isSatisfied($visit, $advance->stage);
|
||||||
|
$becameBlocked = false;
|
||||||
|
|
||||||
if ($advance->isBlocked() && $satisfied) {
|
if ($advance->isBlocked() && $satisfied) {
|
||||||
$advance->forceFill([
|
$advance->forceFill([
|
||||||
@@ -187,9 +188,17 @@ class WorkflowEngine
|
|||||||
'blocked_reason' => $this->gate->blockedReason($visit, $advance->stage),
|
'blocked_reason' => $this->gate->blockedReason($visit, $advance->stage),
|
||||||
'cleared_at' => null,
|
'cleared_at' => null,
|
||||||
])->save();
|
])->save();
|
||||||
|
$becameBlocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $advance->fresh();
|
$fresh = $advance->fresh();
|
||||||
|
// Only enqueue when the gate newly blocks — not on every refresh — so
|
||||||
|
// CareQueueBridge::issueForBill → canRelease → refreshGate cannot recurse.
|
||||||
|
if ($becameBlocked && $fresh?->blocked_reason === 'awaiting_payment') {
|
||||||
|
$this->enqueueCashierBooth($visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function enterStage(Visit $visit, FacilityWorkflow $workflow, WorkflowStage $stage): VisitStageAdvance
|
protected function enterStage(Visit $visit, FacilityWorkflow $workflow, WorkflowStage $stage): VisitStageAdvance
|
||||||
@@ -198,7 +207,7 @@ class WorkflowEngine
|
|||||||
|
|
||||||
$satisfied = $this->gate->isSatisfied($visit, $stage);
|
$satisfied = $this->gate->isSatisfied($visit, $stage);
|
||||||
|
|
||||||
return VisitStageAdvance::create([
|
$advance = VisitStageAdvance::create([
|
||||||
'owner_ref' => $visit->owner_ref,
|
'owner_ref' => $visit->owner_ref,
|
||||||
'visit_id' => $visit->id,
|
'visit_id' => $visit->id,
|
||||||
'workflow_id' => $workflow->id,
|
'workflow_id' => $workflow->id,
|
||||||
@@ -209,6 +218,26 @@ class WorkflowEngine
|
|||||||
'entered_at' => now(),
|
'entered_at' => now(),
|
||||||
'cleared_at' => $satisfied ? now() : null,
|
'cleared_at' => $satisfied ? now() : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($advance->isBlocked() && $advance->blocked_reason === 'awaiting_payment') {
|
||||||
|
$this->enqueueCashierBooth($visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve lazily to avoid a constructor cycle with WorkflowQueueReleaseService.
|
||||||
|
*/
|
||||||
|
protected function enqueueCashierBooth(Visit $visit): void
|
||||||
|
{
|
||||||
|
$organization = $visit->organization
|
||||||
|
?? \App\Models\Organization::query()->find($visit->organization_id);
|
||||||
|
if ($organization === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app(WorkflowQueueReleaseService::class)->enqueueCashier($organization, $visit);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function resolveTarget(Visit $visit, ?string $toCode, ?FacilityWorkflow $workflow = null): ?WorkflowStage
|
protected function resolveTarget(Visit $visit, ?string $toCode, ?FacilityWorkflow $workflow = null): ?WorkflowStage
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Services\Care\Workflow;
|
|||||||
|
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Visit;
|
use App\Models\Visit;
|
||||||
|
use App\Models\WorkflowStage;
|
||||||
use App\Services\Care\CareFeatures;
|
use App\Services\Care\CareFeatures;
|
||||||
use App\Services\Care\CareQueueContexts;
|
use App\Services\Care\CareQueueContexts;
|
||||||
|
|
||||||
@@ -42,6 +43,13 @@ class WorkflowQueueGate
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pay-before-service holds belong on the cashier / billing line, not the
|
||||||
|
// clinical service queue for the current stage.
|
||||||
|
if ($queueContext === CareQueueContexts::BILLING
|
||||||
|
&& $this->isAwaitingFinancialGate($organization, $visit, $stage)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $this->contextsMatch($stage->queue_context, $stage->type, $queueContext)) {
|
if (! $this->contextsMatch($stage->queue_context, $stage->type, $queueContext)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -53,12 +61,36 @@ class WorkflowQueueGate
|
|||||||
return $this->engine->isQueueReleasable($visit);
|
return $this->engine->isQueueReleasable($visit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the visit is blocked on a before-service financial gate.
|
||||||
|
*/
|
||||||
|
public function isAwaitingFinancialGate(
|
||||||
|
Organization $organization,
|
||||||
|
Visit $visit,
|
||||||
|
?WorkflowStage $stage = null,
|
||||||
|
): bool {
|
||||||
|
if (! $this->features->enabled($organization, CareFeatures::FINANCIAL_GATES)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stage ??= $this->engine->currentStage($visit);
|
||||||
|
if ($stage === null || ! $stage->gatesBeforeService()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ! $this->engine->isQueueReleasable($visit);
|
||||||
|
}
|
||||||
|
|
||||||
protected function contextsMatch(?string $stageContext, string $stageType, string $queueContext): bool
|
protected function contextsMatch(?string $stageContext, string $stageType, string $queueContext): bool
|
||||||
{
|
{
|
||||||
if ($stageContext === $queueContext) {
|
if ($stageContext === $queueContext) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($stageType === 'payment' && $queueContext === CareQueueContexts::BILLING) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Specialty appointments still fulfill a consultation workflow stage.
|
// Specialty appointments still fulfill a consultation workflow stage.
|
||||||
return $stageType === 'consultation'
|
return $stageType === 'consultation'
|
||||||
&& CareQueueContexts::isSpecialty($queueContext)
|
&& CareQueueContexts::isSpecialty($queueContext)
|
||||||
|
|||||||
@@ -4,16 +4,21 @@ namespace App\Services\Care\Workflow;
|
|||||||
|
|
||||||
use App\Models\Appointment;
|
use App\Models\Appointment;
|
||||||
use App\Models\Bill;
|
use App\Models\Bill;
|
||||||
|
use App\Models\FinancialObligation;
|
||||||
use App\Models\InvestigationRequest;
|
use App\Models\InvestigationRequest;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Prescription;
|
use App\Models\Prescription;
|
||||||
use App\Models\Visit;
|
use App\Models\Visit;
|
||||||
|
use App\Models\WorkflowStage;
|
||||||
|
use App\Services\Care\BillService;
|
||||||
use App\Services\Care\CareQueueBridge;
|
use App\Services\Care\CareQueueBridge;
|
||||||
use App\Services\Care\CareQueueContexts;
|
use App\Services\Care\CareQueueContexts;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases the entity represented by the visit's current workflow stage to
|
* Releases the entity represented by the visit's current workflow stage to
|
||||||
* Ladill Queue after stage entry or financial clearance.
|
* Ladill Queue after stage entry or financial clearance. Also owns the cashier
|
||||||
|
* booth queue for pay-before-service financial gates.
|
||||||
*/
|
*/
|
||||||
class WorkflowQueueReleaseService
|
class WorkflowQueueReleaseService
|
||||||
{
|
{
|
||||||
@@ -24,8 +29,24 @@ class WorkflowQueueReleaseService
|
|||||||
|
|
||||||
public function releaseCurrent(Organization $organization, Visit $visit): void
|
public function releaseCurrent(Organization $organization, Visit $visit): void
|
||||||
{
|
{
|
||||||
$stage = $this->engine->currentStage($visit);
|
$advance = $this->engine->currentAdvance($visit);
|
||||||
if ($stage === null || $stage->queue_context === null) {
|
$stage = $advance?->stage;
|
||||||
|
if ($stage === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hold at the cashier booth while a before-service gate is unpaid.
|
||||||
|
if ($advance->isBlocked() && $advance->blocked_reason === 'awaiting_payment') {
|
||||||
|
$this->enqueueCashier($organization, $visit, $stage);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($stage->queue_context === null) {
|
||||||
|
if ($stage->type === 'payment') {
|
||||||
|
$this->enqueueCashier($organization, $visit, $stage);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +114,112 @@ class WorkflowQueueReleaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($context === CareQueueContexts::BILLING) {
|
if ($context === CareQueueContexts::BILLING) {
|
||||||
Bill::query()
|
$this->enqueueCashier($organization, $visit, $stage);
|
||||||
->where('visit_id', $visit->id)
|
}
|
||||||
->whereNotIn('status', [Bill::STATUS_PAID, Bill::STATUS_VOID])
|
}
|
||||||
->get()
|
|
||||||
->each(fn (Bill $bill) => $this->queue->issueForBill($organization, $bill));
|
/**
|
||||||
|
* Ensure a visit blocked on payment has an open bill and an active cashier
|
||||||
|
* booth ticket. No-ops when Care Queue Engine is disabled.
|
||||||
|
*/
|
||||||
|
public function enqueueCashier(
|
||||||
|
Organization $organization,
|
||||||
|
Visit $visit,
|
||||||
|
?WorkflowStage $stage = null,
|
||||||
|
): ?Bill {
|
||||||
|
if (! $this->queue->isEnabled($organization)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stage ??= $this->engine->currentStage($visit);
|
||||||
|
if ($stage === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$obligation = FinancialObligation::query()
|
||||||
|
->where('visit_id', $visit->id)
|
||||||
|
->where('workflow_stage_id', $stage->id)
|
||||||
|
->whereNull('deleted_at')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($obligation === null
|
||||||
|
|| $obligation->isCleared()
|
||||||
|
|| (int) $obligation->amount_minor <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$bill = app(BillService::class)->billForObligation(
|
||||||
|
$obligation,
|
||||||
|
(string) $visit->owner_ref,
|
||||||
|
(string) $visit->owner_ref,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->queue->issueForBill($organization, $bill->fresh(['patient', 'visit']));
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::warning('care.cashier_queue_enqueue_failed', [
|
||||||
|
'visit_id' => $visit->id,
|
||||||
|
'stage_code' => $stage->code,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Complete (or retire) the cashier booth ticket after a financial gate clears.
|
||||||
|
* Non-payment clearances void unpaid obligation-only placeholder bills.
|
||||||
|
*/
|
||||||
|
public function completeCashier(
|
||||||
|
Organization $organization,
|
||||||
|
FinancialObligation $obligation,
|
||||||
|
string $clearanceMethod,
|
||||||
|
): void {
|
||||||
|
if (! $this->queue->isEnabled($organization)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$obligation->loadMissing('bill');
|
||||||
|
$bill = $obligation->bill;
|
||||||
|
if ($bill === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filled($bill->queue_ticket_uuid)
|
||||||
|
&& ! in_array($bill->queue_ticket_status, ['completed', 'cancelled'], true)) {
|
||||||
|
$this->queue->complete($organization, $bill);
|
||||||
|
$bill = $bill->fresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($clearanceMethod, ['payment', 'bank_receipt'], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bill = $bill->fresh(['lineItems']) ?? $bill;
|
||||||
|
if ((int) $bill->amount_paid_minor > 0
|
||||||
|
|| in_array($bill->status, [Bill::STATUS_PAID, Bill::STATUS_VOID], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasForeignLines = $bill->lineItems
|
||||||
|
->contains(function ($item) use ($obligation) {
|
||||||
|
return $item->source_type !== FinancialObligation::class
|
||||||
|
|| (int) $item->source_id !== (int) $obligation->id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($hasForeignLines) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
app(BillService::class)->void($bill, (string) $obligation->owner_ref, $obligation->cleared_by);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::warning('care.cashier_placeholder_bill_void_failed', [
|
||||||
|
'bill_id' => $bill->id,
|
||||||
|
'obligation_id' => $obligation->id,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ return [
|
|||||||
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
||||||
['code' => 'consultation', 'name' => 'Consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'pharmacy'],
|
['code' => 'consultation', 'name' => 'Consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'pharmacy'],
|
||||||
['code' => 'pharmacy', 'name' => 'Pharmacy', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'optional' => true, 'default_next' => 'checkout'],
|
['code' => 'pharmacy', 'name' => 'Pharmacy', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'optional' => true, 'default_next' => 'checkout'],
|
||||||
['code' => 'checkout', 'name' => 'Checkout', 'type' => 'payment', 'requires_payment' => true, 'payment_timing' => 'after', 'charge_code' => 'visit_total', 'charge_label' => 'Visit total', 'insurance_eligible' => true, 'default_next' => 'exit'],
|
['code' => 'checkout', 'name' => 'Checkout', 'type' => 'payment', 'queue_context' => 'billing', 'requires_payment' => true, 'payment_timing' => 'after', 'charge_code' => 'visit_total', 'charge_label' => 'Visit total', 'insurance_eligible' => true, 'default_next' => 'exit'],
|
||||||
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -221,7 +221,7 @@ return [
|
|||||||
'description' => 'Reception, payment before sample collection, testing, and results delivery.',
|
'description' => 'Reception, payment before sample collection, testing, and results delivery.',
|
||||||
'stages' => [
|
'stages' => [
|
||||||
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'payment'],
|
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'payment'],
|
||||||
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'requires_payment' => true, 'payment_timing' => 'before', 'charge_code' => 'lab', 'charge_label' => 'Diagnostic tests', 'insurance_eligible' => true, 'default_next' => 'sample'],
|
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'queue_context' => 'billing', 'requires_payment' => true, 'payment_timing' => 'before', 'charge_code' => 'lab', 'charge_label' => 'Diagnostic tests', 'insurance_eligible' => true, 'default_next' => 'sample'],
|
||||||
['code' => 'sample', 'name' => 'Sample collection', 'type' => 'laboratory', 'queue_context' => 'laboratory', 'department_type' => 'laboratory', 'default_next' => 'testing'],
|
['code' => 'sample', 'name' => 'Sample collection', 'type' => 'laboratory', 'queue_context' => 'laboratory', 'department_type' => 'laboratory', 'default_next' => 'testing'],
|
||||||
['code' => 'testing', 'name' => 'Testing', 'type' => 'laboratory', 'department_type' => 'laboratory', 'default_next' => 'results'],
|
['code' => 'testing', 'name' => 'Testing', 'type' => 'laboratory', 'department_type' => 'laboratory', 'default_next' => 'results'],
|
||||||
['code' => 'results', 'name' => 'Results', 'type' => 'results', 'default_next' => 'exit'],
|
['code' => 'results', 'name' => 'Results', 'type' => 'results', 'default_next' => 'exit'],
|
||||||
@@ -238,7 +238,7 @@ return [
|
|||||||
'stages' => [
|
'stages' => [
|
||||||
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
||||||
['code' => 'consultation', 'name' => 'Consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'payment'],
|
['code' => 'consultation', 'name' => 'Consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'payment'],
|
||||||
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'requires_payment' => true, 'payment_timing' => 'after', 'charge_code' => 'consultation', 'charge_label' => 'Consultation fee', 'insurance_eligible' => true, 'default_next' => 'exit'],
|
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'queue_context' => 'billing', 'requires_payment' => true, 'payment_timing' => 'after', 'charge_code' => 'consultation', 'charge_label' => 'Consultation fee', 'insurance_eligible' => true, 'default_next' => 'exit'],
|
||||||
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -251,7 +251,7 @@ return [
|
|||||||
'description' => 'Prescription intake, billing, payment, and dispensing.',
|
'description' => 'Prescription intake, billing, payment, and dispensing.',
|
||||||
'stages' => [
|
'stages' => [
|
||||||
['code' => 'intake', 'name' => 'Prescription intake', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'pharmacy', 'default_next' => 'payment'],
|
['code' => 'intake', 'name' => 'Prescription intake', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'pharmacy', 'default_next' => 'payment'],
|
||||||
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'requires_payment' => true, 'payment_timing' => 'before', 'charge_code' => 'pharmacy', 'charge_label' => 'Medication', 'insurance_eligible' => true, 'default_next' => 'dispensing'],
|
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'queue_context' => 'billing', 'requires_payment' => true, 'payment_timing' => 'before', 'charge_code' => 'pharmacy', 'charge_label' => 'Medication', 'insurance_eligible' => true, 'default_next' => 'dispensing'],
|
||||||
['code' => 'dispensing', 'name' => 'Dispensing', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'default_next' => 'exit'],
|
['code' => 'dispensing', 'name' => 'Dispensing', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'default_next' => 'exit'],
|
||||||
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
||||||
],
|
],
|
||||||
@@ -283,7 +283,7 @@ return [
|
|||||||
'stages' => [
|
'stages' => [
|
||||||
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
['code' => 'reception', 'name' => 'Reception', 'type' => 'registration', 'queue_context' => 'reception', 'department_type' => 'outpatient', 'default_next' => 'consultation'],
|
||||||
['code' => 'consultation', 'name' => 'Herbal consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'payment'],
|
['code' => 'consultation', 'name' => 'Herbal consultation', 'type' => 'consultation', 'queue_context' => 'consultation', 'department_type' => 'general', 'can_return' => true, 'creates_child' => true, 'default_next' => 'payment'],
|
||||||
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'requires_payment' => true, 'payment_timing' => 'before', 'payment_modes' => ['internal_cashier', 'digital'], 'charge_code' => 'pharmacy', 'charge_label' => 'Consultation + herbal medicine', 'insurance_eligible' => false, 'default_next' => 'dispensing'],
|
['code' => 'payment', 'name' => 'Payment', 'type' => 'payment', 'queue_context' => 'billing', 'requires_payment' => true, 'payment_timing' => 'before', 'payment_modes' => ['internal_cashier', 'digital'], 'charge_code' => 'pharmacy', 'charge_label' => 'Consultation + herbal medicine', 'insurance_eligible' => false, 'default_next' => 'dispensing'],
|
||||||
['code' => 'dispensing', 'name' => 'Dispensing', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'default_next' => 'exit'],
|
['code' => 'dispensing', 'name' => 'Dispensing', 'type' => 'pharmacy', 'queue_context' => 'pharmacy', 'department_type' => 'pharmacy', 'default_next' => 'exit'],
|
||||||
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
['code' => 'exit', 'name' => 'Exit', 'type' => 'exit'],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
<td class="px-4 py-3">{{ $statuses[$bill->status] ?? $bill->status }}</td>
|
<td class="px-4 py-3">{{ $statuses[$bill->status] ?? $bill->status }}</td>
|
||||||
<td class="px-4 py-3 text-right">
|
<td class="px-4 py-3 text-right">
|
||||||
<div class="flex items-center justify-end gap-2">
|
<div class="flex items-center justify-end gap-2">
|
||||||
@if (! empty($queueIntegration['enabled']) && $bill->queue_ticket_uuid && ($bill->queue_ticket_status ?? '') !== 'serving' && $bill->balance_minor > 0)
|
@if (! empty($queueIntegration['enabled']) && $bill->queue_ticket_uuid && ! in_array($bill->queue_ticket_status ?? '', ['serving', 'completed', 'cancelled'], true) && $bill->balance_minor > 0)
|
||||||
<form method="POST" action="{{ route('care.bills.serve', $bill) }}">
|
<form method="POST" action="{{ route('care.bills.serve', $bill) }}">
|
||||||
@csrf
|
@csrf
|
||||||
<button type="submit" class="rounded-lg bg-sky-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-sky-700">Serve</button>
|
<button type="submit" class="rounded-lg bg-sky-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-sky-700">Serve</button>
|
||||||
|
|||||||
@@ -5,7 +5,19 @@
|
|||||||
<h1 class="text-xl font-semibold text-slate-900">Financial gates</h1>
|
<h1 class="text-xl font-semibold text-slate-900">Financial gates</h1>
|
||||||
<p class="mt-1 text-sm text-slate-500">Clear payment or authorization before patients enter gated service queues.</p>
|
<p class="mt-1 text-sm text-slate-500">Clear payment or authorization before patients enter gated service queues.</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{ route('care.bills.index') }}" class="rounded-lg border border-slate-200 px-4 py-2 text-sm text-slate-700">Bills & invoices</a>
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
@if (! empty($canManageQueue) && ! empty($queueIntegration['enabled']))
|
||||||
|
<div class="w-full sm:w-auto">
|
||||||
|
@include('care.partials.queue-ops', [
|
||||||
|
'queueIntegration' => $queueIntegration,
|
||||||
|
'queueCallNextRoute' => 'care.bills.call-next',
|
||||||
|
'queueCallNextParams' => [],
|
||||||
|
'branchId' => $branchId ?? null,
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<a href="{{ route('care.bills.index', ['view' => 'list']) }}" class="rounded-lg border border-slate-200 px-4 py-2 text-sm text-slate-700">Bills & invoices</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="GET" class="mt-4 flex flex-wrap gap-3 rounded-2xl border border-slate-200 bg-white p-4">
|
<form method="GET" class="mt-4 flex flex-wrap gap-3 rounded-2xl border border-slate-200 bg-white p-4">
|
||||||
@@ -37,6 +49,12 @@
|
|||||||
<p class="mt-1 text-xs text-slate-400">
|
<p class="mt-1 text-xs text-slate-400">
|
||||||
Created {{ $obligation->created_at->format('d M Y H:i') }}
|
Created {{ $obligation->created_at->format('d M Y H:i') }}
|
||||||
@if ($obligation->bill) · Invoice {{ $obligation->bill->invoice_number }} @endif
|
@if ($obligation->bill) · Invoice {{ $obligation->bill->invoice_number }} @endif
|
||||||
|
@if ($obligation->bill?->queue_ticket_number)
|
||||||
|
· Ticket {{ $obligation->bill->queue_ticket_number }}
|
||||||
|
@if ($obligation->bill->queue_ticket_status)
|
||||||
|
({{ $obligation->bill->queue_ticket_status }})
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-lg font-semibold text-slate-900">{{ $money($obligation->amount_minor) }}</p>
|
<p class="text-lg font-semibold text-slate-900">{{ $money($obligation->amount_minor) }}</p>
|
||||||
|
|||||||
@@ -506,4 +506,158 @@ class CareFinancialWorkflowRuntimeTest extends TestCase
|
|||||||
'status' => FinancialObligation::STATUS_PENDING,
|
'status' => FinancialObligation::STATUS_PENDING,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_awaiting_payment_issues_a_billing_cashier_ticket(): void
|
||||||
|
{
|
||||||
|
Http::fake();
|
||||||
|
$visit = $this->checkIn();
|
||||||
|
|
||||||
|
$obligation = FinancialObligation::query()
|
||||||
|
->where('visit_id', $visit->id)
|
||||||
|
->where('stage_code', 'registration')
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$this->assertNotNull($obligation->bill_id);
|
||||||
|
$bill = $obligation->bill()->first();
|
||||||
|
$this->assertNotNull($bill);
|
||||||
|
$this->assertNotNull($bill->queue_ticket_uuid);
|
||||||
|
$this->assertSame('waiting', $bill->queue_ticket_status);
|
||||||
|
$this->assertStringStartsWith('B', (string) $bill->queue_ticket_number);
|
||||||
|
$this->assertDatabaseHas('care_queue_tickets', [
|
||||||
|
'uuid' => $bill->queue_ticket_uuid,
|
||||||
|
'ticket_number' => $bill->queue_ticket_number,
|
||||||
|
'status' => 'waiting',
|
||||||
|
'care_entity' => 'bill',
|
||||||
|
'care_entity_id' => $bill->id,
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('care_service_queues', [
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'context' => CareQueueContexts::BILLING,
|
||||||
|
]);
|
||||||
|
$this->assertTrue(app(WorkflowQueueGate::class)->canRelease(
|
||||||
|
$this->organization,
|
||||||
|
$visit,
|
||||||
|
CareQueueContexts::BILLING,
|
||||||
|
));
|
||||||
|
$this->assertFalse(app(WorkflowQueueGate::class)->canRelease(
|
||||||
|
$this->organization,
|
||||||
|
$visit,
|
||||||
|
CareQueueContexts::CONSULTATION,
|
||||||
|
));
|
||||||
|
Http::assertNothingSent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_queue_off_keeps_financial_gate_without_cashier_ticket(): void
|
||||||
|
{
|
||||||
|
$settings = $this->organization->settings;
|
||||||
|
$settings['queue_integration_enabled'] = false;
|
||||||
|
$this->organization->update(['settings' => $settings]);
|
||||||
|
|
||||||
|
$visit = $this->checkIn();
|
||||||
|
$obligation = FinancialObligation::query()
|
||||||
|
->where('visit_id', $visit->id)
|
||||||
|
->where('stage_code', 'registration')
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$this->assertSame(FinancialObligation::STATUS_PENDING, $obligation->status);
|
||||||
|
$this->assertNull($obligation->bill_id);
|
||||||
|
$this->assertSame(0, Bill::query()->where('visit_id', $visit->id)->count());
|
||||||
|
$this->assertSame(VisitStageAdvance::STATUS_BLOCKED, app(WorkflowEngine::class)->currentAdvance($visit)->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_clearing_gate_completes_cashier_ticket_and_releases_clinical_queue(): void
|
||||||
|
{
|
||||||
|
Http::fake();
|
||||||
|
$visit = $this->checkIn();
|
||||||
|
$consultation = $this->reachConsultation($visit);
|
||||||
|
$consultation->refresh();
|
||||||
|
$this->assertNotNull($consultation->bill_id);
|
||||||
|
$bill = $consultation->bill()->firstOrFail();
|
||||||
|
$this->assertNotNull($bill->queue_ticket_uuid);
|
||||||
|
$ticketUuid = $bill->queue_ticket_uuid;
|
||||||
|
|
||||||
|
$appointment = Appointment::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_id' => $this->patient->id,
|
||||||
|
'visit_id' => $visit->id,
|
||||||
|
'type' => Appointment::TYPE_WALK_IN,
|
||||||
|
'status' => Appointment::STATUS_WAITING,
|
||||||
|
'scheduled_at' => now(),
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
'waiting_at' => now(),
|
||||||
|
'queue_position' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($this->owner)
|
||||||
|
->post(route('care.obligations.clear', $consultation), [
|
||||||
|
'method' => 'payment',
|
||||||
|
'payment_mode' => 'internal_cashier',
|
||||||
|
'payment_method' => 'cash',
|
||||||
|
'reference' => 'CASH-QUEUE-1',
|
||||||
|
])
|
||||||
|
->assertRedirect()
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$bill->refresh();
|
||||||
|
$this->assertSame('completed', $bill->queue_ticket_status);
|
||||||
|
$this->assertDatabaseHas('care_queue_tickets', [
|
||||||
|
'uuid' => $ticketUuid,
|
||||||
|
'status' => 'completed',
|
||||||
|
]);
|
||||||
|
$this->assertSame(VisitStageAdvance::STATUS_ACTIVE, app(WorkflowEngine::class)->currentAdvance($visit)->status);
|
||||||
|
$this->assertTrue(app(WorkflowQueueGate::class)->canRelease(
|
||||||
|
$this->organization,
|
||||||
|
$visit,
|
||||||
|
CareQueueContexts::CONSULTATION,
|
||||||
|
));
|
||||||
|
|
||||||
|
$appointment->refresh();
|
||||||
|
$this->assertNotNull($appointment->queue_ticket_uuid);
|
||||||
|
$this->assertSame('waiting', $appointment->queue_ticket_status);
|
||||||
|
$this->assertStringStartsWith('C', (string) $appointment->queue_ticket_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_cashier_can_call_next_and_serve_billing_ticket(): void
|
||||||
|
{
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
Member::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'user_ref' => 'cashier-queue-user',
|
||||||
|
'role' => 'cashier',
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
]);
|
||||||
|
$cashier = User::create([
|
||||||
|
'public_id' => 'cashier-queue-user',
|
||||||
|
'name' => 'Cashier',
|
||||||
|
'email' => 'cashier-queue@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$visit = $this->checkIn();
|
||||||
|
$obligation = FinancialObligation::query()
|
||||||
|
->where('visit_id', $visit->id)
|
||||||
|
->where('stage_code', 'registration')
|
||||||
|
->firstOrFail();
|
||||||
|
$bill = $obligation->bill()->firstOrFail();
|
||||||
|
$this->assertNotNull($bill->queue_ticket_uuid);
|
||||||
|
|
||||||
|
$this->actingAs($cashier)
|
||||||
|
->post(route('care.bills.call-next'), ['branch_id' => $this->branch->id])
|
||||||
|
->assertRedirect()
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$bill->refresh();
|
||||||
|
$this->assertSame('called', $bill->queue_ticket_status);
|
||||||
|
|
||||||
|
$this->actingAs($cashier)
|
||||||
|
->post(route('care.bills.serve', $bill))
|
||||||
|
->assertRedirect()
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$this->assertSame('serving', $bill->fresh()->queue_ticket_status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user