/**
 * Récupération des statistiques du nombre de consultations par mois
 * selon plusieurs filtres
 *
 * @param string $debut   Date de début
 * @param string $fin     Date de fin
 * @param int    $prat_id Identifiant du praticien
 *
 * @return array
 */
function graphConsultations($debut = null, $fin = null, $prat_id = 0)
{
    if (!$debut) {
        $debut = CMbDT::date("-1 YEAR");
    }
    if (!$fin) {
        $fin = CMbDT::date();
    }
    $rectif = CMbDT::transform("+0 DAY", $debut, "%d") - 1;
    $debutact = CMbDT::date("-{$rectif} DAYS", $debut);
    $rectif = CMbDT::transform("+0 DAY", $fin, "%d") - 1;
    $finact = CMbDT::date("-{$rectif} DAYS", $fin);
    $finact = CMbDT::date("+ 1 MONTH", $finact);
    $finact = CMbDT::date("-1 DAY", $finact);
    $pratSel = new CMediusers();
    $pratSel->load($prat_id);
    $ticks = array();
    $serie_total = array('label' => 'Total', 'data' => array(), 'markers' => array('show' => true), 'bars' => array('show' => false));
    for ($i = $debut; $i <= $fin; $i = CMbDT::date("+1 MONTH", $i)) {
        $ticks[] = array(count($ticks), CMbDT::transform("+0 DAY", $i, "%m/%Y"));
        $serie_total['data'][] = array(count($serie_total['data']), 0);
    }
    $ds = CSQLDataSource::get("std");
    $total = 0;
    $series = array();
    $query = "SELECT COUNT(consultation.consultation_id) AS total,\r\n    DATE_FORMAT(plageconsult.date, '%m/%Y') AS mois,\r\n    DATE_FORMAT(plageconsult.date, '%Y%m') AS orderitem\r\n    FROM consultation\r\n    INNER JOIN plageconsult\r\n    ON consultation.plageconsult_id = plageconsult.plageconsult_id\r\n    INNER JOIN users_mediboard\r\n    ON plageconsult.chir_id = users_mediboard.user_id\r\n    WHERE plageconsult.date BETWEEN '{$debutact}' AND '{$finact}'\r\n    AND consultation.annule = '0'";
    if ($prat_id) {
        $query .= "\nAND plageconsult.chir_id = '{$prat_id}'";
    }
    $query .= "\nGROUP BY mois ORDER BY orderitem";
    $serie = array('data' => array());
    $result = $ds->loadlist($query);
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($result as $r) {
            if ($tick[1] == $r["mois"]) {
                $serie["data"][] = array($i, $r["total"]);
                $serie_total["data"][$i][1] += $r["total"];
                $total += $r["total"];
                $f = false;
                break;
            }
        }
        if ($f) {
            $serie["data"][] = array(count($serie["data"]), 0);
        }
    }
    $series[] = $serie;
    // Set up the title for the graph
    $title = "Nombre de consultations";
    $subtitle = "- {$total} consultations -";
    if ($prat_id) {
        $subtitle .= " Dr {$pratSel->_view} -";
    }
    $options = CFlotrGraph::merge("bars", array('title' => utf8_encode($title), 'subtitle' => utf8_encode($subtitle), 'xaxis' => array('ticks' => $ticks), 'bars' => array('stacked' => true, 'barWidth' => 0.8)));
    return array('series' => $series, 'options' => $options);
}
    $options = CFlotrGraph::merge("lines", array('title' => utf8_encode("Logs par heure"), 'xaxis' => array('ticks' => $labels), 'yaxis' => array('tickDecimals' => 0, 'min' => 0, 'autoscaleMargin' => 1), 'y2axis' => array('tickDecimals' => 0, 'min' => 0, 'autoscaleMargin' => 1), 'grid' => array('verticalLines' => true)));
    // Ips distinctes par hour (nb d'ips)
    $serie_b = array('data' => array(), 'yaxis' => 2, 'label' => utf8_encode("Nombre d'ips par heure"));
    $labels = array();
    foreach ($count_by_hour_ip as $_count) {
        $serie_b['data'][] = array(count($serie_b['data']), count($_count));
    }
    $graphs["hour"] = array('series' => array($serie_a, $serie_b), 'options' => $options);
    // Logs par jour
    $serie = array('data' => array(), 'label' => utf8_encode("Logs par jour"));
    $labels = array();
    foreach ($count_by_day as $_day => $count) {
        $labels[] = array(count($labels), CMbDT::dateToLocale($_day));
        $serie['data'][] = array(count($serie['data']), $count);
    }
    $options = CFlotrGraph::merge("bars", array('title' => utf8_encode("Logs par jour"), 'xaxis' => array('ticks' => $labels), 'yaxis' => array('tickDecimals' => 0), 'grid' => array('verticalLines' => true)));
    $graphs["day"] = array('series' => array($serie), 'options' => $options);
    // Logs par IP
    $serie = array('data' => array(), 'label' => utf8_encode("Logs par ip"));
    $labels = array();
    foreach ($count_by_ip as $_ip => $count) {
        $labels[] = array(count($labels), $_ip);
        $serie['data'][] = array(count($serie['data']), $count);
    }
    $options = CFlotrGraph::merge("bars", array('title' => utf8_encode("Logs par ip"), 'xaxis' => array('ticks' => $labels), 'yaxis' => array('tickDecimals' => 0), 'grid' => array('verticalLines' => true)));
    $graphs["ip"] = array('series' => array($serie), 'options' => $options);
}
$smarty = new CSmartyDP();
$smarty->assign("graphs", $graphs);
$smarty->assign("filename", $filename);
$smarty->display("inc_inspect_error_log.tpl");
    $total = 0;
    foreach ($traces as $_trace) {
        $total += $_trace->quantity;
    }
    $max = max($max, $total);
    $series[1]["data"][] = array(count($series[1]["data"]) * 2, $total);
    // Output expired ///////////////////
    if (count($services_expired_ids)) {
        $where[100] = "product_delivery.type = 'expired' OR product_delivery.service_id IN (" . implode(',', $services_expired_ids) . ")";
    } else {
        $where[100] = "product_delivery.type = 'expired'";
    }
    $traces = $trace->loadList($where, null, null, null, $ljoin);
    $total_expired = 0;
    foreach ($traces as $_trace) {
        $total_expired += $_trace->quantity;
    }
    $max = max($max, $total_expired + $total);
    $series[2]["data"][] = array(count($series[2]["data"]) * 2 + 0.6, $total_expired);
    ///////////////
    $date = $to;
}
$series = array_reverse($series);
$data = array("series" => $series, "options" => CFlotrGraph::merge("bars", array("fontSize" => 7, "shadowSize" => 0, "bars" => array("barWidth" => 0.6), "xaxis" => array("showLabels" => true, "ticks" => $ticks, "labelsAngle" => 0), "yaxis" => array("showLabels" => false, "ticks" => array(array(0, ""), array($max, "{$max}")), "max" => $max * 1.4), "legend" => array("show" => false), "grid" => array("outlineWidth" => 1), "spreadsheet" => array("show" => false), "markers" => array("show" => true))));
// Smarty template
$smarty = new CSmartyDP();
$smarty->assign('data', $data);
$smarty->assign('product', $product);
$smarty->assign('width', $width);
$smarty->assign('height', $height);
$smarty->display('inc_product_consumption_graph.tpl');
Example #4
0
}
$series[] = $serie;
$day = $date_min;
$serie = array('data' => array(), 'label' => utf8_encode("Nombre de nuits placées"));
$ljoin["affectation"] = "affectation.sejour_id = operations.sejour_id";
while ($day <= $date_max) {
    $day_min = CMbDT::date("-{$max_uscpo} DAY", $day);
    $where[10] = "operations.date BETWEEN '{$day_min}' AND '{$day}'";
    $where[11] = "DATE_ADD(operations.date, INTERVAL duree_uscpo DAY) > '{$day}'";
    $where[12] = "DATE_ADD(operations.date, INTERVAL duree_uscpo DAY) <= affectation.sortie";
    $day = CMbDT::date("+1 day", $day);
    $count = $operation->countList($where, null, $ljoin);
    $serie['data'][] = array(count($serie['data']) + 0.2, intval($count));
}
$series[] = $serie;
$options = CFlotrGraph::merge("bars", array('title' => utf8_encode("Durées USCPO"), 'xaxis' => array('ticks' => $dates), 'yaxis' => array('tickDecimals' => 0), 'grid' => array('verticalLines' => true), 'bars' => array('barWidth' => 0.4)));
$graph = array('series' => $series, 'options' => $options);
$group = CGroups::loadCurrent();
$service = new CService();
$where = array();
$where["group_id"] = "= '{$group->_id}'";
$where["cancelled"] = "= '0'";
$order = "nom";
$services = $service->loadListWithPerms(PERM_READ, $where, $order);
$dates = array();
$day = $date_min;
while ($day <= $date_max) {
    $dates[] = $day;
    $day = CMbDT::date("+1 day", $day);
}
$smarty = new CSmartyDP();
Example #5
0
/**
 * Récupération des statistiques du nombre d'interventions par jour
 * selon plusieurs filtres
 *
 * @param string $date          Date de début
 * @param int    $prat_id       Identifiant du praticien
 * @param int    $salle_id      Identifiant de la sall
 * @param int    $bloc_id       Identifiant du bloc
 * @param int    $discipline_id Identifiant de la discipline
 * @param string $codes_ccam    Code CCAM
 * @param string $type_hospi    Type d'hospitalisation
 * @param bool   $hors_plage    Prise en compte des hors plage
 *
 * @return array
 */
