/** * Loads siblings (prev, next) * * @param bool $use_sejour Try to use sejour bounds to guess prev et next (mostly no prev nor next) * * @return void */ function loadRefsAffectations($use_sejour = false) { $sejour = $this->_ref_sejour; $this->_ref_prev = new CAffectation(); $guess_no_prev = $use_sejour && $sejour && $this->entree == $sejour->entree; if (!$guess_no_prev) { $where = array("affectation_id" => "!= '{$this->_id}'", "sejour_id" => "= '{$this->sejour_id}'", "sortie" => "= '{$this->entree}'"); $this->_ref_prev->loadObject($where); } $this->_ref_next = new CAffectation(); $guess_no_next = $use_sejour && $sejour && $this->sortie == $sejour->sortie; if (!$guess_no_next) { $where = array("affectation_id" => "!= '{$this->_id}'", "sejour_id" => "= '{$this->sejour_id}'", "entree" => "= '{$this->sortie}'"); $this->_ref_next->loadObject($where); } }
/** * Check dispo * * @param string $date Date * * @return void */ function checkDispo($date) { assert($this->_ref_affectations !== null); $index = "lit_id"; // Last Dispo $where = array("lit_id" => "= '{$this->lit_id}'", "sortie" => "<= '{$date} 23:59:59'"); $order = "sortie DESC"; $this->_ref_last_dispo = new CAffectation(); $this->_ref_last_dispo->loadObject($where, $order, null, null, $index); $this->_ref_last_dispo->checkDaysRelative($date); // Next Dispo $where = array("lit_id" => "= '{$this->lit_id}'", "entree" => ">= '{$date} 00:00:00'"); $order = "entree ASC"; $this->_ref_next_dispo = new CAffectation(); $this->_ref_next_dispo->loadObject($where, $order, null, null, $index); $this->_ref_next_dispo->checkDaysRelative($date); }
$sortie_sejour = CMbDT::dateTime(); if ($sejour->sortie_reelle) { $sortie_sejour = $sejour->sortie_reelle; } $where = array(); $where["entree"] = "<= '" . $sortie_sejour . "'"; $where["sortie"] = ">= '" . $sortie_sejour . "'"; $where["function_id"] = "IS NOT NULL"; $affectatione = new CAffectation(); /** @var CAffectation[] $blocages_lit */ $blocages_lit = $affectatione->loadList($where); $where["function_id"] = "IS NULL"; foreach ($blocages_lit as $key => $blocage) { $blocage->loadRefLit()->loadRefChambre()->loadRefService(); $where["lit_id"] = "= '{$blocage->lit_id}'"; if (!$sejour->_id && $affectatione->loadObject($where)) { $affectatione->loadRefSejour(); $affectatione->_ref_sejour->loadRefPatient(); $jusqua = CMbDT::transform($affectatione->sortie, null, "%Hh%Mmin %d-%m-%Y") . " (" . $affectatione->_ref_sejour->_ref_patient->_view; $blocage->_ref_lit->_view .= " indisponible jusqu'à " . $jusqua . ")"; } } $exchange_source = CExchangeSource::get("mediuser-" . CAppUI::$user->_id, "smtp"); $_functions = array(); if ($chir->_id) { $_functions = $chir->loadBackRefs("secondary_functions"); } $op->loadRefChir2(); $op->loadRefChir3(); $op->loadRefChir4(); if (!$op->_id) {
$where = array("actif" => "= '1'"); $list_mode_sortie = $mode_sortie->loadGroupList($where); } } $where = array(); $where["entree"] = "<= '" . CMbDT::dateTime() . "'"; $where["sortie"] = ">= '" . CMbDT::dateTime() . "'"; $where["function_id"] = "IS NOT NULL"; $affectation = new CAffectation(); /** @var CAffectation[] $blocages_lit */ $blocages_lit = $affectation->loadList($where); $where["function_id"] = "IS NULL"; foreach ($blocages_lit as $blocage) { $blocage->loadRefLit()->loadRefChambre()->loadRefService(); $where["lit_id"] = "= '{$blocage->lit_id}'"; if ($affectation->loadObject($where)) { $sejour = $affectation->loadRefSejour(); $patient = $sejour->loadRefPatient(); $blocage->_ref_lit->_view .= " indisponible jusqu'à " . CMbDT::transform($affectation->sortie, null, "%Hh%Mmin %d-%m-%Y"); $blocage->_ref_lit->_view .= " (" . $patient->_view . " (" . strtoupper($patient->sexe) . ") "; $blocage->_ref_lit->_view .= CAppUI::conf("dPurgences age_patient_rpu_view") ? $patient->_age . ")" : ")"; } } // Tableau de contraintes pour les champs du RPU // Contraintes sur le mode d'entree / provenance //$contrainteProvenance[6] = array("", 1, 2, 3, 4); $contrainteProvenance[7] = array("", 1, 2, 3, 4); $contrainteProvenance[8] = array("", 5, 8); // Contraintes sur le mode de sortie / destination $contrainteDestination["mutation"] = array("", 1, 2, 3, 4); $contrainteDestination["transfert"] = array("", 1, 2, 3, 4);
/** * Chargement des affectations courantes et à venir du patient * * @param date $date Date de référence * * @return void */ function loadRefsAffectations($date = null) { $affectation = new CAffectation(); // Affectations inactives if (!$affectation->_ref_module) { $this->_ref_curr_affectation = null; $this->_ref_next_affectation = null; } if (!$date) { $date = CMbDT::dateTime(); } $sejours = $this->loadRefsSejours(); $group = CGroups::loadCurrent(); // Affectation actuelle et prochaine affectation $where["affectation.sejour_id"] = CSQLDataSource::prepareIn(array_keys($sejours)); $where["sejour.group_id"] = "= '{$group->_id}'"; $order = "affectation.entree"; // @FIXME A quoi sert cette jointure ? $ljoin["sejour"] = "sejour.sejour_id = affectation.sejour_id"; // Affection courante $this->_ref_curr_affectation = new CAffectation(); $where["affectation.entree"] = "< '{$date}'"; $where["affectation.sortie"] = ">= '{$date}'"; $this->_ref_curr_affectation->loadObject($where, $order, null, $ljoin); // Prochaine affectations $this->_ref_next_affectation = new CAffectation(); $where["affectation.entree"] = "> '{$date}'"; $this->_ref_next_affectation->loadObject($where, $order, null, $ljoin); }
/** * Mapping et enregistrement de l'affectation * * @param CSejour $newVenue Admit * @param array $data Datas * @param CMovement $movement Movement * * @return CAffectation|string|null */ function mapAndStoreAffectation(CSejour $newVenue, $data, CMovement $movement = null) { $sender = $this->_ref_sender; if ($newVenue->annule) { return null; } $PV1_3 = $this->queryNode("PV1.3", $data["PV1"]); $affectation = new CAffectation(); $affectation->sejour_id = $newVenue->_id; $event_code = $this->_ref_exchange_hl7v2->code; // Récupération de la date de réalisation de l'évènement // Dans le cas spécifique de quelques évènements, on récupère le code sur le ZBE $datetime = $this->queryTextNode("EVN.6/TS.1", $data["EVN"]); if (array_key_exists("ZBE", $data) && $data["ZBE"] && CMbArray::in($event_code, array("A01", "A02", "A04", "A15", "Z80", "Z84"))) { $datetime = $this->queryTextNode("ZBE.2/TS.1", $data["ZBE"]); } switch ($event_code) { // Cas d'une suppression de mutation ou d'une permission d'absence case "A12": case "A52": // Quand on a un mouvement (provenant d'un ZBE) if (array_key_exists("ZBE", $data) && $data["ZBE"]) { if (!$movement) { return null; } $affectation->load($movement->affectation_id); if (!$affectation->_id) { return "Le mouvement '{$movement->_id}' n'est pas lié à une affectation dans Mediboard"; } } else { $affectation->entree = $datetime; $affectation->loadMatchingObject(); if (!$affectation->_id) { return null; } } // Pas de synchronisation $affectation->_no_synchro = true; if ($msgAffectation = $affectation->delete()) { return $msgAffectation; } return null; // Annulation admission // Annulation admission case "A11": if (!$movement) { return null; } $affectation = $newVenue->getCurrAffectation($datetime); // Si le mouvement n'a pas d'affectation associée, et que l'on a déjà une affectation dans MB if (!$movement->affectation_id && $affectation->_id) { return "Le mouvement '{$movement->_id}' n'est pas lié à une affectation dans Mediboard"; } // Si on a une affectation associée, alors on charge celle-ci if ($movement->affectation_id) { $affectation = $movement->loadRefAffectation(); } // Pas de synchronisation $affectation->_no_synchro = true; if ($msg = $affectation->delete()) { return $msg; } return null; // Annuler le retour du patient // Annuler le retour du patient case "A53": if (!$movement) { return null; } $affectation->load($movement->affectation_id); if (!$affectation->_id) { return "Le mouvement '{$movement->_id}' n'est pas lié à une affectation dans Mediboard"; } $affectation->effectue = 0; // Pas de synchronisation $affectation->_no_synchro = true; $affectation->_eai_sender_guid = $sender->_guid; if ($msg = $affectation->store()) { return $msg; } return $affectation; // Cas d'un départ pour une permission d'absence // Cas d'un départ pour une permission d'absence case "A21": $affectation->entree = $datetime; $affectation->loadMatchingObject(); // Si on ne retrouve pas une affectation // Création de l'affectation // et mettre à 'effectuee' la précédente si elle existe sinon création de celle-ci if (!$affectation->_id) { $service_externe = CService::loadServiceExterne($sender->group_id); if (!$service_externe->_id) { return "CService-externe-none"; } $affectation->service_id = $service_externe->_id; $return_affectation = $newVenue->forceAffectation($affectation, true); //$datetime, $affectation->lit_id, $affectation->service_id); if (is_string($return_affectation)) { return $return_affectation; } $affectation = $return_affectation; } return $affectation; // Cas d'un retour pour une permission d'absence // Cas d'un retour pour une permission d'absence case "A22": $service_externe = CService::loadServiceExterne($sender->group_id); if (!$service_externe->_id) { return "CService-externe-none"; } // Recherche de l'affectation correspondant à une permission d'absence $search = new CAffectation(); $where = array(); $where["sejour_id"] = "= '{$newVenue->_id}'"; $where["service_id"] = "= '{$service_externe->_id}'"; $where["effectue"] = "= '0'"; $where["entree"] = "<= '{$datetime}'"; $where["sortie"] = ">= '{$datetime}'"; $search->loadObject($where); // Si on ne la retrouve pas on prend la plus proche if (!$search->_id) { $where = array(); $where["sejour_id"] = "= '{$newVenue->_id}'"; $where["service_id"] = "= '{$service_externe->_id}'"; $where["effectue"] = "= '0'"; $search->loadObject($where); } $search->effectue = 1; $search->sortie = $datetime; $search->_eai_sender_guid = $sender->_guid; if ($msg = $search->store()) { return $msg; } return $search; // Cas mutation // Cas mutation case "A02": $affectation->entree = $datetime; $affectation->loadMatchingObject(); // Si on ne retrouve pas une affectation // Création de l'affectation // et mettre à 'effectuee' la précédente si elle existe sinon création de celle-ci if (!$affectation->_id) { // Récupération du Lit et UFs $this->getPL($PV1_3, $affectation, $newVenue); $return_affectation = $newVenue->forceAffectation($affectation, true); //$datetime, $affectation->lit_id, $affectation->service_id); if (is_string($return_affectation)) { return $return_affectation; } $affectation = $return_affectation; } break; // Cas modification // Cas modification case "Z99": if (!$movement) { return null; } // Si on a une affectation associée, alors on charge celle-ci if ($movement->affectation_id) { $affectation = $movement->loadRefAffectation(); } else { // On recherche l'affectation "courante" // Si qu'une affectation sur le séjour $newVenue->loadRefsAffectations(); if (count($newVenue->_ref_affectations) == 1) { $affectation = reset($newVenue->_ref_affectations); } else { // On recherche l'affectation "courante" $affectation = $newVenue->getCurrAffectation($datetime); } // Sinon on récupère et on met à jour la première affectation if (!$affectation->_id) { $affectation->sejour_id = $newVenue->_id; $affectation->entree = $newVenue->entree; $affectation->sortie = $newVenue->sortie; } } break; // Tous les autres cas on récupère et on met à jour la première affectation // Tous les autres cas on récupère et on met à jour la première affectation default: $newVenue->loadRefsAffectations(); $affectation = $newVenue->_ref_first_affectation; if (!$affectation->_id) { $affectation->sejour_id = $newVenue->_id; $affectation->entree = $newVenue->entree; $affectation->sortie = $newVenue->sortie; } } // Si pas d'UF/service/chambre/lit on retourne une affectation vide if (!$PV1_3) { if ($msgVenue = self::storeUFMedicaleSoinsSejour($data, $newVenue)) { return $msgVenue; } return $affectation; } if ($this->queryTextNode("PL.1", $PV1_3) == $sender->_configs["handle_PV1_3_null"]) { if ($msgVenue = self::storeUFMedicaleSoinsSejour($data, $newVenue)) { return $msgVenue; } return $affectation; } // Si pas de lit on affecte le service sur le séjour if (!$this->queryTextNode("PL.3", $PV1_3)) { $affectation_uf = new CAffectationUniteFonctionnelle(); // On essaye de récupérer le service dans ce cas depuis l'UF d'hébergement $date_deb = $affectation->_id ? CMbDT::date($affectation->sortie) : CMbDT::date($newVenue->sortie); $date_fin = $affectation->_id ? CMbDT::date($affectation->entree) : CMbDT::date($newVenue->entree); $uf = CUniteFonctionnelle::getUF($this->queryTextNode("PL.1", $PV1_3), "hebergement", $newVenue->group_id, $date_deb, $date_fin); if ($uf->code && $uf->_id) { $affectation_uf->uf_id = $uf->_id; $affectation_uf->object_class = "CService"; $affectation_uf->loadMatchingObject(); } // Dans le cas où l'on retrouve un service associé à l'UF d'hébergement if ($affectation_uf->_id) { $newVenue->service_id = $affectation_uf->object_id; $newVenue->uf_hebergement_id = $affectation_uf->uf_id; } $uf_med = $this->mappingUFMedicale($data, $newVenue, $affectation); $newVenue->uf_medicale_id = $uf_med ? $uf_med->_id : null; $uf_soins = $this->mappingUFSoins($data, $newVenue, $affectation); $newVenue->uf_soins_id = $uf_soins ? $uf_soins->_id : null; // On ne check pas la cohérence des dates des consults/intervs $newVenue->_skip_date_consistencies = true; $newVenue->_eai_sender_guid = $sender->_guid; if ($msgVenue = self::storeUFMedicaleSoinsSejour($data, $newVenue)) { return $msgVenue; } // Si on a pas d'UF on retourne une affectation vide if (!$uf->_id || !$affectation_uf->_id) { return $affectation; } } // Récupération du Lit et UFs $this->getPL($PV1_3, $affectation, $newVenue); $uf_med = $this->mappingUFMedicale($data, $newVenue, $affectation); $affectation->uf_medicale_id = $uf_med ? $uf_med->_id : null; $uf_soins = $this->mappingUFSoins($data, $newVenue, $affectation); $affectation->uf_soins_id = $uf_soins ? $uf_soins->_id : null; $affectation->_eai_sender_guid = $sender->_guid; if ($msg = $affectation->store()) { return $msg; } return $affectation; }
function getAffectation() { $sejour = $this->_ref_sejour; if (!$this->_ref_sejour) { $sejour = $this->loadRefSejour(); } if (!$this->_datetime_best) { $this->loadRefPlageOp(); } $affectation = new CAffectation(); $order = "entree"; $where = array(); $where["sejour_id"] = "= '{$this->sejour_id}'"; $moment = $this->_datetime_best; // Si l'intervention est en dehors du séjour, // on recadre dans le bon intervalle if ($moment < $sejour->entree) { $moment = $sejour->entree; } if ($moment > $sejour->sortie) { $moment = $sejour->sortie; } if (CMbDT::time(null, $moment) == "00:00:00") { $where["entree"] = $this->_spec->ds->prepare("<= %", CMbDT::date(null, $moment) . " 23:59:59"); $where["sortie"] = $this->_spec->ds->prepare(">= %", CMbDT::date(null, $moment) . " 00:00:01"); } else { $where["entree"] = $this->_spec->ds->prepare("<= %", $moment); $where["sortie"] = $this->_spec->ds->prepare(">= %", $moment); } $affectation->loadObject($where, $order); return $affectation; }
$max_sortie = 0; $ds = $lit->getDS(); foreach ($lits as $key => $_lit) { $_lit->_ref_affectations = array(); $_lit->loadCompleteView(); if ($_lit->_id == $affectation->lit_id) { $_lit->_ref_last_dispo = new CAffectation(); $_lit->_ref_last_dispo->sortie = $entree; $_lit->_dispo_depuis = 0; } else { $where = array(); $where["lit_id"] = "= '{$_lit->_id}'"; $where["entree"] = "<= '{$sortie}'"; $where["sortie"] = ">= '{$entree}'"; $affectation_collide = new CAffectation(); $affectation_collide->loadObject($where); if ($affectation_collide->_id) { unset($lits[$key]); continue; } $where = array("lit_id" => "= '{$_lit->_id}'", "sortie" => "<= '{$entree}'"); $index = "lit_id"; $_lit->_ref_last_dispo = new CAffectation(); $_lit->_ref_last_dispo->loadObject($where, "sortie DESC", null, null, $index); $_lit->_dispo_depuis = strtotime($entree) - strtotime($_lit->_ref_last_dispo->sortie); if ($_lit->_dispo_depuis < 0) { unset($lits[$key]); continue; } if ($_lit->_ref_last_dispo->_id && $_lit->_dispo_depuis > $max_entree) { $max_entree = $_lit->_dispo_depuis;
function addRPU($elParent, CRPU $mbObject) { $sejour = $mbObject->loadRefSejour(); $this->addElement($elParent, "CP", $mbObject->_cp); $this->addElement($elParent, "COMMUNE", $mbObject->_ville); $this->addElement($elParent, "NAISSANCE", CMbDT::transform($mbObject->_naissance, null, "%d/%m/%Y")); $this->addElement($elParent, "SEXE", strtoupper($mbObject->_sexe)); $this->addElement($elParent, "ENTREE", CMbDT::transform($sejour->entree, null, "%d/%m/%Y %H:%M")); $this->addElement($elParent, "MODE_ENTREE", $sejour->mode_entree); $this->addElement($elParent, "PROVENANCE", $sejour->provenance == "8" ? "5" : $sejour->provenance); if ($sejour->transport == "perso_taxi") { $sejour->transport = "perso"; } if ($sejour->transport == "ambu_vsl") { $sejour->transport = "ambu"; } $this->addElement($elParent, "TRANSPORT", strtoupper($sejour->transport)); $this->addElement($elParent, "TRANSPORT_PEC", strtoupper($mbObject->pec_transport)); $motif = CMbString::htmlSpecialChars($mbObject->motif); if (CAppUI::conf("dPurgences CRPU gestion_motif_sfmu", $sejour->loadRefEtablissement()) == 2 || $mbObject->motif_sfmu) { $motif = $mbObject->loadRefMotifSFMU()->code; } $this->addElement($elParent, "MOTIF", $motif); if (CModule::getActive("oscour") && CAppUI::conf("dPurgences gerer_circonstance") && CAppUI::conf("oscour version_complete")) { $circonstance = $mbObject->loadRefCirconstance(); $this->addElement($elParent, "CIRCONSTANCE", $circonstance->code); } $this->addElement($elParent, "GRAVITE", strtoupper($mbObject->ccmu)); $this->addElement($elParent, "DP", $mbObject->_DP[0] . preg_replace("/[^\\d]/", "", substr($mbObject->_DP, 1))); $liste_da = $this->addElement($elParent, "LISTE_DA"); if ($dr = $sejour->_ext_diagnostic_relie) { $this->addDiagAssocie($liste_da, $dr->code[0] . preg_replace("/[^\\d]/", "", substr($dr->code, 1))); } $das = $sejour->_diagnostics_associes; if (is_array($das)) { foreach ($das as $_da) { $_da = $_da[0] . preg_replace("/[^\\d]/", "", substr($_da, 1)); $this->addDiagAssocie($liste_da, $_da); } } $liste_actes = $this->addElement($elParent, "LISTE_ACTES"); $codes_ccam = $sejour->_ref_consult_atu->_codes_ccam; if (is_array($codes_ccam)) { foreach ($codes_ccam as $_code_ccam) { $this->addActeCCAM($liste_actes, $_code_ccam); } } $sortie = null; if ($sejour->sortie_reelle) { $sortie = $sejour->sortie_reelle; } else { // on recherche la première affectation qui n'est pas dans un service d'urgences ou externe $affectation = new CAffectation(); $ljoin["service"] = "`service`.`service_id` = `affectation`.`service_id`"; $where = array(); $where["sejour_id"] = " = '{$sejour->_id}'"; $where["service.cancelled"] = " = '0'"; $where["service.uhcd"] = " = '0'"; $where["service.urgence"] = " = '0'"; $affectation->loadObject($where, "entree ASC", null, $ljoin); if ($affectation->_id) { $sortie = $affectation->entree; } } if ($sortie) { $this->addElement($elParent, "SORTIE", CMbDT::transform($sortie, null, "%d/%m/%Y %H:%M")); } if (CModule::getActive("cerveau")) { // on recherche la première affectation vers UHCD $affectation = new CAffectation(); $ljoin["service"] = "`service`.`service_id` = `affectation`.`service_id`"; $ljoin["sejour"] = "`affectation`.`sejour_id` = `sejour`.`sejour_id`"; $where = array(); $where["affectation.sejour_id"] = " = '{$sejour->_id}'"; $where["service.cancelled"] = " = '0'"; $where["service.uhcd"] = " = '1'"; $where["sejour.uhcd"] = " = '1'"; $affectation->loadObject($where, "entree ASC", null, $ljoin); if (!$affectation->_id) { $mode_sortie = $mbObject->_mode_sortie; $destination = $sejour->destination; $orientation = $mbObject->orientation; // Dans le cas où l'on ne créé pas un relicat, on va aller chercher les valeurs sur l'affectation de médecine if ($mbObject->mutation_sejour_id && CAppUI::conf("dPurgences create_sejour_hospit")) { // on recherche la première affectation qui ni UHCD, ni URG $affectation_medecine = new CAffectation(); $ljoin["service"] = "`service`.`service_id` = `affectation`.`service_id`"; $ljoin["sejour"] = "`affectation`.`sejour_id` = `sejour`.`sejour_id`"; $where = array(); $where["affectation.sejour_id"] = " = '{$sejour->_id}'"; $where["service.cancelled"] = " = '0'"; $where["service.uhcd"] = " != '1'"; $where["service.urgence"] = " != '1'"; $affectation_medecine->loadObject($where, "entree ASC", null, $ljoin); if ($affectation_medecine) { $service = $affectation_medecine->loadRefService(); $mode_sortie = "6"; $destination = $service->default_destination; $orientation = $service->default_orientation; } } } else { // Dans le cas où l'on a eu une mutation les données du RPU concerne la mut. UHCD $mode_sortie = "6"; $destination = "1"; $orientation = "UHCD"; } $this->addElement($elParent, "MODE_SORTIE", $mode_sortie); $this->addElement($elParent, "DESTINATION", $destination); $this->addElement($elParent, "ORIENT", strtoupper($orientation)); if ($affectation->_id) { $this->addElement($elParent, "ENTREE_UHCD", CMbDT::transform($affectation->entree, null, "%d/%m/%Y %H:%M")); $this->addElement($elParent, "MODE_SORTIE_UHCD", $mbObject->_mode_sortie); $this->addElement($elParent, "DESTINATION_UHCD", $sejour->destination); $this->addElement($elParent, "ORIENT_UHCD", strtoupper($mbObject->orientation)); } } else { if (!$sortie) { $this->addElement($elParent, "SORTIE", CMbDT::transform($sejour->sortie_prevue, null, "%d/%m/%Y %H:%M")); } $this->addElement($elParent, "MODE_SORTIE", $mbObject->_mode_sortie); $this->addElement($elParent, "DESTINATION", $sejour->destination); $this->addElement($elParent, "ORIENT", strtoupper($mbObject->orientation)); } }
/** * Force la création d'une affectation en fonction de la tolérance(?) * * @param CAffectation $affectation Affectation concernée * @param bool $no_synchro No synchro * * @todo A détailler * @return CAffectation|null|string|void */ function forceAffectation(CAffectation $affectation, $no_synchro = false) { $datetime = $affectation->entree; $lit_id = $affectation->lit_id; $service_id = $affectation->service_id; $tolerance = CAppUI::conf("dPhospi CAffectation create_affectation_tolerance", CGroups::loadCurrent()); $splitting = new CAffectation(); $where["sejour_id"] = "= '{$this->_id}'"; $where["entree"] = "<= '{$datetime}'"; $where["sortie"] = ">= '{$datetime}'"; $splitting->loadObject($where); $create = new CAffectation(); // On retrouve une affectation a spliter if ($splitting->_id) { //on ne splite pas et on ne créé pas d'affectation si la tolérance n'est pas atteinte if (CMbDT::addDateTime("00:{$tolerance}:00", $splitting->entree) <= $affectation->entree || $affectation->_mutation_urg) { // Affecte la sortie de l'affectation a créer avec l'ancienne date de sortie $create->sortie = $splitting->sortie; $create->entree = $datetime; // On passe à effectuer la split $splitting->effectue = 1; $splitting->sortie = $datetime; $splitting->_no_synchro = $no_synchro; $splitting->_mutation_urg = $affectation->_mutation_urg; if ($msg = $splitting->store()) { return $msg; } } else { $create->affectation_id = $splitting->affectation_id; $create->sortie = $splitting->sortie; } } else { $create->entree = $datetime; $create->sortie = $this->sortie; } // Créé la nouvelle affectation $create->sejour_id = $this->_id; $create->lit_id = $lit_id; $create->service_id = $service_id; $create->_mutation_urg = $affectation->_mutation_urg; $create->_no_synchro = $no_synchro; if ($msg = $create->store()) { return $msg; } return $create; }