diff --git a/app/Http/Controllers/Care/AssessmentController.php b/app/Http/Controllers/Care/AssessmentController.php index fe22fbd..bcad35d 100644 --- a/app/Http/Controllers/Care/AssessmentController.php +++ b/app/Http/Controllers/Care/AssessmentController.php @@ -59,6 +59,22 @@ class AssessmentController extends Controller ]); } + /** + * Consultation-scoped assessments list (same patient forms UI with return context). + * Supports GET /consultations/{uuid}/assessments — previously only POST existed. + */ + public function indexForConsultation(Request $request, Consultation $consultation): View + { + $this->authorizeConsultation($request, $consultation); + $consultation->loadMissing('patient'); + + $return = app(ConsultationReturnContext::class); + $return->remember($consultation); + $request->query->set(ConsultationReturnContext::QUERY_KEY, $consultation->uuid); + + return $this->index($request, $consultation->patient); + } + public function create(Request $request, Patient $patient): View { $this->assertEngineEnabled($request); diff --git a/resources/views/care/consultations/show.blade.php b/resources/views/care/consultations/show.blade.php index bf55321..ba470f5 100644 --- a/resources/views/care/consultations/show.blade.php +++ b/resources/views/care/consultations/show.blade.php @@ -202,7 +202,7 @@

Clinical forms this visit

- All patient forms + All patient forms
@if (($consultationAssessments ?? collect())->isNotEmpty()) diff --git a/routes/web.php b/routes/web.php index 43499d4..6549598 100644 --- a/routes/web.php +++ b/routes/web.php @@ -219,6 +219,7 @@ Route::middleware(['auth', 'platform.session'])->group(function () { Route::get('/patients/{patient}/assessments', [AssessmentController::class, 'index'])->name('care.assessments.index'); Route::get('/patients/{patient}/assessments/create', [AssessmentController::class, 'create'])->name('care.assessments.create'); Route::post('/patients/{patient}/assessments', [AssessmentController::class, 'store'])->name('care.assessments.store'); + Route::get('/consultations/{consultation}/assessments', [AssessmentController::class, 'indexForConsultation'])->name('care.consultations.assessments.index'); Route::post('/consultations/{consultation}/assessments', [AssessmentController::class, 'storeForConsultation'])->name('care.consultations.assessments.store'); Route::get('/assessments/{assessment}', [AssessmentController::class, 'show'])->name('care.assessments.show'); Route::put('/assessments/{assessment}', [AssessmentController::class, 'update'])->name('care.assessments.update'); diff --git a/tests/Feature/CareAssessmentCaptureTest.php b/tests/Feature/CareAssessmentCaptureTest.php index c43b8a2..0cbe1d2 100644 --- a/tests/Feature/CareAssessmentCaptureTest.php +++ b/tests/Feature/CareAssessmentCaptureTest.php @@ -11,6 +11,7 @@ use App\Models\Consultation; use App\Models\Member; use App\Models\Organization; use App\Models\Patient; +use App\Models\Practitioner; use App\Models\User; use App\Models\Visit; use App\Services\Care\CareFeatures; @@ -60,17 +61,30 @@ class CareAssessmentCaptureTest extends TestCase ], ]); + $this->branch = Branch::create([ + 'owner_ref' => $this->user->public_id, + 'organization_id' => $this->organization->id, + 'name' => 'Main', + 'is_active' => true, + ]); + $this->member = Member::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->user->public_id, 'role' => 'doctor', + 'branch_id' => $this->branch->id, ]); - $this->branch = Branch::create([ + // Doctors are branch-scoped via linked practitioner desks. + Practitioner::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, - 'name' => 'Main', + 'branch_id' => $this->branch->id, + 'member_id' => $this->member->id, + 'user_ref' => $this->user->public_id, + 'name' => 'Dr Capture', + 'specialty' => 'General Practice', 'is_active' => true, ]); @@ -320,6 +334,39 @@ class CareAssessmentCaptureTest extends TestCase $this->assertDatabaseHas('care_audit_logs', ['action' => 'assessment.cancelled']); } + public function test_doctor_can_view_consultation_scoped_assessments_index(): void + { + $this->setMemberRole('doctor'); + + $visit = Visit::create([ + 'owner_ref' => $this->user->public_id, + 'organization_id' => $this->organization->id, + 'branch_id' => $this->branch->id, + 'patient_id' => $this->patient->id, + 'status' => Visit::STATUS_OPEN, + 'checked_in_at' => now(), + ]); + + $consultation = Consultation::create([ + 'owner_ref' => $this->user->public_id, + 'visit_id' => $visit->id, + 'patient_id' => $this->patient->id, + 'status' => Consultation::STATUS_DRAFT, + 'started_at' => now(), + ]); + + $this->actingAs($this->user) + ->get(route('care.consultations.assessments.index', $consultation)) + ->assertOk() + ->assertSee('Clinical assessments') + ->assertSee($this->patient->fullName()); + + // Path shape matches care.ladill.com/consultations/{uuid}/assessments + $this->actingAs($this->user) + ->get('/consultations/'.$consultation->uuid.'/assessments') + ->assertOk(); + } + public function test_consultation_scoped_start_links_consultation_and_visit(): void { $this->setMemberRole('doctor');