if ($plageAfter->_id) {
            $plageBefore->fin = $plageAfter->debut;
        } else {
            $plageBefore->fin = max($plageBefore->fin, $hour_next);
        }
        $plage =& $plageBefore;
    } elseif ($plageAfter->_id) {
        $plageAfter->debut = min($plageAfter->debut, $hour_now);
        $plage =& $plageAfter;
    } else {
        $plage->chir_id = $prat_id;
        $plage->date = $day_now;
        $plage->freq = "00:" . CPlageconsult::$minutes_interval . ":00";
        $plage->debut = $hour_now;
        $plage->fin = $hour_next;
        $plage->libelle = "automatique";
    }
    $plage->updateFormFields();
    if ($msg = $plage->store()) {
        CAppUI::setMsg($msg, UI_MSG_ERROR);
    }
}
$consult->plageconsult_id = $plage->_id;
if ($msg = $consult->store()) {
    CAppUI::setMsg($msg, UI_MSG_ERROR);
}
if ($current_m == "dPurgences") {
    CAppUI::redirect("m=dPurgences&tab=edit_consultation&selConsult={$consult->_id}&ajax={$ajax}");
} else {
    CAppUI::redirect("m=dPcabinet&tab=edit_consultation&selConsult={$consult->_id}&ajax={$ajax}");
}