public function importNeuropathNominatif($folderNominatif) { $countNotImported = 0; $attributes = array(); if (substr($folderNominatif, -1) != '/') { $folderNominatif .= '/'; } chdir(Yii::app()->basePath . "/" . $folderNominatif); $files = array_filter(glob('*'), 'is_file'); echo count($files) . " files detected \n"; foreach ($files as $importedFile) { $pos = strpos($importedFile, '.'); $file_pos = substr($importedFile, 0, $pos); if (file_exists("not_imported/{$file_pos}.txt")) { unlink("not_imported/{$file_pos}.txt"); } $dataPatient = simplexml_load_file($importedFile); foreach ($dataPatient->children() as $samples) { foreach ($samples->children() as $sample) { $neuropath = new Neuropath(); $patient = (object) null; $patient->id = null; $patient->source = 1; // Banque de cerveaux $patient->sourceId = null; foreach ($sample->children() as $notes) { foreach ($notes->children() as $note) { switch ($note->key) { case "id_donor": $id_donor = (string) $note->value; break; case "birthName": $patient->birthName = (string) $note->value; break; case "useName": $patient->useName = (string) $note->value; break; case "firstName": $pos = strpos((string) $note->value, ","); if ($pos) { $patient->firstName = substr((string) $note->value, 0, $pos); } else { $patient->firstName = (string) $note->value; } break; case "birthDate": $patient->birthDate = (string) $note->value; break; case "gender": $patient->sex = (string) $note->value; if ($patient->sex == null) { $patient->sex = "U"; } if ($patient->sex == "M" && $patient->birthName == null && $patient->useName != null) { $patient->birthName = $patient->useName; } break; default: if (!in_array($note->key, $attributes)) { $attributes[(string) $note->key] = (string) $note->value; } } } if ($this->emptyFieldExist($patient) != true) { $patientest = CommonTools::wsGetPatient($patient); if ($patientest === 'NoPatient') { $patient = CommonTools::wsAddPatient($patient); $patientSIP = get_object_vars($patient); foreach ($patientSIP as $k => $v) { if ($k == "id") { $criteria = new EMongoCriteria(); $criteria->id_donor = $id_donor; $neuropath = Neuropath::model()->find($criteria); if ($neuropath != null) { $neuropath->initSoftAttribute("id_cbsd"); $neuropath->id_cbsd = $v; foreach ($attributes as $key => $value) { $neuropath->initSoftAttribute($key); $neuropath->{$key} = $value; } $neuropath->save(); } } } } } else { $countNotImported++; $this->writePatientsNotImported($patient, $file_pos); } } } } if ($countNotImported > 0) { $this->log($countNotImported); } //copy($importedFile, "treated/$importedFile"); //unlink($importedFile); } }
/** * testing method to check if patient is found and return an object */ public function testWsGetPatient() { $patient = $this->patient(); $this->assertInternalType('string', CommonTools::wsGetPatient($patient)); // TODO : test exception }
public function actionAffichepatient() { $model = new PatientForm(); $patient = (object) null; if (isset($_SESSION['datapatient'])) { $patient = $_SESSION['datapatient']; $model->copyPatient($patient); } if (isset($_POST['PatientForm'])) { $actionForm = $_POST['PatientForm']['action']; $model = new PatientForm(); $model->attributes = $_POST['PatientForm']; if ($_POST['PatientForm']['prenom'] == "" || $_POST['PatientForm']['nom_naissance'] == "" || $_POST['PatientForm']['date_naissance'] == "") { Yii::app()->user->setFlash(TbAlert::TYPE_ERROR, Yii::t('common', 'missingFields')); $this->redirect(array('site/patient')); } if ($model->dateFormat($model->date_naissance) == false) { Yii::app()->user->setFlash('error', Yii::t('common', 'unvalidDate')); $this->redirect(array('site/patient')); } $patient->id = null; $patient->source = null; //à identifier en fonction de l'app $patient->sourceId = null; $patient->birthName = $model->nom_naissance; if ($model->nom != "") { $patient->useName = $model->nom; } else { $patient->useName = null; } $patient->firstName = $model->prenom; $patient->birthDate = $model->date_naissance; if ($model->sexe != "") { $patient->sex = $model->sexe; } else { $patient->sex = null; } if ($actionForm == 'create') { $patient->source = $model->source == "1" ? "1" : "2"; $patientest = CommonTools::wsGetPatient($patient); if ($patientest == 'NoPatient') { $patient = CommonTools::wsAddPatient($patient); } else { $patient = $patientTest; } } else { $patient = CommonTools::wsGetPatient($patient); } } switch ($patient) { case "NoPatient": Yii::app()->user->setFlash(TbAlert::TYPE_ERROR, Yii::t('common', 'noPatient')); Yii::app()->user->setState('patientModel', $model); $model->scenario = 'create'; $this->render('patient_bis', array('model' => $model, 'actionForm' => 'create')); exit; break; case "PatientNotSaved": Yii::app()->user->setFlash(TbAlert::TYPE_ERROR, Yii::t('common', 'patientNotSaved')); Yii::app()->user->setState('patientModel', $model); $model->scenario = 'create'; $this->render('patient_bis', array('model' => $model, 'actionForm' => 'create')); exit; break; case "ManyPatient": Yii::app()->user->setFlash(TbAlert::TYPE_ERROR, Yii::t('common', 'manyPatient')); Yii::app()->user->setState('patientModel', $model); $this->render('patient_bis', array('model' => $model, 'actionForm' => 'search')); exit; break; default: } if ($model->validate() && isset($patient->id)) { $model->id = $patient->id; $criteria = new EMongoCriteria(); $criteria->id_patient = (string) $model->id; $criteriaCliniques = new EMongoCriteria($criteria); if (Yii::app()->user->getState('activeProfil') == "clinicien") { $criteriaCliniques->login = Yii::app()->user->id; } $criteriaCliniques->type = "clinique"; $criteriaNeuropathologiques = new EMongoCriteria($criteria); $criteriaNeuropathologiques->type = "neuropathologique"; $neuropath = Answer::model()->findAll($criteriaNeuropathologiques); $criteriaGenetiques = new EMongoCriteria($criteria); $criteriaGenetiques->type = "genetique"; $genetique = Answer::model()->findAll($criteriaGenetiques); $dataProviderCliniques = new EMongoDocumentDataProvider('Answer'); $dataProviderCliniques->setId('dpCli'); $dataProviderNeuropathologiques = new EMongoDocumentDataProvider('Answer'); $dataProviderCliniques->setId('dpNeuPa'); $dataProviderGenetiques = new EMongoDocumentDataProvider('Answer'); $dataProviderCliniques->setId('dpGen'); $dataProviderCliniques->setCriteria($criteriaCliniques); $dataProviderNeuropathologiques->setCriteria($criteriaNeuropathologiques); $dataProviderGenetiques->setCriteria($criteriaGenetiques); $questionnaire = Questionnaire::model()->findAll(); $_SESSION['datapatient'] = $patient; if (isset($_SESSION['datapatient'])) { $this->render('affichepatient', array('model' => $model, 'dataProviderCliniques' => $dataProviderCliniques, 'dataProviderNeuropathologiques' => $dataProviderNeuropathologiques, 'dataProviderGenetiques' => $dataProviderGenetiques, 'questionnaire' => $questionnaire, 'patient' => $patient, 'neuropath' => $neuropath, 'genetique' => $genetique)); } elseif (isset($_POST['PatientForm'])) { $this->render('affichepatient', array('model' => $model, 'dataProviderCliniques' => $dataProviderCliniques, 'dataProviderNeuropathologiques' => $dataProviderNeuropathologiques, 'dataProviderGenetiques' => $dataProviderGenetiques, 'patient' => $patient)); } else { $this->redirect(array('site/patient')); } } else { $this->redirect(array('site/patient')); } }