$mediuser = CMediusers::get(); if ($mediuser->isPraticien()) { $chir = $mediuser->createUser(); } // Praticien selectionné $chirSel = CValue::getOrSession("chirSel", $chir ? $chir->user_id : null); // Type de vue $show_payees = CValue::getOrSession("show_payees", 1); $show_annulees = CValue::getOrSession("show_annulees", 0); // Plage de consultation selectionnée $plageconsult_id = CValue::getOrSession("plageconsult_id", null); $plageSel = new CPlageconsult(); if ($plageconsult_id === null && $chirSel && $is_in_period) { $nowTime = CMbDT::time(); $where = array("chir_id = '{$chirSel}' OR remplacant_id = '{$chirSel}' OR pour_compte_id = '{$chirSel}'", "date" => "= '{$today}'", "debut" => "<= '{$nowTime}'", "fin" => ">= '{$nowTime}'"); $plageSel->loadObject($where); } if (!$plageSel->plageconsult_id) { $plageSel->load($plageconsult_id); } else { $plageconsult_id = $plageSel->plageconsult_id; } $plageSel->loadRefChir(); $plageSel->loadRefRemplacant(); $plageSel->loadRefPourCompte(); $plageSel->loadRefsNotes(); $plageSel->loadRefsBack($show_annulees, true, $show_payees); if ($plageSel->_affected && count($plageSel->_ref_consultations)) { $firstconsult = reset($plageSel->_ref_consultations); $_firstconsult_time = substr($firstconsult->heure, 0, 5); $lastconsult = end($plageSel->_ref_consultations);
$where["chir_id"] = "= '{$prat_id}'"; $where["date"] = "= '{$day_now}'"; $where["debut"] = "<= '{$time_now}'"; $where["fin"] = "> '{$time_now}'"; $plage->loadObject($where); if (!$plage->_id) { // Cas ou on a des plage en collision $where = array(); $where["chir_id"] = "= '{$prat_id}'"; $where["date"] = "= '{$day_now}'"; $where["debut"] = "<= '{$hour_now}'"; $where["fin"] = ">= '{$hour_now}'"; $plageBefore->loadObject($where); $where["debut"] = "<= '{$hour_next}'"; $where["fin"] = ">= '{$hour_next}'"; $plageAfter->loadObject($where); if ($plageBefore->_id) { if ($plageAfter->_id) { $plageBefore->fin = $plageAfter->debut; } else { $plageBefore->fin = max($plageBefore->fin, $hour_next); } $plage =& $plageBefore; } elseif ($plageAfter->_id) { $plageAfter->debut = min($plageAfter->debut, $hour_now); $plage =& $plageAfter; } else { $plage->chir_id = $prat_id; $plage->date = $day_now; $plage->freq = "00:" . CPlageconsult::$minutes_interval . ":00"; $plage->debut = $hour_now;
/** * Crée une consultation à une horaire arbitraire et créé les plages correspondantes au besoin * * @param string $datetime Date et heure * @param ref $praticien_id Praticien * @param ref $patient_id Patient * * @return null|string Store-like message */ function createByDatetime($datetime, $praticien_id, $patient_id) { $day_now = CMbDT::format($datetime, "%Y-%m-%d"); $time_now = CMbDT::format($datetime, "%H:%M:00"); $hour_now = CMbDT::format($datetime, "%H:00:00"); $hour_next = CMbDT::time("+1 HOUR", $hour_now); $plage = new CPlageconsult(); $plageBefore = new CPlageconsult(); $plageAfter = new CPlageconsult(); // Cas ou une plage correspond $where = array(); $where["chir_id"] = "= '{$praticien_id}'"; $where["date"] = "= '{$day_now}'"; $where["debut"] = "<= '{$time_now}'"; $where["fin"] = "> '{$time_now}'"; $plage->loadObject($where); if (!$plage->plageconsult_id) { // Cas ou on a des plage en collision $where = array(); $where["chir_id"] = "= '{$praticien_id}'"; $where["date"] = "= '{$day_now}'"; $where["debut"] = "<= '{$hour_now}'"; $where["fin"] = ">= '{$hour_now}'"; $plageBefore->loadObject($where); $where["debut"] = "<= '{$hour_next}'"; $where["fin"] = ">= '{$hour_next}'"; $plageAfter->loadObject($where); if ($plageBefore->_id) { $plageBefore->fin = $plageAfter->_id ? $plageAfter->debut : max($plageBefore->fin, $hour_next); $plage = $plageBefore; } elseif ($plageAfter->_id) { $plageAfter->debut = min($plageAfter->debut, $hour_now); $plage = $plageAfter; } else { $plage->chir_id = $praticien_id; $plage->date = $day_now; $plage->freq = "00:" . CPlageconsult::$minutes_interval . ":00"; $plage->debut = $hour_now; $plage->fin = $hour_next; } $plage->updateFormFields(); if ($msg = $plage->store()) { return $msg; } } $this->plageconsult_id = $plage->_id; $this->patient_id = $patient_id; // Chargement de la consult avec la plageconsult && le patient $this->loadMatchingObject(); if (!$this->_id) { $this->heure = $time_now; $this->arrivee = "{$day_now} {$time_now}"; $this->duree = 1; $this->chrono = CConsultation::PLANIFIE; } return $this->store(); }
function getPreviousPlage() { $plage = new CPlageconsult(); if (!$this->_id) { return $plage; } $where = array(); $where[] = " chir_id = '{$this->chir_id}' OR remplacant_id = '{$this->remplacant_id}'"; $where["locked"] = " != '1' "; $where["date"] = "< '{$this->date}' "; $where["plageconsult_id"] = " != '{$this->plageconsult_id}' "; $plage->loadObject($where, "date DESC, debut DESC"); return $plage; }
static function makeConsult($patient_id, $chir_id, $date, $store = true, $time = null) { $consult = new CConsultation(); $date = CMbDT::date($date); $plage = new CPlageconsult(); $where = array("plageconsult.chir_id" => "= '{$chir_id}'", "plageconsult.date" => "= '{$date}'"); $plage->loadObject($where); if (!$plage->_id) { $plage->date = $date; $plage->chir_id = $chir_id; $plage->debut = "09:00:00"; $plage->fin = "19:00:00"; $plage->freq = "00:30:00"; $plage->libelle = "Importation"; if ($msg = $plage->store()) { return $msg; } } $consult->patient_id = $patient_id; $consult->plageconsult_id = $plage->_id; $consult->heure = $time ? $time : "09:00:00"; $consult->chrono = $date < CMbDT::date() ? CConsultation::TERMINE : CConsultation::PLANIFIE; if ($store) { if ($msg = $consult->store()) { return $msg; } if (!$consult->_id) { CAppUI::setMsg("Consultation non trouvée et non importée : {$patient_id} / {$chir_id} / {$date}", UI_MSG_WARNING); return false; } } return $consult; }
if (!$resolve) { CMbObject::massLoadFwdRef($consultations, "plageconsult_id"); } foreach ($consultations as $consult) { $consult->loadRefPlageConsult(); if (!$resolve) { $consult->loadRefPatient(); } } if ($resolve) { foreach ($consultations as $consult) { $where = array(); $where["chir_id"] = " = '" . $consult->_ref_plageconsult->chir_id . "'"; $where["date"] = " = '" . $consult->_ref_plageconsult->date . "'"; $where[] = " '{$consult->heure}' BETWEEN debut AND fin"; $plage = new CPlageconsult(); if ($plage->loadObject($where)) { $consult->plageconsult_id = $plage->_id; if ($msg = $consult->store()) { mbLog($msg); } } } } // Création du template $smarty = new CSmartyDP(); $smarty->assign("nb_consult", $nb_consult); $smarty->assign("consultations", $consultations); $smarty->assign("resolve", $resolve); $smarty->assign("limit", $limit); $smarty->display("vw_move_consult_plage.tpl");
$date = CValue::get("date"); $chir_id = CValue::get("chir_id"); $function_id = CValue::get("function_id"); $plages = array(); if (!$type || !$nb) { CApp::json($plages); } // get current $plage_consult = new CPlageconsult(); $ds = $plage_consult->getDS(); $where = array(); $where['date'] = " = '{$date}' "; $where['locked'] = " != '1' "; if ($chir_id) { $where['chir_id'] = " = '{$chir_id}' "; $plage_consult->loadObject($where); } if (!$plage_consult->_id && $function_id) { $mediuser = new CMediusers(); $users = $mediuser->loadProfessionnelDeSante(PERM_READ, $function_id); $where["chir_id"] = $ds->prepareIn(array_keys($users)); $plage_consult->loadObject($where); } if (!$plage_consult->_id) { CApp::json($plages); } // guess next dates $dates = array(); for ($a = 1; $a <= $nb; $a++) { $dates[$a] = CMbDT::date("+{$a} {$type}", $date); }