@extends('layouts.master')
@section('title', $title)
@section('page_css')
@endsection
@section('content')
@php
$ppPatientLine = collect([$patient->name, 'ID ' . $patient->patient_id, ucfirst((string) $patient->gender) ?: null, $age, $patient->phone])->filter()->implode(' · ');
$fmt = fn ($d) => $d ? \Carbon\Carbon::parse($d)->format('d M, Y') : '-';
$money = fn ($v) => '$ ' . number_format((float) $v, 2);
$female = strtolower((string) $patient->gender) === 'female';
$kinds = [
'visit' => ['Visit', 'ti-stethoscope', 'primary'],
'admission' => ['Admission', 'ti-bed', 'warning'],
'emergency' => ['Emergency', 'ti-ambulance', 'danger'],
];
$balancePill = function ($m) use ($money) {
if (!$m) return '';
if ($m['balance'] > 0.009) return 'Owes ' . $money($m['balance']) . '';
return 'Paid';
};
@endphp
{{-- ===== Who the patient is + what you can do ===== --}}
{{-- History: everything, newest first --}}
@if ($show['history'])
Everything that happened to this patient, newest first. Click Open to manage it, Record to see all of its information on one page.
@if ($timeline->isEmpty())
No visits, admissions or emergencies yet.
@else
@foreach ($timeline as $t)
@php [$kLabel, $kIcon, $kColor] = $kinds[$t['kind']]; $it = $t['item']; @endphp
{{ $kLabel }} {{ $fmt($t['date']) }}
{{ $t['title'] }}
@if ($t['sub'])
{{ $t['sub'] }}
@endif
@if ($canFinancial){!! $balancePill($it['money'] ?? null) !!}@endif
@if (!empty($it['record']))
Record@endif
@if (!empty($it['open']))
Open@endif
@endforeach
@endif
@endif
{{-- Visits --}}
@if ($show['visits'])
| Date | No. | Doctor / department | Type | Complaint / diagnosis | Seen |
@if ($canFinancial)Charge | Balance | @endif |
@forelse ($visits as $v)
| {{ $fmt($v['date']) }} |
#{{ $v['no'] }} |
{{ $v['doctor'] ?? '-' }} {{ $v['department'] }} |
{{ $v['type'] ?? '-' }} |
{{ $v['diagnosis'] ?: ($v['complaint'] ?: '-') }} |
{{ $v['entry'] === 'Entered' ? 'Seen' : 'Not seen' }} |
@if ($canFinancial)
{{ $v['money'] ? $money($v['money']['charge']) : '-' }} |
{!! $balancePill($v['money']) ?: '-' !!} |
@endif
@if ($v['record']) Record@endif
@if ($v['open']) Open@endif
|
@empty
| No visits yet. |
@endforelse
@endif
{{-- Admissions --}}
@if ($show['admissions'])
| No. | Admitted | Discharged | Days | Doctor | Room / bed | Status |
@if ($canFinancial)Charge | Balance | @endif |
@forelse ($admissions as $a)
| #{{ $a['no'] }} |
{{ $fmt($a['date_in']) }} |
{{ $a['date_out'] ? $fmt($a['date_out']) : 'Still admitted' }} |
{{ $a['days'] }} |
{{ $a['doctor'] ?? '-' }} |
{{ $a['room'] }} |
{{ $a['status'] }} |
@if ($canFinancial)
{{ $a['money'] ? $money($a['money']['charge']) : '-' }} |
{!! $balancePill($a['money']) ?: '-' !!} |
@endif
@if ($a['record']) Record@endif
@if ($a['open']) Open@endif
|
@empty
| Never admitted. |
@endforelse
@endif
{{-- Emergency --}}
@if ($show['emergency'])
| No. | Arrived | Left | Doctor | Complaint | Status |
@if ($canFinancial)Charge | Balance | @endif |
@forelse ($emergencies as $e)
| #{{ $e['no'] }} |
{{ $fmt($e['date']) }} |
{{ $e['date_out'] ? $fmt($e['date_out']) : '-' }} |
{{ $e['doctor'] ?? '-' }} |
{{ $e['complaint'] ?: '-' }} |
{{ $e['status'] }} |
@if ($canFinancial)
{{ $e['money'] ? $money($e['money']['charge']) : '-' }} |
{!! $balancePill($e['money']) ?: '-' !!} |
@endif
@if ($e['open']) Open@endif |
@empty
| No emergency visits. |
@endforelse
@endif
{{-- Medical history: one sub-tab per kind of record, each searchable and printable --}}
@if ($canMedical)
@php
$md = $medical;
// "Admission #3" badge, linked to that section of it when allowed
$src = function ($x) {
$text = e($x['from']) . ($x['no'] ? ' #' . e($x['no']) : '');
return $x['open'] ? '
' . $text . ''
: '
' . $text . '';
};
$at = fn ($v) => $v ? \Carbon\Carbon::parse($v)->format('d M, Y') . (strlen($v) > 10 ? ' · ' . \Carbon\Carbon::parse($v)->format('h:i A') : '') : '-';
$statusPill = fn ($st) => '
' . e($st) . '';
$hist = array_filter($md['history'], fn ($v) => trim((string) $v) !== '');
$subs = [
'summary' => ['ti-clipboard-heart', 'Summary', count($md['diagnoses']) + count($hist)],
'vitals' => ['ti-heartbeat', 'Vital signs', count($md['vitals'])],
'labs' => ['ti-microscope', 'Laboratory', count($md['labs'])],
'images' => ['ti-photo', 'Imaging', count($md['images'])],
'pres' => ['ti-prescription', 'Prescriptions', count($md['prescriptions'])],
'orders' => ['ti-clipboard-list', 'Doctor orders', count($md['orders'])],
'given' => ['ti-pill', 'Medication given', count($md['given'])],
'fluid' => ['ti-droplet', 'Fluid chart', count($md['fluid'])],
'insulin' => ['ti-vaccine', 'Insulin chart', count($md['insulin'])],
'ops' => ['ti-scissors', 'Operations', count($md['operations'])],
];
$secHead = fn ($key, $help, $search = null) => '';
@endphp
@foreach ($subs as $key => [$icon, $label, $n])
@endforeach
{{-- Summary: diagnoses + past history --}}
{!! $secHead('summary', 'Diagnoses from every visit and the latest past history written') !!}
Diagnoses
@forelse ($md['diagnoses'] as $d)
{{ $d['name'] }}{{ $fmt($d['date']) }}
@empty
No diagnosis recorded.
@endforelse
Past history
@forelse ($hist as $label => $text)
@empty
No past history recorded.
@endforelse
{{-- Vital signs --}}
{!! $secHead('vitals', 'Every vital sign taken in a visit, an admission or emergency — newest first', 'Find…') !!}
| Date / time | Taken in | Temp | BP | Pulse | Resp | SpO₂ | Weight | Other |
@forelse ($md['vitals'] as $v)
| {{ $at($v['at']) }} | {!! $src($v) !!} |
{{ $v['temp'] ? $v['temp'] . ' °C' : '-' }} | {{ $v['bp'] ?: '-' }} |
{{ $v['pulse'] ?: '-' }} | {{ $v['resp'] ?: '-' }} |
{{ $v['spo2'] ? $v['spo2'] . '%' : '-' }} |
{{ $v['weight'] ? $v['weight'] . ' kg' : '-' }} | {{ $v['other'] ?: '-' }} |
@empty
| No vital signs recorded. |
@endforelse
{{-- Laboratory --}}
{!! $secHead('labs', 'Every lab request — View shows its results; Print includes all results', 'Find a test…') !!}
| Date | Request | Tests | Status | |
@php
$statusColor = ['Processed' => 'success', 'Draft' => 'info'];
// "4.0 - 11.0" → is the value outside it?
$outOfRange = function ($value, $range) {
if (!is_numeric($value) || !preg_match('/^\s*(-?[\d.]+)\s*-\s*(-?[\d.]+)\s*$/', (string) $range, $m)) return false;
return $value < (float) $m[1] || $value > (float) $m[2];
};
@endphp
@forelse ($md['labs'] as $l)
| {{ $fmt($l['date']) }} |
#{{ $l['no'] }}
|
{{ $l['tests'] ?: '-' }}
{{-- the results, copied into the modal by "View" (also what "Find a test" searches) --}}
@if ($l['rows'])
| Test | Result | Normal range |
@foreach ($l['rows'] as $r)
@if ($r['type'] === 'header')
| {{ $r['title'] }} |
@else
@php $bad = $outOfRange($r['value'], $r['normal_range']); @endphp
| {{ $r['name'] }} |
{{ $r['value'] }} {{ $r['unit'] }}@if ($bad) @endif |
{{ $r['normal_range'] ?: '-' }} |
@endif
@endforeach
@else
{{ $l['status'] === 'Draft' ? 'The lab has started this request — results are not completed yet.' : 'Waiting for the lab — no results yet.' }}
@endif
|
{{ $l['status'] === 'Processed' ? 'Completed' : $l['status'] }} |
|
@empty
| No lab requests. |
@endforelse
{{-- Imaging --}}
{!! $secHead('images', 'Every imaging exam with its report', 'Find an exam…') !!}
| Date | Exam | From | Status | Report |
@forelse ($md['images'] as $i)
| {{ $fmt($i['date']) }} #{{ $i['no'] }} |
{{ $i['exam'] }} | {!! $src($i['src']) !!} | {!! $statusPill($i['status'] === 'Processed' ? 'Completed' : $i['status']) !!} |
@forelse ($i['report'] as $r) @if ($r['name']){{ $r['name'] }}: @endif{{ $r['text'] }} @empty{{ $i['notes'] ?: 'No report yet.' }}@endforelse |
@empty
| No imaging. |
@endforelse
{{-- Prescriptions --}}
{!! $secHead('pres', 'Every prescription with where it was written — appointment, admission or emergency', 'Find a drug…') !!}
| Date | From | Drug | Dose | Frequency | Duration | Qty | Instruction |
@forelse ($md['prescriptions'] as $h)
@foreach ($h['drugs'] as $d)
@if ($loop->first)
| {{ $fmt($h['date']) }} Rx #{{ $h['no'] }}{{ $h['type'] === 'POS' ? ' · pharmacy sale' : '' }} |
{!! $src($h) !!} |
@endif
{{ $d->name ?? '-' }} | {{ $d->dose ?: '-' }} | {{ $d->frequency ?: '-' }} |
{{ $d->duration ? (is_numeric($d->duration) ? $d->duration . ' days' : $d->duration) : '-' }} | {{ $d->quantity ? $d->quantity + 0 : '-' }} | {{ $d->instruction ?: '' }} |
@endforeach
@empty
| No prescriptions. |
@endforelse
{{-- Doctor orders --}}
{!! $secHead('orders', 'Orders written for admissions and emergency, with who completed them', 'Find…') !!}
| Date / time | From | Order | Dose / route | How | Doctor | Status |
@forelse ($md['orders'] as $o)
| {{ $at($o['at']) }} | {!! $src($o) !!} |
{{ $o['drug'] ?: $o['type'] }} {{ $o['type'] }}{{ $o['instruction'] ? ' — ' . $o['instruction'] : '' }} |
{{ collect([$o['dose'], $o['route']])->filter()->implode(' · ') ?: '-' }} | {{ $o['how'] ?: '-' }} | {{ $o['doctor'] ?? '-' }} |
{!! $statusPill($o['status']) !!}@if ($o['done']) {{ $o['done'] }} @endif |
@empty
| No doctor orders. |
@endforelse
{{-- Medication given (ward chart) --}}
{!! $secHead('given', 'Medication given on the ward during admissions', 'Find a drug…') !!}
| Date / time | From | Drug | Dose | Route | Given by | Status |
@forelse ($md['given'] as $m)
| {{ $at($m['at']) }} | {!! $src($m) !!} | {{ $m['drug'] ?: '-' }}@if ($m['note']) {{ $m['note'] }} @endif |
{{ $m['dose'] ?: '-' }} | {{ $m['route'] ?: '-' }} | {{ $m['by'] ?? '-' }} | {!! $statusPill($m['status'] ?: '-') !!} |
@empty
| No medication given on the ward. |
@endforelse
{{-- Fluid chart --}}
{!! $secHead('fluid', 'IV fluids, intake and output recorded during admissions') !!}
| Date / time | From | Fluid | Intake | Output | Balance | Observation |
@forelse ($md['fluid'] as $f)
@php $bal = $f['in_total'] - $f['out_total']; @endphp
| {{ $at($f['at']) }} | {!! $src($f) !!} | {{ $f['fluid'] ?: '-' }} |
{{ $f['in'] ?: '-' }} | {{ $f['out'] ?: '-' }} |
{{ ($f['in'] || $f['out']) ? ($bal > 0 ? '+' : '') . ($bal + 0) . ' ml' : '-' }} |
{{ $f['note'] }}{{ $f['by'] ? ' — ' . $f['by'] : '' }} |
@empty
| No fluid chart entries. |
@endforelse
{{-- Insulin chart --}}
{!! $secHead('insulin', 'Blood sugar results and insulin given during admissions') !!}
| Date / time | From | Result | Insulin (units) | Observation | By |
@forelse ($md['insulin'] as $i)
| {{ $at($i['at']) }} | {!! $src($i) !!} | {{ $i['result'] ?: '-' }} |
{{ $i['unit'] ?: '-' }} | {{ $i['note'] }} | {{ $i['by'] ?? '-' }} |
@empty
| No insulin chart entries. |
@endforelse
{{-- Operations --}}
{!! $secHead('ops', 'Every operation of this patient') !!}
| Date | From | Operation | Surgeon | Status | Notes |
@forelse ($md['operations'] as $o)
| {{ $fmt($o['date']) }} #{{ $o['no'] }} | {!! $src($o) !!} | {{ $o['name'] }} |
{{ $o['surgeon'] ?? '-' }} | {!! $statusPill($o['status']) !!} | {{ $o['notes'] }} |
@empty
| No operations. |
@endforelse
{{-- the hospital header for the section prints (shared print header) --}}
@endif
{{-- Financial history --}}
@if ($canFinancial)
| Date | What | Charge | Paid | Discount | Balance | |
@forelse ($episodes as $i => $e)
| {{ $fmt($e['date']) }} |
{{ $e['title'] }} {{ $e['subtitle'] ?? '' }} |
{{ $money($e['totals']['charge']) }} |
{{ $money($e['totals']['paid']) }} |
{{ $money($e['totals']['discount']) }} |
{{ $money($e['totals']['balance']) }} |
|
@foreach ($e['items'] as $b)
| {{ $b['label'] }} | {{ $fmt($b['date']) }} |
{{ $money($b['charge']) }} | {{ $money($b['paid']) }} |
{{ $money($b['discount']) }} | {{ $money($b['balance']) }} |
@endforeach
|
@empty
| No bills yet. |
@endforelse
@if ($episodes->isNotEmpty())
| Total | {{ $money($totals['charge']) }} | {{ $money($totals['paid']) }} |
{{ $money($totals['discount']) }} | {{ $money($totals['balance']) }} | |
@endif
@endif
{{-- one lab request's results (filled by ppLab) --}}
@if (!empty($md['labs']) && $md['labs']->isNotEmpty())