<?php
list($problemPoints, $counts) = \App\Models\Point::getPointsOfCategoryExtended($client, 'PROBLEM', $note);
$problemNames = [];
foreach ($problemPoints as $problemPoint) {
    if($problemPoint->relevanceToNote($note)) {
        $problemNames[] = $problemPoint->data->name;
    }
}
$problems = '';
for($i = 0; $i < count($problemNames); $i++) {
    if($i > 0) {
        if($i === count($problemNames) - 1) {
            $problems .= " and ";
        }
        else {
            $problems .= ", ";
        }
    }
    $problems .= $problemNames[$i];
}
$defaultCC = "Patient {$client->name_first} {$client->name_last} " .
    "is a {$client->age_in_years} year old" .
    ($client->sex ? ($client->sex === 'F' ? ' female' : ($client->sex === 'M' ? ' male' : ' ' . $client->sex)) : '') .
    ($problems ? " with a history of {$problems}" : "") .
    ($note->new_or_fu_or_na === 'NEW' ? ' presenting for establishing care' : ' presenting for follow-up') .
    ".";
echo json_encode([
    "success" => true,
    "data" => $defaultCC
]);
?>
