/** * Creates a new Patient model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Patient(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->patient_id]); } else { return $this->render('create', ['model' => $model]); } }
public function import() { if ($this->validate()) { if ($handle = fopen($this->file->tempName, 'r')) { ini_set('max_execution_time', 6000); while ($data = fgetcsv($handle, 1000, ',')) { $physician_snils = preg_replace('/[^0-9]/', '', $data[1]); if (empty($physician_snils)) { continue; } $physician = Physician::findOne(['snils' => $physician_snils]); if ($physician === null) { $physician = new Physician(); $physician->specialty_id = 1; $physician->snils = $physician_snils; $physician->last_name = 'Необходимо заполнить'; $physician->first_name = 'Необходимо заполнить'; $physician->patronymic = 'Необходимо заполнить'; $physician->save(); } if (isset($physician->physician_id)) { $last_name = mb_convert_case(trim($data[2]), MB_CASE_TITLE); $first_name = mb_convert_case(trim($data[3]), MB_CASE_TITLE); $patronymic = mb_convert_case(trim($data[4]), MB_CASE_TITLE); $birth_date = trim($data[5]); $policy = trim($data[6]); $patient = Patient::findOne(['policy' => $policy]); if ($patient === null) { $patient = new Patient(); $patient->physician_id = $physician->physician_id; $patient->policy = $policy; $patient->last_name = $last_name; $patient->first_name = $first_name; $patient->patronymic = $patronymic; $patient->birth_date = date('Y-m-d', strtotime($birth_date)); $patient->save(); } } } fclose($handle); return true; } } return false; }