Add full Pediatrics, Orthopedics, and ENT specialty clinical suites.
Deploy Ladill Care / deploy (push) Successful in 43s

Mirror Cardiology-depth stage flows, workspace tabs, reports/print, clinical
alerts, demo seeds, and PHPUnit coverage for child health, fracture clinic,
and ENT pathways.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-19 19:12:38 +00:00
co-authored by Cursor
parent 8e23cdeae3
commit dc86b51ed5
36 changed files with 4021 additions and 38 deletions
@@ -0,0 +1,215 @@
<?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\Ent\EntAnalyticsService;
use App\Services\Care\Ent\EntWorkflowService;
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 EntWorkspaceController extends Controller
{
use ScopesToAccount;
protected function assertEntAccess(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanAccess($organization, $this->member($request), 'ent'), 403);
}
protected function assertEntManage(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanManage($organization, $this->member($request), 'ent'), 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,
SpecialtyShellService $shell,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertEntManage($request, $modules);
$this->assertVisit($request, $visit);
$validated = $request->validate([
'stage' => ['required', 'string', 'max:32'],
]);
try {
$stages->setStage(
$this->organization($request),
$visit,
'ent',
$validated['stage'],
$this->ownerRef($request),
$this->actorRef($request),
);
} catch (\InvalidArgumentException $e) {
return back()->with('error', $e->getMessage());
}
return redirect()
->route('care.specialty.workspace', [
'module' => 'ent',
'visit' => $visit,
'tab' => $shell->workspaceTabForStage('ent', $validated['stage']),
])
->with('success', 'Visit stage updated.');
}
public function saveProcedure(
Request $request,
Visit $visit,
SpecialtyModuleService $modules,
SpecialtyClinicalRecordService $clinical,
SpecialtyVisitStageService $stages,
EntWorkflowService $workflow,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertEntManage($request, $modules);
$this->assertVisit($request, $visit);
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$payload = (array) $request->input('payload', []);
foreach ($clinical->fieldsFor('ent', 'ent_procedure') as $field) {
if (($field['type'] ?? '') === 'boolean') {
$payload[$field['name']] = $request->boolean('payload.'.$field['name']);
}
}
$request->merge(['payload' => $payload, 'tab' => 'procedure']);
$validated = $request->validate(array_merge([
'tab' => ['required', 'string'],
], $clinical->validationRules('ent', 'ent_procedure')));
$record = $clinical->upsert(
$organization,
$visit,
'ent',
'ent_procedure',
$clinical->payloadFromRequest($validated),
$owner,
$owner,
EntWorkflowService::STAGE_PROCEDURE,
SpecialtyClinicalRecord::STATUS_COMPLETED,
);
try {
$stages->setStage(
$organization,
$visit,
'ent',
EntWorkflowService::STAGE_PROCEDURE,
$owner,
$owner,
);
} catch (\InvalidArgumentException) {
}
if ($workflow->shouldCompleteVisit($record->payload ?? [])) {
try {
$stages->setStage(
$organization,
$visit,
'ent',
EntWorkflowService::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' => 'ent', 'visit' => $visit, 'tab' => 'procedure'])
->with('success', 'ENT procedure saved.');
}
public function reports(
Request $request,
SpecialtyModuleService $modules,
SpecialtyShellService $shell,
EntAnalyticsService $analytics,
): View {
$this->authorizeAbility($request, 'consultations.view');
$this->assertEntAccess($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.ent.reports', [
'moduleKey' => 'ent',
'definition' => $modules->definition('ent'),
'shellNav' => $shell->navItems('ent'),
'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->assertEntAccess($request, $modules);
$this->assertVisit($request, $visit);
$visit->loadMissing(['patient', 'appointment.practitioner', 'branch']);
return view('care.specialty.ent.print', [
'visit' => $visit,
'patient' => $visit->patient,
'history' => $clinical->findForVisit($visit, 'ent', 'ent_history'),
'exam' => $clinical->findForVisit($visit, 'ent', 'ent_exam'),
'investigation' => $clinical->findForVisit($visit, 'ent', 'ent_investigation'),
'plan' => $clinical->findForVisit($visit, 'ent', 'ent_plan'),
'procedure' => $clinical->findForVisit($visit, 'ent', 'ent_procedure'),
]);
}
}
@@ -0,0 +1,215 @@
<?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\Orthopedics\OrthopedicsAnalyticsService;
use App\Services\Care\Orthopedics\OrthopedicsWorkflowService;
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 OrthopedicsWorkspaceController extends Controller
{
use ScopesToAccount;
protected function assertOrthopedicsAccess(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanAccess($organization, $this->member($request), 'orthopedics'), 403);
}
protected function assertOrthopedicsManage(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanManage($organization, $this->member($request), 'orthopedics'), 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,
SpecialtyShellService $shell,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertOrthopedicsManage($request, $modules);
$this->assertVisit($request, $visit);
$validated = $request->validate([
'stage' => ['required', 'string', 'max:32'],
]);
try {
$stages->setStage(
$this->organization($request),
$visit,
'orthopedics',
$validated['stage'],
$this->ownerRef($request),
$this->actorRef($request),
);
} catch (\InvalidArgumentException $e) {
return back()->with('error', $e->getMessage());
}
return redirect()
->route('care.specialty.workspace', [
'module' => 'orthopedics',
'visit' => $visit,
'tab' => $shell->workspaceTabForStage('orthopedics', $validated['stage']),
])
->with('success', 'Visit stage updated.');
}
public function saveProcedure(
Request $request,
Visit $visit,
SpecialtyModuleService $modules,
SpecialtyClinicalRecordService $clinical,
SpecialtyVisitStageService $stages,
OrthopedicsWorkflowService $workflow,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertOrthopedicsManage($request, $modules);
$this->assertVisit($request, $visit);
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$payload = (array) $request->input('payload', []);
foreach ($clinical->fieldsFor('orthopedics', 'ortho_procedure') as $field) {
if (($field['type'] ?? '') === 'boolean') {
$payload[$field['name']] = $request->boolean('payload.'.$field['name']);
}
}
$request->merge(['payload' => $payload, 'tab' => 'procedure']);
$validated = $request->validate(array_merge([
'tab' => ['required', 'string'],
], $clinical->validationRules('orthopedics', 'ortho_procedure')));
$record = $clinical->upsert(
$organization,
$visit,
'orthopedics',
'ortho_procedure',
$clinical->payloadFromRequest($validated),
$owner,
$owner,
OrthopedicsWorkflowService::STAGE_PROCEDURE,
SpecialtyClinicalRecord::STATUS_COMPLETED,
);
try {
$stages->setStage(
$organization,
$visit,
'orthopedics',
OrthopedicsWorkflowService::STAGE_PROCEDURE,
$owner,
$owner,
);
} catch (\InvalidArgumentException) {
}
if ($workflow->shouldCompleteVisit($record->payload ?? [])) {
try {
$stages->setStage(
$organization,
$visit,
'orthopedics',
OrthopedicsWorkflowService::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' => 'orthopedics', 'visit' => $visit, 'tab' => 'procedure'])
->with('success', 'Procedure / cast saved.');
}
public function reports(
Request $request,
SpecialtyModuleService $modules,
SpecialtyShellService $shell,
OrthopedicsAnalyticsService $analytics,
): View {
$this->authorizeAbility($request, 'consultations.view');
$this->assertOrthopedicsAccess($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.orthopedics.reports', [
'moduleKey' => 'orthopedics',
'definition' => $modules->definition('orthopedics'),
'shellNav' => $shell->navItems('orthopedics'),
'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->assertOrthopedicsAccess($request, $modules);
$this->assertVisit($request, $visit);
$visit->loadMissing(['patient', 'appointment.practitioner', 'branch']);
return view('care.specialty.orthopedics.print', [
'visit' => $visit,
'patient' => $visit->patient,
'history' => $clinical->findForVisit($visit, 'orthopedics', 'ortho_history'),
'exam' => $clinical->findForVisit($visit, 'orthopedics', 'ortho_exam'),
'imaging' => $clinical->findForVisit($visit, 'orthopedics', 'ortho_imaging'),
'plan' => $clinical->findForVisit($visit, 'orthopedics', 'ortho_plan'),
'procedure' => $clinical->findForVisit($visit, 'orthopedics', 'ortho_procedure'),
]);
}
}
@@ -0,0 +1,215 @@
<?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\Pediatrics\PediatricsAnalyticsService;
use App\Services\Care\Pediatrics\PediatricsWorkflowService;
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 PediatricsWorkspaceController extends Controller
{
use ScopesToAccount;
protected function assertPediatricsAccess(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanAccess($organization, $this->member($request), 'pediatrics'), 403);
}
protected function assertPediatricsManage(Request $request, SpecialtyModuleService $modules): void
{
$organization = $this->organization($request);
abort_unless($modules->memberCanManage($organization, $this->member($request), 'pediatrics'), 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,
SpecialtyShellService $shell,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertPediatricsManage($request, $modules);
$this->assertVisit($request, $visit);
$validated = $request->validate([
'stage' => ['required', 'string', 'max:32'],
]);
try {
$stages->setStage(
$this->organization($request),
$visit,
'pediatrics',
$validated['stage'],
$this->ownerRef($request),
$this->actorRef($request),
);
} catch (\InvalidArgumentException $e) {
return back()->with('error', $e->getMessage());
}
return redirect()
->route('care.specialty.workspace', [
'module' => 'pediatrics',
'visit' => $visit,
'tab' => $shell->workspaceTabForStage('pediatrics', $validated['stage']),
])
->with('success', 'Visit stage updated.');
}
public function saveTreatment(
Request $request,
Visit $visit,
SpecialtyModuleService $modules,
SpecialtyClinicalRecordService $clinical,
SpecialtyVisitStageService $stages,
PediatricsWorkflowService $workflow,
): RedirectResponse {
$this->authorizeAbility($request, 'consultations.manage');
$this->assertPediatricsManage($request, $modules);
$this->assertVisit($request, $visit);
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$payload = (array) $request->input('payload', []);
foreach ($clinical->fieldsFor('pediatrics', 'ped_treatment') as $field) {
if (($field['type'] ?? '') === 'boolean') {
$payload[$field['name']] = $request->boolean('payload.'.$field['name']);
}
}
$request->merge(['payload' => $payload, 'tab' => 'treatment']);
$validated = $request->validate(array_merge([
'tab' => ['required', 'string'],
], $clinical->validationRules('pediatrics', 'ped_treatment')));
$record = $clinical->upsert(
$organization,
$visit,
'pediatrics',
'ped_treatment',
$clinical->payloadFromRequest($validated),
$owner,
$owner,
PediatricsWorkflowService::STAGE_TREATMENT,
SpecialtyClinicalRecord::STATUS_COMPLETED,
);
try {
$stages->setStage(
$organization,
$visit,
'pediatrics',
PediatricsWorkflowService::STAGE_TREATMENT,
$owner,
$owner,
);
} catch (\InvalidArgumentException) {
}
if ($workflow->shouldCompleteVisit($record->payload ?? [])) {
try {
$stages->setStage(
$organization,
$visit,
'pediatrics',
PediatricsWorkflowService::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' => 'pediatrics', 'visit' => $visit, 'tab' => 'treatment'])
->with('success', 'Treatment / immunization saved.');
}
public function reports(
Request $request,
SpecialtyModuleService $modules,
SpecialtyShellService $shell,
PediatricsAnalyticsService $analytics,
): View {
$this->authorizeAbility($request, 'consultations.view');
$this->assertPediatricsAccess($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.pediatrics.reports', [
'moduleKey' => 'pediatrics',
'definition' => $modules->definition('pediatrics'),
'shellNav' => $shell->navItems('pediatrics'),
'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->assertPediatricsAccess($request, $modules);
$this->assertVisit($request, $visit);
$visit->loadMissing(['patient', 'appointment.practitioner', 'branch']);
return view('care.specialty.pediatrics.print', [
'visit' => $visit,
'patient' => $visit->patient,
'history' => $clinical->findForVisit($visit, 'pediatrics', 'ped_history'),
'exam' => $clinical->findForVisit($visit, 'pediatrics', 'pediatric_exam'),
'investigation' => $clinical->findForVisit($visit, 'pediatrics', 'ped_investigation'),
'plan' => $clinical->findForVisit($visit, 'pediatrics', 'ped_plan'),
'treatment' => $clinical->findForVisit($visit, 'pediatrics', 'ped_treatment'),
]);
}
}
@@ -159,6 +159,9 @@ class SpecialtyModuleController extends Controller
'radiology' => 'protocol',
'cardiology' => 'history',
'psychiatry' => 'history',
'pediatrics' => 'history',
'orthopedics' => 'history',
'ent' => 'history',
default => (collect(array_keys($shellTabs))
->first(fn (string $tab) => $clinical->recordTypeForTab($module, $tab) !== null)
?? 'clinical_notes'),
@@ -236,6 +239,9 @@ class SpecialtyModuleController extends Controller
'radiology' => 'protocol',
'cardiology' => 'history',
'psychiatry' => 'history',
'pediatrics' => 'history',
'orthopedics' => 'history',
'ent' => 'history',
default => (collect(array_keys($shellTabs))
->first(fn (string $tab) => $clinical->recordTypeForTab($module, $tab) !== null)
?? 'clinical_notes'),
@@ -656,6 +662,150 @@ class SpecialtyModuleController extends Controller
}
}
if ($module === 'pediatrics' && in_array($recordType, ['ped_history', 'pediatric_exam', 'ped_investigation', 'ped_plan'], true)) {
$workflow = app(\App\Services\Care\Pediatrics\PediatricsWorkflowService::class);
$stageService = app(\App\Services\Care\SpecialtyVisitStageService::class);
$suggested = match ($recordType) {
'ped_history' => $workflow->stageFromHistory($record->payload ?? []),
'pediatric_exam' => $workflow->stageFromExam($record->payload ?? []),
'ped_investigation' => $workflow->stageFromInvestigation($record->payload ?? []),
'ped_plan' => $workflow->stageFromPlan($record->payload ?? []),
default => null,
};
$current = $visit->specialty_stage;
$early = ['check_in', 'waiting', null, ''];
$order = [
'check_in' => 0,
'history' => 1,
'exam' => 2,
'investigation' => 3,
'plan' => 4,
'treatment' => 5,
'completed' => 6,
];
if ($suggested && (! $current || in_array($current, $early, true))) {
try {
$stageService->setStage(
$organization,
$visit,
'pediatrics',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
} elseif ($suggested && $suggested !== $current && ($order[$suggested] ?? 0) > ($order[$current] ?? 0)) {
try {
$stageService->setStage(
$organization,
$visit,
'pediatrics',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
}
}
if ($module === 'orthopedics' && in_array($recordType, ['ortho_history', 'ortho_exam', 'ortho_imaging', 'ortho_plan'], true)) {
$workflow = app(\App\Services\Care\Orthopedics\OrthopedicsWorkflowService::class);
$stageService = app(\App\Services\Care\SpecialtyVisitStageService::class);
$suggested = match ($recordType) {
'ortho_history' => $workflow->stageFromHistory($record->payload ?? []),
'ortho_exam' => $workflow->stageFromExam($record->payload ?? []),
'ortho_imaging' => $workflow->stageFromImaging($record->payload ?? []),
'ortho_plan' => $workflow->stageFromPlan($record->payload ?? []),
default => null,
};
$current = $visit->specialty_stage;
$early = ['check_in', 'waiting', null, ''];
$order = [
'check_in' => 0,
'history' => 1,
'exam' => 2,
'imaging' => 3,
'plan' => 4,
'procedure' => 5,
'completed' => 6,
];
if ($suggested && (! $current || in_array($current, $early, true))) {
try {
$stageService->setStage(
$organization,
$visit,
'orthopedics',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
} elseif ($suggested && $suggested !== $current && ($order[$suggested] ?? 0) > ($order[$current] ?? 0)) {
try {
$stageService->setStage(
$organization,
$visit,
'orthopedics',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
}
}
if ($module === 'ent' && in_array($recordType, ['ent_history', 'ent_exam', 'ent_investigation', 'ent_plan'], true)) {
$workflow = app(\App\Services\Care\Ent\EntWorkflowService::class);
$stageService = app(\App\Services\Care\SpecialtyVisitStageService::class);
$suggested = match ($recordType) {
'ent_history' => $workflow->stageFromHistory($record->payload ?? []),
'ent_exam' => $workflow->stageFromExam($record->payload ?? []),
'ent_investigation' => $workflow->stageFromInvestigation($record->payload ?? []),
'ent_plan' => $workflow->stageFromPlan($record->payload ?? []),
default => null,
};
$current = $visit->specialty_stage;
$early = ['check_in', 'waiting', null, ''];
$order = [
'check_in' => 0,
'history' => 1,
'exam' => 2,
'investigation' => 3,
'plan' => 4,
'procedure' => 5,
'completed' => 6,
];
if ($suggested && (! $current || in_array($current, $early, true))) {
try {
$stageService->setStage(
$organization,
$visit,
'ent',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
} elseif ($suggested && $suggested !== $current && ($order[$suggested] ?? 0) > ($order[$current] ?? 0)) {
try {
$stageService->setStage(
$organization,
$visit,
'ent',
$suggested,
$this->ownerRef($request),
$this->ownerRef($request),
);
} catch (\InvalidArgumentException) {
}
}
}
return redirect()
->route('care.specialty.workspace', [
'module' => $module,
@@ -1091,6 +1241,27 @@ class SpecialtyModuleController extends Controller
$psychiatryFollowup = null;
$psychiatryStageCodes = [];
$psychiatryStageFlow = [];
$pediatricsHistory = null;
$pediatricsExam = null;
$pediatricsInvestigation = null;
$pediatricsPlan = null;
$pediatricsTreatment = null;
$pediatricsStageCodes = [];
$pediatricsStageFlow = [];
$orthopedicsHistory = null;
$orthopedicsExam = null;
$orthopedicsImaging = null;
$orthopedicsPlan = null;
$orthopedicsProcedure = null;
$orthopedicsStageCodes = [];
$orthopedicsStageFlow = [];
$entHistory = null;
$entExam = null;
$entInvestigation = null;
$entPlan = null;
$entProcedure = null;
$entStageCodes = [];
$entStageFlow = [];
$activeTab = (string) $request->query('tab', array_key_first($shell->workspaceTabs($module)) ?: 'overview');
$clinical = app(SpecialtyClinicalRecordService::class);
@@ -1255,6 +1426,36 @@ class SpecialtyModuleController extends Controller
$psychiatryStageFlow = app(\App\Services\Care\Psychiatry\PsychiatryWorkflowService::class)->stageFlow();
}
if ($module === 'pediatrics') {
$pediatricsHistory = $clinical->findForVisit($workspaceVisit, 'pediatrics', 'ped_history');
$pediatricsExam = $clinical->findForVisit($workspaceVisit, 'pediatrics', 'pediatric_exam');
$pediatricsInvestigation = $clinical->findForVisit($workspaceVisit, 'pediatrics', 'ped_investigation');
$pediatricsPlan = $clinical->findForVisit($workspaceVisit, 'pediatrics', 'ped_plan');
$pediatricsTreatment = $clinical->findForVisit($workspaceVisit, 'pediatrics', 'ped_treatment');
$pediatricsStageCodes = collect($shell->stages('pediatrics'))->pluck('code')->all();
$pediatricsStageFlow = app(\App\Services\Care\Pediatrics\PediatricsWorkflowService::class)->stageFlow();
}
if ($module === 'orthopedics') {
$orthopedicsHistory = $clinical->findForVisit($workspaceVisit, 'orthopedics', 'ortho_history');
$orthopedicsExam = $clinical->findForVisit($workspaceVisit, 'orthopedics', 'ortho_exam');
$orthopedicsImaging = $clinical->findForVisit($workspaceVisit, 'orthopedics', 'ortho_imaging');
$orthopedicsPlan = $clinical->findForVisit($workspaceVisit, 'orthopedics', 'ortho_plan');
$orthopedicsProcedure = $clinical->findForVisit($workspaceVisit, 'orthopedics', 'ortho_procedure');
$orthopedicsStageCodes = collect($shell->stages('orthopedics'))->pluck('code')->all();
$orthopedicsStageFlow = app(\App\Services\Care\Orthopedics\OrthopedicsWorkflowService::class)->stageFlow();
}
if ($module === 'ent') {
$entHistory = $clinical->findForVisit($workspaceVisit, 'ent', 'ent_history');
$entExam = $clinical->findForVisit($workspaceVisit, 'ent', 'ent_exam');
$entInvestigation = $clinical->findForVisit($workspaceVisit, 'ent', 'ent_investigation');
$entPlan = $clinical->findForVisit($workspaceVisit, 'ent', 'ent_plan');
$entProcedure = $clinical->findForVisit($workspaceVisit, 'ent', 'ent_procedure');
$entStageCodes = collect($shell->stages('ent'))->pluck('code')->all();
$entStageFlow = app(\App\Services\Care\Ent\EntWorkflowService::class)->stageFlow();
}
if ($patientHeader !== null) {
$patientHeader['clinical_alerts'] = $clinicalAlerts;
}
@@ -1382,6 +1583,27 @@ class SpecialtyModuleController extends Controller
'psychiatryFollowup' => $psychiatryFollowup,
'psychiatryStageCodes' => $psychiatryStageCodes,
'psychiatryStageFlow' => $psychiatryStageFlow,
'pediatricsHistory' => $pediatricsHistory,
'pediatricsExam' => $pediatricsExam,
'pediatricsInvestigation' => $pediatricsInvestigation,
'pediatricsPlan' => $pediatricsPlan,
'pediatricsTreatment' => $pediatricsTreatment,
'pediatricsStageCodes' => $pediatricsStageCodes,
'pediatricsStageFlow' => $pediatricsStageFlow,
'orthopedicsHistory' => $orthopedicsHistory,
'orthopedicsExam' => $orthopedicsExam,
'orthopedicsImaging' => $orthopedicsImaging,
'orthopedicsPlan' => $orthopedicsPlan,
'orthopedicsProcedure' => $orthopedicsProcedure,
'orthopedicsStageCodes' => $orthopedicsStageCodes,
'orthopedicsStageFlow' => $orthopedicsStageFlow,
'entHistory' => $entHistory,
'entExam' => $entExam,
'entInvestigation' => $entInvestigation,
'entPlan' => $entPlan,
'entProcedure' => $entProcedure,
'entStageCodes' => $entStageCodes,
'entStageFlow' => $entStageFlow,
'queueStubs' => $modules->queueStubsFor($organization, $module),
'branchId' => $branchId,
'branchLabel' => $branchLabel,