static function getPosition($datetime, $time_min, $time_max)
 {
     return 100 * (CMbDate::toUTCTimestamp($datetime) - $time_min) / ($time_max - $time_min);
 }
 */
CCanDo::checkRead();
$operation_id = CValue::get("operation_id");
$interv = new COperation();
$interv->load($operation_id);
$interv->loadRefSejour()->loadRefPatient()->loadRefLatestConstantes();
$interv->loadRefPlageOp();
$interv->_ref_sejour->_ref_patient->loadRefDossierMedical();
$consult_anesth = $interv->loadRefsConsultAnesth();
$group = CGroups::loadCurrent();
$pack = $interv->loadRefGraphPack();
list($graphs, $yaxes_count, $time_min, $time_max, $time_debut_op_iso, $time_fin_op_iso) = CObservationResultSet::buildGraphs($interv, $pack->_id);
$time_debut_op = CMbDate::toUTCTimestamp($time_debut_op_iso);
$time_fin_op = CMbDate::toUTCTimestamp($time_fin_op_iso);
$evenements = CObservationResultSet::buildEventsGrid($interv, $time_debut_op_iso, $time_fin_op_iso, $time_min, $time_max);
$now = 100 * (CMbDate::toUTCTimestamp(CMbDT::dateTime()) - $time_min) / ($time_max - $time_min);
$graph_packs = CSupervisionGraphPack::getAllFor($group);
$concentrators = null;
if (CModule::getActive("patientMonitoring")) {
    $concentrator = new CMonitoringConcentrator();
    $concentrators = $concentrator->loadList();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("pack", $pack);
$smarty->assign("interv", $interv);
$smarty->assign("graphs", $graphs);
$smarty->assign("evenements", $evenements);
$smarty->assign("time_debut_op", $time_debut_op);
$smarty->assign("time_fin_op", $time_fin_op);
$smarty->assign("yaxes_count", $yaxes_count);
 /**
  * Donne les heures limites d'une intervention
  *
  * @param COperation $interv Reference interv
  *
  * @return array
  */
 static function getLimitTimes(COperation $interv)
 {
     $round_minutes = 10;
     $round = $round_minutes * 60000;
     // FIXME
     $sejour = $interv->loadRefSejour();
     // Cas du partogramme
     if ($sejour->grossesse_id) {
         $grossesse = $sejour->loadRefGrossesse();
         // Debut = debut travail OU entree salle
         if ($grossesse->datetime_debut_travail) {
             $time_debut_op_iso = $grossesse->datetime_debut_travail;
         } else {
             $time_min = $interv->entree_salle;
             $date = CMbDT::date($interv->_datetime);
             $time_debut_op_iso = "{$date} {$time_min}";
         }
         // Fin = fin accouchement OU debut+1 heure OU maintenant
         if ($grossesse->datetime_accouchement) {
             $time_fin_op_iso = $grossesse->datetime_accouchement;
         } else {
             $time_fin_op_iso = max(CMbDT::dateTime(), CMbDT::dateTime("+1 HOUR", $time_debut_op_iso));
         }
     } else {
         $time_min = $interv->entree_salle;
         $time_max = CMbDT::time("+" . CMbDT::minutesRelative("00:00:00", $interv->temp_operation) . " MINUTES", $interv->entree_salle);
         $date = CMbDT::date($interv->_datetime);
         $fin = CValue::first($interv->sortie_salle, $interv->fin_op, $interv->retrait_garrot);
         if ($fin) {
             $time_max = max($time_max, $fin);
         }
         $time_debut_op_iso = "{$date} {$time_min}";
         $time_fin_op_iso = "{$date} {$time_max}";
     }
     $timestamp_min = floor(CMbDate::toUTCTimestamp($time_debut_op_iso) / $round) * $round;
     $timestamp_max = ceil(CMbDate::toUTCTimestamp($time_fin_op_iso) / $round) * $round;
     return array($timestamp_min, $timestamp_max, $time_debut_op_iso, $time_fin_op_iso);
 }
$operation->loadRefsFwd();
$operation->loadRefsActesCCAM();
foreach ($operation->_ref_actes_ccam as $keyActe => $acte) {
    $acte =& $operation->_ref_actes_ccam[$keyActe];
    $acte->loadRefsFwd();
}
if (CAppUI::conf('dPccam CCodeCCAM use_new_association_rules')) {
    $operation->guessActesAssociation();
} else {
    foreach ($operation->_ref_actes_ccam as $acte) {
        $acte->guessAssociation();
    }
}
$sejour =& $operation->_ref_sejour;
$sejour->loadRefsFwd();
$sejour->loadRefPrescriptionSejour();
$sejour->loadRefGrossesse();
list($perop_graphs, $yaxes_count, $time_min, $time_max, $time_debut_op_iso, $time_fin_op_iso) = CObservationResultSet::buildGraphs($operation, $operation->graph_pack_id);
$time_debut_op = CMbDate::toUTCTimestamp($time_debut_op_iso);
$time_fin_op = CMbDate::toUTCTimestamp($time_fin_op_iso);
$evenements = CObservationResultSet::buildEventsGrid($operation, $time_debut_op_iso, $time_fin_op_iso, $time_min, $time_max);
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("patient", $operation->_ref_sejour->_ref_patient);
$smarty->assign("operation", $operation);
$smarty->assign("perop_graphs", $perop_graphs);
$smarty->assign("yaxes_count", $yaxes_count);
$smarty->assign("time_debut_op", $time_debut_op);
$smarty->assign("time_fin_op", $time_fin_op);
$smarty->assign("evenements", $evenements);
$smarty->display("vw_partogramme.tpl");
示例#5
0
 /**
  * Return the formated datas of a constant for making graphs with Flot
  *
  * @param string                 $constant_name   The name of the constant
  * @param string                 $constant_type   The type of the constant : line|cumul|formula|bandwidth
  * @param CConstantesMedicales[] $constant_values The CConstantesMedicales containing the values
  *
  * @return array
  */
 function getDatasForConstant($constant_name, $constant_type, $constant_values)
 {
     $tick = 1;
     $datas = array('values' => array());
     $values = array();
     /* Initializing the period for the cumul */
     if (($constant_type == 'cumul' || $constant_type == 'formula') && !empty($constant_values)) {
         $reset_hour = CConstantesMedicales::getResetHour($constant_name);
         $first_value = reset($constant_values);
         $start = strtotime(CMbDT::format($first_value->datetime, "%Y-%m-%d 0{$reset_hour}:00:00"));
         if (strtotime($first_value->datetime) < $start) {
             $start = $start - 24 * 3600;
         }
         $current_period = array('start' => $start, 'end' => $start + 24 * 3600);
         $current_value = null;
         $start_tick = 1;
         $periods = array();
     }
     foreach ($constant_values as $_value) {
         /* Calculating the value for the cumul */
         if ($constant_type == 'cumul' || $constant_type == 'formula') {
             if ($constant_type == 'formula') {
                 $_value->{$constant_name} = $_value->applyFormula($constant_name);
             }
             $timestamp = strtotime($_value->datetime);
             /* If the current CConstantesMedicales's datetime is in the current period, we add the value to the cumuled value */
             if ($timestamp > $current_period['start'] && $timestamp <= $current_period['end']) {
                 $current_value += $_value->{$constant_name};
             } else {
                 /* If not, we add the cumuled value to the periods array, and initialize the current period */
                 $periods[] = array('start' => $start_tick, 'end' => $tick, 'start_time' => $current_period['start'], 'end_time' => $current_period['end'], 'value' => $current_value);
                 $current_value = $_value->{$constant_name};
                 $start_tick = $tick;
                 $start = $current_period['end'];
                 if (strtotime($_value->datetime) - $start > 24 * 3600) {
                     $start = strtotime(CMbDT::format($_value->datetime, '%Y-%m-%d' . sprintf('%02d', $reset_hour) . ':00:00'));
                     if (strtotime($_value->datetime) < $start) {
                         $start = $start - 24 * 3600;
                     }
                 }
                 $current_period = array('start' => $start, 'end' => $start + 24 * 3600);
             }
         }
         if (!is_null($_value->{$constant_name}) && $constant_type != 'formula') {
             /* Get the last 5 user logs of the CConstantesMedicales object */
             $users_logs = array();
             if ($constant_name[0] !== "_") {
                 $_value->loadRefUser();
                 if ($_value->_ref_user) {
                     $users_logs[] = utf8_encode(CMbDT::format($_value->getCreationDate(), '%d/%m/%y %H:%M') . ' - ' . $_value->_ref_user->_view);
                 }
             }
             if ($this->display['mode'] == 'time') {
                 $entry = array(CMbDate::toUTCTimestamp($_value->datetime));
             } else {
                 $entry = array($tick);
             }
             if ($constant_type == 'bandwidth') {
                 $field = CConstantesMedicales::$list_constantes[$constant_name]['formfields'];
                 $entry[] = $_value->{$field}[0];
                 $entry[] = $_value->{$field}[1];
                 $values[] = $_value->{$field}[0];
                 $values[] = $_value->{$field}[1];
             } else {
                 if (isset(CConstantesMedicales::$list_constantes[$constant_name]['formfields'])) {
                     $field = CConstantesMedicales::$list_constantes[$constant_name]['formfields'];
                     $entry[] = $_value->{$field}[0];
                     $values[] = $_value->{$field}[0];
                 } else {
                     $entry[] = $_value->{$constant_name};
                     $values[] = $_value->{$constant_name};
                 }
             }
             $entry['id'] = $_value->_id;
             $entry['date'] = utf8_encode(CMbDT::format($_value->datetime, '%d/%m/%y'));
             $entry['hour'] = utf8_encode(CMbDT::format($_value->datetime, '%Hh%M'));
             $entry['users'] = $users_logs;
             if ($_value->comment) {
                 $entry['comment'] = utf8_encode($_value->comment);
             }
             if ("{$_value->context_class}-{$_value->context_id}" !== $this->context_guid) {
                 $_value->loadRefContext();
                 if ($_value->_ref_context) {
                     $_value->_ref_context->loadRefsFwd();
                     $entry['context'] = utf8_encode($_value->_ref_context->_view);
                     $entry['context_guid'] = "{$_value->context_class}-{$_value->context_id}";
                 }
             }
             $datas['values'][] = $entry;
         }
         $tick++;
     }
     if ($constant_type == 'cumul' || $constant_type == 'formula') {
         $cumul_datas = array();
         if (!empty($constant_values)) {
             $periods[] = array('start' => $start_tick, 'end' => $tick, 'start_time' => $current_period['start'], 'end_time' => $current_period['end'], 'value' => $current_value);
             $cumul_datas = array();
             $dtz = new DateTimeZone('Europe/Paris');
             $tz_ofsset = $dtz->getOffset(new DateTime('now', $dtz));
             foreach ($periods as $_period) {
                 if ($this->display['mode'] == 'time') {
                     $x = ($_period['start_time'] + $tz_ofsset) * 1000;
                     $bar_width = ($_period['end_time'] - $_period['start_time']) * 1000;
                 } else {
                     $x = $_period['start'];
                     $bar_width = $_period['end'] - $_period['start'];
                 }
                 if ($this->widget) {
                     $first_value = reset($constant_values);
                     $start_date = strftime('%Y-%m-%d %H:%M:%S', $_period['start_time']);
                     $end_date = strftime('%Y-%m-%d %H:%M:%S', $_period['end_time']);
                     $query = new CRequest();
                     $query->addSelect("SUM(`{$constant_name}`)");
                     $query->addTable('constantes_medicales');
                     $query->addWhere(array("`patient_id` = {$first_value->patient_id}", "`context_class` = '{$first_value->context_class}'", "`context_id` = {$first_value->context_id}", "`datetime` >= '{$start_date}'", "`datetime` <= '{$end_date}'", "`{$constant_name}` IS NOT NULL"));
                     $ds = CSQLDataSource::get('std');
                     $_period['value'] = $ds->loadResult($query->makeSelect());
                 }
                 $cumul_datas[] = array($x, $_period['value'], 'date' => utf8_encode(strftime('%d/%m/%y %H:%M', $_period['start_time']) . ' au ' . strftime('%d/%m/%y %H:%M', $_period['end_time'])), 'barWidth' => $bar_width);
                 $values[] = $_period['value'];
             }
         }
         $datas['cumul'] = $cumul_datas;
     }
     if (!empty($values)) {
         $datas['min'] = floor(min($values));
         $datas['max'] = ceil(max($values));
     }
     return $datas;
 }