<?php

$contentData = [
    "count" => 0,
    "unknown" => false,
    "items" => []
];
if($patient->canvas_data) {
    $canvasData = json_decode($patient->canvas_data, true);
    if(isset($canvasData["fhx"])) {
        $contentData = $canvasData["fhx"];
        if(!isset($contentData['items'])){
            $contentData['items'] = [];
        }
    }
}

$labels = [
    'general_no_health_concern' => 'No health concern',
    'general_arthritis' => 'Arthritis',
    'general_asthma' => 'Asthma',
    'general_bleeding_disorder' => 'Bleeding disorder',
    'general_cad_lt_age_55' => 'CAD &gt; age 55',
    'general_copd' => 'COPD',
    'general_diabetes' => 'Diabetes',
    'general_heart_attack' => 'Heart attack',
    'general_heart_disease' => 'Heart disease',
    'general_high_cholesterol' => 'High cholesterol',
    'general_hypertension' => 'Hypertension',
    'general_mental_illness' => 'Mental illness',
    'general_osteoporosis' => 'Osteoporosis',
    'general_stroke' => 'Stroke',
    'cancer_breast_ca' => 'Breast cancer',
    'cancer_colon_ca' => 'Colon cancer',
    'cancer_other_ca' => 'Other cancer',
    'cancer_ovarian_ca' => 'Ovarian cancer',
    'cancer_uterine_ca' => 'Uterine cancer',
];

if(!$contentData['unknown'] && !!$contentData['count']) {
    for ($i = 0; $i < $contentData['count']; $i++) {
?>
        <div class="<?= $i > 0 ? 'mt-2' : '' ?>">
            <div class="pb-1">
                <b><?= isset($contentData['items'][$i]['relationship']) ? $contentData['items'][$i]['relationship'] : '--' ?></b>
                <?php if(isset($contentData['items'][$i]['status']) && !empty($contentData['items'][$i]['status'])): ?>
                    <span class="ml-1 text-secondary">(<?= $contentData['items'][$i]['status'] ?>)</span>
                <?php endif; ?>
            </div>
            <div class="ml-3">
                <?php foreach ($labels as $k => $v): ?>
                    <?= isset($contentData['items'][$i][$k]) ? '<div>' . $v . ': <b>' . $contentData['items'][$i][$k] . '</b></div>' : '' ?>
                <?php endforeach; ?>
            </div>
            <?php if(isset($contentData['items'][$i]['comments']) && !empty($contentData['items'][$i]['comments'])): ?>
                <div class="ml-3 pt-1 text-secondary client-rs-contents">
                    <b>Comments: </b><?= $contentData['items'][$i]['comments'] ?>
                </div>
            <?php endif; ?>
        </div>
<?php
    }
}
else {
    ?>
    <div class="text-secondary">Family History is unknown/unavailable</div>
    <?php
}
?>
