@php
$results=collect($custom_test['results']);
// Relative (%) / absolute (#) pairs of the differential count, in display order
$differential_pairs=['neutrophil','lymphocytes','monocytes','eosinophils','basophils','ig'];
// Microscopic differential, in display order (first half = left column, second half = right column)
$microscopic_names=[
'micro'
];
// Main parameters printed in bold
$bold_names=['hb','hemoglobin','hemoglobin (hb)','plt','platelets','wbc','wbcs'];
$find=function ($custom_name) use ($results) {
return $results->first(function ($value) use ($custom_name) {
return $value['component']['custom_name']==$custom_name;
});
};
$differential_names=[];
$differential=[];
foreach($differential_pairs as $name){
$differential_names[]=$name;
$differential_names[]=$name.'_absolute';
$relative=$find($name);
$absolute=$find($name.'_absolute');
if(isset($relative['result'])||isset($absolute['result'])){
$differential[]=['relative'=>$relative,'absolute'=>$absolute];
}
}
$microscopic=$results->filter(function ($value) use ($microscopic_names) {
return in_array($value['component']['custom_name'],$microscopic_names)
&&isset($value['result'])&&$value['result']!=='';
})
->values();
$microscopic_rows=(int) ceil($microscopic->count()/2);
$microscopic_left=$microscopic->take($microscopic_rows)->values();
$microscopic_right=$microscopic->slice($microscopic_rows)->values();
$blood_picture_tests=$results->filter(function ($value) use ($differential_names,$microscopic_names) {
return isset($value['result'])
&&!in_array($value['component']['custom_name'],array_merge($differential_names,$microscopic_names));
})
->values();
$graphs=is_array($custom_test['graphs_arr']??null) ? array_values($custom_test['graphs_arr']) : [];
$analyzer=$custom_test['analyzer']??null;
$has_histogram=count($graphs)||$analyzer;
// Prefer the formatted comment, fall back to the plain one (escaped)
$comment_html=!empty($custom_test['comment_html']) ? $custom_test['comment_html'] : e($custom_test['comment']??'');
$has_comment=!empty($custom_test['blood_film_html'])||trim(strip_tags($comment_html))!=='';
$flag=function ($status) {
return ['Low'=>'L','High'=>'H','Critical'=>'C'][$status??'']??'';
};
$is_abnormal=function ($test) {
return isset($test['status'])&&$test['status']!='Normal'&&$test['status']!='';
};
@endphp
| {{$custom_test['test']['report_name']}} |
| Test |
Result |
Unit |
Normals |
@foreach($blood_picture_tests as $test)
| {{$test['component']['report_name']}} |
{{$test['result']}}
|
{{$test['unit']}} |
@include('pdf.partials.medical_report_reference_range',['result'=>$test])
|
@endforeach
|
| @if($has_histogram) Histogram @endif |
@if($has_histogram)
@foreach(array_chunk($graphs,2) as $row)
@foreach($row as $graph)
|
@endforeach
@if(count($row)==1)
|
@endif
@endforeach
@if($analyzer)
| {{$analyzer}} |
@endif
@endif
|
@if(count($differential))
| Differential Count |
| Relative |
Absolute |
@foreach($differential as $pair)
@foreach(['relative','absolute'] as $type)
@php($test=$pair[$type])
| {{$test['component']['report_name']??''}} |
@if(isset($test['result']))
{{$test['result']}}
@endif
|
{{$test['unit']??''}} |
{!! $test['reference_range_html']??'' !!} |
@endforeach
@endforeach
@endif
@if($microscopic->count()||$has_comment)
| @if($microscopic->count()) Microscopic Differential (If needed) @endif |
@if($has_comment) Comment @endif |
@for($i=0;$i
@foreach([$microscopic_left,$microscopic_right] as $column)
@php($test=$column->get($i))
{{$test ? $test['component']['report_name'] : ''}} |
@if($test)
{{$test['result']}}
@endif
|
@endforeach
@if($i==0)
@endif
@endfor
@endif
@if($custom_test['show_history']??false)
@include('pdf.partials.test_history',['test'=>$custom_test])
@endif