/** * Génére un xml d'après un jeu de valeurs * * @param String $file chemin du fichier * @param String $path Chemin du répertoire * * @return void */ static function jvToXML($file, $path) { $name = self::deleteDate(basename($file)); $csv = new CCSVFile($file); $csv->jumpLine(3); $xml = new CXDSXmlJvDocument(); while ($line = $csv->readLine()) { list($oid, $code, $code_xds, ) = $line; $xml->appendLine($oid, $code, $code_xds); } $xml->save("{$path}/{$name}.xml"); }
/** * 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(); }
$files = glob("{$path}/*.jv"); $lineCount = 0; foreach ($files as $_file) { $name = basename($_file); $name = substr($name, strpos($name, "_") + 1); $table = substr($name, 0, strrpos($name, ".")); $table = strtolower($table); if (!$ds) { CAppUI::stepAjax("Import impossible - Source non présente", UI_MSG_ERROR); continue; } $ds->query("CREATE TABLE IF NOT EXISTS `{$table}` (\r\n `table_id` INT (11) UNSIGNED NOT NULL auto_increment PRIMARY KEY,\r\n `code` VARCHAR (255) NOT NULL,\r\n `oid` VARCHAR (255) NOT NULL,\r\n `libelle` VARCHAR (255) NOT NULL,\r\n INDEX (`table_id`)\r\n )/*! ENGINE=MyISAM */;"); $ds->query("DELETE FROM `{$table}`"); $csv = new CCSVFile($_file); $csv->jumpLine(3); while ($line = $csv->readLine()) { list($oid, $code, $libelle) = $line; if (strpos($code, "/") === false || $oid === "1.2.250.1.213.1.1.4.6") { continue; } $query = "INSERT INTO `{$table}`(\r\n `code`, `oid`, `libelle`)\r\n VALUES (?1, ?2, ?3);"; $query = $ds->prepare($query, $code, $oid, $libelle); $result = $ds->query($query); if (!$result) { $msg = $ds->error(); CAppUI::displayAjaxMsg("Erreur de requête SQL: {$msg}", UI_MSG_ERROR); CApp::rip(); } $lineCount++; } }
* @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ $motif_path = "modules/dPurgences/resources/motif_sfmu.csv"; $motif_sfmu = new CMotifSFMU(); $ds = $motif_sfmu->getDS(); $ds->exec("TRUNCATE TABLE motif_sfmu"); CAppUI::stepAjax("motifs supprimés", UI_MSG_OK); $handle = fopen($motif_path, "r"); $motif_csv = new CCSVFile($handle); $motif_csv->jumpLine(1); $count = 0; $categorie = null; while ($line = $motif_csv->readLine()) { list($libelle, $code) = $line; if (!$code) { $categorie = ucfirst(strtolower($libelle)); continue; } $motif_sfmu = new CMotifSFMU(); $motif_sfmu->code = $code; $motif_sfmu->libelle = $libelle; $motif_sfmu->categorie = $categorie; if ($msg = $motif_sfmu->store()) { CAppUI::stepAjax($msg, UI_MSG_ERROR); $count--; } $count++; }