/** * import the patient file * * @param string $file path to the file * @param int $start start int * @param int $count number of iterations * @param resource $file_import file for report * * @return null */ function importFile($file, $start, $count, $file_import) { $fp = fopen($file, 'r'); $csv_file = new CCSVFile($fp); $csv_file->column_names = $csv_file->readLine(); if ($start == 0) { $start++; } elseif ($start > 1) { $csv_file->jumpLine($start); } $group_id = CGroups::loadCurrent()->_id; $treated_line = 0; while ($treated_line < $count) { $treated_line++; $patient = new CPatient(); $_patient = $csv_file->readLine(true); if (!$_patient) { CAppUI::stepAjax('Importation terminée', UI_MSG_OK); CApp::rip(); } $patient->bind($_patient); $patient->loadFromIPP($group_id); if ($patient->_id) { $start++; continue; } $nom = $_patient['nom'] ? $_patient['nom'] : $_patient['nom_jeune_fille']; if (!$patient->nom) { if ($patient->nom_jeune_fille) { $patient->nom = $patient->nom_jeune_fille; } else { CMbDebug::log("Ligne #{$start} : Pas de nom"); $start++; continue; } } $naissance = null; if ($patient->naissance) { $naissance = preg_replace('/(\\d{2})\\/(\\d{2})\\/(\\d{4})/', '\\3-\\2-\\1', $patient->naissance); $patient->naissance = $naissance; } $patient->repair(); if (!$patient->naissance) { CMbDebug::log($_patient); CMbDebug::log("Ligne #{$start} : Date de naissance invalide ({$_patient['naissance']})"); $start++; continue; } $patient->loadMatchingPatient(); if (!$patient->_id) { $patient->bind($_patient); $patient->nom = $nom; $patient->naissance = $naissance; $patient->tel = preg_replace("/[^0-9]/", "", $patient->tel); $patient->tel_autre = preg_replace("/[^0-9]/", "", $patient->tel_autre); $patient->sexe = strtolower($patient->sexe); $patient->repair(); if ($msg = $patient->store()) { CMbDebug::log($patient, null, true); CMbDebug::log("Ligne #{$start} :{$msg}"); $start++; continue; } } $ipp = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP($group_id), $patient->_IPP, $patient->_id); if ($ipp->_id && $ipp->id400 != $patient->_IPP) { CMbDebug::log("Ligne #{$start} : Ce patient possède déjà un IPP ({$ipp->id400})"); $start++; continue; } if (!$ipp->_id) { if ($msg = $ipp->store()) { CMbDebug::log("Ligne #{$start} :{$msg}"); $start++; continue; } } CAppUI::setMsg('CPatient-msg-create', UI_MSG_OK); } echo CAppUI::getMsg(); }
/** * Recording patient * * @param CPatient $newPatient Patient * @param CInteropSender $sender Sender * @param bool $generateIPP Generate IPP ? * * @return null|string null if successful otherwise returns and error message */ static function storePatient(CPatient $newPatient, CInteropSender $sender, $generateIPP = false) { // Notifier les autres destinataires autre que le sender $newPatient->_eai_sender_guid = $sender->_guid; $newPatient->_generate_IPP = $generateIPP; if ($msg = $newPatient->store()) { if ($sender->_configs && $sender->_configs["repair_patient"]) { $newPatient->repair(); } // Notifier les autres destinataires autre que le sender $newPatient->_eai_sender_guid = $sender->_guid; $newPatient->_generate_IPP = $generateIPP; return $newPatient->store(); } }