function graphActiviteZoom($date, $prat_id = 0, $salle_id = 0, $bloc_id = 0, $func_id = 0, $discipline_id = 0, $codes_ccam = '', $type_hospi = "", $hors_plage = true)
{
    if (!$date) {
        $date = CMbDT::transform("+0 DAY", CMbDT::date(), "%m/%Y");
    }
    $prat = new CMediusers();
    $prat->load($prat_id);
    $salle = new CSalle();
    $salle->load($salle_id);
    $discipline = new CDiscipline();
    $discipline->load($discipline_id);
    // Gestion de la date
    $debut = substr($date, 3, 7) . "-" . substr($date, 0, 2) . "-01";
    $fin = CMbDT::date("+1 MONTH", $debut);
    $fin = CMbDT::date("-1 DAY", $fin);
    $step = "+1 DAY";
    // Tableaux des jours
    $ticks = array();
    $ticks2 = array();
    $serie_total = array('label' => 'Total', 'data' => array(), 'markers' => array('show' => true), 'bars' => array('show' => false));
    for ($i = $debut; $i <= $fin; $i = CMbDT::date($step, $i)) {
        $ticks[] = array(count($ticks), CMbDT::format($i, "%a %d"));
        $ticks2[] = array(count($ticks), CMbDT::format($i, "%d"));
        $serie_total['data'][] = array(count($serie_total['data']), 0);
    }
    $salles = CSalle::getSallesStats($salle_id, $bloc_id);
    $series = array();
    $total = 0;
    foreach ($salles as $salle) {
        $serie = array('data' => array(), 'label' => utf8_encode($salle->nom));
        $query = "SELECT COUNT(operations.operation_id) AS total,\r\n      DATE_FORMAT(operations.date, '%d') AS jour,\r\n      sallesbloc.nom AS nom\r\n      FROM operations\r\n      INNER JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n      INNER JOIN sallesbloc ON operations.salle_id = sallesbloc.salle_id\r\n      INNER JOIN plagesop ON operations.plageop_id = plagesop.plageop_id\r\n      INNER JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\r\n      WHERE operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n      AND operations.plageop_id IS NOT NULL\r\n      AND operations.annulee = '0'\r\n      AND sallesbloc.salle_id = '{$salle->_id}'";
        if ($prat_id && !$prat->isFromType(array("Anesthésiste"))) {
            $query .= "\nAND operations.chir_id = '{$prat_id}'";
        }
        if ($prat_id && $prat->isFromType(array("Anesthésiste"))) {
            $query .= "\nAND (operations.anesth_id = '{$prat_id}' OR \r\n                       (plagesop.anesth_id = '{$prat_id}' AND (operations.anesth_id = '0' OR operations.anesth_id IS NULL)))";
        }
        if ($discipline_id) {
            $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
        }
        if ($codes_ccam) {
            $query .= "\nAND operations.codes_ccam LIKE '%{$codes_ccam}%'";
        }
        if ($type_hospi) {
            $query .= "\nAND sejour.type = '{$type_hospi}'";
        }
        $query .= "\nGROUP BY jour ORDER BY jour";
        $result = $salle->_spec->ds->loadlist($query);
        $result_hors_plage = array();
        if ($hors_plage) {
            $query_hors_plage = "SELECT COUNT(operations.operation_id) AS total,\r\n        DATE_FORMAT(operations.date, '%d') AS jour,\r\n        sallesbloc.nom AS nom\r\n      FROM operations\r\n      INNER JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n      INNER JOIN sallesbloc ON operations.salle_id = sallesbloc.salle_id\r\n      INNER JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\r\n      WHERE operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n      AND operations.plageop_id IS NULL\r\n      AND operations.annulee = '0'\r\n      AND sallesbloc.salle_id = '{$salle->_id}'";
            if ($prat_id && !$prat->isFromType(array("Anesthésiste"))) {
                $query_hors_plage .= "\nAND operations.chir_id = '{$prat_id}'";
            }
            if ($prat_id && $prat->isFromType(array("Anesthésiste"))) {
                $query_hors_plage .= "\nAND operations.anesth_id = '{$prat_id}'";
            }
            if ($discipline_id) {
                $query_hors_plage .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
            }
            if ($codes_ccam) {
                $query_hors_plage .= "\nAND operations.codes_ccam LIKE '%{$codes_ccam}%'";
            }
            if ($type_hospi) {
                $query_hors_plage .= "\nAND sejour.type = '{$type_hospi}'";
            }
            $query_hors_plage .= "\nGROUP BY jour ORDER BY jour";
            $result_hors_plage = $salle->_spec->ds->loadlist($query_hors_plage);
        }
        foreach ($ticks2 as $i => $tick) {
            $f = true;
            foreach ($result as $r) {
                if ($tick[1] == $r["jour"]) {
                    if ($hors_plage) {
                        foreach ($result_hors_plage as &$_r_h) {
                            if ($tick[1] == $_r_h["jour"]) {
                                $r["total"] += $_r_h["total"];
                                unset($_r_h);
                                break;
                            }
                        }
                    }
                    $serie["data"][] = array($i, $r["total"]);
                    $serie_total["data"][$i][1] += $r["total"];
                    $total += $r["total"];
                    $f = false;
                }
            }
            if ($f) {
                $serie["data"][] = array(count($serie["data"]), 0);
            }
        }
        $series[] = $serie;
    }
    $series[] = $serie_total;
    // Set up the title for the graph
    if ($prat_id && $prat->isFromType(array("Anesthésiste"))) {
        $title = "Nombre d'anesthésie par salle - " . CMbDT::format($debut, "%m/%Y");
        $subtitle = "{$total} anesthésies";
    } else {
        $title = "Nombre d'interventions par salle - " . CMbDT::format($debut, "%m/%Y");
        $subtitle = "{$total} interventions";
    }
    if ($prat_id) {
        $subtitle .= " - Dr {$prat->_view}";
    }
    if ($discipline_id) {
        $subtitle .= " - {$discipline->_view}";
    }
    if ($codes_ccam) {
        $subtitle .= " - CCAM : {$codes_ccam}";
    }
    if ($type_hospi) {
        $subtitle .= " - " . CAppUI::tr("CSejour.type.{$type_hospi}");
    }
    $options = CFlotrGraph::merge("bars", array('title' => utf8_encode($title), 'subtitle' => utf8_encode($subtitle), 'xaxis' => array('ticks' => $ticks), 'bars' => array('stacked' => true, 'barWidth' => 0.8)));
    return array('series' => $series, 'options' => $options);
}
 /**
  * Compute stock balance
  *
  * @param CProduct[] $products Products
  * @param CService[] $services Services
  * @param int        $year     Year
  * @param int        $month    Month
  *
  * @return array
  */
 static function computeBalance(array $products, array $services, $year, $month = null)
 {
     $flows = array();
     // YEAR //////////
     $year_flows = array("in" => array(), "out" => array());
     $start = CMbDT::date(null, "{$year}-01-01");
     self::fillFlow($year_flows, $products, 12, $start, "MONTH", $services);
     $flows["year"] = array($year_flows, "%b", "Bilan annuel", "graph" => self::getFlowGraph($year_flows, "Bilan annuel", $services));
     // MONTH //////////
     if ($month) {
         $month_flows = array("in" => array(), "out" => array());
         $start = CMbDT::date(null, "{$year}-{$month}-01");
         self::fillFlow($month_flows, $products, CMbDT::transform("+1 MONTH -1 DAY", $start, "%d"), $start, "DAY", $services);
         $flows["month"] = array($month_flows, "%d", "Bilan mensuel", "graph" => self::getFlowGraph($month_flows, "Bilan mensuel", $services));
     }
     // Balance des stocks ////////////////
     $balance = array("in" => $flows["year"][0]["in"], "out" => array(), "diff" => array());
     $start = CMbDT::date(null, "{$year}-01-01");
     for ($i = 0; $i < 12; $i++) {
         $from = CMbDT::date("+{$i} MONTH", $start);
         $to = CMbDT::date("+1 MONTH", $from);
         $balance["in"][$from] = array(0, 0);
         $balance["out"][$from] = array(0, 0);
         $supply_multiple = self::getSupplyMultiple($products, $from, $to);
         $consum_multiple = self::getConsumptionMultipleProducts($products, $from, $to, null, false);
         /** @var CProduct $_product */
         foreach ($products as $_product) {
             $supply = CValue::read($supply_multiple, $_product->_id, 0);
             //$supply = $_product->getSupply($from, $to);
             $consum = CValue::read($consum_multiple, $_product->_id, 0);
             //$consum = $_product->getConsumption($from, $to, null, false);
             $coeff = 1;
             $ref = reset($_product->loadRefsReferences(true));
             if ($ref) {
                 $coeff = $ref->price;
             }
             $balance["in"][$from][0] += $supply;
             $balance["in"][$from][1] += $supply * $coeff;
             $balance["out"][$from][0] += $consum;
             $balance["out"][$from][1] += $consum * $coeff;
         }
     }
     $cumul = 0;
     $cumul_price = 0;
     foreach ($balance["in"] as $_date => $_balance) {
         $diff = $balance["in"][$_date][0] - $balance["out"][$_date][0];
         $diff_price = $balance["in"][$_date][1] - $balance["out"][$_date][1];
         $balance["diff"][$_date][0] = $diff + $cumul;
         $balance["diff"][$_date][1] = $diff_price + $cumul_price;
         $cumul += $diff;
         $cumul_price += $diff_price;
     }
     $balance = array_map_recursive(array("CProduct", "round2"), $balance);
     $options = CFlotrGraph::merge("bars", array("title" => "Rotation des stocks", "legend" => array("show" => true), "xaxis" => array("ticks" => array()), "yaxis" => array("min" => null, "title" => utf8_encode("Valeur (euro)")), "y2axis" => array("min" => null)));
     $graph = array("data" => array(), "options" => $options);
     $params = array("in" => array("label" => "Entrée", "color" => "#4DA74D"), "out" => array("label" => "Sortie", "color" => "#CB4B4B"), "diff" => array("label" => "Cumul", "color" => "#00A8F0"));
     foreach ($balance as $_type => $_data) {
         $data = array("data" => array(), "label" => utf8_encode($params[$_type]["label"]), "color" => $params[$_type]["color"]);
         if ($_type == "diff") {
             $data["lines"]["show"] = true;
             $data["bars"]["show"] = false;
             $data["points"]["show"] = true;
             $data["mouse"]["track"] = true;
             //$data["yaxis"] = 2;
         }
         if (empty($graph["options"]["xaxis"]["ticks"])) {
             foreach ($_data as $_date => $_values) {
                 if ($_date == "total") {
                     continue;
                 }
                 $graph["options"]["xaxis"]["ticks"][] = array(count($graph["options"]["xaxis"]["ticks"]), $_date);
             }
         }
         foreach ($_data as $_date => $_values) {
             if ($_date == "total") {
                 continue;
             }
             $v = $_type === "out" ? -$_values[1] : $_values[1];
             $data["data"][] = array(count($data["data"]), $v);
         }
         $graph["data"][] = $data;
     }
     $balance["graph"] = $graph;
     return array($flows, $balance, "flows" => $flows, "balance" => $balance);
 }
