*
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
// @todo bloc n'est pas forcément actif
global $can;
$can->read |= CModule::getActive("dPbloc")->_can->read;
$can->needsRead();
$operation_id = CValue::getOrSession("operation_id", null);
$operation = new COperation();
$operation->load($operation_id);
$operation->loadRefsAnesthPerops();
$operation->loadRefsFwd();
$operation->loadRefsActesCCAM();
foreach ($operation->_ref_actes_ccam as $acte) {
    $acte->loadRefsFwd();
}
$operation->loadAffectationsPersonnel();
if (CAppUI::conf('dPccam CCodeCCAM use_new_association_rules')) {
    $operation->guessActesAssociation();
} else {
    foreach ($operation->_ref_actes_ccam as $acte) {
        $acte->guessAssociation();
    }
}
$operation->loadRefSortieLocker()->loadRefFunction();
$sejour = $operation->_ref_sejour;
$sejour->loadRefsFwd();
 /**
  * @deprecated
  * @see parent::loadRefsFwd()
  */
 function loadRefsFwd()
 {
     $this->loadRefChir();
     // Chargement operation/sejour
     $this->loadRefOperation();
     $this->_ref_operation->loadRefsFwd();
     $this->_date_op =& $this->_ref_operation->_datetime;
     // Chargement consultation
     $this->loadRefConsultation();
     $this->_ref_consultation->loadRefsFwd();
     $this->_ref_plageconsult =& $this->_ref_consultation->_ref_plageconsult;
     $this->_date_consult =& $this->_ref_consultation->_date;
     // Calcul de la Clairance créatinine
     $patient =& $this->_ref_consultation->_ref_patient;
     $patient->loadRefLatestConstantes(null, null, $this->_ref_consultation, false);
     $const_med = $patient->_ref_constantes_medicales;
     $const_med->updateFormFields();
     $age = intval($patient->_annees);
     if ($const_med->poids && $this->creatinine && $age && $age >= 18 && $age <= 110 && $const_med->poids >= 35 && $const_med->poids <= 120 && $this->creatinine >= 6 && $this->creatinine <= 70) {
         $this->_clairance = $const_med->poids * (140 - $age) / (7.2 * $this->creatinine);
         if ($patient->sexe == 'm') {
             $this->_clairance *= 1.04;
         } else {
             $this->_clairance *= 0.85;
         }
         $this->_clairance = round($this->_clairance, 2);
     }
     // Calcul des Pertes Sanguines Acceptables
     if ($this->ht && $this->ht_final && $const_med->_vst) {
         $this->_psa = $const_med->_vst * ($this->ht - $this->ht_final) / 100;
     }
 }
$pdf = CValue::get("pdf", 1);
$lines = array();
$lines_per_op = array();
// Consultation courante
$dossier_anesth = new CConsultAnesth();
if (!$dossier_anesth_id) {
    $where = array();
    $where["operation_id"] = " = '{$operation_id}'";
    $dossier_anesth->loadObject($where);
} else {
    $dossier_anesth->load($dossier_anesth_id);
}
if (!$dossier_anesth->_id) {
    $selOp = new COperation();
    $selOp->load($operation_id);
    $selOp->loadRefsFwd();
    $selOp->_ref_sejour->loadRefsFwd();
    $selOp->_ref_sejour->loadRefsConsultAnesth();
    $selOp->_ref_sejour->_ref_consult_anesth->loadRefsFwd();
    $patient = $selOp->_ref_sejour->_ref_patient;
    $patient->loadRefsConsultations();
    // Chargement des praticiens
    $listAnesths = array();
    if ($offline == "false") {
        $anesths = new CMediusers();
        $listAnesths = $anesths->loadAnesthesistes(PERM_READ);
    }
    foreach ($patient->_ref_consultations as $consultation) {
        $consultation->loadRefConsultAnesth();
        foreach ($consultation->_refs_dossiers_anesth as $_dossier_anesth) {
            $consultation->loadRefPlageConsult();
/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Cabinet
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
// !! Attention, régression importante si ajout de type de paiement
// Récupération des paramètres
$operation_id = CValue::get("operation_id", null);
$op = new COperation();
$op->load($operation_id);
$op->loadRefsFwd();
$op->_ref_sejour->loadRefsFwd();
$patient =& $op->_ref_sejour->_ref_patient;
$pack_id = CValue::get("pack_id", null);
$pack = new CPack();
$pack->load($pack_id);
// Creation des template manager
$listCr = array();
foreach ($pack->_modeles as $key => $value) {
    $listCr[$key] = new CTemplateManager();
    $listCr[$key]->valueMode = true;
    $op->fillTemplate($listCr[$key]);
    $patient->fillTemplate($listCr[$key]);
    $listCr[$key]->applyTemplate($value);
}
// Création du template