<?php
use App\Models\Note;
use App\Models\Client;
/** @var Note $note */
/** @var Client $patient */
if(!@$contentData) {
    $contentData = [
        "effectiveDate" => (@$note ? friendlier_date($note->effective_dateest) : date('Y-m-d')),
        "note_uid" => (@$note ? $note->uid : ''),
        "temperature" => [
            "value" => '',
            "baseline" => '',
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "bp" => [
            "valueSystolic" => '',
            "valueDiastolic" => '',
            "baselineSystolicMin" => '',
            "baselineSystolicMax" => '',
            "baselineDiastolicMin" => '',
            "baselineDiastolicMax" => '',
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "pulse" => [
            "value" => '',
            "baseline" => '',
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "spO2" => [
            "value" => '',
            "baseline" => '',
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "weight" => [
            "value" => '',
            "baselineMin" => '',
            "baselineMax" => '',
            "isCHF" => null,
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "height" => [
            "valueFeet" => '',
            "valueInches" => '',
            "baselineFeet" => '',
            "baselineInches" => '',
            "isCHF" => null,
            "deviceRemarks" => [
                "hasDevice" => null,
                "issues" => null,
                "other" => null,
            ]
        ],
        "other" => null,
    ];
    if ($patient->canvas_data) {
        $canvasData = json_decode($patient->canvas_data, true);
        if (isset($canvasData["vitals_may21"])) {
            if (isset($canvasData["vitals_may21"]["note_uid"]) && $canvasData["vitals_may21"]["note_uid"] === @$note->uid) {
                $contentData = $canvasData["vitals_may21"];
            }
        }
    }
}
?>
<table class="table table-sm table-bordered mb-2">
    <thead>
    <tr class="text-secondary font-weight-bold">
        <td class="border-bottom-0">&nbsp;</td>
        <td class="border-bottom-0">Value (<?= @$note ? friendlier_date($note->effective_dateest) : date('Y-m-d') ?>)</td>
        <td class="border-bottom-0">Baseline</td>
        <td class="border-bottom-0">Device Remarks</td>
    </tr>
    </thead>
    <tbody>
    <!--temp-->
    <?php if (isset($contentData["temperature"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">Temperature</td>
            <td><?= @$contentData["temperature"]["value"] ? $contentData["temperature"]["value"] . ' ℉' : '-' ?></td>
            <td><?= @$contentData["temperature"]["baseline"] ? $contentData["temperature"]["baseline"] . ' ℉' : '-' ?></td>
            <td>
                <?php if (isset($contentData["temperature"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["temperature"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["temperature"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["temperature"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["temperature"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["temperature"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["temperature"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--bp-->
    <?php if (isset($contentData["bp"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">BP</td>
            <td><?= $contentData["bp"]["valueSystolic"] . '/' . $contentData["bp"]["valueDiastolic"] . ' mmHg' ?></td>
            <td>
                <div>
                    Systolic: <?= @$contentData["bp"]["baselineSystolicMin"] . ' - ' . $contentData["bp"]["baselineSystolicMax"] . 'mmHg' ?>
                </div>
                <div>
                    Diastolic: <?= @$contentData["bp"]["baselineDiastolicMin"] . ' - ' . $contentData["bp"]["baselineDiastolicMax"] . 'mmHg' ?>
                </div>
            </td>
            <td>
                <?php if (isset($contentData["bp"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["bp"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["bp"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["bp"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["bp"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["bp"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["bp"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--pulse-->
    <?php if (isset($contentData["pulse"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">Pulse</td>
            <td><?= @$contentData["pulse"]["value"] ? $contentData["pulse"]["value"] . ' bpm' : '-' ?></td>
            <td><?= @$contentData["pulse"]["baseline"] ? $contentData["pulse"]["baseline"] . ' bpm' : '-' ?></td>
            <td>
                <?php if (isset($contentData["pulse"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["pulse"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["pulse"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["pulse"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["pulse"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["pulse"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["pulse"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--spO2-->
    <?php if (isset($contentData["spO2"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">SpO2</td>
            <td><?= @$contentData["spO2"]["value"] ? $contentData["spO2"]["value"] . ' %' : '-' ?></td>
            <td><?= @$contentData["spO2"]["baseline"] ? $contentData["spO2"]["baseline"] . ' %' : '-' ?></td>
            <td>
                <?php if (isset($contentData["spO2"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["spO2"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["spO2"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["spO2"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["spO2"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["spO2"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["spO2"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--weight-->
    <?php if (isset($contentData["weight"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">Weight</td>
            <td><?= @$contentData["weight"]["value"] ? $contentData["weight"]["value"] . ' lbs' : '-' ?></td>
            <td>
                <?= @$contentData["weight"]["baselineMin"] . ' - ' . $contentData["weight"]["baselineMax"] . 'lbs' ?>
                <div>
                    CHF: <?= @$contentData["weight"]["isCHF"] ? 'Yes' : 'No' ?>
                </div>
            </td>
            <td>
                <?php if (isset($contentData["weight"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["weight"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["weight"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["weight"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["weight"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["weight"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["weight"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--height-->
    <?php if (isset($contentData["height"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">Height</td>
            <td>
                <?= @$contentData["height"]["valueFeet"] . ' ft ' . @$contentData["height"]["valueInches"] . ' in' ?>
            </td>
            <td>
                <?= @$contentData["height"]["baselineFeet"] . ' ft ' . $contentData["height"]["baselineInches"] . ' in' ?>
            </td>
            <td>
                <?php if (isset($contentData["height"]["deviceRemarks"]["hasDevice"])): ?>
                    Has device: <b><?= $contentData["height"]["deviceRemarks"]["hasDevice"] ? 'Yes' : 'No ' ?></b>
                    <?php if ($contentData["height"]["deviceRemarks"]["hasDevice"]): ?>
                        <?php if (isset($contentData["height"]["deviceRemarks"]["issues"])): ?>
                            <div class="text-sm">
                                Issues: <?= $contentData["height"]["deviceRemarks"]["issues"] ?></div>
                        <?php endif; ?>
                        <?php if (isset($contentData["height"]["deviceRemarks"]["other"])): ?>
                            <div class="text-sm">
                                Other: <?= $contentData["height"]["deviceRemarks"]["other"] ?></div>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else: ?>
                    -
                <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>

    <!--other-->
    <?php if (isset($contentData["other"])): ?>
        <tr>
            <td class="bg-white text-secondary font-weight-bold">Other</td>
            <td colspan="3"><?= @$contentData["other"] ?></td>
        </tr>
    <?php endif; ?>
    </tbody>
    </thead>
</table>

