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); }
public function addDiagnosis($disorder_id, $eye_id = false, $date = false) { if (!$date) { $date = date('Y-m-d'); } if (!($disorder = Disorder::model()->findByPk($disorder_id))) { throw new Exception('Disorder not found: ' . $disorder_id); } if ($disorder->specialty_id) { $type = strtolower(Specialty::model()->findByPk($disorder->specialty_id)->code); } else { $type = 'sys'; } if (!($sd = SecondaryDiagnosis::model()->find('patient_id=? and disorder_id=? and eye_id=? and date=?', array($this->id, $disorder_id, $eye_id, $date)))) { $action = "add-diagnosis-{$type}"; $sd = new SecondaryDiagnosis(); $sd->patient_id = $this->id; $sd->disorder_id = $disorder_id; $sd->eye_id = $eye_id; $sd->date = $date; if (!$sd->save()) { throw new Exception('Unable to save secondary diagnosis: ' . print_r($sd->getErrors(), true)); } $this->audit('patient', $action); } }