Fix empty demo lab catalog for admins.
Deploy Ladill Care / deploy (push) Successful in 2m7s

Seed investigation types early (before clinical data), expand the default catalog, scope Lab → Catalog by organization, and harden practitioner-branch sync so a mid-reseed failure cannot wipe the catalog.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 09:06:35 +00:00
co-authored by Cursor
parent 899b08179e
commit f87f216fb4
5 changed files with 73 additions and 13 deletions
@@ -164,7 +164,7 @@ class ConsultationController extends Controller
->orderBy('name')
->get();
$investigationTypes = InvestigationType::owned($this->ownerRef($request))
$investigationTypes = InvestigationType::query()
->where('organization_id', $organization->id)
->where('is_active', true)
->orderBy('name')
@@ -23,7 +23,7 @@ class InvestigationTypeController extends Controller
$this->authorizeAbility($request, 'lab.manage');
$organization = $this->organization($request);
$types = InvestigationType::owned($this->ownerRef($request))
$types = InvestigationType::query()
->where('organization_id', $organization->id)
->orderBy('category')
->orderBy('name')
@@ -83,7 +83,6 @@ class InvestigationTypeController extends Controller
protected function authorizeType(Request $request, InvestigationType $type): void
{
$this->authorizeOwner($request, $type);
abort_unless($type->organization_id === $this->organization($request)->id, 404);
}
+7
View File
@@ -85,6 +85,13 @@ class Practitioner extends Model
*/
public function syncAssignedBranches(array $branchIds): void
{
if (! \Illuminate\Support\Facades\Schema::hasTable('care_practitioner_branch')) {
$ids = array_values(array_unique(array_filter(array_map('intval', $branchIds))));
$this->forceFill(['branch_id' => $ids[0] ?? null])->save();
return;
}
$ids = array_values(array_unique(array_filter(array_map('intval', $branchIds))));
$this->branches()->sync($ids);
$this->forceFill([
+55 -9
View File
@@ -107,6 +107,10 @@ class DemoTenantSeeder
$this->upsertOwnerMember($organization, $ownerRef);
$branches = $this->seedBranches($organization, $ownerRef, $volumes);
// Lab catalog early — survives if later clinical seeding fails mid-run.
$investigationTypes = $volumes['paid_modules']
? $this->seedInvestigationCatalog($organization, $ownerRef)
: [];
$this->seedStaffMembers($organization, $ownerRef, $plan, $branches);
$departments = $this->seedDepartments($branches, $ownerRef, $volumes);
if (in_array($plan, ['pro', 'enterprise'], true)) {
@@ -138,7 +142,11 @@ class DemoTenantSeeder
$this->assignAllDemoWaiters($organization, $ownerRef, $branches, $practitioners);
$this->renumberWaitingQueuePositions($organization, $ownerRef, $branches);
// Catalog first so a later lab-request failure never leaves Lab → Catalog empty.
if ($volumes['paid_modules']) {
if ($investigationTypes === []) {
$investigationTypes = $this->seedInvestigationCatalog($organization, $ownerRef);
}
$this->seedPaidModules(
$organization,
$branches,
@@ -146,6 +154,7 @@ class DemoTenantSeeder
$patients,
$ownerRef,
$volumes,
$investigationTypes,
);
$this->seedDevices($organization, $branches, $ownerRef);
}
@@ -434,6 +443,12 @@ class DemoTenantSeeder
DB::table('care_patients')->where('owner_ref', $ownerRef)->delete();
DB::table('care_practitioner_schedules')->where('owner_ref', $ownerRef)->delete();
if (Schema::hasTable('care_practitioner_branch')) {
$practitionerIds = DB::table('care_practitioners')->where('owner_ref', $ownerRef)->pluck('id');
if ($practitionerIds->isNotEmpty()) {
DB::table('care_practitioner_branch')->whereIn('practitioner_id', $practitionerIds)->delete();
}
}
DB::table('care_practitioners')->where('owner_ref', $ownerRef)->delete();
// Keep the owner member + organization so SSO redirects never see
@@ -1214,21 +1229,26 @@ class DemoTenantSeeder
}
}
private function seedPaidModules(
Organization $organization,
array $branches,
array $practitioners,
array $patients,
string $ownerRef,
array $volumes,
): void {
/**
* @return list<InvestigationType>
*/
private function seedInvestigationCatalog(Organization $organization, string $ownerRef): array
{
$types = [];
foreach ([
['name' => 'Fasting Blood Glucose', 'code' => 'FBG', 'category' => 'blood', 'unit' => 'mmol/L', 'low' => 3.9, 'high' => 6.1, 'price' => 2500],
['name' => 'Full Blood Count', 'code' => 'FBC', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 4500],
['name' => 'Malaria Parasite', 'code' => 'MP', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 1500],
['name' => 'Urinalysis', 'code' => 'UA', 'category' => 'urine', 'unit' => null, 'low' => null, 'high' => null, 'price' => 2000],
] as $i => $spec) {
['name' => 'HbA1c', 'code' => 'HBA1C', 'category' => 'blood', 'unit' => '%', 'low' => null, 'high' => 5.7, 'price' => 6000],
['name' => 'Lipid Profile', 'code' => 'LIPID', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 5500],
['name' => 'Liver Function Test', 'code' => 'LFT', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 5000],
['name' => 'Kidney Function Test', 'code' => 'KFT', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 5000],
['name' => 'Blood Group & Rh', 'code' => 'BGRH', 'category' => 'blood', 'unit' => null, 'low' => null, 'high' => null, 'price' => 1800],
['name' => 'Pregnancy Test (Urine)', 'code' => 'HCG', 'category' => 'urine', 'unit' => null, 'low' => null, 'high' => null, 'price' => 1200],
['name' => 'Stool Routine Examination', 'code' => 'SRE', 'category' => 'stool', 'unit' => null, 'low' => null, 'high' => null, 'price' => 2200],
['name' => 'Chest X-Ray', 'code' => 'CXR', 'category' => 'xray', 'unit' => null, 'low' => null, 'high' => null, 'price' => 8000],
] as $spec) {
$types[] = InvestigationType::withTrashed()->updateOrCreate(
[
'organization_id' => $organization->id,
@@ -1248,6 +1268,28 @@ class DemoTenantSeeder
);
}
return $types;
}
/**
* @param list<Branch> $branches
* @param list<Practitioner> $practitioners
* @param list<Patient> $patients
* @param list<InvestigationType> $types
*/
private function seedPaidModules(
Organization $organization,
array $branches,
array $practitioners,
array $patients,
string $ownerRef,
array $volumes,
array $types = [],
): void {
if ($types === []) {
$types = $this->seedInvestigationCatalog($organization, $ownerRef);
}
$drugs = [];
foreach ([
['name' => 'Amoxicillin 500mg', 'unit' => 'capsule', 'price' => 1500],
@@ -1288,6 +1330,10 @@ class DemoTenantSeeder
$drugs[] = $drug;
}
if ($patients === [] || $practitioners === [] || $types === [] || $branches === []) {
return;
}
for ($i = 0; $i < $volumes['lab_requests']; $i++) {
$patient = $patients[$i % count($patients)];
$branch = $branches[$i % count($branches)];