<?php


use App\Models\Page;

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

/** @var \App\Models\Pro $hcpPro */
/** @var \App\Models\Pro $pro */
/** @var \App\Models\Note $note */

if(!@$hcpPro) {
    if(@$note) {
        $hcpPro = $note->hcpPro;
    }
    else {
        $hcpPro = $pro; // should never get here
    }
}

$contentData = [];

if($page){
    $contentData = json_decode($page->data, true);
}else{
    if ($patient->canvas_data) {
        $canvasData = json_decode($patient->canvas_data, true);
        if(!isset($canvasData["next_fu"])) $canvasData["next_fu"] = [];
        $contentData = $canvasData['next_fu'];
    }
}

if(!isset($contentData[$hcpPro->id])) $contentData[$hcpPro->id] = [];
$contentData = $canvasData['next_fu'][$hcpPro->id];
