$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);
$constantes = new CConstantesMedicales();
$constantes->load($const_id);
$constantes->loadRefContext();
$constantes->loadRefPatient();
$constantes->updateFormFields();
// Pour forcer le chargement des unités lors de la saisie d'une nouvelle constante
if ($context) {
    $constantes->patient_id = $patient_id;
        $where['context_id'] = " = {$context->_id}";
    }
}
$where['patient_id'] = " = {$patient->_id}";
$limit = "0, {$nb_input_display}";
$constantes = new CConstantesMedicales();
$constantes->patient_id = $patient->_id;
$constantes->loadRefPatient();
$constantes->updateFormFields();
if ($context) {
    $constantes->context_id = $context->_id;
    $constantes->context_class = $context->_class;
    $constantes->loadRefContext();
}
if (empty($selection) || is_null($host)) {
    $constants_ranks = CConstantesMedicales::getConstantsByRank('form', false, $host);
} else {
    $constants_ranks = CConstantesMedicales::selectConstants($selection, 'form', $host);
}
$list_constantes = $constantes->loadList($where, 'datetime DESC', $limit);
$smarty = new CSmartyDP();
$smarty->assign('patient_id', $patient_id);
$smarty->assign('constantes', $constantes);
$smarty->assign('latest_constantes', $latest_constantes);
$smarty->assign('list_constantes', $list_constantes);
$smarty->assign('context', $context);
$smarty->assign('context_guid', $context_guid);
$smarty->assign('constants_ranks', $constants_ranks);
$smarty->assign('selection', $selection);
$smarty->assign('display_search_field', $display_search_field);
$smarty->display('inc_constantes_table_mode.tpl');