Add ambulance New call flow under ambulance.manage.
Deploy Ladill Care / deploy (push) Successful in 1m41s

Walk-in appointments require appointments.manage, which blocked EMS staff; New call now uses a dedicated specialty route that lands on the dispatch board.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-20 12:20:29 +00:00
co-authored by Cursor
parent 4e753e68c0
commit 527a469b78
5 changed files with 246 additions and 2 deletions
@@ -4,10 +4,17 @@ namespace App\Http\Controllers\Care;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Http\Controllers\Controller;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\Department;
use App\Models\Patient;
use App\Models\SpecialtyClinicalRecord;
use App\Models\Visit;
use App\Services\Care\Ambulance\AmbulanceAnalyticsService;
use App\Services\Care\Ambulance\AmbulanceWorkflowService;
use App\Services\Care\AppointmentService;
use App\Services\Care\AuditLogger;
use App\Services\Care\OrganizationResolver;
use App\Services\Care\SpecialtyClinicalRecordService;
use App\Services\Care\SpecialtyModuleService;
use App\Services\Care\SpecialtyShellService;
@@ -38,6 +45,115 @@ class AmbulanceWorkspaceController extends Controller
$this->authorizeBranch($request, (int) $visit->branch_id);
}
public function newCallCreate(
Request $request,
SpecialtyModuleService $modules,
): View {
$this->authorizeAbility($request, 'ambulance.manage');
$this->assertAmbulanceManage($request, $modules);
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branches = Branch::owned($owner)
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchScope, fn ($q) => $q->where('id', $branchScope))
->orderBy('name')
->get();
$defaultBranch = $branchScope ?? $branches->first()?->id;
$patients = Patient::owned($owner)
->where('organization_id', $organization->id)
->when($branchScope, fn ($q) => $q->where('branch_id', $branchScope))
->orderBy('first_name')
->limit(200)
->get();
return view('care.specialty.ambulance.new-call', [
'organization' => $organization,
'branches' => $branches,
'defaultBranch' => $defaultBranch,
'patients' => $patients,
]);
}
public function newCallStore(
Request $request,
SpecialtyModuleService $modules,
AppointmentService $appointments,
): RedirectResponse {
$this->authorizeAbility($request, 'ambulance.manage');
$this->assertAmbulanceManage($request, $modules);
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$validated = $request->validate([
'branch_id' => ['required', 'integer', 'exists:care_branches,id'],
'patient_id' => ['required', 'integer', 'exists:care_patients,id'],
'reason' => ['nullable', 'string', 'max:500'],
'notes' => ['nullable', 'string', 'max:2000'],
'location' => ['nullable', 'string', 'max:500'],
]);
$branchId = (int) $validated['branch_id'];
if ($branchScope !== null) {
abort_unless($branchId === (int) $branchScope, 403);
}
$this->authorizeBranch($request, $branchId);
$department = Department::owned($owner)
->where('type', 'ambulance')
->where('branch_id', $branchId)
->where('is_active', true)
->orderBy('id')
->first();
if (! $department) {
return back()->withInput()->with('error', 'No active ambulance department at this branch.');
}
$patient = Patient::owned($owner)
->where('organization_id', $organization->id)
->findOrFail((int) $validated['patient_id']);
$reason = trim((string) ($validated['reason'] ?? ''));
if ($reason === '') {
$reason = 'Ambulance call';
}
if (! empty($validated['location'])) {
$reason .= ' · '.$validated['location'];
}
$appointment = $appointments->walkIn($organization, $owner, [
'patient_id' => $patient->id,
'branch_id' => $branchId,
'department_id' => $department->id,
'reason' => $reason,
'notes' => $validated['notes'] ?? null,
], $this->actorRef($request) ?? $owner);
AuditLogger::record(
$owner,
'ambulance.new_call',
$organization->id,
$this->actorRef($request) ?? $owner,
Appointment::class,
$appointment->id,
['department_id' => $department->id],
);
return redirect()
->route('care.specialty.show', 'ambulance')
->with('success', 'New call logged for '.$patient->fullName().'.');
}
public function setStage(
Request $request,
Visit $visit,