/* We display at most 4 graph with cumuled constants */
        if (isset(CConstantesMedicales::$list_constantes[$_cste]['cumul_reset_config'])) {
            if ($cumul_nb < 4) {
                $list_cumul[] = $_cste;
                $cumul_nb++;
            }
            continue;
        }
        /* A most, we display only one graph with at most 5 constants */
        if ($cste_nb < 5) {
            $list_cste[] = $_cste;
            $cste_nb++;
        }
    }
}
$graph = new CConstantGraph(CConstantesMedicales::guessHost($context), $context_guid, true);
$graphs = array();
$titles = array();
if (!empty($list_cste) || !empty($list_cumul)) {
    // Global structure
    $graphs_struct = array("Constantes" => $list_cste);
    foreach ($list_cumul as $_cumul) {
        $graphs_struct[CAppUI::tr("CConstantesMedicales-{$_cumul}-court")] = array($_cumul);
    }
    $where = array('patient_id' => " = '{$context->patient_id}'", 'context_class' => " = '{$context->_class}'", 'context_id' => " = '{$context->_id}'");
    $whereOr = array();
    $constants_by_graph = array();
    $i = 1;
    foreach ($graphs_struct as $_name => $_fields) {
        if (empty($_fields)) {
            continue;
$patient_id = CValue::get('patient_id');
$can_edit = CValue::get('can_edit');
$selection = CValue::get('selection');
$host_guid = CValue::get('host_guid');
$display_graph = CValue::get('display_graph', 1);
$unique_id = CValue::get('unique_id', '');
$context = null;
if ($context_guid) {
    $context = CMbObject::loadFromGuid($context_guid);
}
/** @var CGroups|CService|CRPU $host */
// On cherche le meilleur "herbegement" des constantes, pour charger les configuration adequat
if ($host_guid) {
    $host = CMbObject::loadFromGuid($host_guid);
} else {
    $host = CConstantesMedicales::guessHost($context);
}
$show_cat_tabs = CConstantesMedicales::getHostConfig("show_cat_tabs", $host);
$show_enable_all_button = CConstantesMedicales::getHostConfig("show_enable_all_button", $host);
$dates = array();
if (!$selection) {
    $selection = CConstantesMedicales::getConstantsByRank('form', true, $host);
} else {
    $selection = CConstantesMedicales::selectConstants($selection, 'form');
}
foreach (CConstantesMedicales::$list_constantes as $key => $cst) {
    $dates["{$key}"] = CMbDT::format(null, '%d/%m/%y');
}
$patient_id = $constantes->patient_id ? $constantes->patient_id : $patient_id;
$patient = CPatient::loadFromGuid("CPatient-{$patient_id}");
$patient->loadRefLatestConstantes(null, array("poids", "taille"), null, false);
        default:
    }
}
$whereOr = array();
foreach ($selection as $_constant) {
    $whereOr[] = "{$_constant} IS NOT NULL";
}
if (!empty($whereOr)) {
    $where[] = implode(' OR ', $whereOr);
}
$constant = new CConstantesMedicales();
$constants = $constant->loadList($where, 'datetime DESC', null, 'datetime');
$smarty = new CSmartyDP();
if (!empty($constants)) {
    $time = false;
    if ($period) {
        $time = true;
    }
    $graph = new CConstantGraph(CConstantesMedicales::guessHost($context), $context_guid, false, $time);
    $constants_by_graph = array(1 => array($selection));
    $graph->formatGraphDatas(array_reverse($constants, true), $constants_by_graph);
    $smarty->assign('graphs', array(1 => $graph->graphs[1][0]));
    $smarty->assign('min_x_index', $graph->min_x_index);
    $smarty->assign('min_x_value', $graph->min_x_value);
    if (!$period) {
        $smarty->assign('patient', $patient);
    }
} else {
    $smarty->assign('msg', CAppUI::tr('CConstantGraph-msg-no_values'));
}
$smarty->display('inc_custom_constants_graph.tpl');