$whereOr = array(); $constants_by_graph = array(); $i = 1; foreach ($graphs_struct as $_name => $_fields) { if (empty($_fields)) { continue; } foreach ($_fields as $_field) { $whereOr[] = "{$_field} IS NOT NULL"; } $constants_by_graph[$i] = array($_fields); $i++; } if (!empty($whereOr)) { $where[] = implode(' OR ', $whereOr); $constants = array_reverse($const->loadList($where, 'datetime DESC', 10), true); } else { $constants = array(new CConstantesMedicales()); } $graph->formatGraphDatas($constants, $constants_by_graph); /* Sorting the graphs data by tab name */ foreach ($graph->graphs as $_key => $_graph) { if (($name = array_search($constants_by_graph[$_key][0], $graphs_struct)) !== false) { $graphs[md5($name)] = $_graph[0]; } } foreach ($graphs_struct as $title => $consts) { $titles[md5($title)] = $title; } } else { $graph->min_x_index = 0;
/** * Get the latest constantes values * * @param int|CPatient $patient The patient to load the constantes for * @param string $datetime The reference datetime * @param array $selection A selection of constantes to load * @param CMbObject $context The context * @param boolean $use_cache Force the function to return the latest_values is already set * * @return array The constantes values and dates */ static function getLatestFor($patient, $datetime = null, $selection = array(), $context = null, $use_cache = true) { $patient_id = $patient instanceof CPatient ? $patient->_id : $patient; if (isset(self::$_latest_values[$patient_id][$datetime]) && $use_cache === true) { return self::$_latest_values[$patient_id][$datetime]; } if (empty($selection)) { $list_constantes = CConstantesMedicales::$list_constantes; } else { $list_constantes = array_intersect_key(CConstantesMedicales::$list_constantes, array_flip($selection)); } // Constante que l'on va construire $constante = new CConstantesMedicales(); if (!$patient_id) { return array($constante, array()); } $constante->patient_id = $patient_id; $constante->datetime = CMbDT::dateTime(); $constante->loadRefPatient(); $where = array("patient_id" => "= '{$patient_id}'"); if ($context) { $where["context_class"] = " = '{$context->_class}'"; $where["context_id"] = " = '{$context->_id}'"; } if ($datetime) { $where["datetime"] = "<= '{$datetime}'"; } if (count($selection)) { $ors = array(); foreach ($selection as $_item) { $ors[] = "{$_item} IS NOT NULL"; } $where[] = implode(" OR ", $ors); } $count = $constante->countList($where); // Load all constants instead of checking every type to reduce number of SQL queries /** @var self[] $all_list */ $all_list = array(); if ($count <= 30) { $all_list = $constante->loadList($where, "datetime DESC"); } $list_datetimes = array(); foreach ($list_constantes as $type => $params) { $list_datetimes[$type] = null; if ($type[0] == "_") { continue; } // Load them, if any ... if ($count > 0) { // Load them all and dispatch if ($count <= 30) { foreach ($all_list as $_const) { $_value = $_const->{$type}; if ($_value != null) { $constante->{$type} = $_value; $list_datetimes[$type] = $_const->datetime; break; } } } else { $_where = $where; $_where[$type] = "IS NOT NULL"; $_list = $constante->loadList($_where, "datetime DESC", 1); if (count($_list)) { $_const = reset($_list); $constante->{$type} = $_const->{$type}; $list_datetimes[$type] = $_const->datetime; } } } } // Cumul de la diurese if ($datetime) { foreach ($list_constantes as $_name => $_params) { if (isset($_params["cumul_reset_config"]) || isset($_params["formula"])) { $day_defore = CMbDT::dateTime("-24 hours", $datetime); if (isset($_params["cumul_reset_config"]) && !isset($_params['formula'])) { $cumul_field = '_' . $_name . '_cumul'; $reset_hour = str_pad(self::getHostConfig($_params["cumul_reset_config"], $context), 2, '0', STR_PAD_LEFT); $cumul_begin = ''; $cumul_end = ''; if ($datetime >= CMbDT::format($datetime, "%Y-%m-%d {$reset_hour}:00:00")) { $cumul_begin = CMbDT::format($datetime, "%Y-%m-%d {$reset_hour}:00:00"); $cumul_end = CMbDT::format(CMbDT::date('+1 DAY', $datetime), "%Y-%m-%d {$reset_hour}:00:00"); } else { $cumul_begin = CMbDT::format(CMbDT::date('-1 DAY', $datetime), "%Y-%m-%d {$reset_hour}:00:00"); $cumul_end = CMbDT::format($datetime, "%Y-%m-%d {$reset_hour}:00:00"); } $query = new CRequest(); $query->addSelect("SUM(`{$_name}`)"); $query->addTable('constantes_medicales'); $query->addWhere(array("`datetime` >= '{$cumul_begin}'", "`datetime` <= '{$cumul_end}'", "`{$_name}` IS NOT NULL", "`patient_id` = {$patient_id}")); $ds = CSQLDataSource::get('std'); $constante->{$cumul_field} = $ds->loadResult($query->makeSelect()); } else { // cumul de plusieurs champs (avec formule) $formula = $_params["formula"]; foreach ($formula as $_field => $_sign) { $_where = $where; $_where[$_field] = "IS NOT NULL"; $_where[] = "datetime >= '{$day_defore}'"; $_list = $constante->loadList($_where); foreach ($_list as $_const) { if ($_sign === "+") { $constante->{$_name} += $_const->{$_field}; } else { $constante->{$_name} -= $_const->{$_field}; } } } } } } } $constante->updateFormFields(); // Don't cache partial loadings if (empty($selection)) { self::$_latest_values[$patient_id][$datetime] = array($constante, $list_datetimes); } return array($constante, $list_datetimes); }
} elseif ($context instanceof CMbObject) { $context->loadRefPatient(); } $where = array(); if ($context) { if ($context instanceof CCsejour) { $whereOr = array(); $whereOr[] = "(context_class = '{$context->_class}' AND context_id = '{$context->_id}')"; foreach ($context->_ref_consultations as $_ref_consult) { $whereOr[] = "(context_class = '{$_ref_consult->_class}' AND context_id = '{$_ref_consult->_id}')"; } if ($context->_ref_consult_anesth) { $consult = $context->_ref_consult_anesth->loadRefConsultation(); $whereOr[] = "(context_class = '{$consult->_class}' AND context_id = '{$consult->_id}')"; } $where[] = implode(" OR ", $whereOr); } else { $where['context_class'] = " = '{$context->_class}'"; $where['context_id'] = " = {$context->_id}"; } } $where['patient_id'] = " = {$patient->_id}"; /** @var CConstantesMedicales[] $list_constantes */ $constantes = new CConstantesMedicales(); $list_constantes = $constantes->loadList($where, 'datetime DESC'); $constantes_medicales_grid = CConstantesMedicales::buildGrid($list_constantes, false, true); $smarty = new CSmartyDP(); $smarty->assign('list_constantes', $list_constantes); $smarty->assign('constantes_medicales_grid', $constantes_medicales_grid); $smarty->assign('full_size', 1); $smarty->display('print_constantes_vert.tpl');
CMbObject::massLoadFwdRef($observations, "user_id"); foreach ($observations as $_obs) { $_obs->loadRefUser(); $_obs->loadTargetObject(); if ($_obs->_ref_object) { $_obs->_ref_object->loadRefsFwd(); } $_obs->_ref_sejour = $sejours[$_obs->sejour_id]; $trans_and_obs[$_obs->_ref_sejour->patient_id][$_obs->date][] = $_obs; } $cste = new CConstantesMedicales(); $whereCstes = array(); $whereCstes[] = "(datetime >= '{$dateTime_min} ' AND datetime <= '{$dateTime_max}')"; $whereCstes["context_class"] = " = 'CSejour'"; $whereCstes["context_id"] = CSQLDataSource::prepareIn(array_keys($sejours)); $constantes = $cste->loadList($whereCstes, "FIND_IN_SET(context_id, '" . implode(',', $sejours_ids) . "')"); CMbObject::massLoadFwdRef($constantes, "user_id"); foreach ($constantes as $_constante) { $_constante->loadRefUser(); $_constante->_ref_context = $sejours[$_constante->context_id]; $trans_and_obs[$_constante->patient_id][$_constante->datetime][] = $_constante; } // Tri des transmission, observations et constantes par date décroissante foreach ($trans_and_obs as &$_trans) { krsort($_trans, SORT_STRING); } } if ($do_medicaments || $do_injections || $do_perfusions || $do_aerosols || $do_elements || $do_stupefiants) { $prescription = new CPrescription(); $wherePresc = array(); $wherePresc["object_class"] = " = 'CSejour'";
break; case 'year': $where['datetime'] = " > '" . CMbDT::dateTime('-1 year') . "'"; break; default: } } $whereOr = array(); foreach ($selection as $_constant) { $whereOr[] = "{$_constant} IS NOT NULL"; } if (!empty($whereOr)) { $where[] = implode(' OR ', $whereOr); } $constant = new CConstantesMedicales(); $constants = $constant->loadList($where, 'datetime DESC', null, 'datetime'); $smarty = new CSmartyDP(); if (!empty($constants)) { $time = false; if ($period) { $time = true; } $graph = new CConstantGraph(CConstantesMedicales::guessHost($context), $context_guid, false, $time); $constants_by_graph = array(1 => array($selection)); $graph->formatGraphDatas(array_reverse($constants, true), $constants_by_graph); $smarty->assign('graphs', array(1 => $graph->graphs[1][0])); $smarty->assign('min_x_index', $graph->min_x_index); $smarty->assign('min_x_value', $graph->min_x_value); if (!$period) { $smarty->assign('patient', $patient); }
/** * Chargement de constantes médicales * * @param array $where Clauses where * * @return CConstantesMedicales[] */ function loadListConstantesMedicales($where = array()) { if ($this->_list_constantes_medicales) { return $this->_list_constantes_medicales; } $this->loadRefsConsultations(); $this->loadRefsConsultAnesth(); if (!empty($this->_ref_consultations) || $this->_ref_consult_anesth) { $whereOr = array(); $whereOr[] = "(context_class = '{$this->_class}' AND context_id = '{$this->_id}')"; foreach ($this->_ref_consultations as $_ref_consult) { $whereOr[] = "(context_class = '{$_ref_consult->_class}' AND context_id = '{$_ref_consult->_id}')"; } if ($this->_ref_consult_anesth) { $consult = $this->_ref_consult_anesth->loadRefConsultation(); $whereOr[] = "(context_class = '{$consult->_class}' AND context_id = '{$consult->_id}')"; } $where[] = implode(" OR ", $whereOr); } else { $where['context_class'] = " = '{$this->_class}'"; $where['context_id'] = " = '{$this->_id}'"; } $constantes = new CConstantesMedicales(); $where['patient_id'] = " = '{$this->patient_id}'"; return $this->_list_constantes_medicales = $constantes->loadList($where, 'datetime ASC'); }
$whereOr[] = "{$name} IS NOT NULL "; } } } if (!empty($whereOr)) { $where[] = implode(" OR ", $whereOr); } if ($date_min) { $where[] = "datetime >= '{$date_min}'"; } if ($date_max) { $where[] = "datetime <= '{$date_max}'"; } /** @var CConstantesMedicales[] $list_constantes */ // Les constantes qui correspondent (dans le contexte cette fois) $list_constantes = $constantes->loadList($where, "datetime DESC", $limit); $total_constantes = $constantes->countList($where); $constantes_medicales_grid = CConstantesMedicales::buildGrid($list_constantes, false, true); $const_ids = array(); foreach ($list_constantes as $_cst) { $const_ids[] = $_cst->_id; } $list_constantes = array_reverse($list_constantes, true); $context_guid_graph = $context_guid; if ($selected_context_guid == 'all') { $context_guid_graph = $selected_context_guid; } $graph = new CConstantGraph($host, $context_guid_graph); $graph->formatGraphDatas($list_constantes); // Création du template $smarty = new CSmartyDP();