Add workflow-centric patient journey with financial gates.
Deploy Ladill Care / deploy (push) Failing after 45s

Introduces a facility workflow engine as Care's primary configuration
object: onboarding now leads with a facility category (which modules to
enable) and a workflow template (how patients move + where money is
collected), including standard herbal hospital/clinic templates.

Templates materialize into care_facility_workflows/care_workflow_stages.
The engine tracks a visit's position via care_visit_stage_advances and,
with FinancialGateService, gates a stage's queue behind a cleared
FinancialObligation (paid/authorized/waived/deferred) for "before"
payment timing while leaving "after" (pay-at-exit) flows unblocked.
Gated behavior is opt-in behind the workflow_engine/financial_gates
rollout flags; legacy orgs keep current behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 20:47:33 +00:00
co-authored by Cursor
parent c319692b33
commit 86bfce1e17
16 changed files with 1564 additions and 27 deletions
+31 -1
View File
@@ -7,6 +7,8 @@ use App\Models\Department;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use App\Services\Care\Workflow\WorkflowTemplateInstaller;
use App\Services\Care\Workflow\WorkflowTemplateRegistry;
use Illuminate\Support\Str;
class OrganizationResolver
@@ -73,6 +75,15 @@ class OrganizationResolver
{
$ref = $user->ownerRef();
$registry = app(WorkflowTemplateRegistry::class);
// New onboarding leads with Facility Category (modules) + Workflow
// Template (patient flow); legacy callers may still pass facility_type.
$category = $data['facility_category'] ?? $this->categoryFromLegacyType($data['facility_type'] ?? null);
$templateKey = $data['workflow_template']
?? $registry->defaultTemplateForCategory($category);
$modules = $registry->modulesForCategory($category);
$organization = Organization::create([
'owner_ref' => $ref,
'name' => $data['organization_name'],
@@ -80,7 +91,10 @@ class OrganizationResolver
'timezone' => $data['timezone'] ?? config('app.timezone', 'UTC'),
'settings' => [
'onboarded' => true,
'facility_type' => $data['facility_type'] ?? 'clinic',
'facility_category' => $category,
'facility_type' => $data['facility_type'] ?? $category,
'modules' => $modules,
'workflow_template' => $templateKey,
],
]);
@@ -103,12 +117,28 @@ class OrganizationResolver
'is_active' => true,
]);
if ($registry->hasTemplate($templateKey)) {
app(WorkflowTemplateInstaller::class)->install($organization, $branch, $templateKey, [
'category' => $category,
]);
}
AuditLogger::record($ref, 'organization.created', $organization->id, $ref, Organization::class, $organization->id);
AuditLogger::record($ref, 'branch.created', $organization->id, $ref, Branch::class, $branch->id);
return $organization;
}
protected function categoryFromLegacyType(?string $type): string
{
return match ($type) {
'hospital' => 'hospital',
'diagnostic' => 'diagnostic',
'specialist' => 'specialist',
default => 'clinic',
};
}
/** Branch ID the member may access; null = all branches. */
public function branchScope(?Member $member): ?int
{