authorizeAbility($request, 'settings.view'); $organization = $this->organization($request); $canManage = app(CarePermissions::class)->can($this->member($request), 'settings.manage'); $credential = $credentials->forOrganization($organization); $branchCount = Branch::owned($this->ownerRef($request)) ->where('organization_id', $organization->id) ->count(); return view('care.settings.edit', [ 'organization' => $organization, 'canManage' => $canManage, 'branchCount' => $branchCount, 'messagingSmsReady' => $credential->hasValidSms(), 'messagingEmailReady' => $credential->hasValidBird(), 'facilityTypes' => [ 'clinic' => 'Clinic', 'hospital' => 'Hospital', 'diagnostic' => 'Diagnostic laboratory', 'specialist' => 'Specialist practice', ], ]); } public function update(Request $request, QueueClient $queue): RedirectResponse { $this->authorizeAbility($request, 'settings.manage'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $validated = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'timezone' => ['required', 'timezone'], 'facility_type' => ['required', 'string', 'in:clinic,hospital,diagnostic,specialist'], 'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'], 'remove_logo' => ['nullable', 'boolean'], 'queue_integration_enabled' => ['nullable', 'boolean'], 'notify_appointment_booked_sms' => ['nullable', 'boolean'], 'notify_appointment_booked_email' => ['nullable', 'boolean'], 'notify_video_scheduled_sms' => ['nullable', 'boolean'], 'notify_video_scheduled_email' => ['nullable', 'boolean'], ]); $settings = $organization->settings ?? []; $settings['onboarded'] = true; $settings['facility_type'] = $validated['facility_type']; $wantsQueue = $request->boolean('queue_integration_enabled'); $settings['queue_integration_enabled'] = $wantsQueue; $settings[AppointmentPatientNotifier::SETTING_BOOKED_SMS] = $request->boolean('notify_appointment_booked_sms'); $settings[AppointmentPatientNotifier::SETTING_BOOKED_EMAIL] = $request->boolean('notify_appointment_booked_email'); $settings[AppointmentPatientNotifier::SETTING_VIDEO_SMS] = $request->boolean('notify_video_scheduled_sms'); $settings[AppointmentPatientNotifier::SETTING_VIDEO_EMAIL] = $request->boolean('notify_video_scheduled_email'); if ($wantsQueue && $queue->configured()) { $branch = Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->first(); try { $queue->enable($owner, $organization->name, $branch?->name); } catch (\Throwable) { return back()->withInput()->with('error', 'Could not provision Ladill Queue for this account. Ensure Queue API keys are configured and Queue allows Care integration.'); } } $logoPath = $organization->logo_path; if ($request->boolean('remove_logo')) { OrganizationBranding::deleteStoredLogo($organization); $logoPath = null; } if ($request->hasFile('logo')) { $logoPath = OrganizationBranding::storeLogo($organization, $request->file('logo')); } $organization->update([ 'name' => $validated['name'], 'timezone' => $validated['timezone'], 'logo_path' => $logoPath, 'settings' => $settings, ]); AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, \App\Models\Organization::class, $organization->id); return back()->with('success', 'Settings saved.'); } }