<?php

use App\Models\Point;

$point = Point::where('added_in_note_id', $note->id)->where('category', 'SUBJECTIVE_GENERAL')->orderBy('id', 'DESC')->first();
$parsed = null;
if (!!@$point->data) {
    $parsed = json_decode($point->data);
}
?>
<div class="wrapping-pre-container">
    <?php
    if (!!$parsed && @$parsed->free_text) {
        echo $parsed->free_text;
    }
    else {
        if($note->visit_number === 1) {
            $intakeDataFields = config('patient-intake-data');
            $patientCanvasData = json_decode($patient->canvas_data ?? null);
            $patientIntakeData = null;
            if ($patientCanvasData && @$patientCanvasData->INTAKE_DATA) {
                $patientIntakeData = @$patientCanvasData->INTAKE_DATA;
                foreach($intakeDataFields as $key=>$label) {
                    if($key == 'ethnicity_checkboxes') {
                        foreach($label as $eKey => $eLabel) {
                            if(@$patientIntakeData->{$eKey}) {
                                echo $eLabel . ': ' . @$patientIntakeData->{$eKey} . '&nbsp;&nbsp;&nbsp;';
                            }
                        }
                    }
                    else {
                        if(@$patientIntakeData->{$key}) {
                            echo ($key !== 'stickyNote' ? $label . ': ' : '<br>') . @$patientIntakeData->{$key} . '&nbsp;&nbsp;&nbsp;';
                        }
                    }
                }
            }
            else {
                echo "-";
            }
        }
        else {
            echo "-";
        }
    }
    ?>
</div>

