Beispiel #1
0
/**
 * 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');
    $patient = new CPatient();
    $patient_specs = CModelObjectFieldDescription::getSpecList($patient);
    CModelObjectFieldDescription::addBefore($patient->_specs["_IPP"], $patient_specs);
    /** @var CMbFieldSpec[] $_patient_specs */
    $_patient_specs = CModelObjectFieldDescription::getArray($patient_specs);
    echo count($_patient_specs) . " traits d'import";
    //0 = first line
    if ($start == 0) {
        $start++;
    }
    $line_nb = 0;
    while ($line = fgetcsv($fp, null, ";")) {
        $patient = new CPatient();
        if ($line_nb >= $start && $line_nb < $start + $count) {
            $line_rapport = "ligne {$line_nb} - ";
            //foreach SPECS, first load
            foreach ($_patient_specs as $key => $_specs) {
                $field = $_specs->fieldName;
                $data = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $line[$key]);
                //specific cleanups
                if ($_specs instanceof CPhoneSpec) {
                    $data = preg_replace('/\\D/', '', $data);
                }
                if ($field == "sexe") {
                    $data = strtolower($data);
                }
                if ($field == "deces" && $data == "0000-00-00") {
                    $data = null;
                }
                $patient->{$field} = $data;
            }
            $line_rapport .= "Patient {$patient->nom} {$patient->prenom} ({$patient->naissance})";
            //clone and IPP
            $IPP = $patient->_IPP;
            $patient->_generate_IPP = false;
            $patient_full = new CPatient();
            $patient_full->extendsWith($patient);
            // load by ipp if basic didn't find.
            if (!$patient->_id) {
                $patient->loadFromIPP();
                if ($patient->_id) {
                    $line_rapport .= " (trouvé par IPP)";
                }
            }
            //load patient with basics
            if (!$patient->_id) {
                $patient->_IPP = null;
                $patient->loadMatchingPatient();
                if ($patient->_id) {
                    $line_rapport .= " (trouvé par matching)";
                }
            }
            //update fields if import have more data
            foreach ($patient->getPlainFields() as $field => $value) {
                if (!$patient->{$field}) {
                    $patient->{$field} = $patient_full->{$field};
                }
            }
            // fields created by store, let the store do the job for these
            $patient->civilite = "guess";
            //found
            if ($patient->_id) {
                //check IPP
                $patient->loadIPP();
                //update
                $patient->store();
                if (!$patient->_IPP) {
                    $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id);
                    $idex->last_update = CMbDT::dateTime();
                    $idex->store();
                    if ($idex->_id) {
                        $line_rapport .= ", IPP créé : {$IPP}";
                    }
                    echo "<tr style=\"color:#c98000\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] déjà existant (MAJ ipp : {$idex->id400})</td></tr>";
                } else {
                    $line_rapport .= " déjà existant";
                    if ($patient->_IPP != $IPP) {
                        mbLog($patient->_view . " [ipp: " . $patient->_IPP . " / ipp_import:" . $IPP);
                        $line_rapport .= " [IPP du fichier: {$IPP} / ipp en base: {$patient->_IPP} ]";
                    }
                    $line_rapport .= " [IPP en base et fichier identiques]";
                    echo "<tr style=\"color:#c98000\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] déjà existant (ipp : {$patient->_IPP})</td></tr>";
                }
            } else {
                $result = $patient->store();
                if (!$result) {
                    $line_rapport .= " créé avec succes";
                    //create IPP
                    $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id);
                    if ($idex->_id) {
                        $line_rapport .= ", IPP précédente : {$idex->id400}";
                    }
                    $idex->last_update = CMbDT::dateTime();
                    $idex->store();
                    if ($idex->_id) {
                        $line_rapport .= ", IPP enregistrée : {$idex->id400}";
                    }
                    echo "<tr style=\"color:green\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] créé (ipp : {$idex->id400})</td></tr>";
                } else {
                    $patient->repair();
                    $result = $patient->store();
                    $line_rapport .= " réparé et créé";
                    if (!$result) {
                        //create IPP
                        $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id);
                        if ($idex->_id) {
                            $line_rapport .= ", IPP précédente : {$idex->id400}";
                        }
                        $idex->last_update = CMbDT::dateTime();
                        $idex->store();
                        if ($idex->_id) {
                            $line_rapport .= ", IPP enregistrée : {$idex->id400}";
                        }
                        echo "<tr style=\"color:green\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] créé (ipp : {$idex->id400})</td></tr>";
                    } else {
                        $line_rapport .= " non créé : {$result}";
                        mbLog("LINE {$line_nb} : erreur: " . $result);
                        echo "<tr  style=\"color:red\"><td>{$line_nb}</td><td>\n              <div class=\"error\">le patient [{$patient->nom} {$patient->prenom}] n'a pas été créé<br/>\n            erreur: {$result}</div></td></tr>";
                    }
                }
            }
            $line_rapport .= "\n";
            fwrite($file_import, $line_rapport);
        }
        if ($line_nb > $start + $count) {
            break;
        }
        $line_nb++;
    }
}
Beispiel #2
0
 * View import
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 25718 $
 */
CCanDo::checkAdmin();
// Nombre de patients
$patient = new CPatient();
$nb_patients = $patient->countList();
// import
$patient = new CPatient();
$patient_specs = CModelObjectFieldDescription::getSpecList($patient);
CModelObjectFieldDescription::addBefore($patient->_specs["_IPP"], $patient_specs);
// import temp file
$start_pat = 0;
$count_pat = 20;
if ($data = @file_get_contents(CAppUI::conf("root_dir") . "/tmp/import_patient.txt", "r")) {
    $nb = explode(";", $data);
    $start_pat = $nb[0];
    $count_pat = $nb[1];
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("count_pat", $count_pat);
$smarty->assign("start_pat", $start_pat);
$smarty->assign("patient_specs", $patient_specs);
$smarty->assign("nb_patients", $nb_patients);
$smarty->display("inc_vw_import.tpl");