Speed up Queue board loads by dropping sync and gate side effects.
Deploy Ladill Care / deploy (push) Successful in 1m22s
Deploy Ladill Care / deploy (push) Successful in 1m22s
Stop issuing missing tickets and refreshing financial gates on every GET; eager-load advances, cap board rows, and cache specialty department maps. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Care\Workflow;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Visit;
|
||||
use App\Models\VisitStageAdvance;
|
||||
use App\Models\WorkflowStage;
|
||||
use App\Services\Care\CareFeatures;
|
||||
use App\Services\Care\CareQueueContexts;
|
||||
@@ -24,6 +25,10 @@ class WorkflowQueueGate
|
||||
return $this->features->enabled($organization, CareFeatures::WORKFLOW_ENGINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutating gate used when issuing tickets or starting encounters.
|
||||
* May start a workflow or refresh financial gate state.
|
||||
*/
|
||||
public function canRelease(
|
||||
Organization $organization,
|
||||
?Visit $visit,
|
||||
@@ -36,29 +41,31 @@ class WorkflowQueueGate
|
||||
$advance = $this->engine->currentAdvance($visit)
|
||||
? $this->engine->refreshGate($visit)
|
||||
: $this->engine->start($visit);
|
||||
$stage = $advance?->stage;
|
||||
|
||||
// An enabled org without a materialized workflow keeps legacy behavior.
|
||||
if ($stage === null) {
|
||||
return $this->evaluateAdvance($organization, $visit, $advance, $queueContext, mutate: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only gate for waiting-list / board rendering.
|
||||
* Does not start workflows, create obligations, or refresh gate rows.
|
||||
*/
|
||||
public function isReleasedForDisplay(
|
||||
Organization $organization,
|
||||
?Visit $visit,
|
||||
string $queueContext,
|
||||
): bool {
|
||||
if (! $this->enabled($organization) || $visit === null) {
|
||||
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)) {
|
||||
$advance = $this->engine->currentAdvance($visit);
|
||||
|
||||
// No materialized advance yet — keep legacy visibility (do not start on GET).
|
||||
if ($advance === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->contextsMatch($stage->queue_context, $stage->type, $queueContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->features->enabled($organization, CareFeatures::FINANCIAL_GATES)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->engine->isQueueReleasable($visit);
|
||||
return $this->evaluateAdvance($organization, $visit, $advance, $queueContext, mutate: false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +88,46 @@ class WorkflowQueueGate
|
||||
return ! $this->engine->isQueueReleasable($visit);
|
||||
}
|
||||
|
||||
protected function evaluateAdvance(
|
||||
Organization $organization,
|
||||
Visit $visit,
|
||||
?VisitStageAdvance $advance,
|
||||
string $queueContext,
|
||||
bool $mutate,
|
||||
): bool {
|
||||
$stage = $advance?->stage;
|
||||
|
||||
// An enabled org without a materialized workflow keeps legacy behavior.
|
||||
if ($stage === null) {
|
||||
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) {
|
||||
if ($mutate
|
||||
? $this->isAwaitingFinancialGate($organization, $visit, $stage)
|
||||
: ($advance->isBlocked() && $stage->gatesBeforeService())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->contextsMatch($stage->queue_context, $stage->type, $queueContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->features->enabled($organization, CareFeatures::FINANCIAL_GATES)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Display path trusts advance status (payment clear paths refresh the gate).
|
||||
if (! $mutate) {
|
||||
return ! $advance->isBlocked();
|
||||
}
|
||||
|
||||
return $this->engine->isQueueReleasable($visit);
|
||||
}
|
||||
|
||||
protected function contextsMatch(?string $stageContext, string $stageType, string $queueContext): bool
|
||||
{
|
||||
if ($stageContext === $queueContext) {
|
||||
|
||||
Reference in New Issue
Block a user