Include checked-in clinic visits on outpatient nursing boards.
Deploy Ladill Care / deploy (push) Successful in 2m12s
Deploy Ladill Care / deploy (push) Successful in 2m12s
OPD/service units list open department appointments without manual place; nursing actions soft-place the visit onto the unit. Inpatient wards stay placement-only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Department;
|
|||||||
use App\Models\Visit;
|
use App\Models\Visit;
|
||||||
use App\Services\Care\AuditLogger;
|
use App\Services\Care\AuditLogger;
|
||||||
use App\Services\Care\CarePermissions;
|
use App\Services\Care\CarePermissions;
|
||||||
|
use App\Services\Care\CareUnitCensusService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
@@ -110,13 +111,8 @@ class CareUnitController extends Controller
|
|||||||
|
|
||||||
$careUnit->load(['department.branch', 'beds']);
|
$careUnit->load(['department.branch', 'beds']);
|
||||||
|
|
||||||
$placedVisits = Visit::owned($this->ownerRef($request))
|
$census = app(CareUnitCensusService::class);
|
||||||
->where('organization_id', $organization->id)
|
$placedVisits = $census->visitsForUnit($careUnit, $this->ownerRef($request));
|
||||||
->where('care_unit_id', $careUnit->id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->orderBy('placed_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$placeableVisits = Visit::owned($this->ownerRef($request))
|
$placeableVisits = Visit::owned($this->ownerRef($request))
|
||||||
->where('organization_id', $organization->id)
|
->where('organization_id', $organization->id)
|
||||||
@@ -126,6 +122,7 @@ class CareUnitController extends Controller
|
|||||||
$q->whereNull('care_unit_id')
|
$q->whereNull('care_unit_id')
|
||||||
->orWhere('care_unit_id', '!=', $careUnit->id);
|
->orWhere('care_unit_id', '!=', $careUnit->id);
|
||||||
})
|
})
|
||||||
|
->whereNotIn('id', $placedVisits->pluck('id')->all() ?: [0])
|
||||||
->with(['patient', 'careUnit'])
|
->with(['patient', 'careUnit'])
|
||||||
->orderByDesc('checked_in_at')
|
->orderByDesc('checked_in_at')
|
||||||
->limit(50)
|
->limit(50)
|
||||||
@@ -146,6 +143,7 @@ class CareUnitController extends Controller
|
|||||||
'placeableVisits' => $placeableVisits,
|
'placeableVisits' => $placeableVisits,
|
||||||
'availableBeds' => $availableBeds,
|
'availableBeds' => $availableBeds,
|
||||||
'canPlace' => $canPlace,
|
'canPlace' => $canPlace,
|
||||||
|
'isClinicUnit' => $census->isClinicUnit($careUnit),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Models\Visit;
|
|||||||
use App\Services\Care\AssessmentService;
|
use App\Services\Care\AssessmentService;
|
||||||
use App\Services\Care\CareFeatures;
|
use App\Services\Care\CareFeatures;
|
||||||
use App\Services\Care\CarePermissions;
|
use App\Services\Care\CarePermissions;
|
||||||
|
use App\Services\Care\CareUnitCensusService;
|
||||||
use App\Services\Care\NursingAssessmentService;
|
use App\Services\Care\NursingAssessmentService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -50,13 +51,16 @@ class NursingAssessmentController extends Controller
|
|||||||
Visit $visit,
|
Visit $visit,
|
||||||
AssessmentService $assessments,
|
AssessmentService $assessments,
|
||||||
CareFeatures $features,
|
CareFeatures $features,
|
||||||
|
CareUnitCensusService $census,
|
||||||
): RedirectResponse {
|
): RedirectResponse {
|
||||||
$this->authorizeAbility($request, 'nursing.assessments.manage');
|
$this->authorizeAbility($request, 'nursing.assessments.manage');
|
||||||
$this->authorizeOwner($request, $careUnit);
|
$this->authorizeOwner($request, $careUnit);
|
||||||
$this->authorizeOwner($request, $visit);
|
$this->authorizeOwner($request, $visit);
|
||||||
abort_unless((int) $visit->care_unit_id === (int) $careUnit->id, 404);
|
abort_unless((int) $careUnit->organization_id === (int) $this->organization($request)->id, 404);
|
||||||
abort_unless($features->enabled($this->organization($request), CareFeatures::ASSESSMENTS_ENGINE), 404);
|
abort_unless($features->enabled($this->organization($request), CareFeatures::ASSESSMENTS_ENGINE), 404);
|
||||||
|
|
||||||
|
$visit = $census->ensurePlaced($visit, $careUnit, $this->ownerRef($request), $this->actorRef($request));
|
||||||
|
|
||||||
$features->ensureAssessmentCatalog();
|
$features->ensureAssessmentCatalog();
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
@@ -84,11 +88,14 @@ class NursingAssessmentController extends Controller
|
|||||||
CareUnit $careUnit,
|
CareUnit $careUnit,
|
||||||
Visit $visit,
|
Visit $visit,
|
||||||
NursingAssessmentService $nursing,
|
NursingAssessmentService $nursing,
|
||||||
|
CareUnitCensusService $census,
|
||||||
): RedirectResponse {
|
): RedirectResponse {
|
||||||
$this->authorizeAbility($request, 'vitals.manage');
|
$this->authorizeAbility($request, 'vitals.manage');
|
||||||
$this->authorizeOwner($request, $careUnit);
|
$this->authorizeOwner($request, $careUnit);
|
||||||
$this->authorizeOwner($request, $visit);
|
$this->authorizeOwner($request, $visit);
|
||||||
abort_unless((int) $visit->care_unit_id === (int) $careUnit->id, 404);
|
abort_unless((int) $careUnit->organization_id === (int) $this->organization($request)->id, 404);
|
||||||
|
|
||||||
|
$visit = $census->ensurePlaced($visit, $careUnit, $this->ownerRef($request), $this->actorRef($request));
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'bp_systolic' => ['nullable', 'integer', 'min:40', 'max:300'],
|
'bp_systolic' => ['nullable', 'integer', 'min:40', 'max:300'],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Models\CareUnit;
|
|||||||
use App\Models\Visit;
|
use App\Models\Visit;
|
||||||
use App\Models\WardHandover;
|
use App\Models\WardHandover;
|
||||||
use App\Services\Care\CarePermissions;
|
use App\Services\Care\CarePermissions;
|
||||||
|
use App\Services\Care\CareUnitCensusService;
|
||||||
use App\Services\Care\NursingDocumentationService;
|
use App\Services\Care\NursingDocumentationService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -18,30 +19,23 @@ class NursingDocumentationController extends Controller
|
|||||||
{
|
{
|
||||||
use ScopesToAccount;
|
use ScopesToAccount;
|
||||||
|
|
||||||
public function unitNotes(Request $request, CareUnit $careUnit, NursingDocumentationService $docs): View
|
public function unitNotes(Request $request, CareUnit $careUnit, NursingDocumentationService $docs, CareUnitCensusService $census): View
|
||||||
{
|
{
|
||||||
$this->authorizeAbility($request, 'nursing.notes.view');
|
$this->authorizeAbility($request, 'nursing.notes.view');
|
||||||
$this->authorizeOwner($request, $careUnit);
|
$this->authorizeOwner($request, $careUnit);
|
||||||
abort_unless((int) $careUnit->organization_id === (int) $this->organization($request)->id, 404);
|
abort_unless((int) $careUnit->organization_id === (int) $this->organization($request)->id, 404);
|
||||||
|
|
||||||
$placedVisits = Visit::owned($this->ownerRef($request))
|
|
||||||
->where('care_unit_id', $careUnit->id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->orderBy('placed_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return view('care.nursing.notes', [
|
return view('care.nursing.notes', [
|
||||||
'unit' => $careUnit->load('department.branch'),
|
'unit' => $careUnit->load('department.branch'),
|
||||||
'notes' => $docs->notesForUnit($careUnit, $this->ownerRef($request)),
|
'notes' => $docs->notesForUnit($careUnit, $this->ownerRef($request)),
|
||||||
'placedVisits' => $placedVisits,
|
'placedVisits' => $census->visitsForUnit($careUnit, $this->ownerRef($request)),
|
||||||
'canWrite' => app(CarePermissions::class)->can($this->member($request), 'nursing.notes.manage'),
|
'canWrite' => app(CarePermissions::class)->can($this->member($request), 'nursing.notes.manage'),
|
||||||
'noteTypes' => config('care.nursing_note_types'),
|
'noteTypes' => config('care.nursing_note_types'),
|
||||||
'shiftCodes' => config('care.staff_shift_codes'),
|
'shiftCodes' => config('care.staff_shift_codes'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeNote(Request $request, CareUnit $careUnit, NursingDocumentationService $docs): RedirectResponse
|
public function storeNote(Request $request, CareUnit $careUnit, NursingDocumentationService $docs, CareUnitCensusService $census): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->authorizeAbility($request, 'nursing.notes.manage');
|
$this->authorizeAbility($request, 'nursing.notes.manage');
|
||||||
$this->authorizeOwner($request, $careUnit);
|
$this->authorizeOwner($request, $careUnit);
|
||||||
@@ -58,6 +52,8 @@ class NursingDocumentationController extends Controller
|
|||||||
->findOrFail($validated['visit_id']);
|
->findOrFail($validated['visit_id']);
|
||||||
$this->authorizeBranch($request, (int) $visit->branch_id);
|
$this->authorizeBranch($request, (int) $visit->branch_id);
|
||||||
|
|
||||||
|
$visit = $census->ensurePlaced($visit, $careUnit, $this->ownerRef($request), $this->actorRef($request));
|
||||||
|
|
||||||
$docs->addNote(
|
$docs->addNote(
|
||||||
$visit,
|
$visit,
|
||||||
$this->ownerRef($request),
|
$this->ownerRef($request),
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Care;
|
||||||
|
|
||||||
|
use App\Models\CareUnit;
|
||||||
|
use App\Models\Visit;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Who appears on a care unit’s nursing boards.
|
||||||
|
*
|
||||||
|
* Inpatient: visits placed on the unit.
|
||||||
|
* Outpatient / service: placed visits plus open clinic visits for the same
|
||||||
|
* department (checked-in appointments) so OPD nurses do not need manual place.
|
||||||
|
*/
|
||||||
|
class CareUnitCensusService
|
||||||
|
{
|
||||||
|
/** @var list<string> */
|
||||||
|
public const CLINIC_KINDS = ['outpatient', 'service'];
|
||||||
|
|
||||||
|
public function isClinicUnit(CareUnit $unit): bool
|
||||||
|
{
|
||||||
|
return in_array($unit->kind, self::CLINIC_KINDS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active visits nurses should see for this unit.
|
||||||
|
*
|
||||||
|
* @return Collection<int, Visit>
|
||||||
|
*/
|
||||||
|
public function visitsForUnit(CareUnit $unit, string $ownerRef): Collection
|
||||||
|
{
|
||||||
|
$unit->loadMissing('department');
|
||||||
|
|
||||||
|
return $this->queryForUnit($unit, $ownerRef)
|
||||||
|
->with(['patient', 'bed', 'appointment'])
|
||||||
|
->orderByRaw('care_unit_id is null') // placed first
|
||||||
|
->orderBy('placed_at')
|
||||||
|
->orderBy('checked_in_at')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function visitBelongsToUnit(Visit $visit, CareUnit $unit): bool
|
||||||
|
{
|
||||||
|
if ((int) $visit->organization_id !== (int) $unit->organization_id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! in_array($visit->status, [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS], true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int) $visit->care_unit_id === (int) $unit->id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->isClinicUnit($unit) || $visit->care_unit_id !== null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$unit->loadMissing('department');
|
||||||
|
$branchId = $unit->department?->branch_id;
|
||||||
|
if (! $branchId || (int) $visit->branch_id !== (int) $branchId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$departmentId = $unit->department_id;
|
||||||
|
if (! $departmentId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$appointment = $visit->relationLoaded('appointment')
|
||||||
|
? $visit->appointment
|
||||||
|
: $visit->appointment()->first();
|
||||||
|
|
||||||
|
return $appointment !== null && (int) $appointment->department_id === (int) $departmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Soft-place an eligible clinic visit onto the unit when a nurse acts on it.
|
||||||
|
*/
|
||||||
|
public function ensurePlaced(
|
||||||
|
Visit $visit,
|
||||||
|
CareUnit $unit,
|
||||||
|
string $ownerRef,
|
||||||
|
?string $actorRef = null,
|
||||||
|
): Visit {
|
||||||
|
$visit->refresh();
|
||||||
|
|
||||||
|
if ((int) $visit->care_unit_id === (int) $unit->id) {
|
||||||
|
return $visit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->visitBelongsToUnit($visit, $unit)) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($visit->care_unit_id !== null) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
app(VisitPlacementService::class)->place(
|
||||||
|
$visit,
|
||||||
|
$unit,
|
||||||
|
null,
|
||||||
|
$ownerRef,
|
||||||
|
$actorRef,
|
||||||
|
'Auto-placed from outpatient nursing board',
|
||||||
|
);
|
||||||
|
|
||||||
|
return $visit->fresh(['patient', 'bed', 'careUnit', 'appointment']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Builder<Visit>
|
||||||
|
*/
|
||||||
|
protected function queryForUnit(CareUnit $unit, string $ownerRef): Builder
|
||||||
|
{
|
||||||
|
$query = Visit::owned($ownerRef)
|
||||||
|
->where('organization_id', $unit->organization_id)
|
||||||
|
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS]);
|
||||||
|
|
||||||
|
if (! $this->isClinicUnit($unit)) {
|
||||||
|
return $query->where('care_unit_id', $unit->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$unit->loadMissing('department');
|
||||||
|
$branchId = $unit->department?->branch_id;
|
||||||
|
$departmentId = $unit->department_id;
|
||||||
|
|
||||||
|
return $query->where(function (Builder $q) use ($unit, $branchId, $departmentId) {
|
||||||
|
$q->where('care_unit_id', $unit->id);
|
||||||
|
|
||||||
|
if ($branchId && $departmentId) {
|
||||||
|
$q->orWhere(function (Builder $clinic) use ($branchId, $departmentId) {
|
||||||
|
$clinic->whereNull('care_unit_id')
|
||||||
|
->where('branch_id', $branchId)
|
||||||
|
->whereHas('appointment', fn (Builder $a) => $a->where('department_id', $departmentId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -101,12 +101,7 @@ class MarService
|
|||||||
{
|
{
|
||||||
$day = Carbon::parse($day ?? now())->startOfDay();
|
$day = Carbon::parse($day ?? now())->startOfDay();
|
||||||
|
|
||||||
$visits = Visit::owned($ownerRef)
|
$visits = app(CareUnitCensusService::class)->visitsForUnit($unit, $ownerRef);
|
||||||
->where('organization_id', $unit->organization_id)
|
|
||||||
->where('care_unit_id', $unit->id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
foreach ($visits as $visit) {
|
foreach ($visits as $visit) {
|
||||||
|
|||||||
@@ -100,9 +100,8 @@ class NursePerformanceService
|
|||||||
return [
|
return [
|
||||||
'from' => $from,
|
'from' => $from,
|
||||||
'to' => $to,
|
'to' => $to,
|
||||||
'placed_patients' => Visit::owned($ownerRef)
|
'placed_patients' => app(CareUnitCensusService::class)
|
||||||
->where('care_unit_id', $unit->id)
|
->visitsForUnit($unit, $ownerRef)
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->count(),
|
->count(),
|
||||||
'mar' => [
|
'mar' => [
|
||||||
'total' => $marTotal,
|
'total' => $marTotal,
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class NurseStationService
|
class NurseStationService
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected CareUnitCensusService $census,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{
|
* @return array{
|
||||||
* units: Collection<int, CareUnit>,
|
* units: Collection<int, CareUnit>,
|
||||||
@@ -89,13 +93,7 @@ class NurseStationService
|
|||||||
|
|
||||||
$patientsByUnit = [];
|
$patientsByUnit = [];
|
||||||
foreach ($ordered as $id => $unit) {
|
foreach ($ordered as $id => $unit) {
|
||||||
$patientsByUnit[$id] = Visit::owned($ownerRef)
|
$patientsByUnit[$id] = $this->census->visitsForUnit($unit, $ownerRef);
|
||||||
->where('organization_id', $organization->id)
|
|
||||||
->where('care_unit_id', $id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->orderBy('placed_at')
|
|
||||||
->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$dutyByUnit = [];
|
$dutyByUnit = [];
|
||||||
|
|||||||
@@ -48,12 +48,7 @@ class NursingAssessmentService
|
|||||||
public function unitBoard(CareUnit $unit, string $ownerRef): array
|
public function unitBoard(CareUnit $unit, string $ownerRef): array
|
||||||
{
|
{
|
||||||
$templates = $this->nursingTemplates();
|
$templates = $this->nursingTemplates();
|
||||||
$visits = Visit::owned($ownerRef)
|
$visits = app(CareUnitCensusService::class)->visitsForUnit($unit, $ownerRef);
|
||||||
->where('care_unit_id', $unit->id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->orderBy('placed_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
foreach ($visits as $visit) {
|
foreach ($visits as $visit) {
|
||||||
|
|||||||
@@ -148,12 +148,7 @@ class NursingDocumentationService
|
|||||||
*/
|
*/
|
||||||
public function defaultPatientSummaries(CareUnit $unit, string $ownerRef): array
|
public function defaultPatientSummaries(CareUnit $unit, string $ownerRef): array
|
||||||
{
|
{
|
||||||
$visits = Visit::owned($ownerRef)
|
$visits = app(CareUnitCensusService::class)->visitsForUnit($unit, $ownerRef);
|
||||||
->where('care_unit_id', $unit->id)
|
|
||||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
|
||||||
->with(['patient', 'bed'])
|
|
||||||
->orderBy('placed_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return $visits->map(fn (Visit $visit) => [
|
return $visits->map(fn (Visit $visit) => [
|
||||||
'visit_id' => $visit->id,
|
'visit_id' => $visit->id,
|
||||||
|
|||||||
@@ -69,9 +69,18 @@
|
|||||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-base font-semibold text-slate-900">Patients on this unit</h2>
|
<h2 class="text-base font-semibold text-slate-900">Patients on this unit</h2>
|
||||||
<p class="text-sm text-slate-500">Active visit placements — open MAR, notes, and handovers from the actions above.</p>
|
<p class="text-sm text-slate-500">
|
||||||
|
@if ($isClinicUnit ?? false)
|
||||||
|
Checked-in clinic visits for this department appear here automatically. Nursing actions attach them to the unit.
|
||||||
|
@else
|
||||||
|
Active visit placements — open MAR, notes, and handovers from the actions above.
|
||||||
|
@endif
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-sm font-medium text-slate-700">{{ $placedVisits->count() }} placed</p>
|
<p class="text-sm font-medium text-slate-700">
|
||||||
|
{{ $placedVisits->count() }}
|
||||||
|
{{ ($isClinicUnit ?? false) ? 'in clinic' : 'placed' }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 overflow-x-auto">
|
<div class="mt-4 overflow-x-auto">
|
||||||
@@ -80,7 +89,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="pb-2 pr-4">Patient</th>
|
<th class="pb-2 pr-4">Patient</th>
|
||||||
<th class="pb-2 pr-4">Bed</th>
|
<th class="pb-2 pr-4">Bed</th>
|
||||||
<th class="pb-2 pr-4">Placed</th>
|
<th class="pb-2 pr-4">{{ ($isClinicUnit ?? false) ? 'Checked in' : 'Placed' }}</th>
|
||||||
<th class="pb-2"></th>
|
<th class="pb-2"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -92,14 +101,19 @@
|
|||||||
@if ($visit->patient?->patient_number)
|
@if ($visit->patient?->patient_number)
|
||||||
<span class="text-xs text-slate-400">{{ $visit->patient->patient_number }}</span>
|
<span class="text-xs text-slate-400">{{ $visit->patient->patient_number }}</span>
|
||||||
@endif
|
@endif
|
||||||
|
@if (($isClinicUnit ?? false) && $visit->care_unit_id === null)
|
||||||
|
<span class="ml-1 rounded bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-amber-800">Clinic</span>
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td class="py-3 pr-4">{{ $visit->bed?->label ?? '—' }}</td>
|
<td class="py-3 pr-4">{{ $visit->bed?->label ?? '—' }}</td>
|
||||||
<td class="py-3 pr-4 whitespace-nowrap">{{ $visit->placed_at?->format('d M Y H:i') ?? '—' }}</td>
|
<td class="py-3 pr-4 whitespace-nowrap">
|
||||||
|
{{ ($visit->placed_at ?? $visit->checked_in_at)?->format('d M Y H:i') ?? '—' }}
|
||||||
|
</td>
|
||||||
<td class="py-3 text-right whitespace-nowrap">
|
<td class="py-3 text-right whitespace-nowrap">
|
||||||
@if ($canMar ?? false)
|
@if ($canMar ?? false)
|
||||||
<a href="{{ route('care.visits.mar', $visit) }}" class="mr-2 text-indigo-600 hover:text-indigo-800">MAR</a>
|
<a href="{{ route('care.visits.mar', $visit) }}" class="mr-2 text-indigo-600 hover:text-indigo-800">MAR</a>
|
||||||
@endif
|
@endif
|
||||||
@if ($canPlace)
|
@if ($canPlace && $visit->care_unit_id)
|
||||||
<form method="POST" action="{{ route('care.visits.placement.destroy', $visit) }}" class="inline" onsubmit="return confirm('Discharge placement and free the bed?')">
|
<form method="POST" action="{{ route('care.visits.placement.destroy', $visit) }}" class="inline" onsubmit="return confirm('Discharge placement and free the bed?')">
|
||||||
@csrf @method('DELETE')
|
@csrf @method('DELETE')
|
||||||
<button type="submit" class="text-red-600 hover:text-red-800">Discharge bed</button>
|
<button type="submit" class="text-red-600 hover:text-red-800">Discharge bed</button>
|
||||||
@@ -108,7 +122,15 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr><td colspan="4" class="py-4 text-slate-500">No patients placed on this unit.</td></tr>
|
<tr>
|
||||||
|
<td colspan="4" class="py-4 text-slate-500">
|
||||||
|
@if ($isClinicUnit ?? false)
|
||||||
|
No checked-in clinic visits for this department right now.
|
||||||
|
@else
|
||||||
|
No patients placed on this unit.
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -8,7 +8,13 @@
|
|||||||
Nursing assessments
|
Nursing assessments
|
||||||
</p>
|
</p>
|
||||||
<h1 class="mt-1 text-2xl font-semibold text-slate-900">Ward assessment board</h1>
|
<h1 class="mt-1 text-2xl font-semibold text-slate-900">Ward assessment board</h1>
|
||||||
<p class="mt-1 text-sm text-slate-500">NEWS2, Braden, Morse, pain, and visit vitals for placed patients.</p>
|
<p class="mt-1 text-sm text-slate-500">
|
||||||
|
@if (in_array($unit->kind, ['outpatient', 'service'], true))
|
||||||
|
NEWS2, Braden, Morse, pain, and visit vitals for checked-in clinic patients.
|
||||||
|
@else
|
||||||
|
NEWS2, Braden, Morse, pain, and visit vitals for placed patients.
|
||||||
|
@endif
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{ route('care.care-units.performance', $unit) }}" class="btn-secondary">Performance</a>
|
<a href="{{ route('care.care-units.performance', $unit) }}" class="btn-secondary">Performance</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="pb-2 pr-4">Patient</th>
|
<th class="pb-2 pr-4">Patient</th>
|
||||||
<th class="pb-2 pr-4">Bed</th>
|
<th class="pb-2 pr-4">Bed</th>
|
||||||
<th class="pb-2 pr-4">Placed</th>
|
<th class="pb-2 pr-4">{{ in_array($unit->kind, ['outpatient', 'service'], true) ? 'In clinic' : 'Placed' }}</th>
|
||||||
<th class="pb-2 text-right">Chart</th>
|
<th class="pb-2 text-right">Chart</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="py-3 pr-4 text-slate-600">{{ $visit->bed?->label ?? '—' }}</td>
|
<td class="py-3 pr-4 text-slate-600">{{ $visit->bed?->label ?? '—' }}</td>
|
||||||
<td class="py-3 pr-4 whitespace-nowrap text-slate-500">
|
<td class="py-3 pr-4 whitespace-nowrap text-slate-500">
|
||||||
{{ $visit->placed_at?->format('d M H:i') ?? '—' }}
|
{{ ($visit->placed_at ?? $visit->checked_in_at)?->format('d M H:i') ?? '—' }}
|
||||||
</td>
|
</td>
|
||||||
<td class="py-3 text-right whitespace-nowrap">
|
<td class="py-3 text-right whitespace-nowrap">
|
||||||
@if ($canMar)
|
@if ($canMar)
|
||||||
@@ -135,11 +135,12 @@
|
|||||||
@empty
|
@empty
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="py-10 text-center text-slate-500">
|
<td colspan="4" class="py-10 text-center text-slate-500">
|
||||||
No patients placed on this unit yet.
|
@if (in_array($unit->kind, ['outpatient', 'service'], true))
|
||||||
@if ($canServicesHub)
|
No checked-in clinic patients for this department right now.
|
||||||
Placements are managed from the care unit board.
|
@elseif ($canServicesHub)
|
||||||
|
No patients placed on this unit yet. Placements are managed from the care unit board.
|
||||||
@else
|
@else
|
||||||
Ask a charge nurse to place patients on this unit.
|
No patients placed on this unit yet. Ask a charge nurse to place patients on this unit.
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -0,0 +1,306 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Http\Middleware\EnsurePlatformSession;
|
||||||
|
use App\Models\Appointment;
|
||||||
|
use App\Models\Branch;
|
||||||
|
use App\Models\CareUnit;
|
||||||
|
use App\Models\Department;
|
||||||
|
use App\Models\Member;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\Patient;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Visit;
|
||||||
|
use App\Services\Care\CareFeatures;
|
||||||
|
use App\Services\Care\CareUnitCensusService;
|
||||||
|
use App\Services\Care\RosterService;
|
||||||
|
use Database\Seeders\AssessmentTemplateSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CareOutpatientCensusTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected User $owner;
|
||||||
|
|
||||||
|
protected Organization $organization;
|
||||||
|
|
||||||
|
protected Branch $branch;
|
||||||
|
|
||||||
|
protected Department $department;
|
||||||
|
|
||||||
|
protected CareUnit $opd;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||||
|
|
||||||
|
$this->owner = User::create([
|
||||||
|
'public_id' => 'opd-census-owner',
|
||||||
|
'name' => 'Owner',
|
||||||
|
'email' => 'opd-census-owner@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->organization = Organization::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'name' => 'OPD Clinic',
|
||||||
|
'slug' => 'opd-clinic',
|
||||||
|
'settings' => [
|
||||||
|
'onboarded' => true,
|
||||||
|
'facility_type' => 'hospital',
|
||||||
|
'plan' => 'pro',
|
||||||
|
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||||
|
'rollout' => [CareFeatures::ASSESSMENTS_ENGINE => true],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
Member::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'user_ref' => $this->owner->public_id,
|
||||||
|
'role' => 'hospital_admin',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->branch = Branch::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'name' => 'Tema Harbour Clinic',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->department = Department::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'name' => 'Outpatient',
|
||||||
|
'type' => 'outpatient',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->opd = CareUnit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'department_id' => $this->department->id,
|
||||||
|
'name' => 'OPD',
|
||||||
|
'kind' => 'outpatient',
|
||||||
|
'code' => 'OP',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_outpatient_board_includes_checked_in_department_visits_without_manual_place(): void
|
||||||
|
{
|
||||||
|
$patient = Patient::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_number' => 'P-OPD-1',
|
||||||
|
'first_name' => 'Yaw',
|
||||||
|
'last_name' => 'Adjei',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$visit = Visit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'status' => Visit::STATUS_IN_PROGRESS,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Appointment::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'department_id' => $this->department->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'visit_id' => $visit->id,
|
||||||
|
'type' => Appointment::TYPE_WALK_IN,
|
||||||
|
'status' => Appointment::STATUS_WAITING,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$otherDept = Department::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'name' => 'Dental',
|
||||||
|
'type' => 'dentistry',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
$otherPatient = Patient::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_number' => 'P-OPD-2',
|
||||||
|
'first_name' => 'Ama',
|
||||||
|
'last_name' => 'Other',
|
||||||
|
]);
|
||||||
|
$otherVisit = Visit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_id' => $otherPatient->id,
|
||||||
|
'status' => Visit::STATUS_OPEN,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
Appointment::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'department_id' => $otherDept->id,
|
||||||
|
'patient_id' => $otherPatient->id,
|
||||||
|
'visit_id' => $otherVisit->id,
|
||||||
|
'type' => Appointment::TYPE_WALK_IN,
|
||||||
|
'status' => Appointment::STATUS_WAITING,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$census = app(CareUnitCensusService::class);
|
||||||
|
$visits = $census->visitsForUnit($this->opd, $this->owner->public_id);
|
||||||
|
|
||||||
|
$this->assertTrue($census->isClinicUnit($this->opd));
|
||||||
|
$this->assertCount(1, $visits);
|
||||||
|
$this->assertTrue($visits->contains('id', $visit->id));
|
||||||
|
$this->assertFalse($visits->contains('id', $otherVisit->id));
|
||||||
|
|
||||||
|
$user = User::create([
|
||||||
|
'public_id' => 'opd-nurse',
|
||||||
|
'name' => 'OPD Nurse',
|
||||||
|
'email' => 'opd-nurse@example.com',
|
||||||
|
]);
|
||||||
|
$member = Member::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'user_ref' => $user->public_id,
|
||||||
|
'role' => 'nurse',
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$roster = app(RosterService::class);
|
||||||
|
$day = $roster->ensureDefaultShifts($this->organization, $this->owner->public_id)->firstWhere('code', 'day');
|
||||||
|
$roster->assign(
|
||||||
|
$this->opd,
|
||||||
|
$day,
|
||||||
|
$member,
|
||||||
|
now()->toDateString(),
|
||||||
|
$this->owner->public_id,
|
||||||
|
$this->owner->public_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->get(route('care.nursing.station', ['unit' => $this->opd->id]))
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Yaw Adjei')
|
||||||
|
->assertSee('In clinic')
|
||||||
|
->assertDontSee('Ama Other');
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->get(route('care.care-units.show', $this->opd))
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Yaw Adjei')
|
||||||
|
->assertSee('in clinic')
|
||||||
|
->assertSee('Clinic');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_nursing_action_auto_places_clinic_visit_onto_opd(): void
|
||||||
|
{
|
||||||
|
$this->seed(AssessmentTemplateSeeder::class);
|
||||||
|
|
||||||
|
$patient = Patient::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_number' => 'P-OPD-3',
|
||||||
|
'first_name' => 'Kofi',
|
||||||
|
'last_name' => 'Mensah',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$visit = Visit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'status' => Visit::STATUS_OPEN,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Appointment::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'department_id' => $this->department->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'visit_id' => $visit->id,
|
||||||
|
'type' => Appointment::TYPE_WALK_IN,
|
||||||
|
'status' => Appointment::STATUS_CHECKED_IN,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($this->owner)
|
||||||
|
->post(route('care.care-units.vitals.store', [$this->opd, $visit]), [
|
||||||
|
'pulse' => 78,
|
||||||
|
'spo2' => 98,
|
||||||
|
])
|
||||||
|
->assertRedirect(route('care.care-units.assessments', $this->opd));
|
||||||
|
|
||||||
|
$visit->refresh();
|
||||||
|
$this->assertSame($this->opd->id, (int) $visit->care_unit_id);
|
||||||
|
$this->assertNotNull($visit->placed_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_inpatient_unit_still_requires_placement(): void
|
||||||
|
{
|
||||||
|
$ward = CareUnit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'department_id' => $this->department->id,
|
||||||
|
'name' => 'Medical Ward',
|
||||||
|
'kind' => 'inpatient',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$patient = Patient::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_number' => 'P-WARD-X',
|
||||||
|
'first_name' => 'Efua',
|
||||||
|
'last_name' => 'Boateng',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$visit = Visit::create([
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'status' => Visit::STATUS_OPEN,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Appointment::create([
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'owner_ref' => $this->owner->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'branch_id' => $this->branch->id,
|
||||||
|
'department_id' => $this->department->id,
|
||||||
|
'patient_id' => $patient->id,
|
||||||
|
'visit_id' => $visit->id,
|
||||||
|
'type' => Appointment::TYPE_WALK_IN,
|
||||||
|
'status' => Appointment::STATUS_WAITING,
|
||||||
|
'checked_in_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$visits = app(CareUnitCensusService::class)->visitsForUnit($ward, $this->owner->public_id);
|
||||||
|
$this->assertCount(0, $visits);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user