public function actionLogin() { $this->layout = '//main'; $model = new EntryForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $patient = Patient::findOne(['policy' => $model->policy, 'last_name' => $model->last_name]); Yii::$app->session->set('patient_access_token', $patient->access_token); $this->redirect(['entry']); } else { return $this->render('login', ['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; }
/** * Finds the Patient model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Patient the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Patient::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getPatient() { $patient = Patient::findOne(['policy' => $this->policy, 'last_name' => $this->last_name]); return $patient; }
public function getAvailableTimeByDate($date) { $session = Yii::$app->session; if (($policy = $session->get('policy')) !== null && ($lastName = $session->get('last_name')) !== null) { $patient = Patient::findOne(['policy' => $policy, 'last_name' => $lastName]); $ticket = $patient->getTickets()->where(['physician_id' => $this->physician_id])->orderBy(['date' => SORT_DESC])->one(); if ($ticket !== null) { $days = abs(ceil((strtotime($ticket->date) - strtotime($date)) / 86400)); if ($days <= 7) { return []; } } } $weekday = date('N', strtotime($date)); $receptions = $this->getReceptions()->where(['weekday' => $weekday])->all(); $reservedTimes = $this->getReservedTimeByDate($date); $localities = []; foreach ($receptions as $reception) { if (!in_array($reception->time, $reservedTimes)) { $localities[$reception->locality_id]['title'] = $reception->locality->title; $localities[$reception->locality_id]['times'][] = $reception->time; } } return $localities; }