<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$operation_id = CValue::get("operation_id");
$operation = new COperation();
$operation->load($operation_id);
$sejour = $operation->loadRefSejour();
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("sejour", $sejour);
$smarty->assign("operation", $operation);
$smarty->display("inc_vw_surveillance_perop_administration.tpl");
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$operation_id = CValue::get("operation_id");
$interv = new COperation();
$interv->load($operation_id);
$interv->loadRefSejour()->loadRefPatient()->loadRefLatestConstantes();
$interv->loadRefPlageOp();
$interv->_ref_sejour->_ref_patient->loadRefDossierMedical();
$consult_anesth = $interv->loadRefsConsultAnesth();
$group = CGroups::loadCurrent();
$pack = $interv->loadRefGraphPack();
list($graphs, $yaxes_count, $time_min, $time_max, $time_debut_op_iso, $time_fin_op_iso) = CObservationResultSet::buildGraphs($interv, $pack->_id);
$time_debut_op = CMbDate::toUTCTimestamp($time_debut_op_iso);
$time_fin_op = CMbDate::toUTCTimestamp($time_fin_op_iso);
$evenements = CObservationResultSet::buildEventsGrid($interv, $time_debut_op_iso, $time_fin_op_iso, $time_min, $time_max);
$now = 100 * (CMbDate::toUTCTimestamp(CMbDT::dateTime()) - $time_min) / ($time_max - $time_min);
$graph_packs = CSupervisionGraphPack::getAllFor($group);
$concentrators = null;
if (CModule::getActive("patientMonitoring")) {
    $concentrator = new CMonitoringConcentrator();
    $concentrators = $concentrator->loadList();
    $sejour->_ref_praticien->canDo();
    $prat = $sejour->_ref_praticien;
    $patient = $sejour->_ref_patient;
}
$grossesse = new CGrossesse();
if ($grossesse_id && !$sejour_id && !$operation_id) {
    $grossesse->load($grossesse_id);
    $sejour->grossesse_id = $grossesse->_id;
    $sejour->_ref_grossesse = $grossesse;
    $patient = $grossesse->loadRefParturiente();
}
// On récupère l'opération
$op = new COperation();
$op->load($operation_id);
if ($op->_id) {
    $op->loadRefSejour();
    if (CAppUI::conf("dPplanningOp COperation use_session_praticien")) {
        CValue::setSession("chir_id", $op->chir_id);
    }
    if (CBrisDeGlace::isBrisDeGlaceRequired()) {
        $canAccess = CAccessMedicalData::checkForSejour($op->_ref_sejour);
        if (!$canAccess) {
            if (!$op->canDo()->read) {
                global $m, $tab;
                CAppUI::setMsg("Vous n'avez pas accés à cette intervention hors plage", UI_MSG_WARNING);
                CAppUI::redirect("m={$m}&tab={$tab}&operation_id=0");
            }
        }
    } else {
        if (!$op->canDo()->read) {
            global $m, $tab;
    if ($ccam_intervention) {
        $where_ccam = "`codes_ccam` LIKE '%{$ccam_intervention}%'";
        $where_intervention[] = $where_ccam;
    }
    if ($where_intervention) {
        $where_intervention = implode(" OR ", $where_intervention);
    }
}
$order_intervention = "rques";
$total_intervs = null;
if ($where_intervention) {
    $total_intervs = $intervention->countList($where_intervention);
    $interventions = $intervention->loadlist($where_intervention, $order_intervention, "{$page_interv}, 30");
}
foreach ($interventions as &$intervention) {
    $intervention->loadRefSejour();
    $intervention->_ref_sejour->loadRefPatient();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("dossierMedical", $dossierMedical);
$smarty->assign("canCabinet", $canCabinet);
$smarty->assign("canPlanningOp", $canPlanningOp);
$smarty->assign("sejours", $sejours);
$smarty->assign("page_sejour", $page_sejour);
$smarty->assign("total_sejours", $total_sejours);
$smarty->assign("interventions", $interventions);
$smarty->assign("page_interv", $page_interv);
$smarty->assign("total_intervs", $total_intervs);
$smarty->assign("consultations", $consultations);
$smarty->assign("page_consult", $page_consult);
}
$canUnlockActes = $module == "dPpmsi" || CModule::getCanDo("dPsalleOp")->admin;
if (null == ($object_class = CValue::get("object_class"))) {
    CAppUI::stepMessage(UI_MSG_WARNING, "{$tab}-msg-mode-missing");
    return;
}
$NDA = "";
$IPP = "";
$confirmCloture = CValue::get("confirmCloture", 0);
switch ($object_class) {
    case "COperation":
        $object = new COperation();
        // Chargement de l'opération et génération du document
        $operation_id = CValue::post("mb_operation_id", CValue::getOrSession("object_id"));
        if ($object->load($operation_id)) {
            $object->loadRefSejour();
            $mbSejour = $object->_ref_sejour;
            $mbSejour->loadNDA();
            $NDA = $mbSejour->_NDA;
            $mbSejour->loadRefPatient();
            $mbSejour->_ref_patient->loadIPP();
            $IPP = $mbSejour->_ref_patient->_IPP;
        }
        break;
    case "CSejour":
        $object = new CSejour();
        // Chargement du séjour et génération du document
        $sejour_id = CValue::post("mb_sejour_id", CValue::getOrSession("object_id"));
        if ($object->load($sejour_id)) {
            $object->loadRefPatient();
            $object->loadRefDossierMedical();
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("operation_id");
     if ($this->operation_id && $this->fieldModified("operation_id")) {
         $op = new COperation();
         $op->load($this->operation_id);
         $this->sejour_id = $op->sejour_id;
         if (CModule::getActive("maternite")) {
             $sejour = $op->loadRefSejour();
             if ($sejour->grossesse_id) {
                 $consult = $this->loadRefConsultation();
                 $consult->grossesse_id = $sejour->grossesse_id;
                 if ($msg = $consult->store()) {
                     return $msg;
                 }
             }
         }
     }
     return parent::store();
 }
    $anticoagulant = new CBcbClasseATC();
    if ($inLivretTherapeutique) {
        $anticoagulant_list = $anticoagulant->loadRefProduitsLivret("B01AB");
    } else {
        $anticoagulant->loadRefsProduits("B01AB");
        $anticoagulant_list = $anticoagulant->_ref_produits;
    }
} else {
    $list = CAppUI::conf("bloodSalvage AntiCoagulantList");
    $anticoagulant_list = explode("|", $list);
}
$selOp = new COperation();
if ($op) {
    $selOp->load($op);
    $selOp->loadRefsConsultAnesth();
    $selOp->loadRefSejour()->loadRefPatient();
    $selOp->_ref_sejour->_ref_patient->loadRefDossierMedical();
    $selOp->_ref_sejour->_ref_patient->loadRefLatestConstantes();
    $blood_salvage = new CBloodSalvage();
    $blood_salvage->operation_id = $op;
    $blood_salvage->loadMatchingObject();
    $timing["_recuperation_start"] = array();
    $max_add_minutes = CAppUI::conf("dPsalleOp max_add_minutes");
    foreach ($timing as $key => $value) {
        for ($i = -CAppUI::conf("dPsalleOp max_sub_minutes"); $i < $max_add_minutes && $blood_salvage->{$key} !== null; $i++) {
            $timing[$key][] = CMbDT::time("{$i} minutes", $blood_salvage->{$key});
        }
    }
}
/*
 * Liste des cell saver.
 static function buildEventsGrid(COperation $interv, $time_debut_op_iso, $time_fin_op_iso, $time_min, $time_max)
 {
     // ---------------------------------------------------
     // Gestes, Medicaments, Perfusions peranesth
     $evenements = array("CAnesthPerop" => array(), "CAffectationPersonnel" => array());
     // Personnel de l'interv
     $interv->loadAffectationsPersonnel();
     foreach ($interv->_ref_affectations_personnel as $affectations) {
         foreach ($affectations as $_affectation) {
             if (!$_affectation->debut || !$_affectation->fin) {
                 continue;
             }
             $evenements["CAffectationPersonnel"][$_affectation->_id] = array("icon" => null, "label" => $_affectation->_ref_personnel, "unit" => null, "alert" => false, "datetime" => $_affectation->debut, "position" => CSupervisionTimedEntity::getPosition($_affectation->debut, $time_min, $time_max), "width" => CSupervisionTimedEntity::getWidth($_affectation->debut, $_affectation->fin, $time_min, $time_max), "object" => $_affectation, "editable" => false);
         }
     }
     // Personnel de la plage
     $plageop = $interv->_ref_plageop;
     $plageop->loadAffectationsPersonnel();
     foreach ($plageop->_ref_affectations_personnel as $affectations) {
         foreach ($affectations as $_affectation) {
             if (!$_affectation->debut || !$_affectation->fin) {
                 continue;
             }
             $evenements["CAffectationPersonnel"][$_affectation->_id] = array("icon" => null, "label" => $_affectation->_ref_personnel, "unit" => null, "alert" => false, "datetime" => $_affectation->debut, "position" => CSupervisionTimedEntity::getPosition($_affectation->debut, $time_min, $time_max), "width" => CSupervisionTimedEntity::getWidth($_affectation->debut, $_affectation->fin, $time_min, $time_max), "object" => $_affectation, "editable" => false);
         }
     }
     // Gestes perop
     $interv->loadRefsAnesthPerops();
     foreach ($interv->_ref_anesth_perops as $_perop) {
         $evenements["CAnesthPerop"][$_perop->_id] = array("icon" => null, "label" => $_perop->libelle, "unit" => null, "alert" => $_perop->incident, "datetime" => $_perop->datetime, "position" => CSupervisionTimedEntity::getPosition($_perop->datetime, $time_min, $time_max), "object" => $_perop, "editable" => true);
     }
     // Lignes de medicaments et d'elements
     $sejour = $interv->loadRefSejour();
     $prescription = $sejour->loadRefPrescriptionSejour();
     if ($prescription->_id) {
         $lines = $prescription->loadPeropLines(false);
         foreach ($lines as $_line_array) {
             $_line = $_line_array["object"];
             $key = "CPrescription._chapitres.{$_line->_chapitre}";
             if (!isset($evenements[$key])) {
                 $evenements[$key] = array("subitems" => array(), "icon" => $_line->_chapitre);
             }
             // Build view
             $_subkey = array("line" => $_line, "label" => "");
             $_view = "";
             if ($_line instanceof CPrescriptionLineElement) {
                 $_view = $_line->_view;
             } elseif ($_line instanceof CPrescriptionLineMix) {
                 foreach ($_line->_ref_lines as $_mix_item) {
                     $_view .= "{$_mix_item->_ucd_view} / ";
                 }
             } else {
                 $_view = $_line->_ucd_view;
             }
             $_subkey["label"] = $_view;
             $_subkey_guid = $_subkey["line"]->_guid;
             if (!isset($evenements[$key]["subitems"][$_subkey_guid])) {
                 $evenements[$key]["subitems"][$_subkey_guid] = array("label" => $_subkey["label"], "line" => $_line, "items" => array());
             }
             foreach ($_line_array["administrations"] as $_adms) {
                 $_adms = CModelObject::naturalSort($_adms, array("dateTime"));
                 foreach ($_adms as $_adm) {
                     $unite = "";
                     if ($_line instanceof CPrescriptionLineMedicament || $_line instanceof CPrescriptionLineMix) {
                         $unite = $_adm->_ref_object->_ref_produit->libelle_unite_presentation;
                     }
                     $evenements[$key]["subitems"][$_subkey_guid]["items"][] = array("label" => "", "unit" => "{$_adm->quantite} {$unite}", "alert" => false, "datetime" => $_adm->dateTime, "position" => CSupervisionTimedEntity::getPosition($_adm->dateTime, $time_min, $time_max), "object" => $_adm, "editable" => false);
                 }
             }
         }
     }
     return $evenements;
 }
 /**
  * Prepare the data to send from the given operation
  *
  * @param COperation   $operation        The operation
  * @param string       $encoding         The encoding
  * @param string       $modality         The target modality
  * @param string       $calling_ae_title The AE title who requested the worklist
  * @param CDicomConfig $dicom_config     The Exchange Dicom
  *
  * @return array
  */
 protected static function getDataFromOperation($operation, $encoding, $modality, $calling_ae_title, $dicom_config)
 {
     $patient = $operation->loadRefPatient();
     $operation->updateFormFields();
     $operation->loadRefPlageOp();
     $sejour = $operation->loadRefSejour();
     $chir = $operation->loadRefChir();
     $patient->loadIPP();
     $sejour->loadNDA();
     $libelle = "";
     if ($operation->libelle) {
         $libelle = substr($operation->libelle, 0, 64);
     } else {
         $libelle = "Pas de libellé";
     }
     $date = "";
     if ($operation->date) {
         $date = str_replace("-", "", $operation->date);
     } else {
         $date = str_replace("-", "", $operation->_ref_plageop->date);
     }
     $time = "";
     if ($operation->time_operation) {
         $time = str_replace(":", "", $operation->time_operation);
         $time .= ".000000";
     } else {
         $time = str_replace(':', '', CMbDT::time()) . '.000000';
     }
     $sejour_id = $sejour->_id;
     if ($sejour->_NDA) {
         $sejour_id = $sejour->_NDA;
     }
     $patient_id = $patient->_id;
     if ($patient->_IPP) {
         $patient_id = $patient->_IPP;
     }
     $age = intval(substr(trim($patient->_age), 0, 2));
     $chir_name = "{$chir->_user_last_name} {$chir->_user_first_name}";
     $data = array(0x8 => array(0x50 => self::encodeValue($sejour_id, $encoding)), 0x10 => array(0x10 => self::encodeValue("{$patient->nom}^{$patient->prenom}", $encoding), 0x20 => self::encodeValue("{$patient_id}", $encoding), 0x30 => self::encodeValue(str_replace("-", "", $patient->naissance), $encoding), 0x40 => self::encodeValue(strtoupper($patient->sexe), $encoding)), 0x20 => array(0xd => self::encodeValue($sejour_id, $encoding)), 0x38 => array(0x10 => self::encodeValue($sejour->_NDA, $encoding)), 0x40 => array(0x100 => array(array(array("group_number" => 0x8, "element_number" => 0x60, "value" => self::encodeValue($modality, $encoding)), array("group_number" => 0x40, "element_number" => 0x1, "value" => self::encodeValue($calling_ae_title, $encoding)), array("group_number" => 0x40, "element_number" => 0x2, "value" => self::encodeValue($date, $encoding)), array("group_number" => 0x40, "element_number" => 0x3, "value" => self::encodeValue($time, $encoding)), array("group_number" => 0x40, "element_number" => 0x6, "value" => self::encodeValue($chir_name, $encoding)), array("group_number" => 0x40, "element_number" => 0x7, "value" => self::encodeValue($libelle, $encoding)), array("group_number" => 0x40, "element_number" => 0x9, "value" => self::encodeValue($sejour_id, $encoding)))), 0x1001 => self::encodeValue($sejour_id, $encoding)));
     /* We had the field 0x0032,0x1032 if it's configured */
     if ($dicom_config->send_0032_1032) {
         if (!array_key_exists(0x32, $data)) {
             $data[0x32] = array();
         }
         $data[0x32][0x1032] = self::encodeValue($chir_name, $encoding);
         /* Add the field into the sequence of item 0x0040,0x0100 */
         /*$data[0x0040][0x0100][0][] = array(
             "group_number" => 0x0032,
             "element_number" => 0x1032, "value" => self::encodeValue($chir_name, $encoding)
           );*/
     }
     return $data;
 }
 */
CCanDo::checkRead();
$chir_id = CValue::get("chir_id");
$plageop = new CPlageOp();
$plageop->load(CValue::get("plageop_id"));
$plageop->loadRefSalle();
$where = array("chir_id" => "= '{$chir_id}'");
$plageop->loadRefsOperations(false, null, true, null, $where);
$plageop->guessHoraireVoulu();
$rank_validated = array();
$rank_not_validated = array();
$_op = new COperation();
$_last_op = null;
foreach ($plageop->_ref_operations as $_op) {
    $_op->loadRefChir()->loadRefFunction();
    $_op->loadRefSejour()->loadRefPatient()->loadRefDossierMedical()->countAllergies();
    $_op->loadExtCodesCCAM();
    if ($_op->_horaire_voulu) {
        $_last_op = $_op;
    }
}
$horaire_voulu = $plageop->debut;
if ($_last_op) {
    $horaire_voulu = $_last_op->_horaire_voulu;
    $horaire_voulu = CMbDT::addTime($_last_op->temp_operation, $horaire_voulu);
    $horaire_voulu = CMbDT::addTime($plageop->temps_inter_op, $horaire_voulu);
    $horaire_voulu = CMbDT::addTime($_last_op->pause, $horaire_voulu);
}
$new_op = new COperation();
$new_op->_horaire_voulu = $horaire_voulu;
$plageop->_ref_operations[] = $new_op;
 function addIntervention($elParent, COperation $operation, $referent = null, $light = false)
 {
     $identifiant = $this->addElement($elParent, "identifiant");
     $this->addElement($identifiant, "emetteur", $operation->_id);
     $last_idex = $operation->_ref_last_id400;
     if (isset($last_idex->_id)) {
         $this->addElement($identifiant, "recepteur", $last_idex->id400);
     }
     $sejour = $operation->loadRefSejour();
     if (!$operation->plageop_id) {
         $operation->completeField("date");
     }
     // Calcul du début de l'intervention
     $mbOpDate = CValue::first($operation->_ref_plageop->date, $operation->date);
     $time_operation = $operation->time_operation == "00:00:00" ? null : $operation->time_operation;
     $mbOpHeureDebut = CValue::first($operation->debut_op, $operation->entree_salle, $time_operation, $operation->horaire_voulu, $operation->_ref_plageop->debut);
     $mbOpDebut = CMbRange::forceInside($sejour->entree, $sejour->sortie, "{$mbOpDate} {$mbOpHeureDebut}");
     // Calcul de la fin de l'intervention
     $mbOpHeureFin = CValue::first($operation->fin_op, $operation->sortie_salle, CMbDT::addTime($operation->temp_operation, CMbDT::time($mbOpDebut)));
     $mbOpFin = CMbRange::forceInside($sejour->entree, $sejour->sortie, "{$mbOpDate} {$mbOpHeureFin}");
     $debut = $this->addElement($elParent, "debut");
     $this->addElement($debut, "date", CMbDT::date($mbOpDebut));
     $this->addElement($debut, "heure", CMbDT::time($mbOpDebut));
     $fin = $this->addElement($elParent, "fin");
     $this->addElement($fin, "date", CMbDT::date($mbOpFin));
     $this->addElement($fin, "heure", CMbDT::time($mbOpFin));
     if ($light) {
         // Ajout des participants
         $mbParticipants = array();
         foreach ($operation->_ref_actes_ccam as $acte_ccam) {
             $acte_ccam->loadRefExecutant();
             $mbParticipant = $acte_ccam->_ref_executant;
             $mbParticipants[$mbParticipant->user_id] = $mbParticipant;
         }
         $participants = $this->addElement($elParent, "participants");
         foreach ($mbParticipants as $mbParticipant) {
             $participant = $this->addElement($participants, "participant");
             $medecin = $this->addElement($participant, "medecin");
             $this->addProfessionnelSante($medecin, $mbParticipant);
         }
         // Libellé de l'opération
         $this->addTexte($elParent, "libelle", $operation->libelle, 80);
     } else {
         $this->addUniteFonctionnelle($elParent, $operation);
         // Uniquement le responsable de l’'intervention
         $participants = $this->addElement($elParent, "participants");
         $participant = $this->addElement($participants, "participant");
         $medecin = $this->addElement($participant, "medecin");
         $this->addProfessionnelSante($medecin, $operation->loadRefChir());
         // Libellé de l'opération
         $this->addTexte($elParent, "libelle", $operation->libelle, 4000);
         // Remarques sur l'opération
         $this->addTexte($elParent, "commentaire", CMbString::convertHTMLToXMLEntities("{$operation->materiel} - {$operation->rques}"), 4000);
         // Conventionnée ?
         $this->addElement($elParent, "convention", $operation->conventionne ? 1 : 0);
         // TypeAnesthésie : nomemclature externe (idex)
         if ($operation->type_anesth) {
             $tag_hprimxml = $this->_ref_receiver->_tag_hprimxml;
             $idexTypeAnesth = CIdSante400::getMatch("CTypeAnesth", $tag_hprimxml, null, $operation->type_anesth);
             $this->addElement($elParent, "typeAnesthesie", $idexTypeAnesth->id400);
         }
         // Indicateurs
         $indicateurs = $this->addElement($elParent, "indicateurs");
         $dossier_medical = new CDossierMedical();
         $dossier_medical->object_class = "CPatient";
         $dossier_medical->object_id = $operation->loadRefPatient()->_id;
         $dossier_medical->loadMatchingObject();
         $antecedents = $dossier_medical->loadRefsAntecedents();
         foreach ($antecedents as $_antecedent) {
             $rques = CMbString::htmlspecialchars($_antecedent->rques);
             $rques = CMbString::convertHTMLToXMLEntities($rques);
             $this->addCodeLibelle($indicateurs, "indicateur", $_antecedent->_id, $rques);
         }
         // Extemporané
         if ($operation->exam_extempo) {
             $this->addCodeLibelle($indicateurs, "indicateur", "EXT", "Extemporané");
         }
         // Recours / Durée USCPO
         $this->addElement($elParent, "recoursUscpo", $operation->duree_uscpo ? 1 : 0);
         $this->addElement($elParent, "dureeUscpo", $operation->duree_uscpo ? $operation->duree_uscpo : null);
         // Côté (droit|gauche|bilatéral|total|inconnu)
         // D - Droit
         // G - Gauche
         // B - Bilatéral
         // T - Total
         // I - Inconnu
         $cote = array("droit" => "D", "gauche" => "G", "bilatéral" => "B", "total" => "T", "inconnu" => "I", "haut" => "HT", "bas" => "BS");
         $this->addCodeLibelle($elParent, "cote", $cote[$operation->cote], CMbString::capitalize($operation->cote));
     }
 }
<?php

/**
 * Onglet d'accouchement pour une parturiente en salle d'opération
 *  
 * @category Maternite
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html 
 * @version  SVN: $Id:$ 
 * @link     http://www.mediboard.org
 */
$operation_id = CValue::get("operation_id");
$operation = new COperation();
$operation->load($operation_id);
$operation->loadRefPlageOp(1);
$sejour = $operation->loadRefSejour(true);
$grossesse = $sejour->loadRefGrossesse();
$grossesse->loadRefsSejours();
$grossesse->loadRefsConsultations();
foreach ($grossesse->_ref_consultations as $_consult) {
    $_consult->loadRefPlageConsult();
}
$grossesse->_semaine_grossesse = ceil(CMbDT::daysRelative($grossesse->_date_fecondation, CMbDT::date($operation->_datetime)) / 7);
$grossesse->_terme_vs_operation = CMbDT::daysRelative($grossesse->terme_prevu, CMbDT::date($operation->_datetime));
$patient = $operation->loadRefPatient();
$smarty = new CSmartyDP();
$smarty->assign("operation", $operation);
$smarty->display("inc_vw_grossesse.tpl");