<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage SSR
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkAdmin();
$type = CValue::get("type", "CEvenementSSR");
$date = CValue::get("date");
$period = CValue::get("period", "month");
$stats = new CMediusersStats($date, $period, "DATE(debut)", 18);
$consult = new CConsultation();
$ds = $consult->_spec->ds;
$group = CGroups::loadCurrent();
$query = new CRequest();
$query->addColumn("COUNT(*) total");
$query->addColumn("therapeute_id", "user_id");
$query->addColumn($stats->sql_date, "refdate");
$query->addWhere("{$stats->sql_date} BETWEEN '{$stats->min_date}' AND '{$stats->max_date}'");
$query->addWhereClause("functions_mediboard.group_id", "= '{$group->_id}'");
$query->addGroup("therapeute_id, refdate");
$query->addOrder("refdate DESC");
$totals = array();
switch ($type) {
    case "CEvenementSSR":
        $query->addTable("`evenement_ssr`");
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Cabinet
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkAdmin();
$type = CValue::get("type", "RDV");
$date = CValue::get("date");
$period = CValue::get("period", "month");
$stats = new CMediusersStats($date, $period, "date", 18);
$consult = new CConsultation();
$group = CGroups::loadCurrent();
$ds = $consult->_spec->ds;
$query_complement = "1";
if ($type == "consult") {
    $query_complement = "consultation.chrono > 32\r\n     OR consultation.traitement       IS NOT NULL\r\n     OR consultation.histoire_maladie IS NOT NULL\r\n     OR consultation.conclusion       IS NOT NULL\r\n     OR consultation.examen           IS NOT NULL\r\n  ";
}
$query = "SELECT COUNT(*) total, user_id, {$stats->sql_date} AS refdate\r\n  FROM `consultation`\r\n  LEFT JOIN plageconsult AS plage ON plage.plageconsult_id = consultation.plageconsult_id\r\n  LEFT JOIN users_mediboard AS user ON user.user_id = plage.chir_id\r\n  LEFT JOIN functions_mediboard AS function ON function.function_id = user.function_id\r\n  WHERE {$stats->sql_date} BETWEEN '{$stats->min_date}' AND '{$stats->max_date}'\r\n  AND function.group_id = '{$group->_id}'\r\n  AND consultation.annule != '1'\r\n  AND consultation.patient_id IS NOT NULL\r\n  AND consultation.sejour_id IS NULL\r\n  AND ({$query_complement})\r\n  GROUP BY user_id, refdate\r\n  ORDER BY refdate DESC\r\n";
foreach ($result = $ds->loadList($query) as $_row) {
    $stats->addTotal($_row["user_id"], $_row["refdate"], $_row["total"]);
}
$stats->display("CMediusersStats-CConsultation-{$type}");