}
}
CAppUI::stepAjax("Patient utilisés : '{$total}'");
CAppUI::stepAjax("Patient anciennement rapprochés : '{$anc}'");
CAppUI::stepAjax("Nouveaux patients rapprochés : '{$nouv}'");
if ($total - $anc > 0) {
    CAppUI::stepAjax($nouv * 100 / ($total - $anc) . "%% de rapprochement de patients", UI_MSG_OK);
}
// 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();
 function loadRefHprim21Sejours()
 {
     $sejour = new CHprim21Sejour();
     $where["hprim21_patient_id"] = "= '{$this->_id}'";
     $order = "date_mouvement";
     $this->_ref_hprim21_sejours = $sejour->loadList($where, $order);
 }