$_patient->store();
        $echg_hprim->object_class = $IPP->object_class;
        $echg_hprim->object_id = $IPP->object_id;
        $echg_hprim->id_permanent = $IPP->id400;
        $echg_hprim->store();
        $nouv++;
    }
}
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);
 /**
  * @param string          $line     Ligne analysée
  * @param CHprim21Patient &$patient Patient lié
  *
  * @return bool
  */
 function segmentP($line, &$patient)
 {
     if (!$this->has_header) {
         return false;
     }
     if (!$patient->bindToLine($line, $this)) {
         return false;
     }
     $patient->store();
     $medecin = new CHprim21Medecin();
     if ($medecin->bindToLine($line, $this)) {
         if ($medecin->external_id) {
             $medecin->store();
         }
     }
     $sejour = new CHprim21Sejour();
     if ($sejour->bindToLine($line, $this, $patient, $medecin)) {
         if ($sejour->external_id) {
             $sejour->store();
         }
     }
     return true;
 }
 function loadRefHprim21Sejours()
 {
     $sejour = new CHprim21Sejour();
     $where["hprim21_patient_id"] = "= '{$this->_id}'";
     $order = "date_mouvement";
     $this->_ref_hprim21_sejours = $sejour->loadList($where, $order);
 }