/** * Récuparation du graphique du nombre d'interventions annulées le jour même * * @param string $date_min Date de début * @param string $date_max Date de fin * @param int $prat_id Filtre du praticien * @param int $salle_id Filtre de la salle * @param int $bloc_id Filtre du bloc * @param int $func_id Filtre sur un cabinet * @param int $discipline_id Filtre sur une discipline * @param string $code_ccam Code CCAM * @param string $type_sejour Type de séjour * @param bool $hors_plage Prise en charge des hors plage * * @return array */ function graphWorkflowOperation($date_min = null, $date_max = null, $prat_id = null, $salle_id = null, $bloc_id = null, $func_id = null, $discipline_id = null, $code_ccam = null, $type_sejour = null, $hors_plage = false) { $miner = new COperationWorkflow(); $miner->warnUsage(); if (!$date_min) { $date_min = CMbDT::date("-1 YEAR"); } if (!$date_max) { $date_max = CMbDT::date(); } $date_min = CMbDT::format($date_min, "%Y-%m-01"); $date_max = CMbDT::transform("+1 MONTH", $date_max, "%Y-%m-01"); // Series declarations $labels = array("op_count" => utf8_encode("Nombre d'interventions"), "creation" => utf8_encode("Planification intervention"), "consult_chir" => utf8_encode("Consultation chirurgicale"), "consult_anesth" => utf8_encode("Consultation anesthésiste"), "visite_anesth" => utf8_encode("Visite anesthésiste"), "creation_consult_chir" => utf8_encode("RDV de consultation chirurgicale"), "creation_consult_anesth" => utf8_encode("RDV de consultation anesthésiste")); $salles = CSalle::getSallesStats($salle_id, $bloc_id); $query = new CRequest(); $query->addColumn("DATE_FORMAT(date_operation, '%Y-%m')", "mois"); $query->addColumn("COUNT(operations.operation_id)", "op_count"); // Prévention des données négatives aberrantes $tolerance_in_days = 0; $columns = array("creation", "consult_chir", "consult_anesth", "visite_anesth", "creation_consult_chir", "creation_consult_anesth"); foreach ($columns as $_column) { $field = "date_{$_column}"; $diff = "DATEDIFF(ow.date_operation, ow.{$field})"; $query->addColumn("AVG (IF({$diff} > {$tolerance_in_days}, {$diff}, NULL))", $_column); $query->addColumn("COUNT(IF({$diff} > {$tolerance_in_days}, {$diff}, NULL))", "count_{$_column}"); } $query->addTable("operations"); $query->addLJoin("operation_workflow AS ow ON ow.operation_id = operations.operation_id"); $query->addWhereClause("date_operation", "BETWEEN '{$date_min}' AND '{$date_max}'"); $query->addWhereClause("salle_id", CSQLDataSource::prepareIn(array_keys($salles))); $query->addGroup("mois"); $query->addOrder("mois"); $subtitle = ""; // Filtre sur hors plage if (!$hors_plage) { $query->addWhereClause("plageop_id", "IS NOT NULL"); $subtitle .= " - sans hors plage"; } // Filtre sur le salle (pas besoin de clause supplémentaire) if ($salle_id) { $salle = reset($salles); $subtitle .= " - {$salle->_view}"; } // Filtre sur le praticien if ($prat_id) { $query->addWhereClause("operations.chir_id", "= '{$prat_id}'"); $prat = new CMediusers(); $prat->load($prat_id); $subtitle .= " - Dr {$prat->_view}"; } // Filtre sur le cabinet if ($func_id) { $query->addLJoinClause("users_mediboard", "operations.chir_id = users_mediboard.user_id"); $query->addWhereClause("users_mediboard.function_id", "= '{$func_id}'"); $func = new CFunctions(); $func->load($func_id); $subtitle .= " - {$func->_view}"; } // Filtre sur la discipline if ($discipline_id) { $discipline = new CDiscipline(); $discipline->load($discipline_id); $query->addLJoinClause("users_mediboard", "operations.chir_id = users_mediboard.user_id"); $query->addWhereClause("users_mediboard.discipline_id", "= '{$discipline_id}'"); $subtitle .= " - {$discipline->_view}"; } // Filtre sur les codes CCAM if ($code_ccam) { $query->addWhereClause("operations.codes_ccam", "LIKE '%{$code_ccam}%'"); $subtitle .= " - CCAM: {$code_ccam}"; } // Filtre sur le type d'hospitalisation if ($type_sejour) { $query->addLJoinClause("sejour", "sejour.sejour_id = operations.sejour_id"); $query->addWhereClause("sejour.type", "= '{$type_sejour}'"); $subtitle .= " - " . CAppUI::tr("CSejour.type.{$type_sejour}"); } // Query result $ds = CSQLDataSource::get("std"); $all_values = $ds->loadHashAssoc($query->makeSelect()); // Build horizontal ticks $months = array(); $ticks = array(); for ($_date = $date_min; $_date < $date_max; $_date = CMbDT::date("+1 MONTH", $_date)) { $count_ticks = count($ticks); $ticks[] = array($count_ticks, CMbDT::format($_date, "%m/%Y")); $months[CMbDT::format($_date, "%Y-%m")] = $count_ticks; } // Series building $series = array(); foreach ($labels as $_label_name => $_label_title) { $series[$_label_name] = array("label" => $_label_title, "data" => array(), "yaxis" => 2); } $series["op_count"]["markers"]["show"] = true; $series["op_count"]["yaxis"] = 1; $series["op_count"]["lines"]["show"] = false; $series["op_count"]["points"]["show"] = false; $series["op_count"]["bars"]["show"] = true; $series["op_count"]["bars"]["fillColor"] = "#ccc"; $series["op_count"]["color"] = "#888"; $total = 0; $counts = array(); foreach ($months as $_month => $_tick) { $values = isset($all_values[$_month]) ? $all_values[$_month] : array_fill_keys(array_keys($labels), null); unset($values["mois"]); $_counts = array(); foreach ($values as $_name => $_value) { $parts = explode("_", $_name, 2); if ($parts[0] == "count") { $_counts[$labels[$parts[1]]] = $_value; continue; } $series[$_name]["data"][] = array($_tick, $_value); } $total += $values["op_count"]; $counts[] = $_counts; } // Set up the title for the graph $title = "Anticipation de la programmation des interventions"; $subtitle = "{$total} interventions" . $subtitle; $options = array('title' => utf8_encode($title), 'subtitle' => utf8_encode($subtitle), 'xaxis' => array('labelsAngle' => 45, 'ticks' => $ticks), 'yaxis' => array('autoscaleMargin' => 1, "title" => utf8_encode("Quantité d'interventions"), "titleAngle" => 90), 'y2axis' => array('autoscaleMargin' => 1, "title" => utf8_encode("Anticipation moyenne en jours vs la date d'intervention"), "titleAngle" => 90), "points" => array("show" => true, "radius" => 2, "lineWidth" => 1), "lines" => array("show" => true, "lineWidth" => 1), 'bars' => array('show' => false, 'stacked' => false, 'barWidth' => 0.8), 'HtmlText' => false, 'legend' => array('show' => true, 'position' => 'nw'), 'grid' => array('verticalLines' => false), 'mouse' => array("track" => true, "position" => "ne", "relative" => true, "sensibility" => 2, "trackDecimals" => 3, "trackFormatter" => utf8_encode("(\r\n function(obj) {\r\n var label = obj.series.label;\r\n var total = obj.nearest.allSeries[0].data[obj.index][1];\r\n var date = graph.options.xaxis.ticks[obj.index][1];\r\n\r\n // Barre des nombres d'interventions\r\n if (obj.series.bars.show) {\r\n var format = '%s <br />%s en %s';\r\n return printf(format, label, total, date);\r\n }\r\n\r\n // Courbes d'anticipation\r\n var count = graph.options.counts[obj.index][label];\r\n var value = obj.series.data[obj.index][1];\r\n var percent = Math.round(100*count/total) + '%';\r\n var format = '%s <br />%d jours en %s<br />%s des interventions concernées (%s/%s)';\r\n return printf(format, label, value, date, percent, count, total);\r\n }\r\n )")), 'counts' => $counts, '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' => array_values($series), 'options' => $options); }
*/ CCanDo::checkRead(); $type_modif = CValue::getOrSession("type_modif", "annule"); $date_max = CValue::getOrSession("_date_max", CMbDT::date()); $date_min = CValue::get("_date_min", $date_max); $prat_id = CValue::get("prat_id"); $salle_id = CValue::get("salle_id"); $bloc_id = CValue::get("bloc_id"); $code_ccam = CValue::get("code_ccam"); CView::enforceSlave(); $prat = new CMediusers(); $prat->load($prat_id); $date_min = CMbDT::date("first day of -0 months", $date_min); $date_max = CMbDT::date("last day of +0 months", $date_max); $salles = CSalle::getSallesStats($salle_id, $bloc_id); $miner = new COperationWorkflow(); $miner->warnUsage(); $operation = new COperation(); $ljoin["operation_workflow"] = "operation_workflow.operation_id = operations.operation_id"; $where["date_operation"] = "BETWEEN '{$date_min}' AND '{$date_max}'"; $where["salle_id"] = CSQLDataSource::prepareIn(array_keys($salles)); $where[] = $type_modif == "annule" ? "DATE(date_operation) = DATE(date_cancellation)" : "DATE(date_operation) = DATE(date_creation)"; // Filtre sur le praticien if ($prat_id) { $where["operations.chir_id"] = "= '{$prat_id}'"; } // Filtre sur les codes CCAM if ($code_ccam) { $where["operations.codes_ccam"] = "LIKE '%{$code_ccam}%'"; } $order = "date_operation, salle_id";
/** * Récuparation du graphique du nombre d'interventions annulées le jour même * * @param string $date_min Date de début * @param string $date_max 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 string $code_ccam Code CCAM * @param string $type_sejour Type de séjour * @param bool $hors_plage Prise en charge des hors plage * * @return array */ function graphOpAnnulees($date_min = null, $date_max = null, $prat_id = null, $salle_id = null, $bloc_id = null, $code_ccam = null, $type_sejour = null, $hors_plage = false) { $miner = new COperationWorkflow(); $miner->warnUsage(); if (!$date_min) { $date_min = CMbDT::date("-1 YEAR"); } if (!$date_max) { $date_max = CMbDT::date(); } $date_min = CMbDT::format($date_min, "%Y-%m-01"); $date_max = CMbDT::transform("+1 MONTH", $date_max, "%Y-%m-01"); $prat = new CMediusers(); $prat->load($prat_id); $serie_total = array('label' => 'Total', 'data' => array(), 'markers' => array('show' => true), 'bars' => array('show' => false)); $salles = CSalle::getSallesStats($salle_id, $bloc_id); $query = new CRequest(); $query->addColumn("salle_id"); $query->addColumn("DATE_FORMAT(date_operation, '%Y-%m')", "mois"); $query->addColumn("COUNT(DISTINCT(operations.operation_id))", "total"); $query->addTable("operations"); $query->addLJoinClause("operation_workflow", "operation_workflow.operation_id = operations.operation_id"); $query->addWhere("DATE(date_cancellation) = DATE(date_operation)"); $query->addWhereClause("date_operation", "BETWEEN '{$date_min}' AND '{$date_max}'"); $query->addWhereClause("salle_id", CSQLDataSource::prepareIn(array_keys($salles))); $query->addGroup("mois, salle_id"); $query->addOrder("mois, salle_id"); // Filtre sur hors plage if (!$hors_plage) { $query->addWhereClause("plageop_id", "IS NOT NULL"); } // Filtre sur le praticien if ($prat_id) { $query->addWhereClause("operations.chir_id", "= '{$prat_id}'"); } // Filtre sur les codes CCAM if ($code_ccam) { $query->addWhereClause("operations.codes_ccam", "LIKE '%{$code_ccam}%'"); } // Filtre sur le type d'hospitalisation if ($type_sejour) { $query->addLJoinClause("sejour", "sejour.sejour_id = operations.sejour_id"); $query->addWhereClause("sejour.type", "= '{$type_sejour}'"); } // Query result $ds = CSQLDataSource::get("std"); $tree = $ds->loadTree($query->makeSelect()); // Build horizontal ticks $months = array(); $ticks = array(); for ($_date = $date_min; $_date < $date_max; $_date = CMbDT::date("+1 MONTH", $_date)) { $count_ticks = count($ticks); $ticks[] = array($count_ticks, CMbDT::format($_date, "%m/%Y")); $months[CMbDT::format($_date, "%Y-%m")] = $count_ticks; $serie_total['data'][] = array(count($serie_total['data']), 0); } // Build series $series = array(); $total = 0; foreach ($salles as $_salle) { $_serie = array("label" => utf8_encode($bloc_id ? $_salle->nom : $_salle->_view)); $data = array(); foreach ($months as $_month => $_tick) { $value = isset($tree[$_salle->_id][$_month]) ? $tree[$_salle->_id][$_month] : 0; $data[] = array($_tick, $value); $serie_total["data"][$_tick][1] += $value; $total += $value; } $_serie["data"] = $data; $series[] = $_serie; } $series[] = $serie_total; // Set up the title for the graph $title = "Interventions annulées le jour même"; $subtitle = "{$total} interventions"; if ($prat_id) { $subtitle .= " - Dr {$prat->_view}"; } if ($salle_id) { $salle = reset($salles); $subtitle .= " - {$salle->_view}"; } if ($code_ccam) { $subtitle .= " - CCAM : {$code_ccam}"; } if ($type_sejour) { $subtitle .= " - " . CAppUI::tr("CSejour.type.{$type_sejour}"); } $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); }