<?php

use App\Models\Point;

$category = 'VITALS';
$endPoint = 'upsertNoteSingleton';

$vitalLabels = [
    "heightInInches" => "Ht. (in.)",
    "weightPounds" => "Wt. (lbs.)",
    "bmi" => "BMI (kg/m²)",
    "temperatureF" => "Temp. (F)",
    "systolicBP" => "SBP",
    "diastolicBP" => "DBP",
    "pulseRatePerMinute" => "Pulse",
    "respirationRatePerMinute" => "Resp.",
    "pulseOx" => "Pulse Ox.",
    "smokingStatus" => "Smoking Status",
];

$point = Point::where('added_in_note_id', $note->id)->where('category', $category)->orderBy('id', 'DESC')->first();
$contentData = null;
if (!!@$point->data) {
    $contentData = json_decode($point->data, true);
}

if(!$contentData) {
    $contentData = [
        "date" => $note->effective_dateest,
        "heightInInches" => '',
        "weightPounds" => '',
        "bmi" => '',
        "temperatureF" => '',
        "systolicBP" => '',
        "diastolicBP" => '',
        "pulseRatePerMinute" => '',
        "respirationRatePerMinute" => '',
        "pulseOx" => '',
        "smokingStatus" => '',
    ];
}else {
    if(!isset($contentData['date'])) $contentData['date'] = $note->effective_dateest;
    foreach ($vitalLabels as $k => $v) {
        if (!isset($contentData[$k]) || is_array($contentData[$k])) {
            $contentData[$k] = '';
        }
    }
}
?>

<div class="mb-2">Effective Date: <b>{{friendly_date($contentData['date'])}}</b></div>
@foreach ($vitalLabels as $k => $v)
<div class="d-flex vital-item align-items-center">
        <span class="content-html text-nowrap">
            <?php $vital = @$contentData[$k]; ?>
                @if($k === 'systolicBP')
                    <span>Blood Pressure:</span>
                    <b>{{ @$contentData['systolicBP'] ?: '-' }}/{{ @$contentData['diastolicBP'] ?: '-' }}</b>
                @elseif($k === 'diastolicBP') <!--ignore-->

                @else
                    <span>{{$v}}:</span>
                    <b>{{ !empty($vital) ? $vital : '-' }}</b>
                @endif
            @if($k === 'bmi' && !empty($vital))
                <?php $bmi = floatval($vital); ?>
                <span class="ml-2 py-1 m-0 font-weight-bold">
                     @if($bmi < 18.5)
                        <span class="text-sm text-warning-mellow">(Underweight)</span>
                     @endif
                    @if($bmi >= 18.5 && $bmi < 25)
                         <!--<span class="text-sm text-success">(Healthy Weight)</span>-->
                    @endif
                    @if($bmi >= 25 && $bmi < 30)
                        <span class="text-sm text-warning-mellow">(Overweight)</span>
                    @endif
                    @if($bmi >= 30)
                        <span class="text-sm text-warning-mellow">(Obese)</span>
                    @endif
                </span>
            @endif
        </span>
</div>
@endforeach

