MeasurementReference::beforeSave PHP Méthode

beforeSave() protected méthode

protected beforeSave ( )
    protected function beforeSave()
    {
        if ($this->episode_id && $this->event_id) {
            throw new Exception('Measurement references cannot reference both an episode and an event');
        }
        foreach ($this->findAll('patient_measurement_id = ?', array($this->patient_measurement_id)) as $existing) {
            if ($this->episode_id && $this->episode_id == $existing->episode_id) {
                throw new Exception("Measurement reference already exists from episode {$this->episode_id} to patient measurement {$this->patient_measurement_id}");
            }
            if ($this->event_id && $this->event_id == $existing->event_id) {
                throw new Exception("Measurement reference already exists from event {$this->event_id} to patient measurement {$this->patient_measurement_id}");
            }
            if ($this->origin && $existing->origin) {
                throw new Exception("Origin reference already exists for patient measurement {$this->patient_measurement_id}");
            }
        }
        return parent::beforeSave();
    }