Example #1
0
 public function testInsertAfterKey()
 {
     $array = array("key" => "val", "key2" => "val2");
     $this->stub->insertAfterKey($array, "key", "newKey", "newValue");
     $this->assertArrayHasKey("newKey", $array);
     $this->assertEquals($array["newKey"], "newValue");
 }
 /**
  * Intialize params
  *
  * @return void
  */
 static function initParams()
 {
     if (CAppUi::conf('ref_pays') == 2) {
         self::$list_constantes['saturation_air'] = array('type' => 'physio', 'unit' => '%', 'min' => 50, 'max' => 100);
     }
     // make a copy of the array as it will be modified
     $list_constantes = CConstantesMedicales::$list_constantes;
     foreach ($list_constantes as $_constant => &$_params) {
         self::$list_constantes_type[$_params["type"]][$_constant] =& $_params;
         // Champs de cumuls
         if (isset($_params["cumul_reset_config"])) {
             if (!isset(CConstantesMedicales::$list_constantes[$_constant]["cumul_in"])) {
                 CConstantesMedicales::$list_constantes[$_constant]["cumul_in"] = array();
             }
             if (empty($_params["formula"])) {
                 CMbArray::insertAfterKey(CConstantesMedicales::$list_constantes, $_constant, "_{$_constant}_cumul", array("cumul_for" => $_constant, "unit" => $_params["unit"]));
                 CConstantesMedicales::$list_constantes[$_constant]["cumul_in"][] = "_{$_constant}_cumul";
             } else {
                 foreach ($_params["formula"] as $_const => $_sign) {
                     CConstantesMedicales::$list_constantes[$_const]["cumul_in"][] = $_constant;
                 }
             }
         }
     }
 }
 /**
  * @see parent::store()
  */
 function store($reorder = true)
 {
     /** @var self $old */
     $old = $this->loadOldObject();
     $this->completeField("annulee", "rank", "codes_ccam", "plageop_id", "chir_id", "materiel", "commande_mat", "date");
     // Si on a une plage, la date est celle de la plage
     if ($this->plageop_id) {
         $plage = $this->loadRefPlageOp();
         $this->date = $plage->date;
     }
     // Si on choisit une plage, on copie la salle
     if ($this->fieldValued("plageop_id")) {
         $plage = $this->loadRefPlageOp();
         $this->salle_id = $plage->salle_id;
     }
     // Cas d'une plage que l'on quitte
     /** @var CPlageOp $old_plage */
     $old_plage = null;
     if ($this->fieldAltered("plageop_id") && $old->rank) {
         $old_plage = $old->loadRefPlageOp();
     }
     $comments = $this->prepareAlert();
     $place_after_interv_id = $this->_place_after_interv_id;
     $this->_place_after_interv_id = null;
     // Pré-remplissage de la durée préop si c'est une nouvelle intervention
     if (!$this->_id && !$this->duree_preop) {
         $patient = $this->loadRefSejour()->loadRefPatient();
         if ($patient->_annees >= 18) {
             $this->duree_preop = "00:" . CAppUI::conf("dPplanningOp COperation duree_preop_adulte") . ":00";
         } else {
             $this->duree_preop = "00:" . CAppUI::conf("dPplanningOp COperation duree_preop_enfant") . ":00";
         }
     }
     // On recopie la sortie réveil possible sur le réel si pas utilisée en config
     if (!CAppUI::conf("dPsalleOp COperation use_sortie_reveil_reel", CGroups::loadCurrent()->_guid)) {
         $this->sortie_reveil_reel = $this->sortie_reveil_possible;
     }
     // Création d'une alerte si modification du libellé et/ou du côté
     if ($this->_id && ($this->fieldModified("libelle") || $this->fieldModified("cote"))) {
         $alerte = "";
         $date = CMbDT::dateToLocale(CMbDT::date());
         if ($this->fieldModified("libelle")) {
             $alerte = "Le libellé a été modifié le {$date}\n" . "Ancienne valeur : " . $old->getFormattedValue("libelle") . "\nNouvelle valeur : " . $this->getFormattedValue("libelle");
         }
         $this->createAlert($alerte, true, "libelle");
         $alerte = "";
         if ($this->fieldModified("cote")) {
             $alerte = "Le côté a été modifié le {$date} : \n" . "Ancienne valeur : " . $old->getFormattedValue("cote") . "\nNouvelle valeur : " . $this->getFormattedValue("cote");
         }
         $this->createAlert($alerte, true, "cote");
     }
     $sejour = $this->loadRefSejour();
     $do_store_sejour = false;
     // Flag pour storer le séjour une seule fois
     $do_update_time = false;
     // Synchronisation des heures d'admission
     if ($this->fieldModified('horaire_voulu') || $this->fieldModified('temp_operation') || $this->fieldModified('presence_preop') || $this->fieldModified('presence_postop') || $this->fieldModified('date') || $this->fieldModified('time_operation')) {
         $do_update_time = true;
     }
     if ($this->loadRefCommande()->_id && $this->_ref_commande_mat->etat != "annulee") {
         if ($this->fieldModified("annulee", "1")) {
             $this->_ref_commande_mat->cancelledOp();
         }
         if ($this->fieldModified("materiel") || $this->fieldModified("date")) {
             $this->_ref_commande_mat->modifiedOp($this->materiel);
         }
     }
     // Standard storage
     if ($msg = parent::store()) {
         return $msg;
     }
     if ($do_update_time) {
         $do_store_sejour = $sejour->checkUpdateTimeAmbu();
     }
     // Création des besoins d'après le protocole sélectionné
     // Ne le faire que pour une nouvelle intervention
     // Pour une intervention existante, l'application du protocole
     // store les protocoles
     if (CAppUI::conf("dPbloc CPlageOp systeme_materiel") == "expert" && $this->_types_ressources_ids && !$old->_id) {
         $types_ressources_ids = explode(",", $this->_types_ressources_ids);
         foreach ($types_ressources_ids as $_type_ressource_id) {
             $besoin = new CBesoinRessource();
             $besoin->type_ressource_id = $_type_ressource_id;
             $besoin->operation_id = $this->_id;
             if ($msg = $besoin->store()) {
                 return $msg;
             }
         }
     }
     $this->createAlert($comments);
     // Mise à jour du type de PeC du séjour en Chirurgical si pas déja obstétrique
     $sejour->completeField("type_pec");
     if (!$this->_id && $sejour->type_pec != "O") {
         $sejour->type_pec = "C";
         $do_store_sejour = true;
     }
     // Cas d'une annulation
     if (!$this->annulee) {
         // Si pas une annulation on recupére le sejour
         // et on regarde s'il n'est pas annulé
         if ($sejour->annule) {
             $sejour->annule = 0;
             $do_store_sejour = true;
         }
         // Application des protocoles de prescription en fonction de l'operation->_id
         if ($this->_protocole_prescription_chir_id || $this->_protocole_prescription_anesth_id) {
             $sejour->_protocole_prescription_chir_id = $this->_protocole_prescription_chir_id;
             $sejour->_protocole_prescription_anesth_id = $this->_protocole_prescription_anesth_id;
             $sejour->applyProtocolesPrescription($this->_id);
             // On les nullify pour eviter de les appliquer 2 fois
             $this->_protocole_prescription_anesth_id = null;
             $this->_protocole_prescription_chir_id = null;
             $sejour->_protocole_prescription_chir_id = null;
             $sejour->_protocole_prescription_anesth_id = null;
         }
     } elseif ($this->rank != 0 && !CAppUI::conf("dPplanningOp COperation save_rank_annulee_validee")) {
         $this->rank = 0;
         $this->time_operation = "00:00:00";
     }
     // Store du séjour (une seule fois)
     if ($do_store_sejour) {
         $sejour->store();
     }
     // Vérification qu'on a pas des actes CCAM codés obsolètes
     if ($this->codes_ccam) {
         $this->loadRefsActesCCAM();
         foreach ($this->_ref_actes_ccam as $keyActe => $acte) {
             if (stripos($this->codes_ccam, $acte->code_acte) === false) {
                 $this->_ref_actes_ccam[$keyActe]->delete();
             }
         }
     }
     $reorder_rank_voulu = $this->_reorder_rank_voulu;
     $this->_reorder_rank_voulu = null;
     if ($this->plageop_id) {
         $plage = $this->loadRefPlageOp();
         // Cas de la création dans une plage de spécialité
         if ($plage->spec_id && $plage->unique_chir) {
             $plage->chir_id = $this->chir_id;
             $plage->spec_id = "";
             $plage->store();
         }
         // Placement de l'interv selon la preference (placement souhaité)
         if ($place_after_interv_id) {
             $plage->loadRefsOperations(false, "rank, rank_voulu, horaire_voulu", true);
             unset($plage->_ref_operations[$this->_id]);
             if ($place_after_interv_id == -1) {
                 $reorder = true;
                 $reorder_rank_voulu = true;
                 $plage->_ref_operations = CMbArray::mergeKeys(array($this->_id => $this), $plage->_ref_operations);
                 // To preserve keys (array_unshift does not)
             } elseif (isset($plage->_ref_operations[$place_after_interv_id])) {
                 $reorder = true;
                 $reorder_rank_voulu = true;
                 CMbArray::insertAfterKey($plage->_ref_operations, $place_after_interv_id, $this->_id, $this);
             }
             if ($reorder_rank_voulu) {
                 $plage->_reorder_up_to_interv_id = $this->_id;
             }
         }
     }
     // Gestion du tarif et precodage des actes
     if ($this->_bind_tarif && $this->_id) {
         if ($msg = $this->bindTarif()) {
             return $msg;
         }
     }
     // Standard storage bis
     if ($msg = parent::store()) {
         return $msg;
     }
     // Réordonnancement post-store
     if ($reorder) {
         // Réordonner la plage que l'on quitte
         if ($old_plage) {
             $old_plage->reorderOp();
         }
         $this->_ref_plageop->reorderOp($reorder_rank_voulu ? CPlageOp::RANK_REORDER : null);
     }
     return null;
 }