/** * Ajoute les données des graphiques de supervision * * @param CTemplateManager $template The template manager * @param CMbObject $object The host object * @param string $name The field name * * @return void */ static function addObservationDataToTemplate(CTemplateManager $template, CMbObject $object, $name) { $prefix = "Supervision"; $group_id = CGroups::loadCurrent()->_id; $results = array(); $times = array(); if ($object->_id) { list($results, $times) = CObservationResultSet::getResultsFor($object, false); $times = array_combine($times, $times); } // CSupervisionGraphAxis $axis = new CSupervisionGraphAxis(); $ds = $axis->getDS(); $where = array("supervision_graph_axis.in_doc_template" => "= '1'", "supervision_graph.owner_class" => "= 'CGroups'", "supervision_graph.owner_id" => $ds->prepare("= ?", $group_id)); $ljoin = array("supervision_graph" => "supervision_graph.supervision_graph_id = supervision_graph_axis.supervision_graph_id"); $order = array("supervision_graph.title", "supervision_graph_axis.title"); /** @var CSupervisionGraphAxis[] $axes */ $axes = $axis->loadList($where, $order, null, null, $ljoin); CStoredObject::massLoadFwdRef($axes, "supervision_graph_id", null, true); foreach ($axes as $_axis) { $_graph = $_axis->loadRefGraph(); $_series = $_axis->loadRefsSeries(); $_axis->loadRefsLabels(); $_data = array_fill_keys($times, array()); foreach ($_series as $_serie) { $_unit_id = $_serie->value_unit_id ?: "none"; $_unit_label = $_serie->loadRefValueUnit(); if (!isset($results[$_serie->value_type_id][$_unit_id])) { continue; } foreach ($results[$_serie->value_type_id][$_unit_id] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } $_value["unit"] = $_unit_label->label; $_data["{$_time}"][$_serie->_id] = $_value; break; } } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("series", $_series); $smarty->assign("times", $times); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_graph->title} - {$_axis->title}", trim($view), "", false); } // CSupervisionTimedPicture // CSupervisionTimedData $data = array("CSupervisionTimedPicture", "CSupervisionTimedData"); foreach ($data as $_class) { /** @var CSupervisionTimedPicture|CSupervisionTimedData $_object */ $_object = new $_class(); $_table = $_object->_spec->table; $_ds = $_object->getDS(); $where = array("{$_table}.in_doc_template" => "= '1'", "{$_table}.owner_class" => "= 'CGroups'", "{$_table}.owner_id" => $_ds->prepare("= ?", $group_id)); $order = "title"; /** @var CSupervisionTimedPicture[]|CSupervisionTimedData[] $_objects */ $_objects = $_object->loadList($where, $order); foreach ($_objects as $_timed) { $_data = array_fill_keys($times, null); if (!isset($results[$_timed->value_type_id])) { continue; } foreach ($results[$_timed->value_type_id]["none"] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } if ($_value["file_id"]) { $_file = new CFile(); $_file->load($_value["file_id"]); $_value["datauri"] = $_file->getDataURI(); $_value["file"] = $_file; } $_data["{$_time}"] = $_value; break; } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("times", $times); $smarty->assign("timed_data", true); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_timed->title}", trim($view), "", false); } } }
$pack_id = CValue::get("pack_id"); $result_set_id = CValue::get("result_set_id"); $result_id = CValue::get("result_id"); $result_set = new CObservationResultSet(); if ($result_set_id) { $result_set->load($result_set_id); $object = $result_set->loadRefContext(); } else { /** @var COperation|CSejour $object */ $object = CStoredObject::loadFromGuid($object_guid); $result_set->context_class = $object->_class; $result_set->context_id = $object->_id; $result_set->datetime = CMbDT::dateTime(); $result_set->patient_id = $object->loadRelPatient()->_id; } list($results) = CObservationResultSet::getResultsFor($object); $pack = new CSupervisionGraphPack(); $pack->load($pack_id); $links = $pack->loadRefsGraphLinks(); foreach ($links as $_link) { $_graph = $_link->loadRefGraph(); if ($_graph instanceof CSupervisionGraph) { $axes = $_graph->loadRefsAxes(); foreach ($axes as $_axis) { $series = $_axis->loadRefsSeries(); $_axis->loadRefsLabels(); foreach ($series as $_serie) { $_result = new CObservationResult(); $_result->value_type_id = $_serie->value_type_id; $_result->unit_id = $_serie->value_unit_id ? $_serie->value_unit_id : null; if ($result_set->_id) {
/** * Chargement des graphiques d'intervention * * @param COperation $interv Intervention * * @param int $pack_id Pack de graphiques * * @return array */ static function buildGraphs(COperation $interv, $pack_id) { list($results, ) = CObservationResultSet::getResultsFor($interv); list($time_min, $time_max, $time_debut_op_iso, $time_fin_op_iso, ) = self::getLimitTimes($interv); $pack = new CSupervisionGraphPack(); $pack->load($pack_id); $graph_links = $pack->loadRefsGraphLinks(); $graphs = array(); foreach ($graph_links as $_gl) { $_go = $_gl->loadRefGraph(); $graphs[] = $_go; if ($_go instanceof CSupervisionGraph) { $_go->buildGraph($results, $time_min, $time_max); } elseif ($_go instanceof CSupervisionTimedData) { $_go->loadTimedData($results, $time_min, $time_max); } elseif ($_go instanceof CSupervisionTimedPicture) { $_go->loadTimedPictures($results, $time_min, $time_max); } elseif ($_go instanceof CSupervisionInstantData) { $_go->loadRefValueType(); $_go->loadRefValueUnit(); } } /* $graph_object = new CSupervisionGraph; $graph_objects = $graph_object->loadList(array( "disabled" => "= '0'", )); $graphs = array(); foreach ($graph_objects as $_go) { $graphs[] = $_go->buildGraph($results, $time_min, $time_max); }*/ $yaxes_count = 0; foreach ($graphs as $_graph) { if ($_graph instanceof CSupervisionGraph) { $yaxes_count = max($yaxes_count, count($_graph->_graph_data["yaxes"])); } } foreach ($graphs as $_graph) { if ($_graph instanceof CSupervisionGraph) { if (count($_graph->_graph_data["yaxes"]) < $yaxes_count) { $_graph->_graph_data["yaxes"] = array_pad($_graph->_graph_data["yaxes"], $yaxes_count, CSupervisionGraphAxis::$default_yaxis); } } } return array($graphs, $yaxes_count - 1, $time_min, $time_max, $time_debut_op_iso, $time_fin_op_iso); }