Expand specialty modules; pin Emergency and Blood Bank on Pro.
Deploy Ladill Care / deploy (push) Successful in 1m37s

Add Cardiology through Child Welfare to the specialty catalog, keep Emergency and Blood Bank always enabled on Pro/Enterprise sidebars, and generate matching demo specialty doctors.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 09:27:05 +00:00
co-authored by Cursor
parent f87f216fb4
commit e9a76fec80
9 changed files with 524 additions and 140 deletions
@@ -41,15 +41,69 @@ class SpecialtyModuleService
return $catalog[$key] ?? null;
}
public function isDefaultOnPaidPlans(string $key): bool
{
return (bool) ($this->definition($key)['default_on_paid_plans'] ?? false);
}
public function isEnabled(Organization $organization, string $key): bool
{
if (! $this->definition($key)) {
return false;
}
if ($this->isDefaultOnPaidPlans($key) && $this->plans->hasPaidPlan($organization)) {
return true;
}
return (bool) data_get($organization->settings, "specialty_modules.{$key}", false);
}
/**
* @return list<string>
*/
public function defaultKeysForPaidPlans(): array
{
$keys = [];
foreach (array_keys($this->catalog()) as $key) {
if ($this->isDefaultOnPaidPlans($key)) {
$keys[] = $key;
}
}
return $keys;
}
/**
* Provision Emergency / Blood Bank (and any other default_on_paid_plans modules).
*/
public function ensureDefaultModulesProvisioned(Organization $organization, string $ownerRef): void
{
if (! $this->plans->hasPaidPlan($organization)) {
return;
}
foreach ($this->defaultKeysForPaidPlans() as $key) {
$provisioned = data_get(
$organization->settings,
"specialty_module_provisioning.{$key}.active",
);
if ($provisioned) {
continue;
}
try {
$this->activate($organization->fresh(), $ownerRef, $key);
$organization->refresh();
} catch (\Throwable $e) {
Log::warning('specialty_module.default_provision_failed', [
'key' => $key,
'message' => $e->getMessage(),
]);
}
}
}
/**
* @return list<string>
*/
@@ -116,6 +170,11 @@ class SpecialtyModuleService
}
if ($member && $member->role === 'doctor') {
// Default Pro surfaces (Emergency, Blood Bank) are available to all doctors.
if ($this->isDefaultOnPaidPlans($key)) {
return true;
}
return $this->doctorAssignedToModule($organization, $member, $key);
}
@@ -187,9 +246,23 @@ class SpecialtyModuleService
foreach ($this->catalog() as $key => $definition) {
$want = (bool) ($desired[$key] ?? false);
if ($this->isDefaultOnPaidPlans($key) && $this->plans->hasPaidPlan($organization)) {
$want = true;
}
$have = $this->isEnabled($organization, $key);
if ($want === $have) {
// Still ensure defaults are provisioned even when already "enabled".
if ($want && $this->isDefaultOnPaidPlans($key)
&& ! data_get($organization->settings, "specialty_module_provisioning.{$key}.active")) {
try {
$this->activate($organization, $ownerRef, $key);
$organization->refresh();
} catch (\Throwable $e) {
$errors[] = ($definition['label'] ?? $key).': '.$e->getMessage();
}
}
continue;
}
@@ -274,6 +347,10 @@ class SpecialtyModuleService
throw new \InvalidArgumentException("Unknown specialty module [{$key}].");
}
if ($this->isDefaultOnPaidPlans($key) && $this->plans->hasPaidPlan($organization)) {
throw new \RuntimeException(($this->definition($key)['label'] ?? $key).' stays enabled on Pro and Enterprise.');
}
$settings = $organization->settings ?? [];
$modules = is_array($settings['specialty_modules'] ?? null) ? $settings['specialty_modules'] : [];
$modules[$key] = false;