protected function validateFuzzyMonthYear() { if (strtotime($this->year . "-" . $this->month . "-01") > time()) { $this->addError($this->object, $this->attribute, 'The date cannot be in the future'); } parent::validateFuzzyMonthYear(); }
public function actionValidateAddDiagnosis() { $errors = array(); if (!($patient = Patient::model()->findByPk(@$_POST['patient_id']))) { throw new Exception("Patient not found: " . @$_POST['patient_id']); } if (isset($_POST['DiagnosisSelection']['ophthalmic_disorder_id'])) { $disorder_id = $_POST['DiagnosisSelection']['ophthalmic_disorder_id']; } elseif (isset($_POST['DiagnosisSelection']['systemic_disorder_id'])) { $disorder_id = $_POST['DiagnosisSelection']['systemic_disorder_id']; } $sd = new SecondaryDiagnosis(); $sd->patient_id = $patient->id; $sd->date = $this->processFuzzyDate(); $sd->disorder_id = @$disorder_id; $sd->eye_id = @$_POST['diagnosis_eye']; $errors = array(); if (!$sd->validate()) { foreach ($sd->getErrors() as $field => $_errors) { $errors[$field] = $_errors[0]; } } // Check the diagnosis isn't currently set at the episode level for this patient foreach ($patient->episodes as $episode) { if ($episode->disorder_id == $sd->disorder_id && ($episode->eye_id == $sd->eye_id || $episode->eye_id == 3 || $sd->eye_id == 3)) { $errors['disorder_id'] = "The disorder is already set at the episode level for this patient"; } } // Check that the date isn't in the future if (@$_POST['fuzzy_year'] == date('Y')) { if (@$_POST['fuzzy_month'] > date('n')) { $errors['date'] = "The date cannot be in the future."; } elseif (@$_POST['fuzzy_month'] == date('n')) { if (@$_POST['fuzzy_day'] > date('j')) { $errors['date'] = "The date cannot be in the future."; } } } // Check that the date is valid $v = new OEFuzzyDateValidator(); $v->validateAttribute($sd, 'date'); echo json_encode($errors); }