예제 #1
0
 /**
  * Finds patient siblings with at least two exact matching traits out of
  * nom, prenom, naissance
  * Optimized version with split queries for index usage forcing
  *
  * @return CPatient[] Array of siblings
  */
 function getSiblings()
 {
     $ds =& $this->_spec->ds;
     $where = array("nom" => $ds->prepareLikeName($this->nom), "prenom" => $ds->prepareLikeName($this->prenom), "patient_id" => "!= '{$this->_id}'");
     if (CAppUI::conf('dPpatients CPatient function_distinct')) {
         $function_id = CMediusers::get()->function_id;
         $where["function_id"] = "= '{$function_id}'";
     }
     $siblings = $this->loadList($where);
     if ($this->naissance !== "0000-00-00") {
         $where = array("nom" => $ds->prepareLikeName($this->nom), "naissance" => $ds->prepare(" = %", $this->naissance), "patient_id" => "!= '{$this->_id}'");
         if (CAppUI::conf('dPpatients CPatient function_distinct')) {
             $function_id = CMediusers::get()->function_id;
             $where["function_id"] = "= '{$function_id}'";
         }
         $siblings = CMbArray::mergeKeys($siblings, $this->loadList($where, null, null, "patients.patient_id"));
         $where = array("prenom" => $ds->prepareLikeName($this->prenom), "naissance" => $ds->prepare(" = %", $this->naissance), "patient_id" => "!= '{$this->_id}'");
         if (CAppUI::conf('dPpatients CPatient function_distinct')) {
             $function_id = CMediusers::get()->function_id;
             $where["function_id"] = "= '{$function_id}'";
         }
         $siblings = CMbArray::mergeKeys($siblings, $this->loadList($where, null, null, "patients.patient_id"));
     }
     return $siblings;
 }
 /**
  * @see parent::loadRefsFiles()
  */
 function loadRefsFiles()
 {
     parent::loadRefsFiles();
     if (!$this->_docitems_from_dossier_anesth) {
         // On ajoute les fichiers des dossiers d'anesthésie
         if (!$this->_refs_dossiers_anesth) {
             $this->loadRefConsultAnesth();
         }
         foreach ($this->_refs_dossiers_anesth as $_dossier_anesth) {
             $_dossier_anesth->_docitems_from_consult = true;
             $_dossier_anesth->loadRefsFiles();
             $this->_ref_files = CMbArray::mergeKeys($this->_ref_files, $_dossier_anesth->_ref_files);
         }
     }
     return count($this->_ref_files);
 }
예제 #3
0
 public function testMergeKeys()
 {
     $this->assertNotEmpty($this->stub->mergeKeys(array(1), array(1)));
     $this->assertEquals(array(1 => 1, 2 => 1), $this->stub->mergeKeys(array(1 => 1), array(2 => 1)));
     $this->assertEquals(array(1 => 1, 2 => 1, 3 => 1), $this->stub->mergeKeys(array(1 => 1), array(2 => 1), array(3 => 1)));
 }
예제 #4
0
 /**
  * @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;
 }
예제 #5
0
 /**
  * Chargement des interventions
  *
  * @param bool   $annulee   Prise en compte des interventions annulées
  * @param string $order     Paramètre ORDER SQL
  * @param bool   $sorted    Utilisation du paramètre ORDER SQL passé en paramètre
  * @param null   $validated Uniquement les validées
  * @param array  $where     Tableau de paramètres WHERE SQL
  *
  * @return COperation[]
  */
 function loadRefsOperations($annulee = true, $order = "rank, time_operation, rank_voulu, horaire_voulu", $sorted = false, $validated = null, $where = array())
 {
     $where += array("plageop_id" => "= '{$this->plageop_id}'");
     if (!$annulee) {
         $where["annulee"] = "= '0'";
     }
     /** @var COperation[] $operations */
     $operations = array();
     $op = new COperation();
     if (!$sorted) {
         $operations = $op->loadList($where, $order);
     } else {
         $order = "rank, rank_voulu, horaire_voulu";
         if ($validated === null || $validated === true) {
             $where["rank"] = "> 0";
             $operations = CMbArray::mergeKeys($operations, $op->loadList($where, $order));
         }
         if ($validated === null || $validated === false) {
             // Sans rank
             $where["rank"] = "= 0";
             $where["rank_voulu"] = "> 0";
             $operations = CMbArray::mergeKeys($operations, $op->loadList($where, $order));
             // Sans rank voulu
             $where["rank_voulu"] = "= 0";
             $where["horaire_voulu"] = "IS NOT NULL";
             $operations = CMbArray::mergeKeys($operations, $op->loadList($where, $order));
             $where["horaire_voulu"] = "IS NULL";
             $operations = CMbArray::mergeKeys($operations, $op->loadList($where, $order));
         }
     }
     foreach ($operations as $_operation) {
         $_operation->_ref_plageop = $this;
         if ($_operation->temp_operation) {
             $this->_cumulative_minutes = $this->_cumulative_minutes + CMbDT::minutesRelative("00:00:00", $_operation->temp_operation);
         }
     }
     return $this->_ref_operations = $operations;
 }