示例#1
0
function loadVueTempo(&$objects = array(), $suivi_affectation, $lits = array(), &$operations = array(), $date_min, $date_max, $period, $prestation_id, &$functions_filter = null, $filter_function = null, &$sejours_non_affectes = null)
{
    $maternite_active = CModule::getActive("maternite");
    foreach ($objects as $_object) {
        $_object->_entree = $_object->entree;
        $_object->_sortie = $_object->sortie;
        switch (get_class($_object)) {
            case "CAffectation":
                if ($_object->_is_prolong) {
                    $_object->_sortie = CMbDT::dateTime();
                }
                $_object->loadRefsAffectations();
                $_object->_affectations_enfant_ids = CMbArray::pluck($_object->loadBackRefs("affectations_enfant"), "affectation_id");
                /** @var CSejour $sejour **/
                $sejour = $_object->loadRefSejour();
                if (!$suivi_affectation && $_object->parent_affectation_id) {
                    $suivi_affectation = true;
                }
                $lits[$_object->lit_id]->_ref_affectations[$_object->_id] = $_object;
                if ($_object->_is_prolong) {
                    $_object->_start_prolongation = CMbDate::position(max($date_min, $_object->_entree), $date_min, $period);
                    $_object->_end_prolongation = CMbDate::position(min($date_max, $_object->_sortie), $date_min, $period);
                    $_object->_width_prolongation = $_object->_end_prolongation - $_object->_start_prolongation;
                }
                break;
            case "CSejour":
                $sejour = $_object;
        }
        $sejour->loadRefPraticien()->loadRefFunction();
        if (is_array($functions_filter)) {
            $functions_filter[$sejour->_ref_praticien->function_id] = $sejour->_ref_praticien->_ref_function;
            if ($filter_function && $filter_function != $sejour->_ref_praticien->function_id) {
                unset($objects[$_object->_id]);
                continue;
            }
        }
        $sejour->loadRefPrestation();
        $sejour->loadRefChargePriceIndicator();
        $patient = $sejour->loadRefPatient();
        $patient->loadRefPhotoIdentite();
        $constantes = $patient->getFirstConstantes();
        $patient->_overweight = $constantes->poids > 120;
        $patient->loadRefDossierMedical(false);
        $_object->_entree_offset = CMbDate::position(max($date_min, $_object->_entree), $date_min, $period);
        $_object->_sortie_offset = CMbDate::position(min($date_max, $_object->_sortie), $date_min, $period);
        $_object->_width = $_object->_sortie_offset - $_object->_entree_offset;
        if ($_object->_width === 0) {
            $_object->_width = 0.01;
        }
        if (!isset($operations[$sejour->_id])) {
            $operations[$sejour->_id] = $sejour->loadRefsOperations();
        }
        if ($prestation_id) {
            $sejour->loadRefFirstLiaisonForPrestation($prestation_id);
            $sejour->loadLiaisonsForPrestation($prestation_id, CMbDT::date(max($date_min, $_object->_entree)), CMbDT::date(min($date_max, $_object->_sortie)));
            if ($_object->_class == "CAffectation") {
                $_object->_liaisons_for_prestation = $sejour->_liaisons_for_prestation;
            }
        }
        if ($maternite_active && $sejour->grossesse_id) {
            $sejour->_sejours_enfants_ids = CMbArray::pluck($sejour->loadRefsNaissances(), "sejour_enfant_id");
        }
        foreach ($operations[$sejour->_id] as $_operation) {
            $_operation->loadRefPlageOp(1);
            $hour_operation = CMbDT::format($_operation->temp_operation, "%H");
            $min_operation = CMbDT::format($_operation->temp_operation, "%M");
            $fin_operation = CMbDT::dateTime("+{$hour_operation} hours +{$min_operation} minutes", $_operation->_datetime_best);
            if ($_operation->_datetime_best > $date_max || $fin_operation < $date_min) {
                unset($sejour->_ref_operations[$_operation->_id]);
                continue;
            }
            $_operation->_debut_offset[$_object->_id] = CMbDate::position($_operation->_datetime_best, max($date_min, $_object->_entree), $period);
            $_operation->_fin_offset[$_object->_id] = CMbDate::position($fin_operation, max($date_min, $_object->_entree), $period);
            $_operation->_width[$_object->_id] = $_operation->_fin_offset[$_object->_id] - $_operation->_debut_offset[$_object->_id];
            if ($_operation->_datetime_best > $date_max) {
                $_operation->_width_uscpo[$_object->_id] = 0;
            } else {
                $fin_uscpo = $hour_operation + 24 * $_operation->duree_uscpo;
                $_operation->_width_uscpo[$_object->_id] = CMbDate::position(CMbDT::dateTime("+{$fin_uscpo} hours + {$min_operation} minutes", $_operation->_datetime_best), max($date_min, $_object->_entree), $period) - $_operation->_fin_offset[$_object->_id];
            }
            if (!$sejour->_ref_next_operation && $_operation->_datetime_best >= $date_min && $_operation->_datetime_best <= $date_max) {
                $sejour->_ref_next_operation = $_operation;
            }
        }
        if (is_array($sejours_non_affectes)) {
            $lit = new C**t();
            $lit->_selected_item = new CItemPrestation();
            $lit->_lines = array();
            if ($_object instanceof CAffectation) {
                $lit->_affectation_id = $_object->_id;
                $lit->_lines[] = $_object->_id;
            } else {
                $lit->_sejour_id = $_object->_id;
                $lit->_lines[] = $_object->_guid;
            }
            @($sejours_non_affectes[$_object->service_id ? $_object->service_id : "np"][] = $lit);
        }
    }
}
    $_indispo->_width = $_indispo->_fin_offset - $_indispo->_debut_offset;
    if ($_indispo->_width <= 0) {
        continue;
    }
    $indispos_by_ressource[$_indispo->ressource_materielle_id][] = $_indispo;
}
// Les besoins sur cete même période
$besoins = $ressource->loadRefsBesoins($date_min, $date_max);
unset($besoins[$besoin_ressource_id]);
foreach ($besoins as $key => $_besoin) {
    $_operation = $_besoin->loadRefOperation();
    $_operation->loadRefPlageOp();
    $_debut_op = $_operation->_datetime;
    $_fin_op = CMbDT::addDateTime($_operation->temp_operation, $_debut_op);
    $_besoin->_debut_offset = CMbDate::position($_debut_op, $date_min, "1hour");
    $_besoin->_fin_offset = CMbDate::position(min($date_max, $_fin_op), $date_min, "1hour");
    $_besoin->_width = $_besoin->_fin_offset - $_besoin->_debut_offset;
    if ($_besoin->_width <= 0) {
        unset($besoins[$key]);
    }
    foreach ($ressources as $_ressource) {
        if ($min_fin_op <= $_debut_op && CMbDT::addDateTime($_ressource->retablissement, $min_fin_op) > $_debut_op) {
            $display_alert[$_ressource->_id] = 1;
        }
    }
}
$smarty = new CSmartyDP();
$smarty->assign("ressources", $ressources);
$smarty->assign("hours", $hours);
$smarty->assign("operation", $operation);
$smarty->assign("date", $date);