コード例 #1
0
/**
 * Récupération des statistiques du nombre d'interventions 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
 * @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 graphActivite($debut = null, $fin = null, $prat_id = 0, $salle_id = 0, $bloc_id = 0, $func_id = 0, $discipline_id = 0, $codes_ccam = "", $type_hospi = "", $hors_plage = true)
{
    if (!$debut) {
        $debut = CMbDT::date("-1 YEAR");
    }
    if (!$fin) {
        $fin = CMbDT::date();
    }
    $prat = new CMediusers();
    $prat->load($prat_id);
    $discipline = new CDiscipline();
    $discipline->load($discipline_id);
    $salle = new CSalle();
    $salle->load($salle_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);
    }
    $salles = CSalle::getSallesStats($salle_id, $bloc_id);
    $ds = $salle->_spec->ds;
    // Gestion du hors plage
    $where_hors_plage = !$hors_plage ? "AND operations.plageop_id IS NOT NULL" : "";
    $total = 0;
    $series = array();
    foreach ($salles as $salle) {
        $serie = array('label' => utf8_encode($bloc_id ? $salle->nom : $salle->_view), 'data' => array());
        $query = "SELECT COUNT(operations.operation_id) AS total,\r\n      DATE_FORMAT(operations.date, '%m/%Y') AS mois,\r\n      DATE_FORMAT(operations.date, '%Y%m') AS orderitem,\r\n      sallesbloc.nom AS nom\r\n      FROM operations\r\n      LEFT JOIN sejour ON operations.sejour_id = sejour.sejour_id\r\n      LEFT JOIN sallesbloc ON operations.salle_id = sallesbloc.salle_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      WHERE operations.annulee = '0'\r\n      AND operations.date BETWEEN '{$debut}' AND '{$fin}'\r\n      {$where_hors_plage}\r\n      AND sejour.group_id = '" . CGroups::loadCurrent()->_id . "'";
        if ($type_hospi) {
            $query .= "\nAND sejour.type = '{$type_hospi}'";
        }
        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}%'";
        }
        $query .= "\nAND sallesbloc.salle_id = '{$salle->_id}'";
        $query .= "\nGROUP BY mois ORDER BY orderitem";
        $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;
    }
    $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";
        $subtitle = "{$total} anesthésies";
    } else {
        $title = "Nombre d'interventions par salle";
        $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 = array('title' => utf8_encode($title), 'subtitle' => utf8_encode($subtitle), 'xaxis' => array('labelsAngle' => 45, 'ticks' => $ticks), 'yaxis' => array('autoscaleMargin' => 1), 'bars' => array('show' => true, 'stacked' => true, 'barWidth' => 0.8), 'HtmlText' => false, 'legend' => array('show' => true, 'position' => 'nw'), 'grid' => array('verticalLines' => false), 'spreadsheet' => array('show' => true, 'csvFileSeparator' => ';', 'decimalSeparator' => ',', 'tabGraphLabel' => utf8_encode('Graphique'), 'tabDataLabel' => utf8_encode('Données'), 'toolbarDownload' => utf8_encode('Fichier CSV'), 'toolbarSelectAll' => utf8_encode('Sélectionner tout le tableau')));
    return array('series' => $series, 'options' => $options);
}
コード例 #2
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);
}
コード例 #3
0
ファイル: view_planning.php プロジェクト: fbone/mediboard4
$group = CGroups::loadCurrent();
// On sort les plages opératoires et les interventions hors plage
//  date - salle - horaires
$numOp = 0;
$affectations_plage = array();
$wherePlagesop = array();
$whereOperations = array();
$wherePlagesop["plagesop.date"] = $ds->prepare("BETWEEN %1 AND %2", CMbDT::date($filter->_datetime_min), CMbDT::date($filter->_datetime_max));
$whereOperations["operations.date"] = $ds->prepare("BETWEEN %1 AND %2", CMbDT::date($filter->_datetime_min), CMbDT::date($filter->_datetime_max));
$whereOperations["operations.plageop_id"] = "IS NULL";
$user = CMediusers::get();
$praticien = new CMediusers();
$praticien->load($filter->_prat_id);
// dans le cas d'un anesthesiste, vider le prat_id si l'anesthesiste veut voir tous
// les plannings sinon laisser son prat_id pour afficher son planning perso
if ($praticien->isFromType(array("Anesthésiste")) && !$filter->_planning_perso) {
    $filter->_prat_id = null;
}
// Filtre sur les praticiens ou les spécialités
$function = new CFunctions();
$functions = array();
$praticiens = array();
// Aucun filtre de séléctionné : tous les éléments auxquels on a le droit
if (!$filter->_specialite && !$filter->_prat_id) {
    if (!$user->isFromType(array("Anesthésiste")) && !$praticien->isFromType(array("Anesthésiste"))) {
        $functions = $function->loadListWithPerms(PERM_READ);
        $praticiens = $user->loadPraticiens();
    } else {
        $functions = $function->loadList();
        $praticiens = $praticien->loadList();
    }