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
@@ -2,9 +2,12 @@
namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Http\Controllers\Controller;
use App\Models\Branch;
use App\Models\Organization;
use App\Services\Billing\PlatformEmailClient;
use App\Services\Billing\PlatformSmsClient;
use App\Services\Care\AppointmentPatientNotifier;
use App\Services\Care\AuditLogger;
use App\Services\Care\CareFeatures;
@@ -13,8 +16,8 @@ use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
use App\Services\Care\CareQueueProvisioner;
use App\Services\Care\PlanService;
use App\Services\Billing\PlatformEmailClient;
use App\Services\Billing\PlatformSmsClient;
use App\Services\Care\Workflow\WorkflowTemplateInstaller;
use App\Services\Care\Workflow\WorkflowTemplateRegistry;
use App\Services\Messaging\MessagingCredentialsService;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
@@ -63,18 +66,16 @@ class SettingsController extends Controller
'canUseQueueIntegration' => $plans->canUseQueueIntegration($organization),
'canUseSpecialtyModules' => $plans->canUseSpecialtyModules($organization),
'assessmentsEngineEnabled' => $careFeatures->enabled($organization, CareFeatures::ASSESSMENTS_ENGINE),
'workflowEngineEnabled' => $careFeatures->enabled($organization, CareFeatures::WORKFLOW_ENGINE),
'financialGatesEnabled' => $careFeatures->enabled($organization, CareFeatures::FINANCIAL_GATES),
'hasBillingFeature' => $plans->hasFeature($organization, 'billing'),
'messagingSmsReady' => $suiteSmsReady || $credential->hasValidSms(),
'messagingEmailReady' => $suiteEmailReady || $credential->hasValidBird(),
'suiteMessagingReady' => $suiteEmailReady || $suiteSmsReady,
'messagingSettingsUrl' => function_exists('ladill_account_url')
? ladill_account_url('/account/settings/messaging')
: (string) config('smtp.messaging_settings_url', 'https://account.ladill.com/account/settings/messaging'),
'facilityTypes' => [
'clinic' => 'Clinic',
'hospital' => 'Hospital',
'diagnostic' => 'Diagnostic laboratory',
'specialist' => 'Specialist practice',
],
'facilityTypes' => app(WorkflowTemplateRegistry::class)->categoryOptions(),
]);
}
@@ -88,11 +89,17 @@ class SettingsController extends Controller
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'timezone' => ['required', 'timezone'],
'facility_type' => ['required', 'string', 'in:clinic,hospital,diagnostic,specialist'],
'facility_type' => [
'required',
'string',
'in:'.implode(',', array_keys(app(WorkflowTemplateRegistry::class)->categories())),
],
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
'remove_logo' => ['nullable', 'boolean'],
'queue_integration_enabled' => ['nullable', 'boolean'],
'assessments_engine' => ['nullable', 'boolean'],
'workflow_engine' => ['nullable', 'boolean'],
'financial_gates' => ['nullable', 'boolean'],
'notify_appointment_booked_sms' => ['nullable', 'boolean'],
'notify_appointment_booked_email' => ['nullable', 'boolean'],
'notify_video_scheduled_sms' => ['nullable', 'boolean'],
@@ -102,10 +109,17 @@ class SettingsController extends Controller
$settings = $organization->settings ?? [];
$settings['onboarded'] = true;
$settings['facility_type'] = $validated['facility_type'];
$settings['facility_category'] = $validated['facility_type'];
$settings['modules'] = app(WorkflowTemplateRegistry::class)
->modulesForCategory($validated['facility_type']);
$rollout = is_array($settings['rollout'] ?? null) ? $settings['rollout'] : [];
// Explicit save so opt-out is stored (engine defaults ON when unset).
$rollout[CareFeatures::ASSESSMENTS_ENGINE] = $request->boolean('assessments_engine');
$rollout[CareFeatures::WORKFLOW_ENGINE] = $request->boolean('workflow_engine');
$rollout[CareFeatures::FINANCIAL_GATES] = $request->boolean('financial_gates')
&& $rollout[CareFeatures::WORKFLOW_ENGINE]
&& $plans->hasFeature($organization, 'billing');
$settings['rollout'] = $rollout;
if ($rollout[CareFeatures::ASSESSMENTS_ENGINE]) {
app(CareFeatures::class)->ensureAssessmentCatalog();
@@ -155,6 +169,21 @@ class SettingsController extends Controller
'settings' => $settings,
]);
if ($rollout[CareFeatures::WORKFLOW_ENGINE] && ! $organization->facilityWorkflows()->where('is_active', true)->exists()) {
$branch = Branch::owned($owner)
->where('organization_id', $organization->id)
->orderBy('id')
->first();
if ($branch) {
app(WorkflowTemplateInstaller::class)->install(
$organization->fresh(),
$branch,
(string) ($settings['workflow_template'] ?? config('care_workflows.default_template', 'legacy_clinic')),
['category' => $settings['facility_category'] ?? $settings['facility_type'] ?? 'clinic'],
);
}
}
if ($wantsQueue && $queue->configured()) {
try {
$organization = $organization->fresh();
@@ -178,7 +207,7 @@ class SettingsController extends Controller
}
}
AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, \App\Models\Organization::class, $organization->id);
AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, Organization::class, $organization->id);
return back()->with('success', 'Settings saved.');
}