Add full Eye Care (ophthalmology) specialty clinical suite.
Deploy Ladill Care / deploy (push) Successful in 35s
Deploy Ladill Care / deploy (push) Successful in 35s
Mirror Emergency/Blood Bank depth with stages, workspace tabs, workflow/analytics services, reports/print, demo clinical seed, and feature tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Care;
|
||||
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SpecialtyClinicalRecord;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Care\Ophthalmology\OphthalmologyAnalyticsService;
|
||||
use App\Services\Care\Ophthalmology\OphthalmologyWorkflowService;
|
||||
use App\Services\Care\SpecialtyClinicalRecordService;
|
||||
use App\Services\Care\SpecialtyModuleService;
|
||||
use App\Services\Care\SpecialtyShellService;
|
||||
use App\Services\Care\SpecialtyVisitStageService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class OphthalmologyWorkspaceController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
protected function assertOphthalmologyAccess(Request $request, SpecialtyModuleService $modules): void
|
||||
{
|
||||
$organization = $this->organization($request);
|
||||
abort_unless($modules->memberCanAccess($organization, $this->member($request), 'ophthalmology'), 403);
|
||||
}
|
||||
|
||||
protected function assertOphthalmologyManage(Request $request, SpecialtyModuleService $modules): void
|
||||
{
|
||||
$organization = $this->organization($request);
|
||||
abort_unless($modules->memberCanManage($organization, $this->member($request), 'ophthalmology'), 403);
|
||||
}
|
||||
|
||||
protected function assertVisit(Request $request, Visit $visit): void
|
||||
{
|
||||
abort_unless($visit->organization_id === $this->organization($request)->id, 404);
|
||||
$this->authorizeBranch($request, (int) $visit->branch_id);
|
||||
}
|
||||
|
||||
public function setStage(
|
||||
Request $request,
|
||||
Visit $visit,
|
||||
SpecialtyModuleService $modules,
|
||||
SpecialtyVisitStageService $stages,
|
||||
): RedirectResponse {
|
||||
$this->authorizeAbility($request, 'consultations.manage');
|
||||
$this->assertOphthalmologyManage($request, $modules);
|
||||
$this->assertVisit($request, $visit);
|
||||
|
||||
$validated = $request->validate([
|
||||
'stage' => ['required', 'string', 'max:32'],
|
||||
]);
|
||||
|
||||
try {
|
||||
$stages->setStage(
|
||||
$this->organization($request),
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
$validated['stage'],
|
||||
$this->ownerRef($request),
|
||||
$this->actorRef($request),
|
||||
);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return back()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('care.specialty.workspace', ['module' => 'ophthalmology', 'visit' => $visit, 'tab' => 'overview'])
|
||||
->with('success', 'Visit stage updated.');
|
||||
}
|
||||
|
||||
public function saveProcedure(
|
||||
Request $request,
|
||||
Visit $visit,
|
||||
SpecialtyModuleService $modules,
|
||||
SpecialtyClinicalRecordService $clinical,
|
||||
SpecialtyVisitStageService $stages,
|
||||
OphthalmologyWorkflowService $workflow,
|
||||
): RedirectResponse {
|
||||
$this->authorizeAbility($request, 'consultations.manage');
|
||||
$this->assertOphthalmologyManage($request, $modules);
|
||||
$this->assertVisit($request, $visit);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$payload = (array) $request->input('payload', []);
|
||||
foreach ($clinical->fieldsFor('ophthalmology', 'eye_procedure') as $field) {
|
||||
if (($field['type'] ?? '') === 'boolean') {
|
||||
$payload[$field['name']] = $request->boolean('payload.'.$field['name']);
|
||||
}
|
||||
}
|
||||
$request->merge(['payload' => $payload, 'tab' => 'treat']);
|
||||
|
||||
$validated = $request->validate(array_merge([
|
||||
'tab' => ['required', 'string'],
|
||||
], $clinical->validationRules('ophthalmology', 'eye_procedure')));
|
||||
|
||||
$record = $clinical->upsert(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
'eye_procedure',
|
||||
$clinical->payloadFromRequest($validated),
|
||||
$owner,
|
||||
$owner,
|
||||
OphthalmologyWorkflowService::STAGE_TREATMENT,
|
||||
SpecialtyClinicalRecord::STATUS_COMPLETED,
|
||||
);
|
||||
|
||||
try {
|
||||
$stages->setStage(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
OphthalmologyWorkflowService::STAGE_TREATMENT,
|
||||
$owner,
|
||||
$owner,
|
||||
);
|
||||
} catch (\InvalidArgumentException) {
|
||||
// Stage already treatment or map empty.
|
||||
}
|
||||
|
||||
if ($workflow->shouldCompleteVisit($record->payload ?? [])) {
|
||||
try {
|
||||
$stages->setStage(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
OphthalmologyWorkflowService::STAGE_COMPLETED,
|
||||
$owner,
|
||||
$owner,
|
||||
);
|
||||
} catch (\InvalidArgumentException) {
|
||||
}
|
||||
|
||||
$visit->refresh();
|
||||
if ($visit->status !== Visit::STATUS_COMPLETED) {
|
||||
$visit->update([
|
||||
'status' => Visit::STATUS_COMPLETED,
|
||||
'completed_at' => $visit->completed_at ?? now(),
|
||||
]);
|
||||
}
|
||||
|
||||
$appointment = $visit->appointment;
|
||||
if ($appointment && $appointment->status !== \App\Models\Appointment::STATUS_COMPLETED) {
|
||||
$appointment->update([
|
||||
'status' => \App\Models\Appointment::STATUS_COMPLETED,
|
||||
'completed_at' => $appointment->completed_at ?? now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('care.specialty.workspace', ['module' => 'ophthalmology', 'visit' => $visit, 'tab' => 'treat'])
|
||||
->with('success', 'Procedure / treatment saved.');
|
||||
}
|
||||
|
||||
public function reports(
|
||||
Request $request,
|
||||
SpecialtyModuleService $modules,
|
||||
SpecialtyShellService $shell,
|
||||
OphthalmologyAnalyticsService $analytics,
|
||||
): View {
|
||||
$this->authorizeAbility($request, 'consultations.view');
|
||||
$this->assertOphthalmologyAccess($request, $modules);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
$branchScope = app(\App\Services\Care\OrganizationResolver::class)->branchScope($this->member($request));
|
||||
|
||||
$report = $analytics->report(
|
||||
$organization,
|
||||
$this->ownerRef($request),
|
||||
$branchScope,
|
||||
$request->query('from'),
|
||||
$request->query('to'),
|
||||
);
|
||||
|
||||
return view('care.specialty.ophthalmology.reports', [
|
||||
'moduleKey' => 'ophthalmology',
|
||||
'definition' => $modules->definition('ophthalmology'),
|
||||
'shellNav' => $shell->navItems('ophthalmology'),
|
||||
'report' => $report,
|
||||
'currency' => strtoupper((string) config('care.billing.currency', config('care.currency', 'GHS'))),
|
||||
]);
|
||||
}
|
||||
|
||||
public function printSummary(
|
||||
Request $request,
|
||||
Visit $visit,
|
||||
SpecialtyModuleService $modules,
|
||||
SpecialtyClinicalRecordService $clinical,
|
||||
): View {
|
||||
$this->authorizeAbility($request, 'consultations.view');
|
||||
$this->assertOphthalmologyAccess($request, $modules);
|
||||
$this->assertVisit($request, $visit);
|
||||
|
||||
$visit->loadMissing(['patient', 'appointment.practitioner', 'branch']);
|
||||
|
||||
return view('care.specialty.ophthalmology.print', [
|
||||
'visit' => $visit,
|
||||
'patient' => $visit->patient,
|
||||
'refraction' => $clinical->findForVisit($visit, 'ophthalmology', 'refraction'),
|
||||
'exam' => $clinical->findForVisit($visit, 'ophthalmology', 'eye_exam'),
|
||||
'investigation' => $clinical->findForVisit($visit, 'ophthalmology', 'eye_investigation'),
|
||||
'plan' => $clinical->findForVisit($visit, 'ophthalmology', 'eye_plan'),
|
||||
'procedure' => $clinical->findForVisit($visit, 'ophthalmology', 'eye_procedure'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,7 @@ class SpecialtyModuleController extends Controller
|
||||
'dentistry' => 'odontogram',
|
||||
'emergency' => 'triage',
|
||||
'blood_bank' => 'requests',
|
||||
'ophthalmology' => 'refraction',
|
||||
default => (collect(array_keys($shellTabs))
|
||||
->first(fn (string $tab) => $clinical->recordTypeForTab($module, $tab) !== null)
|
||||
?? 'clinical_notes'),
|
||||
@@ -210,7 +211,7 @@ class SpecialtyModuleController extends Controller
|
||||
} catch (\InvalidArgumentException) {
|
||||
// Stage map may be empty for some modules.
|
||||
}
|
||||
} elseif ($nextStage && in_array($visit->specialty_stage, ['waiting', 'arrival', 'request'], true)) {
|
||||
} elseif ($nextStage && in_array($visit->specialty_stage, ['waiting', 'arrival', 'request', 'check_in'], true)) {
|
||||
try {
|
||||
$stageService->setStage($organization, $visit, $module, $nextStage, $owner, $owner);
|
||||
$visit = $visit->fresh();
|
||||
@@ -224,6 +225,7 @@ class SpecialtyModuleController extends Controller
|
||||
'dentistry' => 'odontogram',
|
||||
'emergency' => 'triage',
|
||||
'blood_bank' => 'requests',
|
||||
'ophthalmology' => 'refraction',
|
||||
default => (collect(array_keys($shellTabs))
|
||||
->first(fn (string $tab) => $clinical->recordTypeForTab($module, $tab) !== null)
|
||||
?? 'clinical_notes'),
|
||||
@@ -356,6 +358,57 @@ class SpecialtyModuleController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($module === 'ophthalmology' && in_array($recordType, ['refraction', 'eye_exam', 'eye_investigation', 'eye_plan'], true)) {
|
||||
$workflow = app(\App\Services\Care\Ophthalmology\OphthalmologyWorkflowService::class);
|
||||
$stageService = app(\App\Services\Care\SpecialtyVisitStageService::class);
|
||||
$suggested = match ($recordType) {
|
||||
'refraction' => $workflow->stageFromRefraction($record->payload ?? []),
|
||||
'eye_exam' => $workflow->stageFromExam($record->payload ?? []),
|
||||
'eye_investigation' => \App\Services\Care\Ophthalmology\OphthalmologyWorkflowService::STAGE_INVESTIGATION,
|
||||
'eye_plan' => $workflow->stageFromPlan($record->payload ?? []),
|
||||
default => null,
|
||||
};
|
||||
$current = $visit->specialty_stage;
|
||||
$early = ['check_in', 'history', 'waiting', null, ''];
|
||||
if ($suggested && (! $current || in_array($current, $early, true))) {
|
||||
try {
|
||||
$stageService->setStage(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
$suggested,
|
||||
$this->ownerRef($request),
|
||||
$this->ownerRef($request),
|
||||
);
|
||||
} catch (\InvalidArgumentException) {
|
||||
}
|
||||
} elseif ($suggested && $suggested !== $current) {
|
||||
$order = [
|
||||
'check_in' => 0,
|
||||
'history' => 1,
|
||||
'refraction' => 2,
|
||||
'exam' => 3,
|
||||
'investigation' => 4,
|
||||
'plan' => 5,
|
||||
'treatment' => 6,
|
||||
'completed' => 7,
|
||||
];
|
||||
if (($order[$suggested] ?? 0) > ($order[$current] ?? 0)) {
|
||||
try {
|
||||
$stageService->setStage(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
$suggested,
|
||||
$this->ownerRef($request),
|
||||
$this->ownerRef($request),
|
||||
);
|
||||
} catch (\InvalidArgumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('care.specialty.workspace', [
|
||||
'module' => $module,
|
||||
@@ -749,6 +802,13 @@ class SpecialtyModuleController extends Controller
|
||||
$bloodBankTransfusion = null;
|
||||
$bloodBankStageCodes = [];
|
||||
$bloodBankStageFlow = [];
|
||||
$ophthalmologyRefraction = null;
|
||||
$ophthalmologyExam = null;
|
||||
$ophthalmologyInvestigation = null;
|
||||
$ophthalmologyPlan = null;
|
||||
$ophthalmologyProcedure = null;
|
||||
$ophthalmologyStageCodes = [];
|
||||
$ophthalmologyStageFlow = [];
|
||||
$activeTab = (string) $request->query('tab', array_key_first($shell->workspaceTabs($module)) ?: 'overview');
|
||||
$clinical = app(SpecialtyClinicalRecordService::class);
|
||||
|
||||
@@ -855,6 +915,16 @@ class SpecialtyModuleController extends Controller
|
||||
$bloodBankStageFlow = app(\App\Services\Care\BloodBank\BloodBankWorkflowService::class)->stageFlow();
|
||||
}
|
||||
|
||||
if ($module === 'ophthalmology') {
|
||||
$ophthalmologyRefraction = $clinical->findForVisit($workspaceVisit, 'ophthalmology', 'refraction');
|
||||
$ophthalmologyExam = $clinical->findForVisit($workspaceVisit, 'ophthalmology', 'eye_exam');
|
||||
$ophthalmologyInvestigation = $clinical->findForVisit($workspaceVisit, 'ophthalmology', 'eye_investigation');
|
||||
$ophthalmologyPlan = $clinical->findForVisit($workspaceVisit, 'ophthalmology', 'eye_plan');
|
||||
$ophthalmologyProcedure = $clinical->findForVisit($workspaceVisit, 'ophthalmology', 'eye_procedure');
|
||||
$ophthalmologyStageCodes = collect($shell->stages('ophthalmology'))->pluck('code')->all();
|
||||
$ophthalmologyStageFlow = app(\App\Services\Care\Ophthalmology\OphthalmologyWorkflowService::class)->stageFlow();
|
||||
}
|
||||
|
||||
if ($patientHeader !== null) {
|
||||
$patientHeader['clinical_alerts'] = $clinicalAlerts;
|
||||
}
|
||||
@@ -940,6 +1010,13 @@ class SpecialtyModuleController extends Controller
|
||||
'bloodBankTransfusion' => $bloodBankTransfusion,
|
||||
'bloodBankStageCodes' => $bloodBankStageCodes,
|
||||
'bloodBankStageFlow' => $bloodBankStageFlow,
|
||||
'ophthalmologyRefraction' => $ophthalmologyRefraction,
|
||||
'ophthalmologyExam' => $ophthalmologyExam,
|
||||
'ophthalmologyInvestigation' => $ophthalmologyInvestigation,
|
||||
'ophthalmologyPlan' => $ophthalmologyPlan,
|
||||
'ophthalmologyProcedure' => $ophthalmologyProcedure,
|
||||
'ophthalmologyStageCodes' => $ophthalmologyStageCodes,
|
||||
'ophthalmologyStageFlow' => $ophthalmologyStageFlow,
|
||||
'queueStubs' => $modules->queueStubsFor($organization, $module),
|
||||
'branchId' => $branchId,
|
||||
'branchLabel' => $branchLabel,
|
||||
|
||||
@@ -1014,6 +1014,7 @@ class DemoTenantSeeder
|
||||
|
||||
$this->seedDentistryClinicalDemo($organization, $ownerRef);
|
||||
$this->seedBloodBankInventoryDemo($organization, $ownerRef);
|
||||
$this->seedOphthalmologyClinicalDemo($organization, $ownerRef);
|
||||
|
||||
return $count;
|
||||
}
|
||||
@@ -1113,6 +1114,134 @@ class DemoTenantSeeder
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed refraction + eye exam (+ optional plan) on open ophthalmology visits.
|
||||
*/
|
||||
private function seedOphthalmologyClinicalDemo(Organization $organization, string $ownerRef): void
|
||||
{
|
||||
$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', 'ophthalmology')
|
||||
->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);
|
||||
$index = 0;
|
||||
|
||||
foreach ($appointments as $appointment) {
|
||||
$visit = $appointment->visit;
|
||||
if (! $visit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$elevated = $index === 0;
|
||||
$clinical->upsert(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
'refraction',
|
||||
[
|
||||
'va_od' => $elevated ? '6/60' : '6/9',
|
||||
'va_os' => $elevated ? '6/36' : '6/6',
|
||||
'va_od_near' => 'N8',
|
||||
'va_os_near' => 'N6',
|
||||
'sphere_od' => $elevated ? '-2.50' : '-0.75',
|
||||
'cylinder_od' => '-0.50',
|
||||
'axis_od' => '90',
|
||||
'sphere_os' => $elevated ? '-1.75' : '-0.50',
|
||||
'cylinder_os' => '-0.25',
|
||||
'axis_os' => '85',
|
||||
'add' => '+1.50',
|
||||
'pd' => 62,
|
||||
'notes' => 'Demo refraction for eye care suite.',
|
||||
],
|
||||
$ownerRef,
|
||||
$ownerRef,
|
||||
'refraction',
|
||||
);
|
||||
|
||||
$clinical->upsert(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
'eye_exam',
|
||||
[
|
||||
'chief_complaint' => $elevated ? 'Blurry vision and headache' : 'Routine eye exam',
|
||||
'history' => $elevated
|
||||
? 'Gradual reduction in vision over 2 weeks; intermittent haloes.'
|
||||
: 'Annual review; no acute symptoms.',
|
||||
'va_od' => $elevated ? '6/60' : '6/9',
|
||||
'va_os' => $elevated ? '6/36' : '6/6',
|
||||
'iop_od' => $elevated ? 32 : 16,
|
||||
'iop_os' => $elevated ? 28 : 15,
|
||||
'pupils' => 'Equal, reactive',
|
||||
'extraocular' => 'Full',
|
||||
'anterior_segment' => $elevated ? 'Quiet; possible early cataract OD' : 'Quiet',
|
||||
'fundus' => $elevated ? 'Cup:disc elevated OD; review for glaucoma' : 'Healthy discs',
|
||||
'findings' => $elevated
|
||||
? 'Elevated IOP with reduced acuity — urgent glaucoma work-up.'
|
||||
: 'Normal examination; refraction updated.',
|
||||
],
|
||||
$ownerRef,
|
||||
$ownerRef,
|
||||
'exam',
|
||||
);
|
||||
|
||||
if ($elevated) {
|
||||
$clinical->upsert(
|
||||
$organization,
|
||||
$visit,
|
||||
'ophthalmology',
|
||||
'eye_plan',
|
||||
[
|
||||
'diagnosis' => 'Suspected primary open-angle glaucoma',
|
||||
'laterality' => 'OU',
|
||||
'plan' => 'Start topical IOP-lowering drops; arrange OCT and visual fields.',
|
||||
'medications' => 'Latanoprost 0.005% OU nocte',
|
||||
'procedure_planned' => false,
|
||||
'follow_up' => '2 weeks',
|
||||
'advice' => 'Return sooner if vision worsens or severe eye pain.',
|
||||
],
|
||||
$ownerRef,
|
||||
$ownerRef,
|
||||
'plan',
|
||||
);
|
||||
}
|
||||
|
||||
if (! $visit->specialty_stage) {
|
||||
$visit->update(['specialty_stage' => $elevated ? 'plan' : 'exam']);
|
||||
}
|
||||
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
private function seedDentistryClinicalDemo(Organization $organization, string $ownerRef): void
|
||||
{
|
||||
// Specialty departments are provisioned without organization_id; scope via branches.
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Care\Ophthalmology;
|
||||
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Bill;
|
||||
use App\Models\BillLineItem;
|
||||
use App\Models\Organization;
|
||||
use App\Models\SpecialtyClinicalRecord;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Care\SpecialtyShellService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class OphthalmologyAnalyticsService
|
||||
{
|
||||
public function __construct(
|
||||
protected SpecialtyShellService $shell,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* arrivals_today: int,
|
||||
* completed_today: int,
|
||||
* elevated_iop_open: int,
|
||||
* diagnosis_breakdown: Collection,
|
||||
* procedure_breakdown: Collection,
|
||||
* avg_los_minutes: ?float,
|
||||
* revenue_by_service: Collection,
|
||||
* from: string,
|
||||
* to: string
|
||||
* }
|
||||
*/
|
||||
public function report(
|
||||
Organization $organization,
|
||||
string $ownerRef,
|
||||
?int $branchId = null,
|
||||
?string $from = null,
|
||||
?string $to = null,
|
||||
): array {
|
||||
$todayStart = now()->startOfDay();
|
||||
$rangeFrom = $from ? Carbon::parse($from)->startOfDay() : now()->startOfMonth();
|
||||
$rangeTo = $to ? Carbon::parse($to)->endOfDay() : now()->endOfDay();
|
||||
|
||||
$departmentIds = $this->shell->departmentIds($organization, 'ophthalmology', $ownerRef, $branchId);
|
||||
|
||||
$appointmentBase = Appointment::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->when($departmentIds !== [], fn ($q) => $q->whereIn('department_id', $departmentIds))
|
||||
->when($departmentIds === [], fn ($q) => $q->whereRaw('1 = 0'))
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId));
|
||||
|
||||
$arrivalsToday = (clone $appointmentBase)
|
||||
->where('checked_in_at', '>=', $todayStart)
|
||||
->count();
|
||||
|
||||
$completedToday = (clone $appointmentBase)
|
||||
->where('status', Appointment::STATUS_COMPLETED)
|
||||
->where('completed_at', '>=', $todayStart)
|
||||
->count();
|
||||
|
||||
$visitIds = (clone $appointmentBase)->whereNotNull('visit_id')->pluck('visit_id');
|
||||
|
||||
$openVisitIds = Visit::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->whereIn('id', $visitIds->isEmpty() ? [0] : $visitIds)
|
||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
||||
->pluck('id');
|
||||
|
||||
$elevatedIopOpen = SpecialtyClinicalRecord::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('module_key', 'ophthalmology')
|
||||
->where('record_type', 'eye_exam')
|
||||
->whereIn('visit_id', $openVisitIds->isEmpty() ? [0] : $openVisitIds)
|
||||
->get()
|
||||
->filter(function (SpecialtyClinicalRecord $r) {
|
||||
$iopOd = (float) ($r->payload['iop_od'] ?? 0);
|
||||
$iopOs = (float) ($r->payload['iop_os'] ?? 0);
|
||||
|
||||
return $iopOd >= 24 || $iopOs >= 24;
|
||||
})
|
||||
->count();
|
||||
|
||||
$planRecords = SpecialtyClinicalRecord::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('module_key', 'ophthalmology')
|
||||
->where('record_type', 'eye_plan')
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
|
||||
->whereBetween('recorded_at', [$rangeFrom, $rangeTo])
|
||||
->get();
|
||||
|
||||
$diagnosisBreakdown = $planRecords
|
||||
->groupBy(fn (SpecialtyClinicalRecord $r) => (string) ($r->payload['diagnosis'] ?? 'Unknown'))
|
||||
->map(fn (Collection $rows, string $diagnosis) => [
|
||||
'diagnosis' => $diagnosis,
|
||||
'total' => $rows->count(),
|
||||
])
|
||||
->values()
|
||||
->sortByDesc('total')
|
||||
->values();
|
||||
|
||||
$procedureRecords = SpecialtyClinicalRecord::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('module_key', 'ophthalmology')
|
||||
->where('record_type', 'eye_procedure')
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
|
||||
->whereBetween('recorded_at', [$rangeFrom, $rangeTo])
|
||||
->get();
|
||||
|
||||
$procedureBreakdown = $procedureRecords
|
||||
->groupBy(fn (SpecialtyClinicalRecord $r) => (string) ($r->payload['procedure'] ?? 'Unknown'))
|
||||
->map(fn (Collection $rows, string $procedure) => [
|
||||
'procedure' => $procedure,
|
||||
'total' => $rows->count(),
|
||||
])
|
||||
->values()
|
||||
->sortByDesc('total')
|
||||
->values();
|
||||
|
||||
$completedVisits = Visit::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->whereIn('id', $visitIds->isEmpty() ? [0] : $visitIds)
|
||||
->where('status', Visit::STATUS_COMPLETED)
|
||||
->whereBetween('completed_at', [$rangeFrom, $rangeTo])
|
||||
->whereNotNull('checked_in_at')
|
||||
->whereNotNull('completed_at')
|
||||
->get();
|
||||
|
||||
$avgLos = null;
|
||||
if ($completedVisits->isNotEmpty()) {
|
||||
$avgLos = round($completedVisits->avg(function (Visit $visit) {
|
||||
return $visit->checked_in_at->diffInMinutes($visit->completed_at);
|
||||
}), 1);
|
||||
}
|
||||
|
||||
$serviceLabels = collect($this->shell->provisionedServices($organization, 'ophthalmology'))
|
||||
->pluck('label')
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$revenueByService = BillLineItem::query()
|
||||
->where('owner_ref', $ownerRef)
|
||||
->where('source_type', 'specialty_service')
|
||||
->whereIn('description', $serviceLabels ?: ['__none__'])
|
||||
->whereBetween('created_at', [$rangeFrom, $rangeTo])
|
||||
->whereHas('bill', function ($q) use ($organization, $visitIds) {
|
||||
$q->where('organization_id', $organization->id)
|
||||
->whereIn('visit_id', $visitIds->isEmpty() ? [0] : $visitIds)
|
||||
->whereNotIn('status', [Bill::STATUS_VOID]);
|
||||
})
|
||||
->selectRaw('description, count(*) as total, sum(total_minor) as amount_minor')
|
||||
->groupBy('description')
|
||||
->orderByDesc('amount_minor')
|
||||
->get();
|
||||
|
||||
return [
|
||||
'arrivals_today' => $arrivalsToday,
|
||||
'completed_today' => $completedToday,
|
||||
'elevated_iop_open' => $elevatedIopOpen,
|
||||
'diagnosis_breakdown' => $diagnosisBreakdown,
|
||||
'procedure_breakdown' => $procedureBreakdown,
|
||||
'avg_los_minutes' => $avgLos,
|
||||
'revenue_by_service' => $revenueByService,
|
||||
'from' => $rangeFrom->toDateString(),
|
||||
'to' => $rangeTo->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Care\Ophthalmology;
|
||||
|
||||
/**
|
||||
* Map eye-care clinical progress onto ophthalmology visit stages.
|
||||
*/
|
||||
class OphthalmologyWorkflowService
|
||||
{
|
||||
public const STAGE_CHECK_IN = 'check_in';
|
||||
|
||||
public const STAGE_HISTORY = 'history';
|
||||
|
||||
public const STAGE_REFRACTION = 'refraction';
|
||||
|
||||
public const STAGE_EXAM = 'exam';
|
||||
|
||||
public const STAGE_INVESTIGATION = 'investigation';
|
||||
|
||||
public const STAGE_PLAN = 'plan';
|
||||
|
||||
public const STAGE_TREATMENT = 'treatment';
|
||||
|
||||
public const STAGE_COMPLETED = 'completed';
|
||||
|
||||
/**
|
||||
* Suggested stage after a refraction / VA payload is saved.
|
||||
*
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function stageFromRefraction(array $payload): string
|
||||
{
|
||||
$vaOd = trim((string) ($payload['va_od'] ?? ''));
|
||||
$vaOs = trim((string) ($payload['va_os'] ?? ''));
|
||||
|
||||
if ($vaOd !== '' || $vaOs !== '') {
|
||||
return self::STAGE_REFRACTION;
|
||||
}
|
||||
|
||||
return self::STAGE_HISTORY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggested stage after an eye exam payload is saved.
|
||||
*
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function stageFromExam(array $payload): string
|
||||
{
|
||||
$findings = strtolower((string) ($payload['findings'] ?? ''));
|
||||
if (str_contains($findings, 'oct')
|
||||
|| str_contains($findings, 'field')
|
||||
|| str_contains($findings, 'imaging')
|
||||
|| str_contains($findings, 'investigate')) {
|
||||
return self::STAGE_INVESTIGATION;
|
||||
}
|
||||
|
||||
return self::STAGE_EXAM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggested stage after a diagnosis/plan payload is saved.
|
||||
*
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function stageFromPlan(array $payload): string
|
||||
{
|
||||
if (! empty($payload['procedure_planned'])) {
|
||||
return self::STAGE_TREATMENT;
|
||||
}
|
||||
|
||||
return self::STAGE_PLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a procedure payload should close the visit episode.
|
||||
*
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function shouldCompleteVisit(array $payload): bool
|
||||
{
|
||||
$outcome = strtolower((string) ($payload['outcome'] ?? ''));
|
||||
|
||||
return str_contains($outcome, 'completed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Default stage progression for action buttons.
|
||||
*
|
||||
* @return array<string, array{next: string, label: string}>
|
||||
*/
|
||||
public function stageFlow(): array
|
||||
{
|
||||
return [
|
||||
self::STAGE_CHECK_IN => ['next' => self::STAGE_HISTORY, 'label' => 'Start history'],
|
||||
self::STAGE_HISTORY => ['next' => self::STAGE_REFRACTION, 'label' => 'Move to VA / refraction'],
|
||||
self::STAGE_REFRACTION => ['next' => self::STAGE_EXAM, 'label' => 'Move to examination'],
|
||||
self::STAGE_EXAM => ['next' => self::STAGE_INVESTIGATION, 'label' => 'Move to investigations'],
|
||||
self::STAGE_INVESTIGATION => ['next' => self::STAGE_PLAN, 'label' => 'Move to diagnosis & plan'],
|
||||
self::STAGE_PLAN => ['next' => self::STAGE_TREATMENT, 'label' => 'Move to treatment'],
|
||||
self::STAGE_TREATMENT => ['next' => self::STAGE_COMPLETED, 'label' => 'Complete visit'],
|
||||
self::STAGE_COMPLETED => ['next' => self::STAGE_COMPLETED, 'label' => 'Completed'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -249,6 +249,52 @@ class SpecialtyClinicalRecordService
|
||||
}
|
||||
}
|
||||
|
||||
if ($moduleKey === 'ophthalmology' && in_array($recordType, ['eye_exam', 'refraction'], true)) {
|
||||
$iopOd = isset($payload['iop_od']) ? (float) $payload['iop_od'] : null;
|
||||
$iopOs = isset($payload['iop_os']) ? (float) $payload['iop_os'] : null;
|
||||
if (($iopOd !== null && $iopOd >= 30) || ($iopOs !== null && $iopOs >= 30)) {
|
||||
$alerts[] = [
|
||||
'code' => 'eye.critical_iop',
|
||||
'severity' => 'critical',
|
||||
'message' => 'Critical IOP (≥30 mmHg) — urgent glaucoma / acute review.',
|
||||
];
|
||||
} elseif (($iopOd !== null && $iopOd >= 24) || ($iopOs !== null && $iopOs >= 24)) {
|
||||
$alerts[] = [
|
||||
'code' => 'eye.elevated_iop',
|
||||
'severity' => 'warning',
|
||||
'message' => 'Elevated IOP (≥24 mmHg).',
|
||||
];
|
||||
}
|
||||
|
||||
foreach (['va_od', 'va_os'] as $vaKey) {
|
||||
$va = strtolower(trim((string) ($payload[$vaKey] ?? '')));
|
||||
if ($va === '') {
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/\b(cf|hm|pl|nlp|counting|hand\s*motion|perception)\b/i', $va)
|
||||
|| preg_match('/^6\/(60|90|120)\b/', $va)
|
||||
|| preg_match('/^20\/(200|400)\b/', $va)) {
|
||||
$alerts[] = [
|
||||
'code' => 'eye.low_vision',
|
||||
'severity' => 'warning',
|
||||
'message' => 'Low visual acuity recorded ('.$vaKey.').',
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($moduleKey === 'ophthalmology' && $recordType === 'eye_procedure') {
|
||||
$outcome = strtolower((string) ($payload['outcome'] ?? ''));
|
||||
if (str_contains($outcome, 'complication') || str_contains($outcome, 'aborted')) {
|
||||
$alerts[] = [
|
||||
'code' => 'eye.procedure_concern',
|
||||
'severity' => 'warning',
|
||||
'message' => 'Procedure outcome needs review (complication or aborted).',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $alerts;
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ class SpecialtyShellService
|
||||
) {
|
||||
$code = (string) ($stage['code'] ?? '');
|
||||
|
||||
if (in_array($moduleKey, ['dentistry', 'emergency', 'blood_bank'], true) && $visitIds->isNotEmpty()) {
|
||||
if (in_array($moduleKey, ['dentistry', 'emergency', 'blood_bank', 'ophthalmology'], true) && $visitIds->isNotEmpty()) {
|
||||
$count = Visit::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->whereIn('id', $visitIds)
|
||||
@@ -300,6 +300,7 @@ class SpecialtyShellService
|
||||
$clinicalOpen = match ($moduleKey) {
|
||||
'emergency' => $clinical->countOpenByType($organization, 'emergency', 'triage', $branchScope),
|
||||
'blood_bank' => $clinical->countOpenByType($organization, 'blood_bank', 'blood_request', $branchScope),
|
||||
'ophthalmology' => $clinical->countOpenByType($organization, 'ophthalmology', 'eye_exam', $branchScope),
|
||||
'dentistry' => \App\Models\DentalPlanItem::query()
|
||||
->whereHas('plan', function ($q) use ($organization, $ownerRef) {
|
||||
$q->owned($ownerRef)
|
||||
|
||||
@@ -96,6 +96,14 @@ class SpecialtyVisitStageService
|
||||
: ($stages[1] ?? ($stages[0] ?? null));
|
||||
}
|
||||
|
||||
if ($moduleKey === 'ophthalmology') {
|
||||
$stages = $this->allowedStages($moduleKey);
|
||||
|
||||
return in_array(\App\Services\Care\Ophthalmology\OphthalmologyWorkflowService::STAGE_HISTORY, $stages, true)
|
||||
? \App\Services\Care\Ophthalmology\OphthalmologyWorkflowService::STAGE_HISTORY
|
||||
: ($stages[1] ?? ($stages[0] ?? null));
|
||||
}
|
||||
|
||||
$stages = $this->allowedStages($moduleKey);
|
||||
foreach (['chair', 'in_care', 'exam', 'assessment', 'treatment'] as $preferred) {
|
||||
if (in_array($preferred, $stages, true)) {
|
||||
|
||||
@@ -282,6 +282,7 @@ return [
|
||||
'specialty_emergency' => 'Emergency document',
|
||||
'specialty_blood_bank' => 'Blood bank document',
|
||||
'specialty_dentistry' => 'Dental document',
|
||||
'specialty_ophthalmology' => 'Eye care document',
|
||||
'other' => 'Other',
|
||||
],
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@ return [
|
||||
'dentistry' => [
|
||||
],
|
||||
'ophthalmology' => [
|
||||
'exam' => 'eye_exam',
|
||||
'refraction' => 'refraction',
|
||||
'clinical_notes' => 'clinical_note',
|
||||
'exam' => 'eye_exam',
|
||||
'investigations' => 'eye_investigation',
|
||||
'plan' => 'eye_plan',
|
||||
'treat' => 'eye_procedure',
|
||||
],
|
||||
'physiotherapy' => [
|
||||
'assessment' => 'pt_assessment',
|
||||
@@ -184,18 +186,13 @@ return [
|
||||
'dentistry' => [
|
||||
],
|
||||
'ophthalmology' => [
|
||||
'eye_exam' => [
|
||||
['name' => 'chief_complaint', 'label' => 'Chief complaint', 'type' => 'text', 'required' => true],
|
||||
'refraction' => [
|
||||
['name' => 'va_od', 'label' => 'Visual acuity OD', 'type' => 'text', 'required' => true],
|
||||
['name' => 'va_os', 'label' => 'Visual acuity OS', 'type' => 'text', 'required' => true],
|
||||
['name' => 'iop_od', 'label' => 'IOP OD (mmHg)', 'type' => 'number'],
|
||||
['name' => 'iop_os', 'label' => 'IOP OS (mmHg)', 'type' => 'number'],
|
||||
['name' => 'pupils', 'label' => 'Pupils', 'type' => 'text'],
|
||||
['name' => 'anterior_segment', 'label' => 'Anterior segment', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'fundus', 'label' => 'Fundus / posterior segment', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'findings', 'label' => 'Key findings', 'type' => 'textarea', 'required' => true, 'rows' => 3],
|
||||
],
|
||||
'refraction' => [
|
||||
['name' => 'va_od_near', 'label' => 'Near VA OD', 'type' => 'text'],
|
||||
['name' => 'va_os_near', 'label' => 'Near VA OS', 'type' => 'text'],
|
||||
['name' => 'pinhole_od', 'label' => 'Pinhole OD', 'type' => 'text'],
|
||||
['name' => 'pinhole_os', 'label' => 'Pinhole OS', 'type' => 'text'],
|
||||
['name' => 'sphere_od', 'label' => 'Sphere OD', 'type' => 'text'],
|
||||
['name' => 'cylinder_od', 'label' => 'Cylinder OD', 'type' => 'text'],
|
||||
['name' => 'axis_od', 'label' => 'Axis OD', 'type' => 'text'],
|
||||
@@ -206,11 +203,45 @@ return [
|
||||
['name' => 'pd', 'label' => 'Pupillary distance (mm)', 'type' => 'number'],
|
||||
['name' => 'notes', 'label' => 'Refraction notes', 'type' => 'textarea', 'rows' => 2],
|
||||
],
|
||||
'clinical_note' => [
|
||||
['name' => 'history', 'label' => 'History of present illness', 'type' => 'textarea', 'required' => true, 'rows' => 4],
|
||||
['name' => 'examination', 'label' => 'Examination', 'type' => 'textarea', 'rows' => 3],
|
||||
['name' => 'working_diagnosis', 'label' => 'Working diagnosis', 'type' => 'text'],
|
||||
['name' => 'plan', 'label' => 'Plan', 'type' => 'textarea', 'rows' => 3],
|
||||
'eye_exam' => [
|
||||
['name' => 'chief_complaint', 'label' => 'Chief complaint', 'type' => 'text', 'required' => true],
|
||||
['name' => 'history', 'label' => 'History of present illness', 'type' => 'textarea', 'rows' => 3],
|
||||
['name' => 'va_od', 'label' => 'Visual acuity OD', 'type' => 'text'],
|
||||
['name' => 'va_os', 'label' => 'Visual acuity OS', 'type' => 'text'],
|
||||
['name' => 'iop_od', 'label' => 'IOP OD (mmHg)', 'type' => 'number'],
|
||||
['name' => 'iop_os', 'label' => 'IOP OS (mmHg)', 'type' => 'number'],
|
||||
['name' => 'pupils', 'label' => 'Pupils', 'type' => 'text'],
|
||||
['name' => 'extraocular', 'label' => 'Extraocular movements', 'type' => 'text'],
|
||||
['name' => 'anterior_segment', 'label' => 'Anterior segment', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'fundus', 'label' => 'Fundus / posterior segment', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'findings', 'label' => 'Key findings', 'type' => 'textarea', 'required' => true, 'rows' => 3],
|
||||
],
|
||||
'eye_investigation' => [
|
||||
['name' => 'modality', 'label' => 'Modality', 'type' => 'select', 'required' => true, 'options' => ['OCT', 'Visual fields', 'Fundus photo', 'Fluorescein angiography', 'Biometry / A-scan', 'B-scan ultrasound', 'Corneal topography', 'Other']],
|
||||
['name' => 'eye', 'label' => 'Eye', 'type' => 'select', 'options' => ['OD', 'OS', 'OU']],
|
||||
['name' => 'indication', 'label' => 'Indication', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'findings', 'label' => 'Findings', 'type' => 'textarea', 'required' => true, 'rows' => 3],
|
||||
['name' => 'impression', 'label' => 'Impression', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'recommendations', 'label' => 'Recommendations', 'type' => 'textarea', 'rows' => 2],
|
||||
],
|
||||
'eye_plan' => [
|
||||
['name' => 'diagnosis', 'label' => 'Diagnosis', 'type' => 'text', 'required' => true],
|
||||
['name' => 'laterality', 'label' => 'Laterality', 'type' => 'select', 'options' => ['OD', 'OS', 'OU', 'N/A']],
|
||||
['name' => 'plan', 'label' => 'Plan', 'type' => 'textarea', 'required' => true, 'rows' => 3],
|
||||
['name' => 'medications', 'label' => 'Medications / drops', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'procedure_planned', 'label' => 'Procedure planned', 'type' => 'boolean'],
|
||||
['name' => 'follow_up', 'label' => 'Follow-up', 'type' => 'text'],
|
||||
['name' => 'advice', 'label' => 'Patient advice', 'type' => 'textarea', 'rows' => 2],
|
||||
],
|
||||
'eye_procedure' => [
|
||||
['name' => 'procedure', 'label' => 'Procedure', 'type' => 'text', 'required' => true],
|
||||
['name' => 'eye', 'label' => 'Eye', 'type' => 'select', 'required' => true, 'options' => ['OD', 'OS', 'OU']],
|
||||
['name' => 'indication', 'label' => 'Indication', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'anaesthesia', 'label' => 'Anaesthesia', 'type' => 'select', 'options' => ['None', 'Topical', 'Local', 'Other']],
|
||||
['name' => 'outcome', 'label' => 'Outcome', 'type' => 'select', 'required' => true, 'options' => ['Completed uneventfully', 'Completed with complications', 'Deferred', 'Aborted']],
|
||||
['name' => 'complications', 'label' => 'Complications', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'post_op_plan', 'label' => 'Post-procedure plan', 'type' => 'textarea', 'rows' => 2],
|
||||
['name' => 'notes', 'label' => 'Notes', 'type' => 'textarea', 'rows' => 2],
|
||||
],
|
||||
],
|
||||
'physiotherapy' => [
|
||||
|
||||
@@ -141,9 +141,13 @@ return [
|
||||
],
|
||||
'ophthalmology' => [
|
||||
'stages' => [
|
||||
['code' => 'waiting', 'label' => 'Waiting room', 'queue_point' => 'waiting'],
|
||||
['code' => 'exam', 'label' => 'Eye exam', 'queue_point' => 'chair'],
|
||||
['code' => 'procedure', 'label' => 'Procedure / treatment', 'queue_point' => 'chair'],
|
||||
['code' => 'check_in', 'label' => 'Check-in', 'queue_point' => 'waiting'],
|
||||
['code' => 'history', 'label' => 'History / intake', 'queue_point' => 'waiting'],
|
||||
['code' => 'refraction', 'label' => 'VA / refraction', 'queue_point' => 'chair'],
|
||||
['code' => 'exam', 'label' => 'Examination', 'queue_point' => 'chair'],
|
||||
['code' => 'investigation', 'label' => 'Investigations', 'queue_point' => 'chair'],
|
||||
['code' => 'plan', 'label' => 'Diagnosis & plan', 'queue_point' => 'chair'],
|
||||
['code' => 'treatment', 'label' => 'Procedure / treatment', 'queue_point' => 'chair'],
|
||||
['code' => 'completed', 'label' => 'Completed', 'queue_point' => null],
|
||||
],
|
||||
'services' => [
|
||||
@@ -151,12 +155,22 @@ return [
|
||||
['code' => 'eye.refraction', 'label' => 'Refraction / glasses exam', 'amount_minor' => 4000, 'type' => 'procedure'],
|
||||
['code' => 'eye.iop', 'label' => 'IOP / pressure check', 'amount_minor' => 3000, 'type' => 'procedure'],
|
||||
['code' => 'eye.fundus', 'label' => 'Fundus examination', 'amount_minor' => 5000, 'type' => 'procedure'],
|
||||
['code' => 'eye.slit_lamp', 'label' => 'Slit-lamp examination', 'amount_minor' => 4500, 'type' => 'procedure'],
|
||||
['code' => 'eye.oct', 'label' => 'OCT imaging', 'amount_minor' => 18000, 'type' => 'imaging'],
|
||||
['code' => 'eye.visual_fields', 'label' => 'Visual fields', 'amount_minor' => 12000, 'type' => 'imaging'],
|
||||
['code' => 'eye.biometry', 'label' => 'Biometry / A-scan', 'amount_minor' => 10000, 'type' => 'imaging'],
|
||||
['code' => 'eye.foreign_body', 'label' => 'Foreign body removal', 'amount_minor' => 15000, 'type' => 'procedure'],
|
||||
['code' => 'eye.yag', 'label' => 'YAG laser', 'amount_minor' => 25000, 'type' => 'procedure'],
|
||||
['code' => 'eye.procedure', 'label' => 'Ocular procedure', 'amount_minor' => 20000, 'type' => 'procedure'],
|
||||
['code' => 'eye.cataract_assess', 'label' => 'Cataract assessment', 'amount_minor' => 8000, 'type' => 'consultation'],
|
||||
],
|
||||
'workspace_tabs' => [
|
||||
'overview' => 'Overview',
|
||||
'exam' => 'Eye exam',
|
||||
'refraction' => 'Refraction',
|
||||
'clinical_notes' => 'Clinical notes',
|
||||
'refraction' => 'VA / refraction',
|
||||
'exam' => 'Examination',
|
||||
'investigations' => 'Investigations',
|
||||
'plan' => 'Diagnosis & plan',
|
||||
'treat' => 'Treatment',
|
||||
'orders' => 'Orders',
|
||||
'billing' => 'Billing',
|
||||
'documents' => 'Documents',
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Eye care summary · {{ $patient->fullName() }}</title>
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; color: #0f172a; margin: 2rem; }
|
||||
h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
|
||||
h2 { font-size: .95rem; margin: 1.25rem 0 .5rem; border-bottom: 1px solid #e2e8f0; padding-bottom: .25rem; }
|
||||
.meta { color: #64748b; font-size: .875rem; }
|
||||
dl { display: grid; grid-template-columns: 10rem 1fr; gap: .35rem .75rem; font-size: .875rem; }
|
||||
dt { color: #64748b; }
|
||||
dd { margin: 0; font-weight: 500; }
|
||||
@media print { .no-print { display: none; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p class="no-print"><a href="{{ route('care.specialty.workspace', ['module' => 'ophthalmology', 'visit' => $visit]) }}">Back</a></p>
|
||||
|
||||
<h1>{{ $patient->fullName() }}</h1>
|
||||
<p class="meta">
|
||||
{{ $patient->patient_number }}
|
||||
· Visit #{{ $visit->id }}
|
||||
· Stage {{ $visit->specialty_stage ?? '—' }}
|
||||
· {{ $visit->checked_in_at?->format('d M Y H:i') ?? '—' }}
|
||||
</p>
|
||||
|
||||
<h2>Visual acuity / refraction</h2>
|
||||
@if ($refraction)
|
||||
<dl>
|
||||
<dt>VA OD / OS</dt><dd>{{ $refraction->payload['va_od'] ?? '—' }} / {{ $refraction->payload['va_os'] ?? '—' }}</dd>
|
||||
<dt>Near VA</dt><dd>{{ $refraction->payload['va_od_near'] ?? '—' }} / {{ $refraction->payload['va_os_near'] ?? '—' }}</dd>
|
||||
<dt>OD Rx</dt>
|
||||
<dd>
|
||||
Sph {{ $refraction->payload['sphere_od'] ?? '—' }}
|
||||
Cyl {{ $refraction->payload['cylinder_od'] ?? '—' }}
|
||||
Axis {{ $refraction->payload['axis_od'] ?? '—' }}
|
||||
</dd>
|
||||
<dt>OS Rx</dt>
|
||||
<dd>
|
||||
Sph {{ $refraction->payload['sphere_os'] ?? '—' }}
|
||||
Cyl {{ $refraction->payload['cylinder_os'] ?? '—' }}
|
||||
Axis {{ $refraction->payload['axis_os'] ?? '—' }}
|
||||
</dd>
|
||||
<dt>Add / PD</dt><dd>{{ $refraction->payload['add'] ?? '—' }} / {{ $refraction->payload['pd'] ?? '—' }}</dd>
|
||||
<dt>Notes</dt><dd>{{ $refraction->payload['notes'] ?? '—' }}</dd>
|
||||
</dl>
|
||||
@else
|
||||
<p class="meta">No refraction recorded.</p>
|
||||
@endif
|
||||
|
||||
<h2>Examination</h2>
|
||||
@if ($exam)
|
||||
<dl>
|
||||
<dt>Chief complaint</dt><dd>{{ $exam->payload['chief_complaint'] ?? '—' }}</dd>
|
||||
<dt>History</dt><dd>{{ $exam->payload['history'] ?? '—' }}</dd>
|
||||
<dt>IOP OD / OS</dt><dd>{{ $exam->payload['iop_od'] ?? '—' }} / {{ $exam->payload['iop_os'] ?? '—' }}</dd>
|
||||
<dt>Pupils</dt><dd>{{ $exam->payload['pupils'] ?? '—' }}</dd>
|
||||
<dt>Anterior segment</dt><dd>{{ $exam->payload['anterior_segment'] ?? '—' }}</dd>
|
||||
<dt>Fundus</dt><dd>{{ $exam->payload['fundus'] ?? '—' }}</dd>
|
||||
<dt>Findings</dt><dd>{{ $exam->payload['findings'] ?? '—' }}</dd>
|
||||
</dl>
|
||||
@else
|
||||
<p class="meta">No examination recorded.</p>
|
||||
@endif
|
||||
|
||||
<h2>Investigations</h2>
|
||||
@if ($investigation)
|
||||
<dl>
|
||||
<dt>Modality</dt><dd>{{ $investigation->payload['modality'] ?? '—' }}</dd>
|
||||
<dt>Eye</dt><dd>{{ $investigation->payload['eye'] ?? '—' }}</dd>
|
||||
<dt>Findings</dt><dd>{{ $investigation->payload['findings'] ?? '—' }}</dd>
|
||||
<dt>Impression</dt><dd>{{ $investigation->payload['impression'] ?? '—' }}</dd>
|
||||
</dl>
|
||||
@else
|
||||
<p class="meta">No investigation recorded.</p>
|
||||
@endif
|
||||
|
||||
<h2>Diagnosis & plan</h2>
|
||||
@if ($plan)
|
||||
<dl>
|
||||
<dt>Diagnosis</dt><dd>{{ $plan->payload['diagnosis'] ?? '—' }}</dd>
|
||||
<dt>Laterality</dt><dd>{{ $plan->payload['laterality'] ?? '—' }}</dd>
|
||||
<dt>Plan</dt><dd>{{ $plan->payload['plan'] ?? '—' }}</dd>
|
||||
<dt>Medications</dt><dd>{{ $plan->payload['medications'] ?? '—' }}</dd>
|
||||
<dt>Follow-up</dt><dd>{{ $plan->payload['follow_up'] ?? '—' }}</dd>
|
||||
</dl>
|
||||
@else
|
||||
<p class="meta">No plan recorded.</p>
|
||||
@endif
|
||||
|
||||
<h2>Procedure / treatment</h2>
|
||||
@if ($procedure)
|
||||
<dl>
|
||||
<dt>Procedure</dt><dd>{{ $procedure->payload['procedure'] ?? '—' }}</dd>
|
||||
<dt>Eye</dt><dd>{{ $procedure->payload['eye'] ?? '—' }}</dd>
|
||||
<dt>Outcome</dt><dd>{{ $procedure->payload['outcome'] ?? '—' }}</dd>
|
||||
<dt>Post-op plan</dt><dd>{{ $procedure->payload['post_op_plan'] ?? '—' }}</dd>
|
||||
<dt>Notes</dt><dd>{{ $procedure->payload['notes'] ?? '—' }}</dd>
|
||||
</dl>
|
||||
@else
|
||||
<p class="meta">No procedure recorded.</p>
|
||||
@endif
|
||||
|
||||
<script>window.print();</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,88 @@
|
||||
<x-app-layout title="Eye care reports">
|
||||
<div class="space-y-6">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 class="text-xl font-semibold text-slate-900">Eye care reports</h1>
|
||||
<p class="mt-1 text-sm text-slate-500">Arrivals, elevated IOP, diagnoses, procedures, length of stay, and eye service revenue.</p>
|
||||
</div>
|
||||
<a href="{{ route('care.specialty.show', 'ophthalmology') }}" class="text-sm font-medium text-indigo-600">← Specialty home</a>
|
||||
</div>
|
||||
|
||||
<form method="GET" class="flex flex-wrap items-end gap-3 rounded-2xl border border-slate-200 bg-white p-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-600">From</label>
|
||||
<input type="date" name="from" value="{{ $report['from'] ?? '' }}" class="mt-1 rounded-xl border border-slate-200 px-3 py-2 text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-600">To</label>
|
||||
<input type="date" name="to" value="{{ $report['to'] ?? '' }}" class="mt-1 rounded-xl border border-slate-200 px-3 py-2 text-sm">
|
||||
</div>
|
||||
<button type="submit" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white">Apply</button>
|
||||
</form>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-4">
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Arrivals today</p>
|
||||
<p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">{{ number_format($report['arrivals_today']) }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Completed today</p>
|
||||
<p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">{{ number_format($report['completed_today']) }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Elevated IOP open</p>
|
||||
<p class="mt-2 text-2xl font-semibold tabular-nums text-rose-700">{{ number_format($report['elevated_iop_open']) }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Avg LOS (range)</p>
|
||||
<p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">
|
||||
{{ $report['avg_los_minutes'] !== null ? $report['avg_los_minutes'].' min' : '—' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<h2 class="text-sm font-semibold text-slate-900">Diagnoses</h2>
|
||||
<ul class="mt-3 space-y-2 text-sm">
|
||||
@forelse ($report['diagnosis_breakdown'] as $row)
|
||||
<li class="flex justify-between gap-3">
|
||||
<span>{{ $row['diagnosis'] }}</span>
|
||||
<span class="tabular-nums text-slate-600">{{ $row['total'] }}</span>
|
||||
</li>
|
||||
@empty
|
||||
<li class="text-slate-500">No diagnosis records in range.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<h2 class="text-sm font-semibold text-slate-900">Procedures</h2>
|
||||
<ul class="mt-3 space-y-2 text-sm">
|
||||
@forelse ($report['procedure_breakdown'] as $row)
|
||||
<li class="flex justify-between gap-3">
|
||||
<span>{{ $row['procedure'] }}</span>
|
||||
<span class="tabular-nums text-slate-600">{{ $row['total'] }}</span>
|
||||
</li>
|
||||
@empty
|
||||
<li class="text-slate-500">No procedures in range.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<h2 class="text-sm font-semibold text-slate-900">Eye care service revenue</h2>
|
||||
<ul class="mt-3 space-y-2 text-sm">
|
||||
@forelse ($report['revenue_by_service'] as $row)
|
||||
<li class="flex justify-between gap-3">
|
||||
<span>{{ $row->description }} <span class="text-slate-400">×{{ $row->total }}</span></span>
|
||||
<span class="tabular-nums">{{ $currency }} {{ number_format($row->amount_minor / 100, 2) }}</span>
|
||||
</li>
|
||||
@empty
|
||||
<li class="text-slate-500">No billed eye care services in range.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
@@ -0,0 +1,126 @@
|
||||
@php
|
||||
$examPayload = $ophthalmologyExam?->payload ?? [];
|
||||
$refractionPayload = $ophthalmologyRefraction?->payload ?? [];
|
||||
$planPayload = $ophthalmologyPlan?->payload ?? [];
|
||||
$currentStage = $workspaceVisit->specialty_stage;
|
||||
$stageFlow = $ophthalmologyStageFlow ?? [];
|
||||
$stageLabels = collect($stages ?? [])->pluck('label', 'code');
|
||||
$canManage = $canAdvanceStage ?? $canConsult ?? false;
|
||||
$vaOd = $refractionPayload['va_od'] ?? ($examPayload['va_od'] ?? null);
|
||||
$vaOs = $refractionPayload['va_os'] ?? ($examPayload['va_os'] ?? null);
|
||||
@endphp
|
||||
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold text-slate-900">Eye care overview</h3>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Visual acuity, IOP, diagnosis, and visit stage for this episode.</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-3 text-sm">
|
||||
<a href="{{ route('care.specialty.ophthalmology.print', $workspaceVisit) }}" target="_blank" class="font-medium text-indigo-600">Print summary</a>
|
||||
<a href="{{ route('care.specialty.ophthalmology.reports') }}" class="font-medium text-indigo-600">Eye care reports</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-3 sm:grid-cols-3">
|
||||
<div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Visual acuity</p>
|
||||
<p class="mt-1 text-sm font-semibold text-slate-900">
|
||||
OD {{ $vaOd ?? '—' }} · OS {{ $vaOs ?? '—' }}
|
||||
</p>
|
||||
<p class="mt-1 text-xs text-slate-500">{{ $examPayload['chief_complaint'] ?? 'No complaint recorded' }}</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">IOP (mmHg)</p>
|
||||
<p class="mt-1 text-sm font-semibold text-slate-900">
|
||||
OD {{ $examPayload['iop_od'] ?? '—' }} · OS {{ $examPayload['iop_os'] ?? '—' }}
|
||||
</p>
|
||||
<p class="mt-1 text-xs text-slate-500">Pupils {{ $examPayload['pupils'] ?? '—' }}</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Diagnosis</p>
|
||||
<p class="mt-1 text-sm font-semibold text-slate-900">{{ $planPayload['diagnosis'] ?? 'Not set' }}</p>
|
||||
<p class="mt-1 text-xs text-slate-500">{{ $planPayload['follow_up'] ?? ($planPayload['laterality'] ?? '—') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Visit stage</p>
|
||||
<p class="mt-1 text-sm font-medium text-slate-900">
|
||||
{{ $currentStage ? ($stageLabels[$currentStage] ?? ucfirst(str_replace('_', ' ', $currentStage))) : 'Not set' }}
|
||||
</p>
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
@foreach (($ophthalmologyStageCodes ?: ['check_in', 'history', 'refraction', 'exam', 'investigation', 'plan', 'treatment', 'completed']) as $stageCode)
|
||||
@if ($canManage)
|
||||
<form method="POST" action="{{ route('care.specialty.ophthalmology.stage', $workspaceVisit) }}">
|
||||
@csrf
|
||||
<input type="hidden" name="stage" value="{{ $stageCode }}">
|
||||
<button type="submit"
|
||||
@class([
|
||||
'rounded-lg px-2.5 py-1 text-xs font-semibold',
|
||||
'bg-indigo-600 text-white' => $currentStage === $stageCode,
|
||||
'border border-slate-200 bg-white text-slate-700 hover:bg-slate-50' => $currentStage !== $stageCode,
|
||||
])>
|
||||
{{ $stageLabels[$stageCode] ?? ucfirst(str_replace('_', ' ', $stageCode)) }}
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<span
|
||||
@class([
|
||||
'rounded-lg px-2.5 py-1 text-xs font-semibold',
|
||||
'bg-indigo-600 text-white' => $currentStage === $stageCode,
|
||||
'border border-slate-200 bg-white text-slate-400' => $currentStage !== $stageCode,
|
||||
])
|
||||
@if ($currentStage !== $stageCode) aria-disabled="true" title="View-only access" @endif
|
||||
>
|
||||
{{ $stageLabels[$stageCode] ?? ucfirst(str_replace('_', ' ', $stageCode)) }}
|
||||
</span>
|
||||
@endif
|
||||
@endforeach
|
||||
@if ($canManage && $currentStage && isset($stageFlow[$currentStage]) && $stageFlow[$currentStage]['next'] !== $currentStage)
|
||||
<form method="POST" action="{{ route('care.specialty.ophthalmology.stage', $workspaceVisit) }}">
|
||||
@csrf
|
||||
<input type="hidden" name="stage" value="{{ $stageFlow[$currentStage]['next'] }}">
|
||||
<button type="submit" class="rounded-lg bg-emerald-600 px-2.5 py-1 text-xs font-semibold text-white hover:bg-emerald-700">
|
||||
{{ $stageFlow[$currentStage]['label'] }} →
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl class="mt-4 grid gap-3 text-sm sm:grid-cols-2">
|
||||
<div>
|
||||
<dt class="text-slate-500">Key findings</dt>
|
||||
<dd class="font-medium text-slate-900">{{ $examPayload['findings'] ?? '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-slate-500">Plan</dt>
|
||||
<dd class="font-medium text-slate-900">{{ $planPayload['plan'] ?? '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-slate-500">Queue</dt>
|
||||
<dd class="font-medium text-slate-900">
|
||||
{{ $workspaceVisit->appointment?->queue_ticket_number ?? '—' }}
|
||||
@if ($workspaceVisit->appointment?->queue_ticket_status)
|
||||
<span class="text-slate-500">({{ $workspaceVisit->appointment->queue_ticket_status }})</span>
|
||||
@endif
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-slate-500">Checked in</dt>
|
||||
<dd class="font-medium text-slate-900">{{ $workspaceVisit->checked_in_at?->format('d M Y H:i') ?? '—' }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
@if (! empty($clinicalAlerts))
|
||||
<div class="mt-4 space-y-1.5 border-t border-slate-100 pt-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Alerts</p>
|
||||
@foreach ($clinicalAlerts as $alert)
|
||||
<p class="text-sm {{ ($alert['severity'] ?? '') === 'critical' ? 'text-rose-700' : 'text-amber-800' }}">
|
||||
{{ $alert['message'] ?? '' }}
|
||||
</p>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</section>
|
||||
@@ -0,0 +1,70 @@
|
||||
@php
|
||||
$record = $ophthalmologyProcedure;
|
||||
$payload = $record?->payload ?? [];
|
||||
$canManage = $canManageClinical ?? $canConsult ?? false;
|
||||
@endphp
|
||||
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold text-slate-900">Procedure / treatment</h3>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Record ocular procedures. Completing a procedure can close the visit.</p>
|
||||
</div>
|
||||
<a href="{{ route('care.specialty.ophthalmology.print', $workspaceVisit) }}" target="_blank" class="text-sm font-medium text-indigo-600">Print summary</a>
|
||||
</div>
|
||||
|
||||
@if ($canManage)
|
||||
<form method="POST" action="{{ route('care.specialty.ophthalmology.procedure', $workspaceVisit) }}" class="mt-4 space-y-4">
|
||||
@csrf
|
||||
<input type="hidden" name="tab" value="treat">
|
||||
<div class="grid gap-3 sm:grid-cols-2">
|
||||
@foreach ($clinicalFields ?? [] as $field)
|
||||
@php
|
||||
$name = $field['name'];
|
||||
$value = old('payload.'.$name, $payload[$name] ?? '');
|
||||
$type = $field['type'] ?? 'text';
|
||||
@endphp
|
||||
<div @class(['sm:col-span-2' => in_array($type, ['textarea'], true)])>
|
||||
<label class="block text-xs font-medium text-slate-600">
|
||||
{{ $field['label'] }}
|
||||
@if (! empty($field['required'])) <span class="text-rose-600">*</span> @endif
|
||||
</label>
|
||||
@if ($type === 'textarea')
|
||||
<textarea name="payload[{{ $name }}]" rows="{{ $field['rows'] ?? 3 }}" @required(! empty($field['required']))
|
||||
class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm">{{ $value }}</textarea>
|
||||
@elseif ($type === 'select')
|
||||
<select name="payload[{{ $name }}]" @required(! empty($field['required']))
|
||||
class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm">
|
||||
<option value="">Select…</option>
|
||||
@foreach ($field['options'] ?? [] as $option)
|
||||
<option value="{{ $option }}" @selected((string) $value === (string) $option)>{{ $option }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@elseif ($type === 'boolean')
|
||||
<label class="mt-2 inline-flex items-center gap-2 text-sm text-slate-700">
|
||||
<input type="checkbox" name="payload[{{ $name }}]" value="1" @checked(old('payload.'.$name, ! empty($payload[$name])))>
|
||||
Yes
|
||||
</label>
|
||||
@else
|
||||
<input type="{{ $type === 'number' ? 'number' : 'text' }}" name="payload[{{ $name }}]" value="{{ $value }}"
|
||||
@required(! empty($field['required']))
|
||||
class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm">
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<button type="submit" class="btn-primary">Save treatment</button>
|
||||
</form>
|
||||
@elseif ($record)
|
||||
<dl class="mt-4 grid gap-3 text-sm sm:grid-cols-2">
|
||||
@foreach ($clinicalFields ?? [] as $field)
|
||||
<div>
|
||||
<dt class="text-slate-500">{{ $field['label'] }}</dt>
|
||||
<dd class="font-medium text-slate-900">{{ $payload[$field['name']] ?? '—' }}</dd>
|
||||
</div>
|
||||
@endforeach
|
||||
</dl>
|
||||
@else
|
||||
<p class="mt-4 text-sm text-slate-500">No procedure recorded yet.</p>
|
||||
@endif
|
||||
</section>
|
||||
@@ -52,6 +52,8 @@
|
||||
@include('care.specialty.emergency.workspace-'.$activeTab)
|
||||
@elseif ($moduleKey === 'blood_bank' && in_array($activeTab, ['overview', 'issue', 'transfusion'], true))
|
||||
@include('care.specialty.blood-bank.workspace-'.$activeTab)
|
||||
@elseif ($moduleKey === 'ophthalmology' && in_array($activeTab, ['overview', 'treat'], true))
|
||||
@include('care.specialty.ophthalmology.workspace-'.$activeTab)
|
||||
@elseif ($activeTab === 'billing')
|
||||
<section class="rounded-2xl border border-slate-200 bg-white p-5">
|
||||
<h3 class="text-sm font-semibold text-slate-900">
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
<a href="{{ route('care.blood-bank.admin.index') }}" class="text-slate-600 hover:text-slate-900">Admin</a>
|
||||
@endif
|
||||
@endif
|
||||
@if ($moduleKey === 'ophthalmology')
|
||||
<a href="{{ route('care.specialty.ophthalmology.reports') }}" class="text-slate-600 hover:text-slate-900">Reports</a>
|
||||
@endif
|
||||
<a href="{{ route('care.specialty.history', $moduleKey) }}" class="text-slate-600 hover:text-slate-900">History</a>
|
||||
@if ($canManageClinical ?? $canManageSpecialty ?? true)
|
||||
<a href="{{ route('care.specialty.billing', $moduleKey) }}" class="text-slate-600 hover:text-slate-900">Billing</a>
|
||||
|
||||
@@ -41,6 +41,7 @@ use App\Http\Controllers\Care\BloodBankAdminController;
|
||||
use App\Http\Controllers\Care\BloodBankWorkspaceController;
|
||||
use App\Http\Controllers\Care\LabAdminController;
|
||||
use App\Http\Controllers\Care\EmergencyWorkspaceController;
|
||||
use App\Http\Controllers\Care\OphthalmologyWorkspaceController;
|
||||
use App\Http\Controllers\Care\SpecialtyModuleController;
|
||||
use App\Http\Controllers\Care\VisitWorkflowController;
|
||||
use App\Http\Controllers\NotificationController;
|
||||
@@ -123,6 +124,7 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
||||
Route::get('/specialty/dentistry/reports', [DentistryWorkspaceController::class, 'reports'])->name('care.specialty.dentistry.reports');
|
||||
Route::get('/specialty/emergency/reports', [EmergencyWorkspaceController::class, 'reports'])->name('care.specialty.emergency.reports');
|
||||
Route::get('/specialty/blood-bank/reports', [BloodBankWorkspaceController::class, 'reports'])->name('care.specialty.blood-bank.reports');
|
||||
Route::get('/specialty/ophthalmology/reports', [OphthalmologyWorkspaceController::class, 'reports'])->name('care.specialty.ophthalmology.reports');
|
||||
Route::get('/specialty/{module}/workspace/{visit?}', [SpecialtyModuleController::class, 'workspace'])->name('care.specialty.workspace');
|
||||
Route::post('/specialty/{module}/workspace/{visit}/clinical', [SpecialtyModuleController::class, 'saveClinical'])->name('care.specialty.clinical.save');
|
||||
Route::post('/specialty/{module}/workspace/{visit}/documents', [SpecialtyModuleController::class, 'uploadDocument'])->name('care.specialty.documents.upload');
|
||||
@@ -156,6 +158,9 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
||||
Route::post('/specialty/blood-bank/workspace/{visit}/issue', [BloodBankWorkspaceController::class, 'confirmIssue'])->name('care.specialty.blood-bank.issue');
|
||||
Route::post('/specialty/blood-bank/workspace/{visit}/transfusion', [BloodBankWorkspaceController::class, 'saveTransfusion'])->name('care.specialty.blood-bank.transfusion');
|
||||
Route::get('/specialty/blood-bank/workspace/{visit}/print', [BloodBankWorkspaceController::class, 'printSummary'])->name('care.specialty.blood-bank.print');
|
||||
Route::post('/specialty/ophthalmology/workspace/{visit}/stage', [OphthalmologyWorkspaceController::class, 'setStage'])->name('care.specialty.ophthalmology.stage');
|
||||
Route::post('/specialty/ophthalmology/workspace/{visit}/procedure', [OphthalmologyWorkspaceController::class, 'saveProcedure'])->name('care.specialty.ophthalmology.procedure');
|
||||
Route::get('/specialty/ophthalmology/workspace/{visit}/print', [OphthalmologyWorkspaceController::class, 'printSummary'])->name('care.specialty.ophthalmology.print');
|
||||
Route::get('/specialty/{module}', [SpecialtyModuleController::class, 'show'])->name('care.specialty.show');
|
||||
Route::post('/specialty/{module}/call-next', [SpecialtyModuleController::class, 'callNext'])->name('care.specialty.call-next');
|
||||
Route::post('/specialty/{module}/refer', [SpecialtyModuleController::class, 'refer'])->name('care.specialty.refer');
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Department;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Patient;
|
||||
use App\Models\SpecialtyClinicalRecord;
|
||||
use App\Models\User;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Care\SpecialtyModuleService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CareOphthalmologySuiteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $owner;
|
||||
|
||||
protected Organization $organization;
|
||||
|
||||
protected Branch $branch;
|
||||
|
||||
protected Patient $patient;
|
||||
|
||||
protected Visit $visit;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
|
||||
$this->owner = User::create([
|
||||
'public_id' => 'eye-owner',
|
||||
'name' => 'Owner',
|
||||
'email' => 'eye-owner@example.com',
|
||||
]);
|
||||
|
||||
$this->organization = Organization::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'name' => 'Eye Clinic',
|
||||
'slug' => 'eye-clinic',
|
||||
'settings' => [
|
||||
'onboarded' => true,
|
||||
'facility_type' => 'clinic',
|
||||
'plan' => 'pro',
|
||||
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||
'queue_integration_enabled' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
Member::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => $this->owner->public_id,
|
||||
'role' => 'hospital_admin',
|
||||
'branch_id' => null,
|
||||
]);
|
||||
|
||||
$this->branch = Branch::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Main',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
app(SpecialtyModuleService::class)->activate(
|
||||
$this->organization,
|
||||
$this->owner->public_id,
|
||||
'ophthalmology',
|
||||
);
|
||||
|
||||
$department = Department::query()
|
||||
->where('branch_id', $this->branch->id)
|
||||
->where('type', 'ophthalmology')
|
||||
->firstOrFail();
|
||||
|
||||
$this->patient = Patient::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_number' => 'P-EYE-SUITE',
|
||||
'first_name' => 'Ama',
|
||||
'last_name' => 'Mensah',
|
||||
'gender' => 'female',
|
||||
'date_of_birth' => '1990-05-12',
|
||||
]);
|
||||
|
||||
$this->visit = Visit::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $this->patient->id,
|
||||
'status' => Visit::STATUS_IN_PROGRESS,
|
||||
'checked_in_at' => now(),
|
||||
'specialty_stage' => 'check_in',
|
||||
]);
|
||||
|
||||
Appointment::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $this->patient->id,
|
||||
'department_id' => $department->id,
|
||||
'visit_id' => $this->visit->id,
|
||||
'type' => Appointment::TYPE_WALK_IN,
|
||||
'status' => Appointment::STATUS_IN_CONSULTATION,
|
||||
'scheduled_at' => now(),
|
||||
'waiting_at' => now(),
|
||||
'checked_in_at' => now(),
|
||||
'started_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_overview_and_refraction_tabs_render(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.specialty.workspace', [
|
||||
'module' => 'ophthalmology',
|
||||
'visit' => $this->visit,
|
||||
'tab' => 'overview',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('Eye care overview')
|
||||
->assertSee('Visit stage')
|
||||
->assertSee('Eye care reports');
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.specialty.workspace', [
|
||||
'module' => 'ophthalmology',
|
||||
'visit' => $this->visit,
|
||||
'tab' => 'refraction',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('Visual acuity OD')
|
||||
->assertSee('Sphere OD');
|
||||
}
|
||||
|
||||
public function test_exam_sets_stage_and_iop_alerts(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.specialty.clinical.save', [
|
||||
'module' => 'ophthalmology',
|
||||
'visit' => $this->visit,
|
||||
]), [
|
||||
'tab' => 'exam',
|
||||
'payload' => [
|
||||
'chief_complaint' => 'Blurry vision',
|
||||
'iop_od' => 32,
|
||||
'iop_os' => 18,
|
||||
'findings' => 'Elevated IOP OD',
|
||||
'va_od' => '6/60',
|
||||
],
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertSame('exam', $this->visit->fresh()->specialty_stage);
|
||||
|
||||
$record = SpecialtyClinicalRecord::query()
|
||||
->where('visit_id', $this->visit->id)
|
||||
->where('record_type', 'eye_exam')
|
||||
->firstOrFail();
|
||||
|
||||
$codes = collect($record->alerts)->pluck('code')->all();
|
||||
$this->assertContains('eye.critical_iop', $codes);
|
||||
$this->assertContains('eye.low_vision', $codes);
|
||||
}
|
||||
|
||||
public function test_stage_advance_and_procedure_completes_visit(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.specialty.ophthalmology.stage', $this->visit), [
|
||||
'stage' => 'treatment',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertSame('treatment', $this->visit->fresh()->specialty_stage);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.specialty.ophthalmology.procedure', $this->visit), [
|
||||
'tab' => 'treat',
|
||||
'payload' => [
|
||||
'procedure' => 'Foreign body removal',
|
||||
'eye' => 'OD',
|
||||
'outcome' => 'Completed uneventfully',
|
||||
'post_op_plan' => 'Antibiotic drops 5 days',
|
||||
],
|
||||
])
|
||||
->assertRedirect(route('care.specialty.workspace', [
|
||||
'module' => 'ophthalmology',
|
||||
'visit' => $this->visit,
|
||||
'tab' => 'treat',
|
||||
]));
|
||||
|
||||
$this->assertSame('completed', $this->visit->fresh()->specialty_stage);
|
||||
$this->assertSame(Visit::STATUS_COMPLETED, $this->visit->fresh()->status);
|
||||
$this->assertDatabaseHas('care_specialty_clinical_records', [
|
||||
'visit_id' => $this->visit->id,
|
||||
'record_type' => 'eye_procedure',
|
||||
'status' => SpecialtyClinicalRecord::STATUS_COMPLETED,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_reports_and_print(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.specialty.ophthalmology.reports'))
|
||||
->assertOk()
|
||||
->assertSee('Eye care reports')
|
||||
->assertSee('Arrivals today');
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.specialty.ophthalmology.print', $this->visit))
|
||||
->assertOk()
|
||||
->assertSee('Eye care summary')
|
||||
->assertSee($this->patient->fullName());
|
||||
}
|
||||
|
||||
public function test_list_index_does_not_auto_open_patient(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.specialty.show', 'ophthalmology'))
|
||||
->assertOk()
|
||||
->assertDontSee('Eye care overview');
|
||||
}
|
||||
}
|
||||
@@ -202,9 +202,11 @@ class CareSpecialtyClinicalTest extends TestCase
|
||||
->fieldsFor('ophthalmology', 'eye_exam');
|
||||
$names = collect($fields)->pluck('name')->all();
|
||||
|
||||
$this->assertContains('va_od', $names);
|
||||
$this->assertContains('iop_od', $names);
|
||||
$this->assertContains('iop_os', $names);
|
||||
$this->assertNotContains('notes', $names);
|
||||
$this->assertContains('findings', $names);
|
||||
$this->assertContains('chief_complaint', $names);
|
||||
$this->assertNotContains('working_diagnosis', $names);
|
||||
|
||||
[$visit] = $this->activateWithVisit('ophthalmology', 'ophthalmology');
|
||||
|
||||
@@ -215,7 +217,7 @@ class CareSpecialtyClinicalTest extends TestCase
|
||||
'tab' => 'exam',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('Visual acuity OD')
|
||||
->assertSee('Chief complaint')
|
||||
->assertSee('IOP OS');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user