$service = new CService();
$services = $service->loadGroupList($where);
foreach ($services as $_service) {
    $_service->loadRefUFSoins();
}
$sortie_sejour = CMbDT::dateTime();
if ($sejour->sortie_reelle) {
    $sortie_sejour = $sejour->sortie_reelle;
}
$where = array();
$where["entree"] = "<= '" . $sortie_sejour . "'";
$where["sortie"] = ">= '" . $sortie_sejour . "'";
$where["function_id"] = "IS NOT NULL";
$affectatione = new CAffectation();
/** @var CAffectation[] $blocages_lit */
$blocages_lit = $affectatione->loadList($where);
$where["function_id"] = "IS NULL";
foreach ($blocages_lit as $key => $blocage) {
    $blocage->loadRefLit()->loadRefChambre()->loadRefService();
    $where["lit_id"] = "= '{$blocage->lit_id}'";
    if (!$sejour->_id && $affectatione->loadObject($where)) {
        $affectatione->loadRefSejour();
        $affectatione->_ref_sejour->loadRefPatient();
        $jusqua = CMbDT::transform($affectatione->sortie, null, "%Hh%Mmin %d-%m-%Y") . " (" . $affectatione->_ref_sejour->_ref_patient->_view;
        $blocage->_ref_lit->_view .= " indisponible jusqu'à " . $jusqua . ")";
    }
}
$exchange_source = CExchangeSource::get("mediuser-" . CAppUI::$user->_id, "smtp");
$_functions = array();
if ($chir->_id) {
    $_functions = $chir->loadBackRefs("secondary_functions");
Beispiel #2
0
            $totalMedecin++;
        }
    }
}
// Calcul des patients par service
// Calcul du nombre d'affectations a la date $date
$affectation = new CAffectation();
$whereAffect = array();
$ljoin = array();
$whereAffect["affectation.entree"] = "<= '{$dateEntree}'";
$whereAffect["affectation.sortie"] = ">= '{$dateSortie}'";
$whereAffect["affectation.sejour_id"] = "!= '0'";
$whereAffect["sejour.group_id"] = "= '" . CGroups::loadCurrent()->_id . "'";
$ljoin["sejour"] = "sejour.sejour_id = affectation.sejour_id";
$groupAffect = "affectation.sejour_id";
$list_affectations = $affectation->loadList($whereAffect, null, null, $groupAffect, $ljoin);
$total_service = array();
foreach ($services as $_service) {
    $total_service[$_service->_id]["service"] = $_service;
    $total_service[$_service->_id]["total"] = 0;
}
foreach ($list_affectations as $key => $_affectation) {
    // Chargement des références nécessaire pour parcourir les affectations
    $_affectation->loadRefLit();
    $_affectation->_ref_lit->loadRefChambre();
    $_affectation->_ref_lit->_ref_chambre->loadRefsFwd();
    $_affectation->loadRefSejour();
    $_affectation->_ref_sejour->loadRefPraticien(1);
    // Stockage des informations liées aux services
    foreach ($services as $key => $_service) {
        if ($_service->_id == $_affectation->_ref_lit->_ref_chambre->_ref_service->_id && !$_affectation->_ref_sejour->annule) {
if ($duree_uscpo) {
    $ljoin["operations"] = "operations.sejour_id = affectation.sejour_id";
    $where["duree_uscpo"] = "> 0";
}
if ($isolement) {
    $ljoin["sejour"] = "sejour.sejour_id = affectation.sejour_id";
    $where["isolement"] = "= '1'";
}
if ($item_prestation_id && $prestation_id) {
    if (isset($items_prestation[$item_prestation_id])) {
        $ljoin["item_liaison"] = "affectation.sejour_id = item_liaison.sejour_id";
        $where["item_liaison.item_souhait_id"] = " = '{$item_prestation_id}'";
    }
}
$affectation = new CAffectation();
$affectations = $affectation->loadList($where, $order, null, null, $ljoin);
$_sejours = CStoredObject::massLoadFwdRef($affectations, "sejour_id");
$services = $services + CStoredObject::massLoadFwdRef($affectations, "service_id");
$patients = CStoredObject::massLoadFwdRef($_sejours, "patient_id");
CPatient::massCountPhotoIdentite($patients);
foreach ($affectations as $_affectation_imc) {
    /* @var CAffectation $_affectation_imc*/
    if (CAppUI::conf("dPhospi vue_temporelle show_imc_patient", "CService-" . $_affectation_imc->service_id)) {
        $_affectation_imc->loadRefSejour()->loadRefPatient()->loadRefLatestConstantes(null, array("poids", "taille"));
    }
}
// Préchargement des users
$user = new CUser();
$where = array("user_id" => CSQLDataSource::prepareIn(CMbArray::pluck($_sejours, "praticien_id")));
$users = $user->loadList($where);
$praticiens = CStoredObject::massLoadFwdRef($_sejours, "praticien_id");
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Hospi
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
global $can, $m, $g;
$affectation = new CAffectation();
$dateMin = CValue::get("dateMin", "YYYY-MM-JJ");
$where = array();
if ($dateMin != "YYYY-MM-JJ") {
    $where["sortie"] = ">= '{$dateMin} 00:00:00'";
}
$listAffectations = $affectation->loadList($where);
$entrees = 0;
$sorties = 0;
foreach ($listAffectations as &$curr_aff) {
    $curr_aff->loadRefsFwd();
    $changeSejour = 0;
    if (!$curr_aff->_ref_prev->affectation_id && $curr_aff->sejour_id) {
        if ($curr_aff->entree != $curr_aff->_ref_sejour->entree_prevue) {
            $curr_aff->_ref_sejour->entree_prevue = $curr_aff->entree;
            $changeSejour = 1;
            $entrees++;
        }
    }
    if (!$curr_aff->_ref_next->affectation_id && $curr_aff->sejour_id) {
        if ($curr_aff->sortie != $curr_aff->_ref_sejour->sortie_prevue) {
            $curr_aff->_ref_sejour->sortie_prevue = $curr_aff->sortie;
Beispiel #5
0
 /**
  * Charge les affectations situées dans un couloir du service
  *
  * @param string $date               Date
  * @param bool   $with_effectue      Avec effectue
  * @param bool   $with_sortie_reelle Avec sortie reelle
  *
  * @return CAffectation[]
  */
 function loadRefsAffectationsCouloir($date, $with_effectue = true, $with_sortie_reelle = false)
 {
     $ljoin = array();
     $where = array("affectation.service_id" => "= '{$this->_id}'", "affectation.entree" => "<= '{$date} 23:59:59'", "affectation.sortie" => ">= '{$date} 00:00:00'");
     if (!$with_effectue) {
         if ($with_sortie_reelle) {
             $complement = "";
             if ($date == CMbDT::date()) {
                 $ljoin["sejour"] = "affectation.sejour_id = sejour.sejour_id";
                 $complement = "OR (sejour.sortie_reelle >= '" . CMbDT::dateTime() . "' AND affectation.sortie >= '" . CMbDT::dateTime() . "')";
             }
             $where[] = "affectation.effectue = '0' {$complement}";
         } else {
             $where["affectation.effectue"] = "= '0'";
         }
     }
     $where["affectation.lit_id"] = "IS NULL";
     $order = "affectation.sortie DESC";
     $affectation = new CAffectation();
     return $this->_ref_affectations_couloir = $affectation->loadList($where, $order, null, null, $ljoin);
 }
    $orderNP = "sejour.entree {$order_way}, patients.nom, patients.prenom";
}
// Récupération des présents du jour
if ($type == "presents") {
    $datetime_check = "{$date} {$hour_instantane}:00:00";
    // Patients placés
    if ($mode) {
        $where[] = "'{$date}' BETWEEN DATE(affectation.entree) AND DATE(affectation.sortie)";
    } else {
        $where[] = "('{$datetime_check}' BETWEEN affectation.entree AND affectation.sortie) AND affectation.effectue = '0'";
    }
    if ($vue) {
        $where["sejour.confirme"] = " IS NULL";
    }
    /** @var CAffectation[] $presents */
    $presents = $affectation->loadList($where, $order, null, "affectation_id", $ljoin);
    // Patients non placés
    if ($mode) {
        $whereNP[] = "'{$date}' BETWEEN DATE(sejour.entree) AND DATE(sejour.sortie)";
    } else {
        $whereNP[] = "'{$datetime_check}' BETWEEN sejour.entree AND sejour.sortie";
    }
    /** @var CSejour[] $presentsNP */
    $presentsNP = $sejour->loadList($whereNP, $orderNP, null, "sejour.sejour_id", $ljoinNP);
    $update_count = count($presents) . "/" . count($presentsNP);
    // Chargements des détails des séjours
    foreach ($presents as $key => $_present) {
        $_present->loadRefsFwd();
        $sejour = $_present->_ref_sejour;
        $sejour->loadRefPatient(1);
        $sejour->loadRefPraticien(1);
        $_sejour->loadRefPatient()->loadRefDossierMedical(false);
        $_sejour->checkDaysRelative($date);
    }
    $_sejour->loadRefPrestation();
}
$dossiers = CMbArray::pluck($listNotAff["Non placés"], "_ref_patient", "_ref_dossier_medical");
CDossierMedical::massCountAntecedentsByType($dossiers, "deficience");
// Chargement des affectations dans les couloirs (sans lit_id)
$where = array();
$ljoin = array();
$where["lit_id"] = "IS NULL";
$where["service_id"] = CSQLDataSource::prepareIn($services_ids);
$where["entree"] = "<= '{$date_max}'";
$where["sortie"] = ">= '{$date_min}'";
$affectation = new CAffectation();
$listNotAff["Couloir"] = $affectation->loadList($where, "entree ASC", null, null, $ljoin);
foreach ($listNotAff["Couloir"] as $_aff) {
    $_aff->loadView();
    $sejour = $_aff->loadRefSejour();
    $sejour->loadRefPatient()->loadRefDossierMedical(false);
    $sejour->checkDaysRelative($date);
    $sejour->loadRefPrestation();
}
$dossiers = CMbArray::pluck($listNotAff["Couloir"], "_ref_sejour", "_ref_patient", "_ref_dossier_medical");
CDossierMedical::massCountAntecedentsByType($dossiers, "deficience");
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("chambres", $chambres);
$smarty->assign("date", $date);
$smarty->assign("chambres_affectees", $listAff);
$smarty->assign("list_patients_notaff", $listNotAff);
Beispiel #8
0
        }
    } else {
        if ($typeVue == 2) {
            // Recherche de tous les lits bloques pour urgences
            $ljoin = array();
            $ljoin["lit"] = "lit.lit_id = affectation.lit_id";
            $ljoin["chambre"] = "lit.chambre_id = chambre.chambre_id";
            $where = array();
            $where["chambre.annule"] = " = '0'";
            $where["lit.annule"] = " = '0'";
            $where["affectation.effectue"] = " = '0'";
            $where["affectation.sejour_id"] = " IS NULL";
            $where["affectation.function_id"] = " IS NOT NULL";
            $where[] = " '{$date_recherche}' BETWEEN affectation.entree AND affectation.sortie";
            $affectation = new CAffectation();
            $occupes = $affectation->loadList($where, null, null, null, $ljoin);
            foreach ($occupes as $_affectation) {
                /* @var CAffectation $_affectation*/
                $_affectation->loadRefLit()->loadRefChambre()->loadRefService();
            }
        }
    }
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("date_recherche", $date_recherche);
$smarty->assign("occupes", $occupes);
$smarty->assign("libre", $libre);
$smarty->assign("typeVue", $typeVue);
$smarty->assign("selPrat", $selPrat);
$smarty->assign("listPrat", $listPrat);
    $item_prestation = $items_prestations[$inverse[$prestation_id]];
    if ($item_prestation->_id) {
        $lit->_selected_item = $item_prestation;
    } else {
        $lit->_selected_item = new CItemPrestation();
    }
} else {
    $lit->_selected_item = new CItemPrestation();
}
// Chargement des affectations
$where = array();
$where["lit_id"] = "= '{$lit_id}'";
$where["entree"] = "<= '{$date_max}'";
$where["sortie"] = ">= '{$date_min}'";
$affectation = new CAffectation();
$affectations = $affectation->loadList($where, "parent_affectation_id ASC");
// Ajout des prolongations anormales
// (séjours avec entrée réelle et sortie non confirmée et sortie < maintenant
$nb_days_prolongation = CAppUI::conf("dPhospi nb_days_prolongation");
if ($nb_days_prolongation) {
    $sejour = new CSejour();
    $max = CMbDT::dateTime();
    $min = CMbDT::date("-{$nb_days_prolongation} days", $max) . " 00:00:00";
    $where = array("entree_reelle" => "IS NOT NULL", "sortie_reelle" => "IS NULL", "sortie_prevue" => "BETWEEN '{$min}' AND '{$max}'", "sejour.confirme" => "IS NULL", "group_id" => "= '{$group_id}'");
    /** @var CSejour[] $sejours_prolonges */
    $sejours_prolonges = $sejour->loadList($where);
    $affectations_prolong = array();
    foreach ($sejours_prolonges as $_sejour) {
        $aff = $_sejour->getCurrAffectation($_sejour->sortie);
        if (!$aff->_id || $aff->lit_id != $lit_id) {
            continue;
/**
 * Chargement des affectations dans les couloirs
 */
function loadAffectationsCouloirs($where, $order = null, $praticien_id = null, $prestation_id = null)
{
    $group_id = CGroups::loadCurrent()->_id;
    $systeme_presta = CAppUI::conf("dPhospi prestations systeme_prestations", "CGroups-{$group_id}");
    $ljoin = array("sejour" => "affectation.sejour_id = sejour.sejour_id", "patients" => "sejour.patient_id = patients.patient_id", "users_mediboard" => "sejour.praticien_id = users_mediboard.user_id", "users" => "users.user_id = users_mediboard.user_id");
    if ($praticien_id) {
        $where["sejour.praticien_id"] = " = '{$praticien_id}'";
    }
    if ($order == null) {
        $order = "users_mediboard.function_id, sejour.entree_prevue, patients.nom, patients.prenom";
    }
    $where["affectation.lit_id"] = " IS NULL";
    $affectation = new CAffectation();
    /* @var CAffectation[] $affectations*/
    $affectations = $affectation->loadList($where, $order, null, null, $ljoin);
    $sejours = CMbObject::massLoadFwdRef($affectations, "sejour_id");
    CMbObject::massLoadFwdRef($sejours, "praticien_id");
    CMbObject::massLoadFwdRef($sejours, "patient_id");
    $tab_affectations = array();
    foreach ($affectations as $affectation) {
        $affectation->loadRefsAffectations();
        $affectation->loadRefSejour()->loadRefPatient();
        $affectation->_ref_prev->loadRefLit();
        $affectation->_ref_next->loadRefLit();
        $sejour =& $affectation->_ref_sejour;
        $sejour->loadRefPrestation();
        $sejour->loadRefsOperations();
        $sejour->loadNDA();
        $sejour->loadRefPraticien();
        $sejour->loadRefPatient();
        $sejour->_ref_patient->loadRefDossierMedical(false);
        if ($systeme_presta == "expert" && $prestation_id) {
            $sejour->loadLiaisonsForPrestation($prestation_id);
        }
        // Chargement des droits CMU
        $sejour->getDroitsCMU();
        foreach ($sejour->_ref_operations as $operation_id => $curr_operation) {
            $sejour->_ref_operations[$operation_id]->loadExtCodesCCAM();
        }
        $tab_affectations[$affectation->service_id][] = $affectation;
    }
    $dossiers = CMbArray::pluck($affectations, "_ref_sejour", "_ref_patient", "_ref_dossier_medical");
    CDossierMedical::massCountAntecedentsByType($dossiers, "deficience");
    return $tab_affectations;
}
Beispiel #11
0
            unset($where_line["signee"]);
            $ljoin_line["prescription"] = "prescription.prescription_id = prescription_line_mix.prescription_id";
            $ljoin_line["sejour"] = "prescription.object_id = sejour.sejour_id";
            $lines = $line_mix->loadList($where_line, null, null, null, $ljoin_line);
            foreach ($lines as $_line) {
                $_line->loadRefPrescription();
                $_sejour = $_line->_ref_prescription->_ref_object;
                if (!isset($sejours[$_sejour->_id])) {
                    $sejours[$_sejour->_id] = $_sejour;
                }
            }
        } else {
            $sejours = array();
            if ($service_id || $praticien_id || $function_id) {
                $affectation = new CAffectation();
                $affectations = $affectation->loadList($where, $order, null, "affectation.sejour_id", $ljoin);
                /** @var CSejour[] $sejours */
                $sejours = CStoredObject::massLoadFwdRef($affectations, "sejour_id", null, true);
                /* @var CAffectation[] $affectations*/
                foreach ($affectations as $_affectation) {
                    $_affectation->loadRefLit()->loadCompleteView();
                    $_affectation->_view = $_affectation->_ref_lit->_view;
                    $sejour = $_affectation->loadRefSejour(1);
                    $sejour->_ref_curr_affectation = $_affectation;
                }
            }
        }
    }
}
/* @var CPatient[] $patients */
$patients = CStoredObject::massLoadFwdRef($sejours, "patient_id");
Beispiel #12
0
// Chargement des affectations
$where = array();
$where["lit_id"] = CSQLDataSource::prepareIn(array_keys($lits));
$where["affectation.entree"] = "< '{$date_max}'";
$where["affectation.sortie"] = "> '{$date_min}'";
$where[] = "sejour.annule = '0' OR sejour.annule IS NULL";
$ljoin = array();
$ljoin["sejour"] = "sejour.sejour_id = affectation.sejour_id";
$affectation = new CAffectation();
$nb_affectations = $affectation->countList($where, null, $ljoin);
if ($nb_affectations > CAppUI::conf("dPhospi max_affectations_view")) {
    $smarty = new CSmartyDP();
    $smarty->display("inc_vw_max_affectations.tpl");
    CApp::rip();
}
$affectations = $affectation->loadList($where, "parent_affectation_id ASC", null, null, $ljoin);
// Ajout des prolongations anormales
// (séjours avec entrée réelle et sortie non confirmée et sortie < maintenant
$nb_days_prolongation = CAppUI::conf("dPhospi nb_days_prolongation");
if ($nb_days_prolongation) {
    $sejour = new CSejour();
    $max = CMbDT::dateTime();
    $min = CMbDT::date("-{$nb_days_prolongation} days", $max) . " 00:00:00";
    $where = array("entree_reelle" => "IS NOT NULL", "sortie_reelle" => "IS NULL", "sortie_prevue" => "BETWEEN '{$min}' AND '{$max}'", "sejour.confirme" => "IS NULL", "group_id" => "= '{$group->_id}'", "annule" => "= '0'");
    /** @var CSejour[] $sejours_prolonges */
    $sejours_prolonges = $sejour->loadList($where);
    $affectations_prolong = array();
    foreach ($sejours_prolonges as $_sejour) {
        $aff = $_sejour->getCurrAffectation($_sejour->sortie);
        if (!$aff->_id || !array_key_exists($aff->lit_id, $lits)) {
            continue;
Beispiel #13
0
 /**
  * Load affectations
  *
  * @param string $date Date
  *
  * @return void
  */
 function loadAffectations($date)
 {
     $where = array("lit_id" => "= '{$this->lit_id}'", "entree" => "<= '{$date} 23:59:59'", "sortie" => ">= '{$date} 00:00:00'");
     $order = "sortie DESC";
     $that = new CAffectation();
     $this->_ref_affectations = $that->loadList($where, $order);
     $this->checkDispo($date);
 }
Beispiel #14
0
 /**
  * Vérification de la possibilité de merger plusieurs séjours
  *
  * @param CSejour[] $sejours Séjours concernés
  *
  * @return void|string
  */
 function checkMerge($sejours = array())
 {
     if ($msg = parent::checkMerge($sejours)) {
         return $msg;
     }
     // Cas des prescriptions
     $count_prescription = 0;
     foreach ($sejours as $_sejour) {
         $_sejour->loadRefPrescriptionSejour();
         if ($_sejour->_ref_prescription_sejour && $_sejour->_ref_prescription_sejour->_id) {
             // Suppression des prescriptions vide
             $prescription = new CPrescription();
             $prescription->load($_sejour->_ref_prescription_sejour->_id);
             $back_props = $prescription->getBackProps();
             $count_back_props = 0;
             // On retire les logs de la liste des backprops
             unset($back_props["logs"]);
             foreach ($back_props as $back_prop => $object) {
                 $count_back_props += $prescription->countBackRefs($back_prop);
             }
             if ($count_back_props == 0) {
                 $prescription->delete();
                 continue;
             }
             if ($count_prescription == 1) {
                 return "Impossible de fusionner des sejours qui comportent chacun des prescriptions de séjour";
             }
             $count_prescription++;
         }
     }
     // Cas des affectations
     $affectation = new CAffectation();
     $where["sejour_id"] = CSQLDataSource::prepareIn(CMbArray::pluck($sejours, "_id"));
     /** @var CAffectation[] $affectations */
     $affectations = $affectation->loadList($where);
     foreach ($affectations as $_affectation_1) {
         foreach ($affectations as $_affectation_2) {
             if ($_affectation_1->collide($_affectation_2)) {
                 return CAppUI::tr("CSejour-merge-warning-affectation-conflict", $_affectation_1->_view, $_affectation_2->_view);
             }
         }
     }
     return null;
 }
Beispiel #15
0
    if ($vue_hospi) {
        $q .= "lit_id = '" . $lit->_id . "'";
    } else {
        $q .= "rpu.box_id = '" . $lit->_id . "'";
    }
    $nb_lits++;
}
//Si on se trouve dans le module hospi
if ($vue_hospi) {
    $date_min = CMbDT::dateTime($date);
    $date_max = CMbDT::dateTime("+1 day", $date_min);
    $affectation = new CAffectation();
    $where["entree"] = "<= '{$date_max}'";
    $where["sortie"] = ">= '{$date_min}'";
    $where[] = $q;
    $affs = $affectation->loadList($where);
    foreach ($affs as $_aff) {
        $affectations[$_aff->lit_id] = "1";
    }
} else {
    $date_tolerance = CAppUI::conf("dPurgences date_tolerance");
    $date_before = CMbDT::date("-{$date_tolerance} DAY", $date);
    $date_after = CMbDT::date("+1 DAY", $date);
    $ljoin = array();
    $ljoin["sejour"] = "rpu.sejour_id = sejour.sejour_id";
    $where = array();
    $where["sejour.type"] = " = 'urg'";
    $where["sejour.entree"] = " BETWEEN '{$date_before}' AND '{$date_after}'";
    $where["sejour.annule"] = " = '0'";
    $where["sejour.group_id"] = "= '" . CGroups::loadCurrent()->_id . "'";
    $where[] = $q;