Activate Care workflows across check-in and financial clearance.
Deploy Ladill Care / deploy (push) Failing after 1m9s

Enforce service-queue gates, cashier settlements, and clinical stage progression so patient journeys cannot bypass configured payment or authorization rules.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 21:13:06 +00:00
co-authored by Cursor
parent 86bfce1e17
commit 3ee59a0956
38 changed files with 1953 additions and 107 deletions
@@ -0,0 +1,103 @@
<?php
namespace App\Services\Care\Workflow;
use App\Models\Appointment;
use App\Models\Bill;
use App\Models\InvestigationRequest;
use App\Models\Organization;
use App\Models\Prescription;
use App\Models\Visit;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
/**
* Releases the entity represented by the visit's current workflow stage to
* Ladill Queue after stage entry or financial clearance.
*/
class WorkflowQueueReleaseService
{
public function __construct(
protected WorkflowEngine $engine,
protected CareQueueBridge $queue,
) {}
public function releaseCurrent(Organization $organization, Visit $visit): void
{
$stage = $this->engine->currentStage($visit);
if ($stage === null || $stage->queue_context === null) {
return;
}
$context = $stage->queue_context;
if ($context === CareQueueContexts::CONSULTATION || CareQueueContexts::isSpecialty($context)) {
$appointment = Appointment::query()
->where('visit_id', $visit->id)
->with(['patient', 'organization', 'practitioner', 'visit'])
->latest('id')
->first();
if ($appointment) {
if ($appointment->status === Appointment::STATUS_COMPLETED) {
$nextPosition = ((int) Appointment::owned($appointment->owner_ref)
->where('branch_id', $appointment->branch_id)
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
->max('queue_position')) + 1;
$appointment->forceFill([
'status' => Appointment::STATUS_WAITING,
'waiting_at' => now(),
'started_at' => null,
'completed_at' => null,
'queue_position' => $nextPosition,
])->save();
}
if (filled($appointment->queue_ticket_uuid)
&& in_array($appointment->queue_ticket_status, ['completed', 'cancelled'], true)) {
$appointment->forceFill([
'queue_ticket_uuid' => null,
'queue_ticket_number' => null,
'queue_ticket_status' => null,
'queue_service_point_uuid' => null,
'queue_destination' => null,
'queue_staff_display_name' => null,
'queue_routing_status' => null,
])->save();
}
$this->queue->issueForAppointment($organization, $appointment);
}
return;
}
if ($context === CareQueueContexts::LABORATORY || $context === CareQueueContexts::IMAGING) {
InvestigationRequest::query()
->where('visit_id', $visit->id)
->with(['patient', 'visit'])
->get()
->each(fn (InvestigationRequest $request) => $this->queue->issueForInvestigation($organization, $request));
return;
}
if ($context === CareQueueContexts::PHARMACY) {
Prescription::query()
->where('visit_id', $visit->id)
->with(['patient', 'visit'])
->get()
->each(fn (Prescription $prescription) => $this->queue->issueForPrescription($organization, $prescription));
return;
}
if ($context === CareQueueContexts::BILLING) {
Bill::query()
->where('visit_id', $visit->id)
->whereNotIn('status', [Bill::STATUS_PAID, Bill::STATUS_VOID])
->get()
->each(fn (Bill $bill) => $this->queue->issueForBill($organization, $bill));
}
}
}