* @link     http://www.mediboard.org
 */
CCanDo::checkRead();
CApp::setMemoryLimit("512M");
$ds = CSQLDataSource::get("std");
$function_id = CValue::get("function_id");
$chir_ids = CValue::get("chir_ids");
$date = CValue::get("date", CMbDT::date());
// Praticiens sélectionnés
$user = new CMediusers();
$praticiens = array();
if ($function_id) {
    $praticiens = CConsultation::loadPraticiens(PERM_EDIT, $function_id);
}
if ($chir_ids) {
    $praticiens = $user->loadAll(explode("-", $chir_ids));
}
//plages de consultation
$where = array();
$where["chir_id"] = CSQLDataSource::prepareIn(array_keys($praticiens));
$where["date"] = " = '{$date}'";
$Pconsultation = new CPlageconsult();
$Pconsultations = $Pconsultation->loadList($where, array("debut"));
$nbConsultations = 0;
$consultations = array();
$resumes_patient = array();
/** @var $Pconsultations CPlageConsult[] */
foreach ($Pconsultations as $_plage_consult) {
    $_plage_consult->loadRefsConsultations(false, false);
    $_plage_consult->loadRefChir();
    $_plage_consult->countPatients();
 /**
  * Find all therapeutes having planned events 
  * 
  * @param date $min Minimal date to start from
  * @param date $max Maximal date to stop to
  * 
  * @return array[CMediusers]
  */
 static function getActiveTherapeutes($min, $max)
 {
     $max = CMbDT::date("+1 DAY", $max);
     $query = "SELECT DISTINCT therapeute_id FROM `evenement_ssr` \r\n      WHERE debut BETWEEN '{$min}' AND '{$max}'";
     $that = new self();
     $ds = $that->_spec->ds;
     $therapeute_ids = $ds->loadColumn($query);
     $therapeute = new CMediusers();
     return $therapeute->loadAll($therapeute_ids);
 }
 /**
  * Charge les exécutants de cet activité et fournit le nombre d'occurences par exécutants
  *
  * @return CMediusers[]
  *
  * @see self::_count_actes_by_executant
  */
 function loadRefsAllExecutants()
 {
     // Comptage par executant
     $query = "SELECT therapeute_id, COUNT(*)\r\n      FROM `acte_cdarr` \r\n      LEFT JOIN `evenement_ssr` ON  `evenement_ssr`.`evenement_ssr_id` = `acte_cdarr`.`evenement_ssr_id`\r\n      WHERE `code` = '{$this->code}'\r\n      GROUP BY `therapeute_id`";
     $acte = new CActeCdARR();
     $ds = $acte->getDS();
     $counts = $ds->loadHashList($query);
     arsort($counts);
     // Chargement des executants
     $user = new CMediusers();
     /** @var CMediusers[] $executants */
     $executants = $user->loadAll(array_keys($counts));
     foreach ($executants as $_executant) {
         $_executant->loadRefFunction();
     }
     // Valeurs de retour
     $this->_count_actes_by_executant = $counts;
     return $this->_ref_all_executants = $executants;
 }