/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
$evenement_guid = CValue::get("evenement_guid");
$operation_id = CValue::get("operation_id");
$datetime = CValue::get("datetime");
$interv = new COperation();
$interv->load($operation_id);
$interv->loadRefAnesth();
if (!$datetime) {
    $datetime = CMbDT::date($interv->_datetime) . " " . CMbDT::time();
}
list($evenement_class, $evenement_id) = explode("-", $evenement_guid);
/** @var CAnesthPerop $evenement */
$evenement = new $evenement_class();
if ($evenement_id) {
    $evenement->load($evenement_id);
    $evenement->loadRefsNotes();
} else {
    $evenement->datetime = $datetime;
}
$evenement->operation_id = $interv->_id;
// Création du template
$smarty = new CSmartyDP();
$salle = new CSalle();
$listSalles = $salle->loadListWithPerms(PERM_READ);
// anesths
$anesth = new CMediusers();
$anesths = $anesth->loadAnesthesistes(PERM_READ);
$operation = new COperation();
$operation->load($operation_id);
$date = $operation->date;
if ($operation->plageop_id) {
    $toRemove = true;
}
if (!$toRemove) {
    $reservation_installed = CModule::getActive("reservation");
    $diff_hour_urgence = CAppUI::conf("reservation diff_hour_urgence");
    $operation->loadRefsFwd();
    $operation->loadRefAnesth();
    $patient = $operation->_ref_sejour->loadRefPatient();
    $dossier_medical = $patient->loadRefDossierMedical();
    $dossier_medical->loadRefsAntecedents();
    $dossier_medical->countAntecedents();
    $dossier_medical->countAllergies();
    $operation->_ref_chir->loadRefsFwd();
    if ($reservation_installed) {
        $first_log = $operation->loadFirstLog();
        if (abs(CMbDT::hoursRelative($operation->_datetime_best, $first_log->date)) <= $diff_hour_urgence) {
            $operation->_is_urgence = true;
        }
    }
    // Chargement des plages disponibles pour cette intervention
    $operation->_ref_chir->loadBackRefs("secondary_functions");
    $secondary_functions = array();