Seed Blood Bank demo inventory_note on open visits.
Deploy Ladill Care / deploy (push) Successful in 28s

Pro/enterprise DemoTenantSeeder now upserts visit-scoped facility stock so the Inventory tab and reports show unit counts and a low-stock alert without manual entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 21:46:13 +00:00
co-authored by Cursor
parent f688a48c37
commit ad3d8b5ce4
2 changed files with 113 additions and 0 deletions
+96
View File
@@ -987,10 +987,106 @@ class DemoTenantSeeder
}
$this->seedDentistryClinicalDemo($organization, $ownerRef);
$this->seedBloodBankInventoryDemo($organization, $ownerRef);
return $count;
}
/**
* Visit-scoped facility stock for Blood Bank Inventory tab / reports.
* Seeds inventory_note on each open BB visit so findForVisit shows stock without manual entry.
*/
private function seedBloodBankInventoryDemo(Organization $organization, string $ownerRef): void
{
// Specialty departments are provisioned without organization_id; scope via branches.
$branchIds = Branch::owned($ownerRef)
->where('organization_id', $organization->id)
->pluck('id');
if ($branchIds->isEmpty()) {
return;
}
$departmentIds = Department::owned($ownerRef)
->whereIn('branch_id', $branchIds)
->where('type', 'blood_bank')
->where('is_active', true)
->pluck('id');
if ($departmentIds->isEmpty()) {
return;
}
$appointments = Appointment::owned($ownerRef)
->where('organization_id', $organization->id)
->whereIn('department_id', $departmentIds)
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
->whereNotNull('visit_id')
->with('visit')
->orderBy('branch_id')
->orderBy('id')
->get();
if ($appointments->isEmpty()) {
return;
}
$clinical = app(SpecialtyClinicalRecordService::class);
/** @var array<int, int> $branchOrder */
$branchOrder = [];
foreach ($appointments as $appointment) {
$visit = $appointment->visit;
if (! $visit) {
continue;
}
$branchId = (int) $appointment->branch_id;
if (! array_key_exists($branchId, $branchOrder)) {
$branchOrder[$branchId] = count($branchOrder);
}
$clinical->upsert(
$organization,
$visit,
'blood_bank',
'inventory_note',
$this->demoBloodBankInventoryPayload($branchOrder[$branchId]),
$ownerRef,
$ownerRef,
);
}
}
/**
* @return array<string, mixed>
*/
private function demoBloodBankInventoryPayload(int $branchIndex): array
{
// First branch: low whole-blood + alert flag so Inventory / reports demo alerts.
if ($branchIndex === 0) {
return [
'whole_blood_units' => 1,
'packed_rbc_units' => 14,
'platelet_units' => 7,
'ffp_units' => 9,
'cryo_units' => 4,
'low_stock_alert' => true,
'notes' => 'Demo morning stock count — whole blood critically low; replenishment requested.',
];
}
return [
'whole_blood_units' => 8 + ($branchIndex * 2),
'packed_rbc_units' => 18 + $branchIndex,
'platelet_units' => 10 + $branchIndex,
'ffp_units' => 12 + $branchIndex,
'cryo_units' => 5,
'low_stock_alert' => false,
'notes' => 'Demo facility stock count for blood bank.',
];
}
private function seedDentistryClinicalDemo(Organization $organization, string $ownerRef): void
{
$departmentIds = Department::owned($ownerRef)