Example #7
0
                $totaux[$i] -= $count;
                $total += $count;
                $series[$j]['data'][$i] = array($i, intval($count));
            }
            $j++;
        }
}
// Ticks
$ticks = array();
foreach ($dates as $i => $_date) {
    $ticks[$i] = array($i, CMbDT::format($_date, $format));
}
$group_view = utf8_encode($group->_view);
foreach ($data as &$_data) {
    $_data["options"] = CFlotrGraph::merge("bars", $_data["options"]);
    $_data["options"] = CFlotrGraph::merge($_data["options"], array('colors' => array("#2075F5", "#A89F16", "#F5C320", "#027894", "#784DFF", "#BC772A", "#FF9B34", "#00A080", "#8407E1", "#D04F3E", "#FF7348", "#A89FC6", "#15C320", "#027804"), 'xaxis' => array('ticks' => $ticks, 'labelsAngle' => 45), 'bars' => array('stacked' => true)));
    $_data["options"]["subtitle"] = "{$group_view} - Total: {$total}";
    $totals = array();
    foreach ($_data["series"] as &$_series) {
        if (isset($_series["lines"]["show"]) && $_series["lines"]["show"]) {
            $_series["bars"]["show"] = false;
            continue;
        }
        foreach ($_series["data"] as $key => $value) {
            if (!isset($totals[$key][0])) {
                $totals[$key][0] = $key;
                $totals[$key][1] = 0;
            }
            $totals[$key][1] += $value[1];
        }
    }
Example #8
0
        $where[] = "blood_salvage.cell_saver_id IS NULL || blood_salvage.cell_saver_id = ''";
    }
    $series[$key] = array('data' => array(), 'label' => $_cell_saver ? utf8_encode($_cell_saver) : CAppUI::tr("Unknown"));
    fillData($where, $ljoin, $series[$key], $dates);
}
if ($mode === "comparison") {
    $data_left = $data[$comparison_left];
    $data_right = $comparison_left == $comparison_right ? array("series" => array()) : $data[$comparison_right];
    $title = $data_left["options"]["title"] . " / " . $data_right["options"]["title"];
    foreach ($data_right["series"] as &$_serie) {
        $_serie["yaxis"] = 2;
        $_serie["lines"] = array("show" => true);
        $_serie["mouse"] = array("track" => true);
        $_serie["bars"] = array("show" => false);
    }
    $data = array("comp" => array("series" => array_merge($data_left["series"], $data_right["series"]), "options" => $data_left["options"]));
}
// Ticks
$i = 0;
$ticks = array();
foreach ($dates as $month => $date) {
    $ticks[$i] = array($i, CMbDT::format($month, '%m/%y'));
    $i++;
}
foreach ($data as &$_data) {
    $ticks[] = array(count($ticks), "Total");
    $_data["options"] = CFlotrGraph::merge("bars", $_data["options"]);
    $_data["options"] = CFlotrGraph::merge($_data["options"], array('xaxis' => array('ticks' => $ticks, 'labelsAngle' => 45), 'bars' => array('stacked' => true)));
    CFlotrGraph::computeTotals($_data["series"], $_data["options"]);
}
CApp::json($data, "text/plain");
/**
 * Récupération du graphique de l'occupation de salle de bloc
 *
 * @param string $debut         Date de début
 * @param string $fin           Date de fin
 * @param int    $prat_id       Identifiant du praticien
 * @param int    $salle_id      Identifiant de la salle
 * @param int    $bloc_id       Identifiant du bloc
 * @param int    $discipline_id Identifiant de la discipline
 * @param string $codeCCAM      Code CCAM
 * @param string $type_hospi    Type d'hospitalisation
 * @param bool   $hors_plage    Pris en compte du hors plage
 * @param string $type_duree    Type de durée (jours / mois)
 *
 * @return array
 */
