Laboratorium (Abnormal)
@php
$badge = function_exists('getStatusBadge')
? getStatusBadge($appointment->labResult)
: ['class' => 'bg-success', 'text' => 'Selesai'];
@endphp
{{ $badge['text'] }}
@php
$resultsData = [];
$packageLabTests = $appointment->getLabTestsIncluded();
if ($appointment->labResult->results_data) {
$resultsData = is_array($appointment->labResult->results_data)
? $appointment->labResult->results_data
: json_decode($appointment->labResult->results_data, true) ?? [];
}
// Helper function to map category names to LabHelper format
function mapCategoryToLabHelperSummary($category, $testName = '')
{
$categoryLower = strtolower($category);
if (in_array($categoryLower, ['hematologi', 'hematology'])) {
return 'hematologi';
} elseif (in_array($categoryLower, ['kimia_klinik', 'chemistry', 'kimia_darah'])) {
return 'kimia_klinik';
} elseif (in_array($categoryLower, ['serologi', 'immunologi', 'serology', 'immunology', 'imunoserologi'])) {
return 'imunoserologi';
} elseif (in_array($categoryLower, ['urinalisis', 'urine', 'urinalisa'])) {
// Check if this is a mikroskopis test
$testNameLower = strtolower($testName);
$testNameKey = str_replace([' ', '-'], '_', $testNameLower);
$mikroskopisTests = ['silinder', 'kristal', 'bakteri', 'leukosit', 'eritrosit', 'sel_epitel', 'sel epitel'];
if ($testNameKey === 'leukosit_makroskopis') {
return 'urinalisa_makroskopis';
}
foreach ($mikroskopisTests as $mikroskopisTest) {
if (strpos($testNameKey, str_replace([' ', '-'], '_', $mikroskopisTest)) !== false) {
return 'urinalisa_mikroskopis';
}
}
return 'urinalisa_makroskopis'; // Default to makroskopis for summary
} elseif (in_array($categoryLower, ['narkoba', 'drugs', 'drug_test'])) {
return 'narkoba';
} elseif (in_array($categoryLower, ['feses', 'stool', 'pemeriksaan_feses'])) {
return 'pemeriksaan_feses';
}
return $categoryLower;
}
// Function to check if a value is abnormal - using LabFormatHelper for consistency
function validateLabValueSummary(
$testName,
$value,
$category,
$patientGender,
$appointmentDate = null,
$normalRangeStr = null,
) {
if ($value === '' || $value === null) {
return 'normal';
}
return \App\Helpers\LabFormatHelper::validateAndNormalize(
$testName,
$value,
$category,
$patientGender,
$appointmentDate,
$normalRangeStr,
);
}
// Get abnormal results only
$abnormalResults = [];
$patientGender = $appointment->patient->gender;
foreach ($resultsData as $category => $tests) {
if (!is_array($tests)) {
continue;
}
foreach ($tests as $testName => $testData) {
$value = '';
$displayName = '';
$testNameLower = strtolower((string) $testName);
$testKeyForHelper = $testName;
if ($testNameLower === 'anti_hiv') {
$testKeyForHelper = 'hiv';
} elseif ($testNameLower === 'tes_kehamilan') {
$testKeyForHelper = 'pregnancy_test';
}
if (is_array($testData)) {
$value = $testData['value'] ?? '';
$displayName = $testData['name'] ?? $testName;
} else {
$value = $testData;
$displayName = ucwords(str_replace('_', ' ', $testName));
}
if (empty($value) || $value === '-' || $value === '') {
continue;
}
if (in_array($testNameLower, ['tes_kehamilan', 'pregnancy_test'], true) && $patientGender !== 'female') {
continue;
}
if (
in_array($testNameLower, ['anti_hiv', 'hiv'], true) &&
$displayName === ucwords(str_replace('_', ' ', $testName))
) {
$displayName = 'HIV';
}
if (
in_array($testNameLower, ['tes_kehamilan', 'pregnancy_test'], true) &&
$displayName === ucwords(str_replace('_', ' ', $testName))
) {
$displayName = 'Tes Kehamilan';
}
$normalRangeStr = is_array($testData) ? $testData['normal_range'] ?? null : null;
$status = validateLabValueSummary(
$testKeyForHelper,
$value,
$category,
$patientGender,
$appointment->created_at,
$normalRangeStr,
);
if (in_array($status, ['low', 'high', 'abnormal'])) {
if (!isset($abnormalResults[$category])) {
$abnormalResults[$category] = [];
}
$abnormalResults[$category][$testKeyForHelper] = [
'value' => $value,
'display_name' => $displayName,
'status' => $status,
];
}
}
}
@endphp
@if (!empty($abnormalResults))
{{-- Hematologi Abnormal --}}
@if (isset($abnormalResults['hematologi']) && count($abnormalResults['hematologi']) > 0)
HEMATOLOGI
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['hematologi'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('hematologi', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
// Set unit based on test name
$unit = '-';
switch ($testName) {
case 'hemoglobin':
$unit = 'g/dL';
break;
case 'leukosit':
case 'trombosit':
$unit = 'sel/uL';
break;
case 'lymph':
case 'mid':
case 'gran':
$unit = '10³/uL';
break;
case 'hematokrit':
$unit = '%';
break;
case 'eritrosit':
$unit = 'juta/mcl';
break;
case 'mcv':
$unit = 'fL';
break;
case 'mch':
$unit = 'pg/sel';
break;
case 'mchc':
$unit = '%';
break;
case 'led':
$unit = 'mm/jam';
break;
}
@endphp
|
{{ $displayName }}
|
{{ $value }} |
{{ $unit }} |
{{ $normalRange }} |
@endforeach
@endif
{{-- Kimia Klinik Abnormal --}}
@if (isset($abnormalResults['kimia_klinik']) && count($abnormalResults['kimia_klinik']) > 0)
KIMIA KLINIK
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['kimia_klinik'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('kimia_klinik', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
// Set unit based on test name
$unit = 'mg/dL';
switch ($testName) {
case 'sgot':
case 'sgpt':
case 'gamma_gt':
$unit = 'U/L';
break;
case 'alkali_fosfatase':
$unit = 'IU/L';
break;
}
@endphp
|
{{ $displayName }}
|
{{ $value }} |
{{ $unit }} |
{{ $normalRange }} |
@endforeach
@endif
{{-- Urinalisa Abnormal --}}
@if (isset($abnormalResults['urinalisa']) && count($abnormalResults['urinalisa']) > 0)
URINALISA
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['urinalisa'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('urinalisa', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
$testNameKey = str_replace([' ', '-'], '_', strtolower((string) $testName));
$displayValue = $value;
if (
$labHelperCategory === 'urinalisa_makroskopis' &&
in_array($testNameKey, ['protein', 'glukosa', 'leukosit_makroskopis', 'keton', 'bilirubin', 'blood'], true) &&
is_numeric(trim((string) $value)) &&
(float) trim((string) $value) > 0 &&
substr(trim((string) $value), 0, 1) !== '+'
) {
$displayValue = '+' . trim((string) $value);
}
// Set unit based on test name
$unit = '-';
if (in_array($testName, ['leukosit', 'eritrosit', 'sel_epitel'])) {
$unit = '/LPB';
}
@endphp
|
{{ $displayName }}
|
{{ $displayValue }} |
{{ $unit }} |
{{ $normalRange }} |
@endforeach
@endif
{{-- Imunoserologi Abnormal --}}
@if (isset($abnormalResults['imunoserologi']) && count($abnormalResults['imunoserologi']) > 0)
IMUNOSEROLOGI
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['imunoserologi'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('imunoserologi', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
@endphp
|
{{ $displayName }}
|
{{ $value }} |
- |
{{ $normalRange }} |
@endforeach
@endif
{{-- Narkoba Abnormal --}}
@if (isset($abnormalResults['narkoba']) && count($abnormalResults['narkoba']) > 0)
NARKOBA (URINE)
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['narkoba'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('narkoba', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
@endphp
|
{{ $displayName }}
|
{{ $value }} |
- |
{{ $normalRange }} |
@endforeach
@endif
{{-- Pemeriksaan Feses Abnormal --}}
@if (isset($abnormalResults['pemeriksaan_feses']) && count($abnormalResults['pemeriksaan_feses']) > 0)
PEMERIKSAAN FESES
| Parameter |
Hasil |
Satuan |
Nilai Normal |
@php $gender = $appointment->patient->gender; @endphp
@foreach ($abnormalResults['pemeriksaan_feses'] as $testName => $testData)
@php
$value = $testData['value'];
$displayName = $testData['display_name'];
$status = $testData['status'];
// Set color class based on status
$colorClass = '';
if ($status === 'low') {
$colorClass = 'text-warning';
} elseif ($status === 'high') {
$colorClass = 'text-danger';
} elseif ($status === 'abnormal') {
$colorClass = 'text-danger';
}
$labHelperCategory = mapCategoryToLabHelperSummary('pemeriksaan_feses', $testName);
$normalRange = \App\Helpers\LabHelper::getNormalRange($labHelperCategory, $testName, $appointment->created_at);
if ($testName === 'serat') {
$normalRange .= ' (Serat Tumbuhan (+), Serat Otot, Serat Larut = Abnormal)';
}
// Set unit based on test name
$unit = '-';
if (in_array($testName, ['wbc', 'rbc'])) {
$unit = '/LPB';
}
// Special handling for darah_samar format
if ($testName === 'darah_samar') {
$isNormal = $value == '(-) Negatif' || $value == '(-)' || $value == 'Negatif';
$colorClass = $isNormal ? 'text-success' : 'text-danger';
}
@endphp
|
{{ $displayName }}
|
{{ $value }} |
{{ $unit }} |
{{ $normalRange }} |
@endforeach
@endif
@else
Semua hasil laboratorium dalam batas normal
@endif
@if ($appointment->labResult->notes || $appointment->labResult->doctor_notes)
@if ($appointment->labResult->notes)
Catatan Laboratorium:
{{ $appointment->labResult->notes }}
@endif
@if ($appointment->labResult->doctor_notes)
@php
$labConc = $appointment->labResult->doctor_notes;
$labConcStr = is_string($labConc) ? strtolower(trim($labConc)) : '';
$isLabAbnormal = $labConc && $labConcStr !== 'normal' && $labConcStr !== 'dalam batas normal';
@endphp
Kesimpulan & Catatan Dokter:
{{ $labConc }}
@endif
@endif