// Gestion des séjours
$hprimSejour = new CHprim21Sejour();
$where = array();
$where["date_mouvement"] = ">= '{$date_limite}'";
$where["sejour_id"] = "IS NULL";
$order = "date_mouvement DESC";
/** @var CHprim21Sejour[] $listHprimSejours */
$listHprimSejours = $hprimSejour->loadList($where, $order, $qte_limite);
$total = count($listHprimSejours);
// Liaison à un sejour existant
$nouv = $anc = $nopat = $moresej = $err = 0;
foreach ($listHprimSejours as $_sejour) {
    $_sejour->loadRefExchange();
    $echg_hprim = $_sejour->_ref_echange_hprim21;
    // Vérification que le patient correspondant est bien lié
    $hprimPatient = new CHprim21Patient();
    $hprimPatient->load($_sejour->hprim21_patient_id);
    if (!$hprimPatient->patient_id) {
        $nopat++;
        continue;
    }
    // Recherche si la liaison a déjà été faite
    $nda = new CIdSante400();
    $nda->object_class = "CSejour";
    $nda->tag = $tag_sejour;
    $nda->id400 = "{$_sejour->external_id}";
    $nda->loadMatchingObject();
    if ($nda->_id) {
        $_sejour->sejour_id = $nda->object_id;
        $_sejour->store();
        $echg_hprim->object_class = $nda->object_class;
Esempio n. 2
0
    }
    $naissance = $year . $month . $day;
    if ($patient_year || $patient_month || $patient_day) {
        $where["naissance"] = $whereSoundex["naissance"] = "LIKE '{$naissance}'";
    }
}
if ($patient_ville) {
    $where["ville"] = $whereSoundex["ville"] = "LIKE '{$patient_ville}%'";
}
if ($patient_cp) {
    $where["cp"] = $whereSoundex["cp"] = "= '{$patient_cp}'";
}
$patients = array();
$patientsSoundex = array();
$order = "nom, prenom, naissance";
$pat = new CHprim21Patient();
// Patient counts
$patientsCount = $where ? $pat->countList($where) : 0;
$patientsSoundexCount = $whereSoundex ? $pat->countList($whereSoundex) : 0;
$patientsSoundexCount -= $patientsCount;
// Chargement des patients
if ($where) {
    $patients = $pat->loadList($where, $order, "0, {$showCount}");
}
if ($whereSoundex) {
    $patientsSoundex = $pat->loadList($whereSoundex, $order, "0, {$showCount}");
    $patientsSoundex = array_diff_key($patientsSoundex, $patients);
}
// Sélection du premier de la liste si aucun n'est déjà sélectionné
if (!$patient->_id and count($patients) == 1) {
    $patient = reset($patients);
}
if ($patient_year || $patient_month || $patient_day) {
    $year = $patient_year ? "{$patient_year}-" : "%-";
    $month = $patient_month ? "{$patient_month}-" : "%-";
    $day = $patient_day ? "{$patient_day}" : "%";
    if ($day != "%") {
        $day = str_pad($day, 2, "0", STR_PAD_LEFT);
    }
    $naissance = $year . $month . $day;
    if ($patient_year || $patient_month || $patient_day) {
        $where["naissance"] = $whereSoundex["naissance"] = "LIKE '{$naissance}'";
    }
}
$limit = "0, {$showCount}";
$order = "hprim21_patient.nom, hprim21_patient.prenom";
$pat = new CHprim21Patient();
$patients = array();
$patientsSoundex = array();
if ($where) {
    $patients = $pat->loadList($where, $order, $limit);
    foreach ($patients as &$curr_pat) {
        $curr_pat->loadRefs();
    }
    if ($nbExact = $showCount - count($patients)) {
        $limit = "0, {$nbExact}";
        $patientsSoundex = $pat->loadList($whereSoundex, $order, $limit);
        $patientsSoundex = array_diff_key($patientsSoundex, $patients);
        foreach ($patientsSoundex as &$curr_pat) {
            $curr_pat->loadRefs();
        }
    }