public function validateReferral($attribute, $params)
{
if (!$this->canChangeReferral() && $this->{$attribute} != $this->_original_referral_id) {
$this->addError($attribute, 'Referral cannot be changed after an operation has been scheduled');
} elseif ($referral_id = $this->{$attribute}) {
if (!($referral = Referral::model()->findByPk($referral_id))) {
throw new Exception('Invalid referral id set on ' . get_class($this));
}
if ($referral->patient_id != $this->getPatient()->id) {
$this->addError($attribute, 'Referral must be for the patient of the event');
}
}
}