<?php
use App\Models\Page;

$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'dx')->first();

$contentData = [
    "items" => []
];

if($page){
    $contentData = json_decode($page->data, true);
}else {
    if ($patient->canvas_data) {
        $canvasData = json_decode($patient->canvas_data, true);
        if (isset($canvasData["dx"])) {
            $contentData = $canvasData["dx"];
            if(!isset($contentData["items"])) {
                $contentData["items"] = [];
            }
            for ($i = 0; $i < count($contentData["items"]); $i++) {
                $contentData["items"][$i]["included"] = 1;
            }
        }
    }
}