function graphOccupationSalle($debut = null, $fin = null, $prat_id = 0, $salle_id = 0, $bloc_id = 0, $func_id = 0, $discipline_id = null, $codeCCAM = "", $type_hospi = "", $hors_plage = true, $type_duree = "MONTH")
{
    $ds = CSQLDataSource::get("std");
    if ($type_duree == "MONTH") {
        $type_duree_fr = "mois";
        $date_format = "%m/%Y";
        $order_key = "%Y%m";
    } else {
        $type_duree_fr = "jour";
        $date_format = "%d/%m/%Y";
        $order_key = "%Y%m%d";
    }
    if (!$debut) {
        $debut = CMbDT::date("-1 YEAR");
    }
    if (!$fin) {
        $fin = CMbDT::date();
    }
    $prat = new CMediusers();
    $prat->load($prat_id);
    $salle = new CSalle();
    $salle->load($salle_id);
    $bloc = new CBlocOperatoire();
    $bloc->load($bloc_id);
    $discipline = new CDiscipline();
    $discipline->load($discipline_id);
    $ticks = array();
    for ($i = $debut; $i <= $fin; $i = CMbDT::date("+1 {$type_duree}", $i)) {
        $ticks[] = array(count($ticks), CMbDT::transform("+0 DAY", $i, $date_format));
    }
    $salles = CSalle::getSallesStats($salle_id, $bloc_id);
    $user = new CMediusers();
    // Chargement des praticiens
    $where = array();
    $where["users_mediboard.actif"] = "= '1'";
    if ($discipline->_id) {
        $where["users_mediboard.discipline_id"] = "= '{$discipline->_id}'";
    }
    // Filter on user type
    $utypes_flip = array_flip(CUser::$types);
    $user_types = array("Chirurgien", "Anesthésiste", "Médecin", "Dentiste");
    foreach ($user_types as &$_type) {
        $_type = $utypes_flip[$_type];
    }
    $where["users.user_type"] = CSQLDataSource::prepareIn($user_types);
    $ljoin = array("users" => "users.user_id = users_mediboard.user_id");
    $order = "users_mediboard.function_id, users_mediboard.discipline_id, users.user_last_name, users.user_first_name";
    $listPrats = $user->loadList($where, $order, null, null, $ljoin);
    $seriesMoy = array();
    $seriesTot = array();
    $totalMoy = 0;
    $totalTot = 0;
    // Gestion du hors plage
    $where_hors_plage = !$hors_plage ? "AND operations.plageop_id IS NOT NULL" : "";
    // First serie : Interv
    $serieMoy = $serieTot = array('data' => array(), 'label' => utf8_encode("Intervention"));
    $query = "SELECT COUNT(*) AS nbInterv,\r\n    SUM(TIME_TO_SEC(operations.fin_op)-TIME_TO_SEC(operations.debut_op)) AS duree_total,\r\n    DATE_FORMAT(operations.date, '{$date_format}') AS {$type_duree_fr},\r\n    DATE_FORMAT(operations.date, '{$order_key}') AS orderitem\r\n    FROM operations\r\n    LEFT JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n    LEFT JOIN plagesop ON operations.plageop_id = plagesop.plageop_id\r\n    LEFT JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\r\n    LEFT JOIN users ON operations.chir_id = users.user_id\r\n    WHERE operations.annulee = '0'\r\n    AND operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n    {$where_hors_plage}\r\n    AND operations.debut_op IS NOT NULL\r\n    AND operations.fin_op IS NOT NULL\r\n    AND operations.debut_op < operations.fin_op\r\n    AND sejour.group_id = '" . CGroups::loadCurrent()->_id . "'\r\n    AND operations.salle_id " . CSQLDataSource::prepareIn(array_keys($salles)) . "\r\n    AND users.user_id " . CSQLDataSource::prepareIn(array_keys($listPrats), $prat_id);
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    $query .= "\nGROUP BY {$type_duree_fr} ORDER BY orderitem";
    $result = $ds->loadList($query);
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($result as $j => $r) {
            if ($tick[1] == $r["{$type_duree_fr}"]) {
                $nb_interv = $r["nbInterv"];
                $serieMoy['data'][] = array($i, $r["duree_total"] / (60 * $nb_interv));
                $totalMoy += $r["duree_total"] / (60 * $nb_interv);
                $serieTot['data'][] = array($i, $r["duree_total"] / (60 * 60));
                $totalTot += $r["duree_total"] / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieMoy["data"][] = array(count($serieMoy["data"]), 0);
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesMoy[] = $serieMoy;
    $seriesTot[] = $serieTot;
    // Second serie : Occupation
    $serieMoy = $serieTot = array('data' => array(), 'label' => utf8_encode("Occupation de salle"));
    $query = "SELECT COUNT(*) AS nbInterv,\r\n    SUM(TIME_TO_SEC(operations.sortie_salle)-TIME_TO_SEC(operations.entree_salle)) AS duree_total,\r\n    DATE_FORMAT(operations.date, '{$date_format}') AS {$type_duree_fr},\r\n    DATE_FORMAT(operations.date, '{$order_key}') AS orderitem\r\n    FROM operations\r\n    LEFT JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n    LEFT JOIN plagesop ON operations.plageop_id = plagesop.plageop_id\r\n    LEFT JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\r\n    LEFT JOIN users ON operations.chir_id = users.user_id\r\n    WHERE operations.annulee = '0'\r\n    AND operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n    {$where_hors_plage}\r\n    AND operations.entree_salle IS NOT NULL\r\n    AND operations.sortie_salle IS NOT NULL\r\n    AND operations.entree_salle < operations.sortie_salle\r\n    AND sejour.group_id = '" . CGroups::loadCurrent()->_id . "'\r\n    AND operations.salle_id " . CSQLDataSource::prepareIn(array_keys($salles)) . "\r\n    AND users.user_id " . CSQLDataSource::prepareIn(array_keys($listPrats), $prat_id);
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    $query .= "\nGROUP BY {$type_duree_fr} ORDER BY orderitem";
    $result = $ds->loadList($query);
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($result as $j => $r) {
            if ($tick[1] == $r["{$type_duree_fr}"]) {
                $nb_interv = $r["nbInterv"];
                $serieMoy['data'][] = array($i, $r["duree_total"] / (60 * $nb_interv));
                $totalMoy += $r["duree_total"] / (60 * $nb_interv);
                $serieTot['data'][] = array($i, $r["duree_total"] / (60 * 60));
                $totalTot += $r["duree_total"] / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieMoy["data"][] = array(count($serieMoy["data"]), 0);
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesMoy[] = $serieMoy;
    $seriesTot[] = $serieTot;
    // Third serie : SSPI
    $serieMoy = $serieTot = array('data' => array(), 'label' => utf8_encode("Salle de reveil"));
    $query = "SELECT COUNT(*) AS nbInterv,\r\n    SUM(TIME_TO_SEC(operations.sortie_reveil_possible)-TIME_TO_SEC(operations.entree_reveil)) AS duree_total,\r\n    DATE_FORMAT(operations.date, '{$date_format}') AS {$type_duree_fr},\r\n    DATE_FORMAT(operations.date, '{$order_key}') AS orderitem\r\n    FROM operations\r\n    LEFT JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n    LEFT JOIN plagesop ON operations.plageop_id = plagesop.plageop_id\r\n    LEFT JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\r\n    LEFT JOIN users ON operations.chir_id = users.user_id\r\n    WHERE operations.annulee = '0'\r\n    AND operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n    {$where_hors_plage}\r\n    AND operations.entree_reveil IS NOT NULL\r\n    AND operations.sortie_reveil_possible IS NOT NULL\r\n    AND operations.entree_reveil < operations.sortie_reveil_possible\r\n    AND sejour.group_id = '" . CGroups::loadCurrent()->_id . "'\r\n    AND operations.salle_id " . CSQLDataSource::prepareIn(array_keys($salles)) . "\r\n    AND users.user_id " . CSQLDataSource::prepareIn(array_keys($listPrats), $prat_id);
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    $query .= "\nGROUP BY {$type_duree_fr} ORDER BY orderitem";
    $result = $ds->loadList($query);
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($result as $j => $r) {
            if ($tick[1] == $r[$type_duree_fr]) {
                $nb_interv = $r["nbInterv"];
                $serieMoy['data'][] = array($i, $r["duree_total"] / (60 * $nb_interv));
                $totalMoy += $r["duree_total"] / (60 * $nb_interv);
                $serieTot['data'][] = array($i, $r["duree_total"] / (60 * 60));
                $totalTot += $r["duree_total"] / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieMoy["data"][] = array(count($serieMoy["data"]), 0);
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesMoy[] = $serieMoy;
    $seriesTot[] = $serieTot;
    // Set up the title for the graph
    $subtitle = "";
    if ($prat_id) {
        $subtitle .= " - Dr {$prat->_view}";
    }
    if ($discipline_id) {
        $subtitle .= " - {$discipline->_view}";
    }
    if ($salle_id) {
        $subtitle .= " - {$salle->nom}";
    }
    if ($bloc_id) {
        $subtitle .= " - {$bloc->nom}";
    }
    if ($codeCCAM) {
        $subtitle .= " - CCAM : {$codeCCAM}";
    }
    if ($type_hospi) {
        $subtitle .= " - " . CAppUI::tr("CSejour.type.{$type_hospi}");
    }
    $optionsMoy = CFlotrGraph::merge("lines", array('title' => utf8_encode("Durées moyennes d'occupation du bloc (en minutes)"), 'subtitle' => utf8_encode("par intervention {$subtitle}"), 'xaxis' => array('ticks' => $ticks), 'grid' => array('verticalLines' => true)));
    if ($totalMoy == 0) {
        $optionsMoy['yaxis']['max'] = 1;
    }
    $optionsTot = CFlotrGraph::merge("lines", array('title' => utf8_encode("Durées totales d'occupation du bloc (en heures)"), 'subtitle' => utf8_encode("total estimé {$subtitle}"), 'xaxis' => array('ticks' => $ticks), 'grid' => array('verticalLines' => true)));
    if ($totalTot == 0) {
        $optionsTot['yaxis']['max'] = 1;
    }
    if ($type_duree == "MONTH") {
        return array("moyenne" => array('series' => $seriesMoy, 'options' => $optionsMoy), "total" => array('series' => $seriesTot, 'options' => $optionsTot));
    } else {
        return array('series' => $seriesTot, 'options' => $optionsTot);
    }
}
Example #10
0
/**
 * Récupération du graphique d'occupation des ressources au bloc opératoire
 * (personnel, vacations attribuées, ouverture de salle)
 *
 * @param string $debut         Date de début
 * @param string $fin           Date de fin
 * @param int    $prat_id       Identifiant du praticien
 * @param int    $salle_id      Identifiant de la salle
 * @param int    $bloc_id       Identifiant du bloc
 * @param null   $discipline_id Identifiant de la discipline
 * @param string $codeCCAM      Code CCAM
 * @param string $type_hospi    Type d'hospitalisation
 * @param bool   $hors_plage    Pris en compte des hors plage
 * @param string $type_duree    Type de durée analysée (jours / mois)
 *
 * @return array
 */
function graphTempsSalle($debut = null, $fin = null, $prat_id = 0, $salle_id = 0, $bloc_id = 0, $func_id = 0, $discipline_id = null, $codeCCAM = "", $type_hospi = "", $hors_plage = true, $type_duree = "MONTH")
{
    $ds = CSQLDataSource::get("std");
    if ($type_duree == "MONTH") {
        $type_duree_fr = "mois";
        $date_format = "%m/%Y";
        $order_key = "%Y%m";
    } else {
        $type_duree_fr = "jour";
        $date_format = "%d/%m/%Y";
        $order_key = "%Y%m%d";
    }
    if (!$debut) {
        $debut = CMbDT::date("-1 YEAR");
    }
    if (!$fin) {
        $fin = CMbDT::date();
    }
    $prat = new CMediusers();
    $prat->load($prat_id);
    $salle = new CSalle();
    $salle->load($salle_id);
    $bloc = new CBlocOperatoire();
    $bloc->load($bloc_id);
    $discipline = new CDiscipline();
    $discipline->load($discipline_id);
    $ticks = array();
    for ($i = $debut; $i <= $fin; $i = CMbDT::date("+1 {$type_duree}", $i)) {
        $ticks[] = array(count($ticks), CMbDT::transform("+0 DAY", $i, $date_format));
    }
    $salles = CSalle::getSallesStats($salle_id, $bloc_id);
    $seriesTot = array();
    $totalTot = 0;
    // First serie : occupation du personnel
    $serieTot = array('data' => array(), 'label' => utf8_encode("Occupation du personnel"));
    $query = "SELECT SUM(TIME_TO_SEC(affectation_personnel.fin) - TIME_TO_SEC(affectation_personnel.debut)) as total,\n    DATE_FORMAT(plagesop.date, '{$date_format}') AS {$type_duree_fr},\n    DATE_FORMAT(plagesop.date, '{$order_key}') AS orderitem\n    FROM plagesop\n    LEFT JOIN operations ON plagesop.plageop_id = operations.plageop_id\n    LEFT JOIN users_mediboard ON plagesop.chir_id = users_mediboard.user_id\n    LEFT JOIN affectation_personnel ON operations.operation_id = affectation_personnel.object_id ";
    if ($type_hospi) {
        $query .= "LEFT JOIN sejour ON sejour.sejour_id = operations.sejour_id ";
    }
    $query .= "WHERE affectation_personnel.debut < affectation_personnel.fin\n    AND affectation_personnel.debut IS NOT NULL\n    AND affectation_personnel.fin IS NOT NULL\n    AND affectation_personnel.object_class = 'COperation'\n    AND plagesop.salle_id " . CSQLDataSource::prepareIn(array_keys($salles));
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($prat_id) {
        $query .= "\nAND plagesop.chir_id = '{$prat_id}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    $query .= "\nAND plagesop.date BETWEEN '{$debut}' AND '{$fin}'\n    GROUP BY operations.plageop_id HAVING total > 0 ORDER BY orderitem";
    $result = $ds->loadlist($query);
    $result_hors_plage = array();
    if ($hors_plage) {
        $query_hors_plage = "SELECT SUM(TIME_TO_SEC(affectation_personnel.fin) - TIME_TO_SEC(affectation_personnel.debut)) as total,\n      DATE_FORMAT(operations.date, '{$date_format}') AS {$type_duree_fr},\n      DATE_FORMAT(operations.date, '{$order_key}') AS orderitem\n      FROM operations\n      LEFT JOIN users_mediboard ON operations.chir_id = users_mediboard.user_id\n      LEFT JOIN affectation_personnel ON operations.operation_id = affectation_personnel.object_id ";
        if ($type_hospi) {
            $query_hors_plage .= "LEFT JOIN sejour ON sejour.sejour_id = operations.sejour_id ";
        }
        $query_hors_plage .= "WHERE affectation_personnel.debut < affectation_personnel.fin\n      AND operations.date IS NOT NULL\n      AND operations.plageop_id IS NULL\n      AND affectation_personnel.debut IS NOT NULL\n      AND affectation_personnel.fin IS NOT NULL\n      AND affectation_personnel.object_class = 'COperation'\n      AND operations.salle_id " . CSQLDataSource::prepareIn(array_keys($salles));
        if ($type_hospi) {
            $query_hors_plage .= "\nAND sejour.type = '{$type_hospi}'";
        }
        if ($prat_id) {
            $query_hors_plage .= "\nAND operations.chir_id = '{$prat_id}'";
        }
        if ($discipline_id) {
            $query_hors_plage .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
        }
        if ($codeCCAM) {
            $query_hors_plage .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
        }
        $query_hors_plage .= "\nAND operations.date BETWEEN '{$debut}' AND '{$fin}'\n      GROUP BY {$type_duree_fr} HAVING total > 0 ORDER BY orderitem";
        $result_hors_plage = $ds->loadlist($query_hors_plage);
    }
    $calcul_temp = array();
    foreach ($result as $r) {
        if (!isset($calcul_temp[$r[$type_duree_fr]])) {
            $calcul_temp[$r[$type_duree_fr]] = 0;
        }
        $calcul_temp[$r[$type_duree_fr]] += $r['total'];
    }
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($calcul_temp as $key => $r) {
            if ($tick[1] == $key) {
                if ($hors_plage) {
                    foreach ($result_hors_plage as &$_r_h) {
                        if ($tick[1] == $_r_h[$type_duree_fr]) {
                            $r += $_r_h["total"];
                            unset($_r_h);
                            break;
                        }
                    }
                }
                $serieTot['data'][] = array($i, $r / (60 * 60));
                $totalTot += $r / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesTot[] = $serieTot;
    // Second serie : Ouverture de salle
    $serieTot = array('data' => array(), 'label' => utf8_encode("Ouverture de salle"));
    $query = "SELECT MAX(TIME_TO_SEC(operations.sortie_salle)) - MIN(TIME_TO_SEC(operations.entree_salle)) as total,\n    DATE_FORMAT(plagesop.date, '{$date_format}') AS {$type_duree_fr},\n    DATE_FORMAT(plagesop.date, '{$order_key}') AS orderitem\n    FROM plagesop\n    LEFT JOIN operations ON plagesop.plageop_id = operations.plageop_id\n    LEFT JOIN users_mediboard ON plagesop.chir_id = users_mediboard.user_id ";
    if ($type_hospi) {
        $query .= "LEFT JOIN sejour ON sejour.sejour_id = operations.sejour_id ";
    }
    $query .= "WHERE operations.entree_salle < operations.sortie_salle\n  AND plagesop.salle_id " . CSQLDataSource::prepareIn(array_keys($salles));
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($prat_id) {
        $query .= "\nAND plagesop.chir_id = '{$prat_id}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    $query .= "\nAND plagesop.date BETWEEN '{$debut}' AND '{$fin}'\n    GROUP BY operations.plageop_id ORDER BY orderitem";
    $result = $ds->loadlist($query);
    $calcul_temp = array();
    foreach ($result as $r) {
        if (!isset($calcul_temp[$r[$type_duree_fr]])) {
            $calcul_temp[$r[$type_duree_fr]] = 0;
        }
        $calcul_temp[$r[$type_duree_fr]] += $r['total'];
    }
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($calcul_temp as $key => $r) {
            if ($tick[1] == $key) {
                $serieTot['data'][] = array($i, $r / (60 * 60));
                $totalTot += $r / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesTot[] = $serieTot;
    // Third serie : reservé
    $serieTot = array('data' => array(), 'label' => utf8_encode("Vacations attribuées"));
    $query = "SELECT SUM(TIME_TO_SEC(plagesop.fin) - TIME_TO_SEC(plagesop.debut)) AS total,\n    DATE_FORMAT(plagesop.date, '{$date_format}') AS {$type_duree_fr},\n    DATE_FORMAT(plagesop.date, '{$order_key}') AS orderitem\n    FROM plagesop\n    LEFT JOIN users_mediboard ON plagesop.chir_id = users_mediboard.user_id ";
    if ($type_hospi || $codeCCAM) {
        $query .= "LEFT JOIN operations ON operations.plageop_id = plagesop.plageop_id\n      LEFT JOIN sejour ON sejour.sejour_id = operations.sejour_id ";
    }
    $query .= "WHERE plagesop.salle_id " . CSQLDataSource::prepareIn(array_keys($salles));
    if ($codeCCAM) {
        $query .= "\nAND operations.codes_ccam LIKE '%{$codeCCAM}%'";
    }
    if ($type_hospi) {
        $query .= "\nAND sejour.type = '{$type_hospi}'";
    }
    if ($prat_id) {
        $query .= "\nAND plagesop.chir_id = '{$prat_id}'";
    }
    if ($discipline_id) {
        $query .= "\nAND users_mediboard.discipline_id = '{$discipline_id}'";
    }
    $query .= "\nAND plagesop.date BETWEEN '{$debut}' AND '{$fin}'\n    GROUP BY {$type_duree_fr} ORDER BY orderitem";
    $result = $ds->loadList($query);
    foreach ($ticks as $i => $tick) {
        $f = true;
        foreach ($result as $r) {
            if ($tick[1] == $r[$type_duree_fr]) {
                $serieTot['data'][] = array($i, $r["total"] / (60 * 60));
                $totalTot += $r["total"] / (60 * 60);
                $f = false;
            }
        }
        if ($f) {
            $serieTot["data"][] = array(count($serieTot["data"]), 0);
        }
    }
    $seriesTot[] = $serieTot;
    // Set up the title for the graph
    $subtitle = "";
    if ($prat_id) {
        $subtitle .= " - Dr {$prat->_view}";
    }
    if ($discipline_id) {
        $subtitle .= " - {$discipline->_view}";
    }
    if ($salle_id) {
        $subtitle .= " - {$salle->nom}";
    }
    if ($bloc_id) {
        $subtitle .= " - {$bloc->nom}";
    }
    if ($codeCCAM) {
        $subtitle .= " - CCAM : {$codeCCAM}";
    }
    if ($type_hospi) {
        $subtitle .= " - " . CAppUI::tr("CSejour.type.{$type_hospi}");
    }
    $optionsTot = CFlotrGraph::merge("lines", array('title' => utf8_encode("Utilisation des ressources"), 'subtitle' => utf8_encode("total estimé {$subtitle}"), 'xaxis' => array('ticks' => $ticks), 'grid' => array('verticalLines' => true)));
    if ($totalTot == 0) {
        $optionsTot['yaxis']['max'] = 1;
    }
    return array('series' => $seriesTot, 'options' => $optionsTot);
}
if (isset($display_stat["reel"])) {
    $serie = array("data" => array(), "label" => utf8_encode("Réel"), "markers" => array("show" => true));
    foreach ($dates as $key => $_date) {
        $date = CMbDT::dateFromLocale($_date[1]);
        $query = "SELECT count(affectation_id) as nb_reel\n    FROM affectation d\n    WHERE entree <= '{$date} 00:00:00' AND sortie >= '{$date} 00:00:00'\n    AND service_id = '{$service_id}'";
        $reel_count = $ds->loadResult($query);
        $serie["data"][] = array(count($serie['data']) + 0.1, $reel_count, isset($lits_ouverts_par_date[$date]) && $lits_ouverts_par_date[$date] != 0 ? $reel_count / $lits_ouverts_par_date[$date] : 0);
    }
    $series[] = $serie;
}
// Entrées dans la journée (nb de placements sur tous les lits sur chaque journée)
// Ne pas compter les blocages
if (isset($display_stat["entree"])) {
    $query = "SELECT d.date, count(affectation_id) as entrees\n    FROM {$tab_name} d\n    LEFT JOIN affectation a ON\n      DATE_FORMAT(a.entree, '%Y-%m-%d') <= d.date AND DATE_FORMAT(a.sortie, '%Y-%m-%d') >= d.date\n      AND a.sejour_id != 0 AND a.service_id = '{$service_id}'\n    GROUP BY d.date\n    ORDER BY d.date";
    $entrees_journee = $ds->loadList($query);
    $serie = array("data" => array(), "label" => utf8_encode("Entrées"), "markers" => array("show" => true));
    foreach ($entrees_journee as $_entrees_by_day) {
        $serie["data"][] = array(count($serie['data']) + 0.3, $_entrees_by_day["entrees"], isset($lits_ouverts_par_date[$_entrees_by_day["date"]]) && $lits_ouverts_par_date[$_entrees_by_day["date"]] != 0 ? $_entrees_by_day["entrees"] / $lits_ouverts_par_date[$_entrees_by_day["date"]] : 0);
    }
    $series[] = $serie;
}
$options = CFlotrGraph::merge("bars", array("title" => utf8_encode("Taux d'occupation"), "xaxis" => array("ticks" => $dates), "grid" => array("verticalLines" => true), "bars" => array("barWidth" => 0.15, "stacked" => true)));
$graph = array("series" => $series, "options" => $options);
$smarty = new CSmartyDP();
$smarty->assign("date_min", $date_min);
$smarty->assign("date_max", $date_max);
$smarty->assign("services", $services);
$smarty->assign("graph", $graph);
$smarty->assign("service_id", $service_id);
$smarty->assign("display_stat", $display_stat);
$smarty->display("inc_vw_stats_occupation.tpl");